Project

General

Profile

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

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

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 the app does not has permission then the user will be prompted to grant permissions
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.saveSeekBar);
69
    barSize.setOnSeekBarChangeListener(this);
70
    barSize.setProgress(50);
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
    
75
  @Override
76
  protected void onPause() 
77
    {
78
    GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
79
    view.onPause();
80
      
81
    super.onPause();
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
    
86
  @Override
87
  protected void onResume() 
88
    {
89
    super.onResume();
90
      
91
    GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
92
    view.onResume();
93

    
94
    SaveWorkerThread.create(this);
95
    }
96
 
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
    
99
  @Override
100
  protected void onDestroy() 
101
    {
102
    Distorted.onDestroy();  
103
    super.onDestroy();
104
    }
105
   
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public void Save(View v)
109
    {
110
    verifyStoragePermissions();
111

    
112
    SaveSurfaceView view = (SaveSurfaceView) this.findViewById(R.id.saveSurfaceView);
113
    view.getRenderer().Save();
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
119
    {
120
    float s = (progress>50 ? ((progress-50)/16.0f + 1.0f):(0.015f*progress + 0.25f));
121
    SaveSurfaceView view = (SaveSurfaceView) this.findViewById(R.id.saveSurfaceView);
122
    view.getRenderer().setSize(s);
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  public void onStartTrackingTouch(SeekBar bar) { }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public void onStopTrackingTouch(SeekBar bar)  { }
132

    
133
  }
(1-1/4)