Revision beb325a0
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
20 | 20 |
package org.distorted.magic; |
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 |
import android.graphics.PorterDuff; |
|
24 |
import android.graphics.drawable.Drawable; |
|
25 | 23 |
import android.opengl.GLSurfaceView; |
26 | 24 |
import android.os.Bundle; |
27 | 25 |
import android.preference.PreferenceManager; |
28 |
import android.support.v4.content.ContextCompat; |
|
29 | 26 |
import android.support.v7.app.AppCompatActivity; |
30 |
import android.util.DisplayMetrics; |
|
31 | 27 |
import android.view.View; |
32 |
import android.view.ViewGroup; |
|
33 |
import android.widget.ImageButton; |
|
34 |
import android.widget.LinearLayout; |
|
35 | 28 |
|
36 | 29 |
import org.distorted.component.HorizontalNumberPicker; |
37 | 30 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
45 | 38 |
public static final int DEF_SCRAMBLE = 1; |
46 | 39 |
public static final int MAX_SCRAMBLE = 18; |
47 | 40 |
|
48 |
private static int mButton = RubikSize.SIZE3.ordinal(); |
|
49 | 41 |
private HorizontalNumberPicker mPicker; |
50 | 42 |
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
|
|
53 |
private void markButton(int button) |
|
54 |
{ |
|
55 |
mButton = button; |
|
56 |
|
|
57 |
for(int b=0; b<RubikSize.LENGTH; b++) |
|
58 |
{ |
|
59 |
Drawable d = findViewById(b).getBackground(); |
|
60 |
|
|
61 |
if( b==button ) |
|
62 |
{ |
|
63 |
d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY); |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
d.clearColorFilter(); |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 44 |
|
74 | 45 |
private void savePreferences() |
... | ... | |
102 | 73 |
mPicker.setValue(scramble); |
103 | 74 |
} |
104 | 75 |
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
private void addSizeButtons() |
|
108 |
{ |
|
109 |
LinearLayout layout = findViewById(R.id.sizeLayout); |
|
110 |
DisplayMetrics metrics = getResources().getDisplayMetrics(); |
|
111 |
float scale = metrics.density; |
|
112 |
int size = (int)(64*scale +0.5f); |
|
113 |
int padding = (int)(3*scale + 0.5f); |
|
114 |
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(size,size); |
|
115 |
|
|
116 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
117 |
{ |
|
118 |
ImageButton button = new ImageButton(this); |
|
119 |
button.setLayoutParams(params); |
|
120 |
button.setId(i); |
|
121 |
button.setPadding(padding,0,padding,0); |
|
122 |
int iconID = RubikSize.getSize(i).getIconID(); |
|
123 |
button.setImageResource(iconID); |
|
124 |
button.setOnClickListener(this); |
|
125 |
layout.addView(button); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
|
|
131 |
static int getRedButton() |
|
132 |
{ |
|
133 |
return mButton; |
|
134 |
} |
|
135 |
|
|
136 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
137 | 77 |
|
138 | 78 |
@Override |
... | ... | |
141 | 81 |
super.onCreate(savedState); |
142 | 82 |
setTheme(R.style.CustomActivityThemeNoActionBar); |
143 | 83 |
setContentView(R.layout.main); |
144 |
addSizeButtons(); |
|
145 |
markButton(mButton); |
|
84 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
85 |
view.addSizeButtons(this); |
|
86 |
view.markButton(view.getRedButton()); |
|
146 | 87 |
|
147 | 88 |
mPicker = findViewById(R.id.rubikNumberPicker); |
148 | 89 |
mPicker.setMin(MIN_SCRAMBLE); |
... | ... | |
199 | 140 |
|
200 | 141 |
if( success ) |
201 | 142 |
{ |
202 |
markButton(id); |
|
143 |
view.markButton(id);
|
|
203 | 144 |
} |
204 | 145 |
} |
205 | 146 |
} |
... | ... | |
218 | 159 |
|
219 | 160 |
public void Scores(View v) |
220 | 161 |
{ |
162 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
221 | 163 |
Bundle bundle = new Bundle(); |
222 |
bundle.putInt("tab", mButton);
|
|
164 |
bundle.putInt("tab", view.getRedButton());
|
|
223 | 165 |
|
224 | 166 |
RubikScores scores = new RubikScores(); |
225 | 167 |
scores.setArguments(bundle); |
... | ... | |
242 | 184 |
|
243 | 185 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
244 | 186 |
view.getRenderer().scrambleCube(scramble); |
187 |
view.enterScrambleMode(); |
|
245 | 188 |
} |
246 | 189 |
|
247 | 190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
250 | 193 |
{ |
251 | 194 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
252 | 195 |
view.getRenderer().solveCube(); |
196 |
view.leaveScrambleMode(); |
|
253 | 197 |
} |
254 | 198 |
} |
Also available in: Unified diff
Major restructuring - separate the Manipulated Objects (i.e. at the time being - Cubes of various sizes) and the class holding knowledge how those Objects move ( RubikCubeMovement ) into a separate package; remove all knowledge of Objects and the way they move from the main package.