Revision 5d8a1d51
Added by Leszek Koltunski over 6 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 |
} |
| src/main/java/org/distorted/examples/rubik/RubikRenderer.java | ||
|---|---|---|
| 36 | 36 |
|
| 37 | 37 |
class RubikRenderer implements GLSurfaceView.Renderer, EffectListener |
| 38 | 38 |
{
|
| 39 |
private static final int NUM_CUBES = 4; |
|
| 40 | 39 |
private static final float CUBE_SCREEN_RATIO = 0.5f; |
| 41 | 40 |
private static final float CAMERA_DISTANCE = 0.6f; // 0.6 of the length of max(scrHeight,scrWidth) |
| 42 | 41 |
|
| ... | ... | |
| 73 | 72 |
|
| 74 | 73 |
mCanRotate = true; |
| 75 | 74 |
|
| 76 |
mCube = new RubikCube(NUM_CUBES, mMove, mScale, mQuatCurrent, mQuatAccumulated);
|
|
| 75 |
mCube = new RubikCube( RubikActivity.DEFAULT_CUBE_SIZE, mMove, mScale, mQuatCurrent, mQuatAccumulated);
|
|
| 77 | 76 |
} |
| 78 | 77 |
|
| 79 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/examples/rubik/RubikSurfaceView.java | ||
|---|---|---|
| 164 | 164 |
return true; |
| 165 | 165 |
} |
| 166 | 166 |
|
| 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 168 |
|
|
| 169 |
void setNewCubeSize(int newCubeSize) |
|
| 170 |
{
|
|
| 171 |
android.util.Log.e("view", "new size="+newCubeSize);
|
|
| 172 |
} |
|
| 173 |
|
|
| 174 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 175 |
|
|
| 176 |
void scrambleCube() |
|
| 177 |
{
|
|
| 178 |
android.util.Log.e("view", "scrambling...");
|
|
| 179 |
} |
|
| 180 |
|
|
| 167 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 168 | 182 |
|
| 169 | 183 |
void setScreenSize(int width, int height) |
| src/main/res/values/colors.xml | ||
|---|---|---|
| 1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 | 2 |
<resources> |
| 3 | 3 |
<color name="blue">#ff0000ff</color> |
| 4 |
<color name="gray">#ffaaaaaa</color> |
|
| 4 | 5 |
<color name="black">#ff000000</color> |
| 5 | 6 |
<color name="red">#ffff0000</color> |
| 6 | 7 |
<color name="yellow">#ffffff00</color> |
Also available in: Unified diff
Rubk App: changes in the UI