Revision c715128d
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/dialog/RubikDialogPattern.java | ||
---|---|---|
131 | 131 |
|
132 | 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
133 | 133 |
|
134 |
public void rememberCategories()
|
|
134 |
public void rememberState()
|
|
135 | 135 |
{ |
136 |
mPagerAdapter.rememberCategories();
|
|
136 |
mPagerAdapter.rememberState();
|
|
137 | 137 |
} |
138 | 138 |
|
139 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.java | ||
---|---|---|
52 | 52 |
|
53 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 54 |
|
55 |
void rememberCategories()
|
|
55 |
void rememberState()
|
|
56 | 56 |
{ |
57 | 57 |
RubikPattern pattern = RubikPattern.getInstance(); |
58 | 58 |
|
59 | 59 |
for(int i=0; i<mNumTabs; i++) |
60 | 60 |
{ |
61 | 61 |
int cat = mViews[i].getCurrentCategory(); |
62 |
pattern.rememberCategory(i,cat); |
|
62 |
int pos = mViews[i].getCurrentScrollPos(); |
|
63 |
pattern.rememberState(i,cat,pos); |
|
63 | 64 |
} |
64 | 65 |
} |
65 | 66 |
|
src/main/java/org/distorted/dialog/RubikDialogPatternView.java | ||
---|---|---|
29 | 29 |
import android.widget.Button; |
30 | 30 |
import android.widget.FrameLayout; |
31 | 31 |
import android.widget.LinearLayout; |
32 |
import android.widget.ScrollView; |
|
32 | 33 |
import android.widget.Spinner; |
33 | 34 |
|
34 | 35 |
import org.distorted.magic.R; |
... | ... | |
43 | 44 |
public class RubikDialogPatternView extends FrameLayout implements AdapterView.OnItemSelectedListener |
44 | 45 |
{ |
45 | 46 |
private LinearLayout mLayout; |
47 |
private ScrollView mScroll; |
|
46 | 48 |
private RubikDialogPattern mDialog; |
47 | 49 |
private int mTab, mPos; |
48 | 50 |
|
... | ... | |
70 | 72 |
mTab = position; |
71 | 73 |
View tab = inflate( act, R.layout.dialog_pattern_tab, null); |
72 | 74 |
mLayout = tab.findViewById(R.id.tabLayout); |
75 |
mScroll = tab.findViewById(R.id.tabScrollView); |
|
73 | 76 |
|
74 | 77 |
String[] categories = createCategories(); |
75 | 78 |
|
... | ... | |
134 | 137 |
|
135 | 138 |
final String[] patterns = createPatterns(category); |
136 | 139 |
int len = patterns.length; |
140 |
final RubikPattern pattern = RubikPattern.getInstance(); |
|
137 | 141 |
|
138 | 142 |
mLayout.removeAllViews(); |
139 | 143 |
|
... | ... | |
150 | 154 |
public void onClick(View view) |
151 | 155 |
{ |
152 | 156 |
int[] sizes = RubikObjectList.CUBE.getSizes(); |
153 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
154 |
int[][] moves = pattern.getMoves(mTab, category, ii); |
|
157 |
int[][] moves = pattern.reInitialize(mTab, category, ii); |
|
155 | 158 |
act.changeObject(RubikObjectList.CUBE,sizes[mTab],moves); |
156 | 159 |
RubikStatePattern state = (RubikStatePattern) RubikState.PATT.getStateClass(); |
157 | 160 |
state.setPattern(act, mTab, category, ii); |
158 |
mDialog.rememberCategories();
|
|
161 |
mDialog.rememberState();
|
|
159 | 162 |
mDialog.dismiss(); |
160 | 163 |
} |
161 | 164 |
}); |
... | ... | |
171 | 174 |
return mPos; |
172 | 175 |
} |
173 | 176 |
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
|
179 |
int getCurrentScrollPos() |
|
180 |
{ |
|
181 |
return mScroll.getScrollY(); |
|
182 |
} |
|
183 |
|
|
184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
185 |
|
|
186 |
@Override |
|
187 |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) |
|
188 |
{ |
|
189 |
super.onLayout(changed,left,top,right,bottom); |
|
190 |
|
|
191 |
if( !changed ) |
|
192 |
{ |
|
193 |
final RubikPattern pattern = RubikPattern.getInstance(); |
|
194 |
mScroll.setScrollY( pattern.recallScrollPos(mTab) ); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
174 | 198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
175 | 199 |
|
176 | 200 |
@Override |
src/main/java/org/distorted/patterns/RubikPattern.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
private int[] numCategories = new int[NUM_CUBES]; |
38 | 38 |
private int[] currentCategory = new int[NUM_CUBES]; |
39 |
private int[] currentScrollPos= new int[NUM_CUBES]; |
|
40 |
|
|
39 | 41 |
private Vector<Category>[] mCategories; |
40 | 42 |
private static RubikPattern mThis; |
41 | 43 |
|
... | ... | |
138 | 140 |
|
139 | 141 |
///////////////////////////////////////////////////////////// |
140 | 142 |
|
141 |
int[][] getMoves(int pattern)
|
|
143 |
int[][] reInitialize(int pattern)
|
|
142 | 144 |
{ |
143 | 145 |
if( pattern>=0 && pattern<numPatterns ) |
144 | 146 |
{ |
145 | 147 |
Pattern p = patterns.elementAt(pattern); |
146 |
if( p!=null ) return p.getMoves();
|
|
148 |
if( p!=null ) return p.reInitialize();
|
|
147 | 149 |
} |
148 | 150 |
|
149 | 151 |
return null; |
... | ... | |
314 | 316 |
|
315 | 317 |
///////////////////////////////////////////////////////////// |
316 | 318 |
|
317 |
int[][] getMoves()
|
|
319 |
int[][] reInitialize()
|
|
318 | 320 |
{ |
319 | 321 |
if( !mInitialized ) |
320 | 322 |
{ |
... | ... | |
323 | 325 |
moveStr = null; |
324 | 326 |
} |
325 | 327 |
|
328 |
mCanRotate = true; |
|
326 | 329 |
curMove = numMove; |
327 | 330 |
return moves; |
328 | 331 |
} |
... | ... | |
415 | 418 |
|
416 | 419 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
417 | 420 |
|
418 |
public void rememberCategory(int size,int num)
|
|
421 |
public void rememberState(int size,int num, int scrollPos)
|
|
419 | 422 |
{ |
420 | 423 |
if( size>=0 && size<NUM_CUBES ) |
421 | 424 |
{ |
422 | 425 |
currentCategory[size] = num; |
426 |
currentScrollPos[size]= scrollPos; |
|
423 | 427 |
} |
424 | 428 |
} |
425 | 429 |
|
... | ... | |
430 | 434 |
return size>=0 && size<NUM_CUBES ? currentCategory[size] : 0; |
431 | 435 |
} |
432 | 436 |
|
437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 |
|
|
439 |
public int recallScrollPos(int size) |
|
440 |
{ |
|
441 |
return size>=0 && size<NUM_CUBES ? currentScrollPos[size] : 0; |
|
442 |
} |
|
443 |
|
|
433 | 444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
434 | 445 |
|
435 | 446 |
public String getPatternName(int size, int cat, int pat) |
... | ... | |
506 | 517 |
|
507 | 518 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
508 | 519 |
|
509 |
public int[][] getMoves(int size, int cat, int pat)
|
|
520 |
public int[][] reInitialize(int size, int cat, int pat)
|
|
510 | 521 |
{ |
511 | 522 |
if( size>=0 && size<NUM_CUBES && cat>=0 && cat< numCategories[size] ) |
512 | 523 |
{ |
513 | 524 |
Category c = mCategories[size].elementAt(cat); |
514 |
if( c!=null ) return c.getMoves(pat);
|
|
525 |
if( c!=null ) return c.reInitialize(pat);
|
|
515 | 526 |
} |
516 | 527 |
|
517 | 528 |
return null; |
src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
---|---|---|
167 | 167 |
} |
168 | 168 |
else |
169 | 169 |
{ |
170 |
diag.rememberCategories();
|
|
170 |
diag.rememberState();
|
|
171 | 171 |
diag.dismiss(); |
172 | 172 |
RubikState.goBack(act); |
173 | 173 |
} |
Also available in: Unified diff
Pretty Patterns Dialog: remember the positions of scrollbars.