Revision 028f3e0d
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikScoresPagerAdapter.java | ||
---|---|---|
32 | 32 |
{ |
33 | 33 |
private FragmentActivity mAct; |
34 | 34 |
private RubikScoresView[] mViews; |
35 |
private ViewPager mViewPager; |
|
35 | 36 |
|
36 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 38 |
|
38 | 39 |
public void receive(final int[][][] country, final String[][][] name, final String[][][] time) |
40 |
{ |
|
41 |
prepareView(); |
|
42 |
|
|
43 |
int c = mViewPager.getCurrentItem(); |
|
44 |
|
|
45 |
addPage(c,country[c],name[c],time[c]); |
|
46 |
|
|
47 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
48 |
{ |
|
49 |
if( i==c ) continue; |
|
50 |
|
|
51 |
addPage(i,country[i],name[i],time[i]); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
private void prepareView() |
|
39 | 58 |
{ |
40 | 59 |
mAct.runOnUiThread(new Runnable() |
41 | 60 |
{ |
... | ... | |
56 | 75 |
{ |
57 | 76 |
|
58 | 77 |
} |
78 |
} |
|
59 | 79 |
|
60 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
|
|
82 |
private void addPage(final int page, final int[][] country, final String[][] name, final String[][] time) |
|
83 |
{ |
|
84 |
for(int section=0; section<RubikActivity.MAX_SCRAMBLE; section++) |
|
61 | 85 |
{ |
62 |
final RubikScoresView view = mViews[i]; |
|
86 |
final int sec = section; |
|
87 |
final int[] c = country[section]; |
|
88 |
final String[] n = name[section]; |
|
89 |
final String[] t = time[section]; |
|
63 | 90 |
|
64 |
for(int j=0; j<RubikActivity.MAX_SCRAMBLE; j++)
|
|
91 |
mAct.runOnUiThread(new Runnable()
|
|
65 | 92 |
{ |
66 |
final int scramble = j; |
|
67 |
final int[] c = country[i][j]; |
|
68 |
final String[] n = name[i][j]; |
|
69 |
final String[] t = time[i][j]; |
|
70 |
|
|
71 |
mAct.runOnUiThread(new Runnable() |
|
72 |
{ |
|
73 |
@Override |
|
74 |
public void run() |
|
75 |
{ |
|
76 |
view.addScramble(mAct, scramble, c, n, t); |
|
77 |
} |
|
78 |
}); |
|
79 |
|
|
80 |
try |
|
93 |
@Override |
|
94 |
public void run() |
|
81 | 95 |
{ |
82 |
Thread.sleep(50);
|
|
96 |
mViews[page].addSection(mAct, sec, c, n, t);
|
|
83 | 97 |
} |
84 |
catch( InterruptedException ie) |
|
85 |
{ |
|
98 |
}); |
|
99 |
|
|
100 |
try |
|
101 |
{ |
|
102 |
Thread.sleep(50); |
|
103 |
} |
|
104 |
catch( InterruptedException ie) |
|
105 |
{ |
|
86 | 106 |
|
87 |
} |
|
88 | 107 |
} |
89 | 108 |
} |
90 | 109 |
} |
... | ... | |
112 | 131 |
{ |
113 | 132 |
mAct = act; |
114 | 133 |
mViews = new RubikScoresView[RubikSize.LENGTH]; |
134 |
mViewPager = viewPager; |
|
115 | 135 |
|
116 | 136 |
viewPager.setAdapter(this); |
117 | 137 |
viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 ); |
Also available in: Unified diff
Downloading High Scores: even better way of displaying scores