1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.rubik;
|
21
|
|
22
|
import android.app.Activity;
|
23
|
import android.app.ActivityManager;
|
24
|
import android.opengl.GLSurfaceView;
|
25
|
import android.os.Bundle;
|
26
|
import android.widget.TextView;
|
27
|
|
28
|
import org.distorted.examples.R;
|
29
|
import org.distorted.library.main.DistortedLibrary;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class RubikActivity extends Activity
|
34
|
{
|
35
|
private TextView mText;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
@Override
|
40
|
protected void onCreate(Bundle icicle)
|
41
|
{
|
42
|
super.onCreate(icicle);
|
43
|
setContentView(R.layout.rubiklayout);
|
44
|
|
45
|
mText = findViewById(R.id.rubikText);
|
46
|
setText(1);
|
47
|
}
|
48
|
|
49
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
|
51
|
@Override
|
52
|
protected void onPause()
|
53
|
{
|
54
|
GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
55
|
view.onPause();
|
56
|
DistortedLibrary.onPause();
|
57
|
super.onPause();
|
58
|
}
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
|
62
|
@Override
|
63
|
protected void onResume()
|
64
|
{
|
65
|
super.onResume();
|
66
|
GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
67
|
view.onResume();
|
68
|
}
|
69
|
|
70
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71
|
|
72
|
@Override
|
73
|
protected void onDestroy()
|
74
|
{
|
75
|
DistortedLibrary.onDestroy();
|
76
|
super.onDestroy();
|
77
|
}
|
78
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
void setText(final int numCube)
|
82
|
{
|
83
|
long availMemory = returnAvailableMemory();
|
84
|
final int availMemoryInMB = (int)(availMemory/1000000);
|
85
|
|
86
|
runOnUiThread(new Runnable()
|
87
|
{
|
88
|
public void run()
|
89
|
{
|
90
|
mText.setText(getString(R.string.rubik_placeholder, numCube, availMemoryInMB));
|
91
|
}
|
92
|
});
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
private long returnAvailableMemory()
|
98
|
{
|
99
|
ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
|
100
|
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
|
101
|
activityManager.getMemoryInfo(memoryInfo);
|
102
|
|
103
|
return memoryInfo.availMem;
|
104
|
}
|
105
|
}
|