Revision 4f470e00
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/dialog/RubikDialogPattern.java | ||
---|---|---|
87 | 87 |
|
88 | 88 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
89 | 89 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
90 |
mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager); |
|
90 |
mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this);
|
|
91 | 91 |
tabLayout.setupWithViewPager(viewPager); |
92 | 92 |
|
93 | 93 |
int[] iconID = { R.drawable.cube2, R.drawable.cube3, R.drawable.cube4, R.drawable.cube5 }; |
... | ... | |
102 | 102 |
|
103 | 103 |
return builder.create(); |
104 | 104 |
} |
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public static String getDialogTag() |
|
109 |
{ |
|
110 |
return "DialogPattern"; |
|
111 |
} |
|
105 | 112 |
} |
src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.java | ||
---|---|---|
25 | 25 |
import android.support.v4.view.ViewPager; |
26 | 26 |
import android.view.View; |
27 | 27 |
import android.view.ViewGroup; |
28 |
import android.widget.LinearLayout; |
|
29 | 28 |
|
30 | 29 |
import org.distorted.patterns.RubikPattern; |
31 | 30 |
|
... | ... | |
35 | 34 |
{ |
36 | 35 |
private FragmentActivity mAct; |
37 | 36 |
private RubikDialogPatternView[] mViews; |
37 |
private RubikDialogPattern mDialog; |
|
38 | 38 |
private int mNumTabs; |
39 | 39 |
|
40 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 |
// TODO: temporary mockup |
|
42 | 41 |
|
43 | 42 |
private String[] createCategories(int pos) |
44 | 43 |
{ |
45 |
String[] ret = new String[8]; |
|
44 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
45 |
int numCat = pattern.getNumCategories(pos); |
|
46 | 46 |
|
47 |
for(int i=0; i<8; i++) |
|
47 |
String[] ret = new String[numCat]; |
|
48 |
|
|
49 |
for(int i=0; i<numCat; i++) |
|
48 | 50 |
{ |
49 |
ret[i] = "CATEGORY "+pos+" "+i;
|
|
51 |
ret[i] = pattern.getCategoryName(pos,i);
|
|
50 | 52 |
} |
51 | 53 |
|
52 | 54 |
return ret; |
... | ... | |
54 | 56 |
|
55 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 58 |
|
57 |
RubikDialogPatternPagerAdapter(FragmentActivity act, ViewPager viewPager) |
|
59 |
RubikDialogPatternPagerAdapter(FragmentActivity act, ViewPager viewPager, RubikDialogPattern dialog)
|
|
58 | 60 |
{ |
59 | 61 |
mAct = act; |
62 |
mDialog = dialog; |
|
60 | 63 |
mNumTabs = RubikPattern.NUM_CUBES; |
61 | 64 |
mViews = new RubikDialogPatternView[mNumTabs]; |
62 | 65 |
|
... | ... | |
71 | 74 |
public Object instantiateItem(@NonNull ViewGroup collection, final int position) |
72 | 75 |
{ |
73 | 76 |
String[] categories = createCategories(position); |
74 |
mViews[position] = new RubikDialogPatternView(mAct, categories); |
|
77 |
mViews[position] = new RubikDialogPatternView(mAct, mDialog, categories);
|
|
75 | 78 |
collection.addView(mViews[position]); |
76 | 79 |
|
77 | 80 |
return mViews[position]; |
src/main/java/org/distorted/dialog/RubikDialogPatternView.java | ||
---|---|---|
29 | 29 |
import android.widget.LinearLayout; |
30 | 30 |
|
31 | 31 |
import org.distorted.magic.R; |
32 |
import org.distorted.magic.RubikActivity; |
|
33 |
import org.distorted.uistate.RubikState; |
|
32 | 34 |
|
33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 36 |
|
35 | 37 |
public class RubikDialogPatternView extends FrameLayout |
36 | 38 |
{ |
37 |
LinearLayout mLayout; |
|
39 |
private LinearLayout mLayout; |
|
40 |
private RubikDialogPattern mDialog; |
|
38 | 41 |
|
39 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 43 |
|
... | ... | |
52 | 55 |
|
53 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 57 |
|
55 |
public RubikDialogPatternView(FragmentActivity act, String[] categories) |
|
58 |
public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, String[] categories)
|
|
56 | 59 |
{ |
57 | 60 |
super(act); |
58 | 61 |
|
62 |
mDialog = dialog; |
|
59 | 63 |
View tab = inflate( act, R.layout.dialog_tab, null); |
60 | 64 |
mLayout = tab.findViewById(R.id.tabLayout); |
61 | 65 |
createSection(act,categories); |
... | ... | |
65 | 69 |
|
66 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
67 | 71 |
|
68 |
private void createSection(FragmentActivity act, final String[] categories) |
|
72 |
private void createSection(final FragmentActivity act, final String[] categories)
|
|
69 | 73 |
{ |
70 | 74 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
71 | 75 |
final float scale = metrics.density; |
... | ... | |
74 | 78 |
LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
75 | 79 |
bParams.setMargins(margin, margin, margin, margin); |
76 | 80 |
|
81 |
final RubikActivity ract = (RubikActivity)getContext(); |
|
82 |
|
|
77 | 83 |
for(int i=0; i<len; i++) |
78 | 84 |
{ |
79 | 85 |
final int fi = i; |
... | ... | |
86 | 92 |
@Override |
87 | 93 |
public void onClick(View view) |
88 | 94 |
{ |
89 |
android.util.Log.e("view", "category "+categories[fi]+" clicked"); |
|
95 |
RubikState.switchState(ract,RubikState.PATT); |
|
96 |
mDialog.dismiss(); |
|
90 | 97 |
} |
91 | 98 |
}); |
92 | 99 |
|
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
30 | 30 |
private static final int MAX_CUBE = 5; |
31 | 31 |
public static final int NUM_CUBES = MAX_CUBE-MIN_CUBE+1; |
32 | 32 |
|
33 |
public int[] numCategories = new int[NUM_CUBES];
|
|
33 |
private int[] numCategories = new int[NUM_CUBES];
|
|
34 | 34 |
private static String buffer=""; |
35 | 35 |
private static Paint mPaint = new Paint(); |
36 |
private static int width;
|
|
36 |
private static int mWidth;
|
|
37 | 37 |
|
38 | 38 |
private Vector<Category>[] mCategories; |
39 | 39 |
|
40 |
private static RubikPattern mThis; |
|
41 |
|
|
40 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 43 |
|
42 | 44 |
private class Category |
... | ... | |
46 | 48 |
private Vector<Pattern> patterns; |
47 | 49 |
private int curPattern; |
48 | 50 |
|
49 |
public Category(String n)
|
|
51 |
Category(String n) |
|
50 | 52 |
{ |
51 | 53 |
name=n; |
52 | 54 |
curPattern=0; |
53 | 55 |
numpatterns=0; |
54 | 56 |
patterns = new Vector<>(); |
55 | 57 |
} |
56 |
public void addPattern(Pattern p)
|
|
58 |
void addPattern(Pattern p) |
|
57 | 59 |
{ |
58 | 60 |
patterns.addElement(p); |
59 | 61 |
numpatterns++; |
60 | 62 |
} |
61 |
public int getNumPatterns()
|
|
63 |
int getNumPatterns() |
|
62 | 64 |
{ |
63 | 65 |
return numpatterns; |
64 |
};
|
|
65 |
public String getName()
|
|
66 |
} |
|
67 |
String getName() |
|
66 | 68 |
{ |
67 | 69 |
return name; |
68 | 70 |
} |
69 |
public void next()
|
|
71 |
void next() |
|
70 | 72 |
{ |
71 | 73 |
curPattern++; |
72 | 74 |
if( curPattern>=numpatterns ) |
73 | 75 |
curPattern=0; |
74 | 76 |
} |
75 |
public void prev()
|
|
77 |
void prev() |
|
76 | 78 |
{ |
77 | 79 |
curPattern--; |
78 | 80 |
if( curPattern<0 ) |
79 | 81 |
curPattern=numpatterns-1; |
80 | 82 |
} |
81 |
public String getPatternName()
|
|
83 |
String getPatternName() |
|
82 | 84 |
{ |
83 | 85 |
Pattern p = patterns.elementAt(curPattern); |
84 | 86 |
return p!=null ? p.getName(curPattern+1,numpatterns):null; |
85 | 87 |
} |
86 |
public int getPatternCurMove()
|
|
88 |
int getPatternCurMove() |
|
87 | 89 |
{ |
88 | 90 |
Pattern p = patterns.elementAt(curPattern); |
89 | 91 |
return p!=null ? p.getCurMove():-1; |
90 | 92 |
} |
91 |
public int getPatternNumMove()
|
|
93 |
int getPatternNumMove() |
|
92 | 94 |
{ |
93 | 95 |
Pattern p = patterns.elementAt(curPattern); |
94 | 96 |
return p!=null ? p.getNumMove():-1; |
95 | 97 |
} |
96 |
public void initializeCube()
|
|
98 |
void initializeCube() |
|
97 | 99 |
{ |
98 | 100 |
Pattern p = patterns.elementAt(curPattern); |
99 | 101 |
if( p!=null ) p.initializeCube(); |
100 | 102 |
} |
101 |
public void makeNextMove()
|
|
103 |
void makeNextMove() |
|
102 | 104 |
{ |
103 | 105 |
Pattern p = patterns.elementAt(curPattern); |
104 | 106 |
if( p!=null ) p.makeNextMove(); |
105 | 107 |
} |
106 |
public void makePrevMove()
|
|
108 |
void makePrevMove() |
|
107 | 109 |
{ |
108 | 110 |
Pattern p = patterns.elementAt(curPattern); |
109 | 111 |
if( p!=null ) p.makePrevMove(); |
... | ... | |
120 | 122 |
private int curmove; |
121 | 123 |
private int nummove; |
122 | 124 |
|
123 |
public Pattern(String n, String m)
|
|
125 |
Pattern(String n, String m) |
|
124 | 126 |
{ |
125 | 127 |
name=n; |
126 | 128 |
moves=m; |
127 | 129 |
nummove = moves.length()/4; |
128 | 130 |
curmove=nummove; |
129 | 131 |
} |
130 |
public String getName(int cur,int num)
|
|
132 |
String getName(int cur,int num) |
|
131 | 133 |
{ |
132 | 134 |
if( shortname==null ) shortname=cutPatternName(name); |
133 | 135 |
return shortname; |
134 | 136 |
} |
135 |
public int getNumMove()
|
|
137 |
int getNumMove() |
|
136 | 138 |
{ |
137 | 139 |
return nummove; |
138 | 140 |
} |
139 |
public int getCurMove()
|
|
141 |
int getCurMove() |
|
140 | 142 |
{ |
141 | 143 |
return curmove; |
142 | 144 |
} |
143 |
public void makeNextMove()
|
|
145 |
void makeNextMove() |
|
144 | 146 |
{ |
145 | 147 |
curmove++; |
146 | 148 |
if( curmove>nummove) |
... | ... | |
150 | 152 |
} |
151 | 153 |
else |
152 | 154 |
{ |
153 |
|
|
154 | 155 |
// TODO |
155 | 156 |
// RubikCube cube = world.getCube(); |
156 | 157 |
// if( cube!=null && !cube.makeMove(moves.substring(4*curmove-4,4*curmove)) ) |
157 | 158 |
curmove--; |
158 | 159 |
} |
159 | 160 |
} |
160 |
public void makePrevMove()
|
|
161 |
void makePrevMove() |
|
161 | 162 |
{ |
162 | 163 |
curmove--; |
163 | 164 |
if( curmove<0) |
... | ... | |
173 | 174 |
curmove++; |
174 | 175 |
} |
175 | 176 |
} |
176 |
public void initializeCube()
|
|
177 |
void initializeCube() |
|
177 | 178 |
{ |
178 | 179 |
// TODO |
179 | 180 |
// RubikCube cube = world.getCube(); |
... | ... | |
183 | 184 |
|
184 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
185 | 186 |
|
186 |
public RubikPattern(int wi, int h)
|
|
187 |
private RubikPattern()
|
|
187 | 188 |
{ |
188 |
width = wi; |
|
189 |
mPaint.setTextSize(24); |
|
190 |
mWidth = 200; |
|
189 | 191 |
mCategories = new Vector[NUM_CUBES]; |
190 |
mPaint.setTextSize(h); |
|
191 |
|
|
192 |
|
|
192 | 193 |
initializeCategories(0, RubikPatternData2.patterns); |
193 | 194 |
initializeCategories(1, RubikPatternData3.patterns); |
194 | 195 |
initializeCategories(2, RubikPatternData4.patterns); |
... | ... | |
232 | 233 |
private static String cutPatternName(String n) |
233 | 234 |
{ |
234 | 235 |
int len1 = (int)mPaint.measureText(n); |
235 |
|
|
236 |
if( len1>width )
|
|
236 |
|
|
237 |
if( len1>mWidth )
|
|
237 | 238 |
{ |
238 | 239 |
int l = n.length(); |
239 | 240 |
|
240 |
while( l>=2 && len1>width )
|
|
241 |
while( l>=2 && len1>mWidth )
|
|
241 | 242 |
{ |
242 | 243 |
l--; |
243 | 244 |
buffer = n.substring(0,l); |
... | ... | |
250 | 251 |
return n; |
251 | 252 |
} |
252 | 253 |
|
254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
255 |
// PUBLIC API |
|
256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
257 |
|
|
258 |
public static RubikPattern getInstance() |
|
259 |
{ |
|
260 |
if( mThis==null ) |
|
261 |
{ |
|
262 |
mThis = new RubikPattern(); |
|
263 |
} |
|
264 |
|
|
265 |
return mThis; |
|
266 |
} |
|
267 |
|
|
253 | 268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
254 | 269 |
|
255 | 270 |
public String getCategoryName(int size,int num) |
256 | 271 |
{ |
257 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
272 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
258 | 273 |
{ |
259 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
274 |
Category c = mCategories[size].elementAt(num); |
|
260 | 275 |
return c!=null ? c.getName() : null; |
261 | 276 |
} |
262 | 277 |
|
... | ... | |
267 | 282 |
|
268 | 283 |
public String getPatternName(int size,int num) |
269 | 284 |
{ |
270 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
285 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
271 | 286 |
{ |
272 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
287 |
Category c = mCategories[size].elementAt(num); |
|
273 | 288 |
return c!=null ? c.getPatternName() : null; |
274 | 289 |
} |
275 | 290 |
|
... | ... | |
280 | 295 |
|
281 | 296 |
public int getNumPatterns(int size, int num ) |
282 | 297 |
{ |
283 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
298 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
284 | 299 |
{ |
285 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
300 |
Category c = mCategories[size].elementAt(num); |
|
286 | 301 |
return c!=null ? c.getNumPatterns() : 0; |
287 | 302 |
} |
288 | 303 |
|
... | ... | |
293 | 308 |
|
294 | 309 |
public void nextPattern(int size, int num ) |
295 | 310 |
{ |
296 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
311 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
297 | 312 |
{ |
298 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
313 |
Category c = mCategories[size].elementAt(num); |
|
299 | 314 |
|
300 | 315 |
if( c!=null ) |
301 | 316 |
{ |
... | ... | |
311 | 326 |
|
312 | 327 |
public void prevPattern(int size, int num ) |
313 | 328 |
{ |
314 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
329 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
315 | 330 |
{ |
316 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
331 |
Category c = mCategories[size].elementAt(num); |
|
317 | 332 |
|
318 | 333 |
if( c!=null ) |
319 | 334 |
{ |
... | ... | |
329 | 344 |
|
330 | 345 |
public int getCurrPattern(int size, int num ) |
331 | 346 |
{ |
332 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
347 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
333 | 348 |
{ |
334 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
349 |
Category c = mCategories[size].elementAt(num); |
|
335 | 350 |
return c!=null ? c.curPattern:0; |
336 | 351 |
} |
337 | 352 |
|
... | ... | |
342 | 357 |
|
343 | 358 |
public int getCurMove(int size, int num ) |
344 | 359 |
{ |
345 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
360 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
346 | 361 |
{ |
347 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
362 |
Category c = mCategories[size].elementAt(num); |
|
348 | 363 |
return c!=null ? c.getPatternCurMove():0; |
349 | 364 |
} |
350 | 365 |
|
... | ... | |
355 | 370 |
|
356 | 371 |
public int getNumMove(int size, int num ) |
357 | 372 |
{ |
358 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
373 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
359 | 374 |
{ |
360 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
375 |
Category c = mCategories[size].elementAt(num); |
|
361 | 376 |
return c!=null ? c.getPatternNumMove():0; |
362 | 377 |
} |
363 | 378 |
|
... | ... | |
368 | 383 |
|
369 | 384 |
public void makeNextMove(int size, int num) |
370 | 385 |
{ |
371 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
386 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
372 | 387 |
{ |
373 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
388 |
Category c = mCategories[size].elementAt(num); |
|
374 | 389 |
if( c!=null ) c.makeNextMove(); |
375 | 390 |
} |
376 | 391 |
} |
... | ... | |
379 | 394 |
|
380 | 395 |
public void makePrevMove(int size, int num) |
381 | 396 |
{ |
382 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
397 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
383 | 398 |
{ |
384 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
399 |
Category c = mCategories[size].elementAt(num); |
|
385 | 400 |
if( c!=null ) c.makePrevMove(); |
386 | 401 |
} |
387 | 402 |
} |
... | ... | |
390 | 405 |
|
391 | 406 |
public void initializeCube(int size,int num) |
392 | 407 |
{ |
393 |
if( size>=MIN_CUBE && size<=MAX_CUBE && num>=0 && num< numCategories[size-MIN_CUBE] )
|
|
408 |
if( size>=0 && size<NUM_CUBES && num>=0 && num< numCategories[size] )
|
|
394 | 409 |
{ |
395 |
Category c = mCategories[size-MIN_CUBE].elementAt(num);
|
|
410 |
Category c = mCategories[size].elementAt(num); |
|
396 | 411 |
if( c!=null ) c.initializeCube(); |
397 | 412 |
} |
398 | 413 |
} |
414 |
|
|
415 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
416 |
|
|
417 |
public int getNumCategories(int size) |
|
418 |
{ |
|
419 |
return size>=0 && size<NUM_CUBES ? numCategories[size] : 0; |
|
420 |
} |
|
399 | 421 |
} |
src/main/java/org/distorted/uistate/RubikState.java | ||
---|---|---|
29 | 29 |
MAIN ( null , new RubikStateMain() ), |
30 | 30 |
PLAY ( MAIN , new RubikStatePlay() ), |
31 | 31 |
SOLV ( PLAY , new RubikStateSolving() ), |
32 |
PATT ( MAIN , new RubikStatePattern() ), |
|
32 | 33 |
; |
33 | 34 |
|
34 | 35 |
public static final int LENGTH = values().length; |
... | ... | |
99 | 100 |
|
100 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
101 | 102 |
|
102 |
public static void switchState(RubikActivity act, RubikState state)
|
|
103 |
public static void switchState(RubikActivity act, RubikState next)
|
|
103 | 104 |
{ |
104 |
if( state!=null )
|
|
105 |
if( next!=null )
|
|
105 | 106 |
{ |
106 | 107 |
if( mCurrState!=null ) mCurrState.leaveState(act); |
107 |
state.enterState(act,mCurrState);
|
|
108 |
next.enterState(act,mCurrState);
|
|
108 | 109 |
mPrevState = mCurrState; |
109 |
mCurrState = state;
|
|
110 |
mCurrState = next;
|
|
110 | 111 |
} |
111 | 112 |
else |
112 | 113 |
{ |
src/main/java/org/distorted/uistate/RubikStateMain.java | ||
---|---|---|
28 | 28 |
import android.widget.TextView; |
29 | 29 |
|
30 | 30 |
import org.distorted.dialog.RubikDialogMain; |
31 |
import org.distorted.dialog.RubikDialogPattern; |
|
31 | 32 |
import org.distorted.magic.R; |
32 | 33 |
import org.distorted.magic.RubikActivity; |
33 | 34 |
|
... | ... | |
63 | 64 |
diag2.show( mana, RubikDialogMain.getDialogTag() ); |
64 | 65 |
} |
65 | 66 |
|
67 |
if( prev==RubikState.PATT ) |
|
68 |
{ |
|
69 |
RubikDialogPattern diag2 = new RubikDialogPattern(); |
|
70 |
diag2.show( mana, RubikDialogPattern.getDialogTag() ); |
|
71 |
} |
|
72 |
|
|
66 | 73 |
LayoutInflater inflater = act.getLayoutInflater(); |
67 | 74 |
|
68 | 75 |
// TOP //////////////////////////// |
src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.uistate; |
|
21 |
|
|
22 |
import android.content.SharedPreferences; |
|
23 |
import android.util.DisplayMetrics; |
|
24 |
import android.view.LayoutInflater; |
|
25 |
import android.widget.Button; |
|
26 |
import android.widget.LinearLayout; |
|
27 |
import android.widget.TextView; |
|
28 |
|
|
29 |
import org.distorted.magic.R; |
|
30 |
import org.distorted.magic.RubikActivity; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public class RubikStatePattern extends RubikStateAbstract |
|
35 |
{ |
|
36 |
private TextView mText; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
RubikStatePattern() |
|
41 |
{ |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
void leaveState(RubikActivity act) |
|
48 |
{ |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
void enterState(RubikActivity act, RubikState prev) |
|
55 |
{ |
|
56 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
57 |
|
|
58 |
// TOP //////////////////////////// |
|
59 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle); |
|
60 |
layoutTop.removeAllViews(); |
|
61 |
mText = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
62 |
mText.setText(R.string.patterns); |
|
63 |
layoutTop.addView(mText); |
|
64 |
|
|
65 |
// BOT //////////////////////////// |
|
66 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
67 |
layoutLeft.removeAllViews(); |
|
68 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
69 |
layoutRight.removeAllViews(); |
|
70 |
|
|
71 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
72 |
float scale = metrics.density; |
|
73 |
int padding = (int)(5*scale + 0.5f); |
|
74 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
75 |
|
|
76 |
Button button = new Button(act); |
|
77 |
button.setLayoutParams(params); |
|
78 |
button.setId(BUTTON_ID_BACK); |
|
79 |
button.setPadding(padding,0,padding,0); |
|
80 |
button.setText(R.string.back); |
|
81 |
button.setOnClickListener(act); |
|
82 |
layoutRight.addView(button); |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public void savePreferences(SharedPreferences.Editor editor) |
|
88 |
{ |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public void restorePreferences(SharedPreferences preferences) |
|
95 |
{ |
|
96 |
|
|
97 |
} |
|
98 |
} |
Also available in: Unified diff
Progress with Pretty Patterns.