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
|
SaveWorkerThread.stopSending();
|
79
|
|
80
|
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
|
81
|
view.onPause();
|
82
|
|
83
|
super.onPause();
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
@Override
|
89
|
protected void onResume()
|
90
|
{
|
91
|
super.onResume();
|
92
|
|
93
|
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
|
94
|
view.onResume();
|
95
|
|
96
|
SaveWorkerThread.startSending(this);
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
@Override
|
102
|
protected void onDestroy()
|
103
|
{
|
104
|
Distorted.onDestroy();
|
105
|
super.onDestroy();
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
public void Save(View v)
|
111
|
{
|
112
|
verifyStoragePermissions();
|
113
|
|
114
|
SaveSurfaceView view = (SaveSurfaceView) this.findViewById(R.id.saveSurfaceView);
|
115
|
view.getRenderer().Save();
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
|
120
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
121
|
{
|
122
|
float s = (progress>50 ? ((progress-50)/16.0f + 1.0f):(0.015f*progress + 0.25f));
|
123
|
SaveSurfaceView view = (SaveSurfaceView) this.findViewById(R.id.saveSurfaceView);
|
124
|
view.getRenderer().setSize(s);
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
public void onStartTrackingTouch(SeekBar bar) { }
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
|
133
|
public void onStopTrackingTouch(SeekBar bar) { }
|
134
|
|
135
|
}
|