Project

General

Profile

Download (5.61 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / save / SaveActivity.java @ 107e4b72

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.save;
21

    
22
import org.distorted.library.main.Distorted;
23
import org.distorted.examples.R;
24

    
25
import android.Manifest;
26
import android.app.Activity;
27
import android.content.pm.PackageManager;
28
import android.opengl.GLSurfaceView;
29
import android.os.Bundle;
30
import android.support.v4.app.ActivityCompat;
31
import android.view.View;
32
import android.widget.SeekBar;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class SaveActivity extends Activity implements SeekBar.OnSeekBarChangeListener
37
  {
38
  private static final int REQUEST_EXTERNAL_STORAGE = 1;
39
  private static String[] PERMISSIONS_STORAGE =
40
     {
41
     Manifest.permission.READ_EXTERNAL_STORAGE,
42
     Manifest.permission.WRITE_EXTERNAL_STORAGE
43
     };
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
// Checks if the app has permission to write to device storage.
47
// If not, the user will be prompted to grant ut.
48

    
49
  private void verifyStoragePermissions()
50
    {
51
    int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
52

    
53
    if (permission != PackageManager.PERMISSION_GRANTED)
54
      {
55
      ActivityCompat.requestPermissions( this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE );
56
      }
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
    
61
  @Override
62
  protected void onCreate(Bundle icicle) 
63
    {
64
    super.onCreate(icicle);
65
     
66
    setContentView(R.layout.savelayout);
67

    
68
    SeekBar barSize  = (SeekBar)findViewById(R.id.saveSeekBarSize);
69
    barSize.setOnSeekBarChangeListener(this);
70
    barSize.setProgress(50);
71

    
72
    SeekBar barScale = (SeekBar)findViewById(R.id.saveSeekBarScale);
73
    barScale.setOnSeekBarChangeListener(this);
74
    barScale.setProgress(100);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
    
79
  @Override
80
  protected void onPause() 
81
    {
82
    GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
83
    view.onPause();
84

    
85
    Distorted.onPause();
86
    super.onPause();
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
    
91
  @Override
92
  protected void onResume() 
93
    {
94
    super.onResume();
95
      
96
    GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
97
    view.onResume();
98

    
99
    SaveWorkerThread.create(this);
100
    }
101
 
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
    
104
  @Override
105
  protected void onDestroy() 
106
    {
107
    Distorted.onDestroy();  
108
    super.onDestroy();
109
    }
110
   
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public void Save(View v)
114
    {
115
    verifyStoragePermissions();
116

    
117
    SaveSurfaceView view = (SaveSurfaceView) this.findViewById(R.id.saveSurfaceView);
118
    view.getRenderer().Save();
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
124
    {
125
    SaveSurfaceView view = (SaveSurfaceView) this.findViewById(R.id.saveSurfaceView);
126

    
127
    switch (bar.getId())
128
      {
129
      case R.id.saveSeekBarSize : view.getRenderer().setSize(progress>50 ? ((progress-50)/16.0f + 1.0f):(0.015f*progress + 0.25f));
130
                                  break;
131
      case R.id.saveSeekBarScale: view.getRenderer().setScale(0.009f*progress+0.1f);
132
                                  break;
133
      }
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public void onStartTrackingTouch(SeekBar bar) { }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  public void onStopTrackingTouch(SeekBar bar)  { }
143

    
144
  }
(1-1/4)