| 21 |
21 |
|
| 22 |
22 |
import android.app.Activity;
|
| 23 |
23 |
import android.graphics.PorterDuff;
|
|
24 |
import android.graphics.drawable.Drawable;
|
| 24 |
25 |
import android.opengl.GLSurfaceView;
|
| 25 |
26 |
import android.os.Bundle;
|
| 26 |
27 |
import android.support.v4.content.ContextCompat;
|
| 27 |
28 |
import android.view.View;
|
| 28 |
|
import android.widget.ImageButton;
|
| 29 |
29 |
|
| 30 |
30 |
import org.distorted.examples.R;
|
| 31 |
31 |
import org.distorted.library.main.Distorted;
|
| ... | ... | |
| 34 |
34 |
|
| 35 |
35 |
public class RubikActivity extends Activity
|
| 36 |
36 |
{
|
| 37 |
|
static final int DEFAULT_CUBE_SIZE = 3;
|
|
37 |
static final int DEFAULT_SIZE = 3;
|
| 38 |
38 |
private static final int STARTING_SIZE = 2;
|
| 39 |
|
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
|
|
39 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
|
| 40 |
40 |
|
| 41 |
41 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 42 |
42 |
|
| ... | ... | |
| 46 |
46 |
super.onCreate(icicle);
|
| 47 |
47 |
setContentView(R.layout.rubiklayout);
|
| 48 |
48 |
|
| 49 |
|
markButton(DEFAULT_CUBE_SIZE);
|
|
49 |
markButton(DEFAULT_SIZE);
|
| 50 |
50 |
}
|
| 51 |
51 |
|
| 52 |
52 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| ... | ... | |
| 98 |
98 |
|
| 99 |
99 |
public void setSize(View v)
|
| 100 |
100 |
{
|
| 101 |
|
int size=0;
|
| 102 |
|
int id = v.getId();
|
| 103 |
|
int numButtons = button_ids.length;
|
|
101 |
int size=0, id = v.getId();
|
| 104 |
102 |
|
| 105 |
|
for(int b=0; b<numButtons; b++)
|
|
103 |
for(int b=0; b<button_ids.length; b++)
|
| 106 |
104 |
if( button_ids[b] == id )
|
| 107 |
105 |
{
|
| 108 |
106 |
size = b+STARTING_SIZE;
|
| ... | ... | |
| 119 |
117 |
|
| 120 |
118 |
private void markButton(int size)
|
| 121 |
119 |
{
|
| 122 |
|
int color, numButtons = button_ids.length;
|
| 123 |
|
ImageButton[] button = new ImageButton[numButtons];
|
| 124 |
|
|
| 125 |
|
for(int b=0; b<numButtons; b++)
|
|
120 |
for(int b=0; b<button_ids.length; b++)
|
| 126 |
121 |
{
|
| 127 |
|
button[b] = findViewById(button_ids[b]);
|
| 128 |
|
color = (b==size-STARTING_SIZE ? R.color.red : R.color.gray);
|
| 129 |
|
button[b].getBackground().setColorFilter(ContextCompat.getColor(this,color), PorterDuff.Mode.MULTIPLY);
|
|
122 |
Drawable d = findViewById(button_ids[b]).getBackground();
|
|
123 |
|
|
124 |
if( size == b+STARTING_SIZE )
|
|
125 |
{
|
|
126 |
d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY);
|
|
127 |
}
|
|
128 |
else
|
|
129 |
{
|
|
130 |
d.clearColorFilter();
|
|
131 |
}
|
| 130 |
132 |
}
|
| 131 |
133 |
}
|
| 132 |
134 |
}
|
Rubik App: minor