Revision 5d8a1d51
Added by Leszek Koltunski about 5 years ago
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; |
|
23 | 24 |
import android.opengl.GLSurfaceView; |
24 | 25 |
import android.os.Bundle; |
26 |
import android.support.v4.content.ContextCompat; |
|
25 | 27 |
import android.view.View; |
28 |
import android.widget.ImageButton; |
|
26 | 29 |
|
27 | 30 |
import org.distorted.examples.R; |
28 | 31 |
import org.distorted.library.main.Distorted; |
... | ... | |
31 | 34 |
|
32 | 35 |
public class RubikActivity extends Activity |
33 | 36 |
{ |
37 |
static final int DEFAULT_CUBE_SIZE = 3; |
|
38 |
private static final int STARTING_SIZE = 2; |
|
39 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4}; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
34 | 43 |
@Override |
35 | 44 |
protected void onCreate(Bundle icicle) |
36 | 45 |
{ |
37 | 46 |
super.onCreate(icicle); |
38 | 47 |
setContentView(R.layout.rubiklayout); |
48 |
|
|
49 |
markButton(DEFAULT_CUBE_SIZE); |
|
39 | 50 |
} |
40 | 51 |
|
41 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
72 | 83 |
|
73 | 84 |
public void Scramble(View v) |
74 | 85 |
{ |
75 |
android.util.Log.e("rubik", "scrambling..."); |
|
86 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
87 |
view.scrambleCube(); |
|
76 | 88 |
} |
77 | 89 |
|
78 | 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
86 | 98 |
|
87 | 99 |
public void setSize(View v) |
88 | 100 |
{ |
89 |
int size=0,id = v.getId(); |
|
101 |
int size=0; |
|
102 |
int id = v.getId(); |
|
103 |
int numButtons = button_ids.length; |
|
104 |
|
|
105 |
for(int b=0; b<numButtons; b++) |
|
106 |
if( button_ids[b] == id ) |
|
107 |
{ |
|
108 |
size = b+STARTING_SIZE; |
|
109 |
break; |
|
110 |
} |
|
90 | 111 |
|
91 |
switch(id) |
|
92 |
{ |
|
93 |
case R.id.rubikSize2: size=2; break; |
|
94 |
case R.id.rubikSize3: size=3; break; |
|
95 |
case R.id.rubikSize4: size=4; break; |
|
96 |
} |
|
112 |
markButton(size); |
|
97 | 113 |
|
98 |
android.util.Log.e("rubik", "setting size to "+size); |
|
114 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
115 |
view.setNewCubeSize(size); |
|
99 | 116 |
} |
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
private void markButton(int size) |
|
121 |
{ |
|
122 |
int color, numButtons = button_ids.length; |
|
123 |
ImageButton[] button = new ImageButton[numButtons]; |
|
124 |
|
|
125 |
for(int b=0; b<numButtons; b++) |
|
126 |
{ |
|
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); |
|
130 |
} |
|
131 |
} |
|
100 | 132 |
} |
Also available in: Unified diff
Rubk App: changes in the UI