Project

General

Profile

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

examples / src / main / java / org / distorted / examples / rubik / RubikActivity.java @ c6bfca20

1 5b4a2d76 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 8647eae2 Leszek Koltunski
// Copyright 2019 Leszek Koltunski                                                               //
3 5b4a2d76 Leszek Koltunski
//                                                                                               //
4 71c8884f Leszek Koltunski
// This file is part of Distorted.                                                               //
5 5b4a2d76 Leszek Koltunski
//                                                                                               //
6 71c8884f Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 5b4a2d76 Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 5b4a2d76 Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 5b4a2d76 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.examples.rubik;
21
22
import android.app.Activity;
23 6e18bd32 Leszek Koltunski
import android.app.ActivityManager;
24 201376f3 Leszek Koltunski
import android.opengl.GLSurfaceView;
25 5b4a2d76 Leszek Koltunski
import android.os.Bundle;
26 6e18bd32 Leszek Koltunski
import android.widget.TextView;
27 5b4a2d76 Leszek Koltunski
28 201376f3 Leszek Koltunski
import org.distorted.examples.R;
29 e3900503 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
30 5b4a2d76 Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33
public class RubikActivity extends Activity
34
{
35 6e18bd32 Leszek Koltunski
    private TextView mText;
36 5d8a1d51 Leszek Koltunski
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 5b4a2d76 Leszek Koltunski
    @Override
40
    protected void onCreate(Bundle icicle)
41
      {
42
      super.onCreate(icicle);
43 201376f3 Leszek Koltunski
      setContentView(R.layout.rubiklayout);
44 5d8a1d51 Leszek Koltunski
45 6e18bd32 Leszek Koltunski
      mText = findViewById(R.id.rubikText);
46
      setText(1);
47 5b4a2d76 Leszek Koltunski
      }
48
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
    
51
    @Override
52
    protected void onPause() 
53
      {
54 201376f3 Leszek Koltunski
      GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
55
      view.onPause();
56 e3900503 Leszek Koltunski
      DistortedLibrary.onPause();
57 5b4a2d76 Leszek Koltunski
      super.onPause();
58
      }
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
    
62
    @Override
63
    protected void onResume() 
64
      {
65
      super.onResume();
66 201376f3 Leszek Koltunski
      GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
67
      view.onResume();
68 5b4a2d76 Leszek Koltunski
      }
69
    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
    
72
    @Override
73
    protected void onDestroy() 
74
      {
75 e3900503 Leszek Koltunski
      DistortedLibrary.onDestroy();
76 5b4a2d76 Leszek Koltunski
      super.onDestroy();
77
      }
78 201376f3 Leszek Koltunski
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
81 c6bfca20 Leszek Koltunski
    void setText(final int numCube)
82 201376f3 Leszek Koltunski
      {
83 6e18bd32 Leszek Koltunski
      long availMemory = returnAvailableMemory();
84 c6bfca20 Leszek Koltunski
      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 201376f3 Leszek Koltunski
      }
94
95 0094886e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97 6e18bd32 Leszek Koltunski
   private long returnAvailableMemory()
98 5d8a1d51 Leszek Koltunski
     {
99 6e18bd32 Leszek Koltunski
     ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
100
     ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
101
     activityManager.getMemoryInfo(memoryInfo);
102 377e1873 Leszek Koltunski
103 6e18bd32 Leszek Koltunski
     return memoryInfo.availMem;
104 5d8a1d51 Leszek Koltunski
     }
105 5b4a2d76 Leszek Koltunski
}