Project

General

Profile

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

examples / src / main / java / org / distorted / examples / save / SaveActivity.java @ d04a4886

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.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
    super.onPause();
86
    }
87

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

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

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

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

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

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

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

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  public void onStartTrackingTouch(SeekBar bar) { }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public void onStopTrackingTouch(SeekBar bar)  { }
142

    
143
  }
(1-1/4)