Project

General

Profile

« Previous | Next » 

Revision 6e18bd32

Added by Leszek Koltunski about 5 years ago

Turn the Rubik app into a MemoryTest.

View differences:

src/main/java/org/distorted/examples/rubik/RubikActivity.java
20 20
package org.distorted.examples.rubik;
21 21

  
22 22
import android.app.Activity;
23
import android.graphics.PorterDuff;
24
import android.graphics.drawable.Drawable;
23
import android.app.ActivityManager;
25 24
import android.opengl.GLSurfaceView;
26 25
import android.os.Bundle;
27
import android.support.v4.content.ContextCompat;
28
import android.view.View;
26
import android.widget.TextView;
29 27

  
30 28
import org.distorted.examples.R;
31 29
import org.distorted.library.main.Distorted;
......
34 32

  
35 33
public class RubikActivity extends Activity
36 34
{
37
            static final int DEFAULT_SIZE  = 3;
38
    private static final int SMALLEST_SIZE = 2;
39
    private static final int[] button_ids  = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
35
    private TextView mText;
40 36

  
41 37
///////////////////////////////////////////////////////////////////////////////////////////////////
42 38

  
......
46 42
      super.onCreate(icicle);
47 43
      setContentView(R.layout.rubiklayout);
48 44

  
49
      markButton(DEFAULT_SIZE);
45
      mText = findViewById(R.id.rubikText);
46
      setText(1);
50 47
      }
51 48

  
52 49
///////////////////////////////////////////////////////////////////////////////////////////////////
......
81 78

  
82 79
///////////////////////////////////////////////////////////////////////////////////////////////////
83 80

  
84
    public void Scramble(View v)
81
    void setText(int numCube)
85 82
      {
86
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
87
      view.scrambleCube();
83
      long availMemory = returnAvailableMemory();
84
      int  availMemoryInMB = (int)(availMemory/1000000);
85
      mText.setText(getString(R.string.rubik_placeholder, numCube, availMemoryInMB));
88 86
      }
89 87

  
90 88
///////////////////////////////////////////////////////////////////////////////////////////////////
91 89

  
92
    public void Credits(View v)
93
      {
94
      android.util.Log.e("rubik", "credits...");
95
      }
96

  
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

  
99
    public void setSize(View v)
100
      {
101
      int size=0, id = v.getId();
102

  
103
      for(int b=0; b<button_ids.length; b++)
104
        if( button_ids[b] == id )
105
          {
106
          size = b+SMALLEST_SIZE;
107
          break;
108
          }
109

  
110
      markButton(size);
111

  
112
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
113
      view.setNewCubeSize(size);
114
      }
115

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

  
118
   private void markButton(int size)
90
   private long returnAvailableMemory()
119 91
     {
120
     for(int b=0; b<button_ids.length; b++)
121
       {
122
       Drawable d = findViewById(button_ids[b]).getBackground();
92
     ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
93
     ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
94
     activityManager.getMemoryInfo(memoryInfo);
123 95

  
124
       if( size == b+SMALLEST_SIZE )
125
         {
126
         d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY);
127
         }
128
       else
129
         {
130
         d.clearColorFilter();
131
         }
132
       }
96
     return memoryInfo.availMem;
133 97
     }
134 98
}

Also available in: Unified diff