Revision f3e12931
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
27 | 27 |
import android.preference.PreferenceManager; |
28 | 28 |
import android.support.v4.content.ContextCompat; |
29 | 29 |
import android.support.v7.app.AppCompatActivity; |
30 |
import android.util.DisplayMetrics; |
|
30 | 31 |
import android.view.View; |
32 |
import android.view.ViewGroup; |
|
33 |
import android.widget.ImageButton; |
|
34 |
import android.widget.LinearLayout; |
|
31 | 35 |
|
32 | 36 |
import org.distorted.component.HorizontalNumberPicker; |
33 | 37 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
35 | 39 |
|
36 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 41 |
|
38 |
public class RubikActivity extends AppCompatActivity |
|
42 |
public class RubikActivity extends AppCompatActivity implements View.OnClickListener
|
|
39 | 43 |
{ |
40 |
static final int DEFAULT_SIZE = 3; |
|
41 |
static final int SMALLEST_SIZE = 2; |
|
42 |
|
|
43 | 44 |
public static final int MIN_SCRAMBLE = 1; |
44 | 45 |
public static final int DEF_SCRAMBLE = 1; |
45 | 46 |
public static final int MAX_SCRAMBLE = 17; |
46 | 47 |
|
47 |
private static int mSize = DEFAULT_SIZE; |
|
48 |
private static int mSize = RubikSize.DEFAULT_SIZE;
|
|
48 | 49 |
private HorizontalNumberPicker mPicker; |
49 | 50 |
|
50 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
55 | 56 |
|
56 | 57 |
for(int b=0; b<RubikSize.LENGTH; b++) |
57 | 58 |
{ |
58 |
Drawable d = findViewById(RubikSize.getSize(b).getImageButton()).getBackground();
|
|
59 |
Drawable d = findViewById(b).getBackground();
|
|
59 | 60 |
|
60 |
if( size == b+SMALLEST_SIZE )
|
|
61 |
if( size == RubikSize.getSize(b).getCubeSize() )
|
|
61 | 62 |
{ |
62 | 63 |
d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY); |
63 | 64 |
} |
... | ... | |
101 | 102 |
mPicker.setValue(scramble); |
102 | 103 |
} |
103 | 104 |
|
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 |
|
|
104 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
105 | 130 |
|
106 | 131 |
static int getSize() |
... | ... | |
116 | 141 |
super.onCreate(savedState); |
117 | 142 |
setTheme(R.style.CustomActivityThemeNoActionBar); |
118 | 143 |
setContentView(R.layout.main); |
144 |
addSizeButtons(); |
|
119 | 145 |
markButton(mSize); |
120 | 146 |
|
121 | 147 |
mPicker = findViewById(R.id.rubikNumberPicker); |
... | ... | |
133 | 159 |
GLSurfaceView view = findViewById(R.id.rubikSurfaceView); |
134 | 160 |
view.onPause(); |
135 | 161 |
DistortedLibrary.onPause(); |
162 |
RubikScoresDownloader.onPause(); |
|
136 | 163 |
savePreferences(); |
137 | 164 |
super.onPause(); |
138 | 165 |
} |
... | ... | |
156 | 183 |
super.onDestroy(); |
157 | 184 |
} |
158 | 185 |
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
@Override |
|
189 |
public void onClick(View v) |
|
190 |
{ |
|
191 |
int id = v.getId(); |
|
192 |
|
|
193 |
if( id>=0 && id<RubikSize.LENGTH ) |
|
194 |
{ |
|
195 |
int size = RubikSize.getSize(id).getCubeSize(); |
|
196 |
|
|
197 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
198 |
boolean success = view.getRenderer().createCube(size); |
|
199 |
|
|
200 |
if( success ) |
|
201 |
{ |
|
202 |
markButton(size); |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
159 | 207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
160 | 208 |
// PUBLIC API |
161 | 209 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
199 | 247 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
200 | 248 |
view.getRenderer().solveCube(); |
201 | 249 |
} |
202 |
|
|
203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
204 |
|
|
205 |
public void setSize(View v) |
|
206 |
{ |
|
207 |
int size=0, id = v.getId(); |
|
208 |
|
|
209 |
for(int b=0; b<RubikSize.LENGTH; b++) |
|
210 |
if( RubikSize.getSize(b).getImageButton() == id ) |
|
211 |
{ |
|
212 |
size = b+SMALLEST_SIZE; |
|
213 |
break; |
|
214 |
} |
|
215 |
|
|
216 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
217 |
boolean success = view.getRenderer().createCube(size); |
|
218 |
|
|
219 |
if( success ) |
|
220 |
{ |
|
221 |
markButton(size); |
|
222 |
} |
|
223 |
} |
|
224 | 250 |
} |
src/main/java/org/distorted/magic/RubikScores.java | ||
---|---|---|
37 | 37 |
|
38 | 38 |
public class RubikScores extends AppCompatDialogFragment |
39 | 39 |
{ |
40 |
interface ScoresReceiver |
|
41 |
{ |
|
42 |
void receive(String scores); |
|
43 |
} |
|
44 |
|
|
40 | 45 |
RubikScoresViewPager mViewPager; |
41 | 46 |
|
42 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
75 | 80 |
for (int i = 0; i< RubikSize.LENGTH; i++) |
76 | 81 |
{ |
77 | 82 |
ImageView imageView = new ImageView(act); |
78 |
imageView.setImageResource(RubikSize.getSize(i).getIcon()); |
|
83 |
imageView.setImageResource(RubikSize.getSize(i).getIconID());
|
|
79 | 84 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
80 | 85 |
if(tab!=null) tab.setCustomView(imageView); |
81 | 86 |
} |
82 | 87 |
|
88 |
RubikScoresDownloader.download(mViewPager); |
|
89 |
|
|
83 | 90 |
return builder.create(); |
84 | 91 |
} |
85 | 92 |
} |
src/main/java/org/distorted/magic/RubikScoresDownloader.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.magic; |
21 | 21 |
|
22 |
import android.support.v7.app.AppCompatDialogFragment; |
|
23 |
|
|
24 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 23 |
|
26 |
public class RubikScoresDownloader extends AppCompatDialogFragment
|
|
24 |
class RubikScoresDownloader extends Thread
|
|
27 | 25 |
{ |
26 |
private static String mScores = ""; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
static void onPause() |
|
31 |
{ |
|
32 |
mScores = ""; |
|
33 |
} |
|
34 |
|
|
35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
|
37 |
static boolean gottaDownload() |
|
38 |
{ |
|
39 |
return mScores.length() == 0; |
|
40 |
} |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
static void download(RubikScores.ScoresReceiver receiver) |
|
45 |
{ |
|
46 |
if( gottaDownload() ) |
|
47 |
{ |
|
48 |
doDownload(); |
|
49 |
} |
|
50 |
|
|
51 |
receiver.receive(mScores); |
|
52 |
} |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
private static void doDownload() |
|
57 |
{ |
|
58 |
mScores = |
|
28 | 59 |
|
60 |
"0 0 0 INEED7X7X7 1 rus" + "\n" + |
|
61 |
"0 0 1 Tilly 1 uk" + "\n" + |
|
62 |
"0 0 2 ARNOLD 1 rus" + "\n" + |
|
63 |
"0 0 3 ALBERTO 1 mex" + "\n" + |
|
64 |
"0 0 4 TO 1 ger" + "\n" + |
|
65 |
"0 1 0 INEED7X7X7 1 rus" + "\n" + |
|
66 |
"0 1 1 Tilly 1 uk" + "\n" + |
|
67 |
"0 1 2 ALBERTO 1 mex" + "\n" + |
|
68 |
"0 1 3 RINAT 1 rus" + "\n" + |
|
69 |
"0 1 4 BOOW 1 tha" + "\n" + |
|
70 |
"0 2 0 Neriel 3 bra" + "\n" + |
|
71 |
"0 2 1 NPPN 3 vie" + "\n" + |
|
72 |
"0 2 2 FREDRIK 4 den" + "\n" + |
|
73 |
"0 2 3 OHIOCUBER 4 usa" + "\n" + |
|
74 |
"0 2 4 S13 4 usa" + "\n" + |
|
75 |
"0 3 0 NIKITOS 8 rus" + "\n" + |
|
76 |
"0 3 1 THISNAVIS 8 usa" + "\n" + |
|
77 |
"0 3 2 MDR04 9 ita" + "\n" + |
|
78 |
"0 3 3 ROBERT04 9 unk" + "\n" + |
|
79 |
"0 3 4 DULCE 10 mex" + "\n" + |
|
80 |
"0 4 0 THISNAVIS 11 usa" + "\n" + |
|
81 |
"0 4 1 Tilly 12 uk" + "\n" + |
|
82 |
"0 4 2 OHIOCUBER 14 usa" + "\n" + |
|
83 |
"0 4 3 GRV 15 mex" + "\n" + |
|
84 |
"0 4 4 INEED7X7X7 16 rus" + "\n" + |
|
85 |
"0 5 0 KADE 6 unk" + "\n" + |
|
86 |
"0 5 1 FREDRIK 11 den" + "\n" + |
|
87 |
"0 5 2 THISNAVIS 11 usa" + "\n" + |
|
88 |
"0 5 3 Tilly 14 uk" + "\n" + |
|
89 |
"0 5 4 A9QSKPJJDM 16 bra" + "\n" + |
|
90 |
"0 6 0 LoiraH 1 bra" + "\n" + |
|
91 |
"0 6 1 KAN 5 unk" + "\n" + |
|
92 |
"0 6 2 Tilly 7 uk" + "\n" + |
|
93 |
"0 6 3 FRITZ 17 ita" + "\n" + |
|
94 |
"0 6 4 JONIWWE 17 ina" + "\n" + |
|
95 |
"0 7 0 SULTANOUU 30 rus" + "\n" + |
|
96 |
"0 7 1 LOLO766 33 fra" + "\n" + |
|
97 |
"0 7 2 ElyKho 37 mly" + "\n" + |
|
98 |
"0 7 3 FREDRIK 37 den" + "\n" + |
|
99 |
"0 7 4 ILXOM707 37 uzb" + "\n" + |
|
100 |
"0 8 0 pardal 16 bra" + "\n" + |
|
101 |
"0 8 1 ILXOM707 32 uzb" + "\n" + |
|
102 |
"0 8 2 LOLO766 43 fra" + "\n" + |
|
103 |
"0 8 3 NIKODZ 44 geo" + "\n" + |
|
104 |
"0 8 4 SHAFFAF 48 ind" + "\n" + |
|
105 |
"1 0 0 INEED7X7X7 1 rus" + "\n" + |
|
106 |
"1 0 1 Tilly 1 uk" + "\n" + |
|
107 |
"1 0 2 REBECCA 1 fra" + "\n" + |
|
108 |
"1 0 3 PRAKOBKRIT 1 tha" + "\n" + |
|
109 |
"1 0 4 E 1 mex" + "\n" + |
|
110 |
"1 1 0 BAYLEY 3 usa" + "\n" + |
|
111 |
"1 1 1 DEMONAIRE 3 uk" + "\n" + |
|
112 |
"1 1 2 UMMWT 3 ina" + "\n" + |
|
113 |
"1 1 3 MDR04 4 ita" + "\n" + |
|
114 |
"1 1 4 FREDRIK 4 den" + "\n" + |
|
115 |
"1 2 0 HAGER 5 egy" + "\n" + |
|
116 |
"1 2 1 S13 7 usa" + "\n" + |
|
117 |
"1 2 2 UTEK 7 ina" + "\n" + |
|
118 |
"1 2 3 UMMWT 7 ina" + "\n" + |
|
119 |
"1 2 4 210JITQU 7 ukr" + "\n" + |
|
120 |
"1 3 0 UTEK 16 ina" + "\n" + |
|
121 |
"1 3 1 LOLO766 21 fra" + "\n" + |
|
122 |
"1 3 2 NIKITOS 21 rus" + "\n" + |
|
123 |
"1 3 3 PYCUK1707 21 rus" + "\n" + |
|
124 |
"1 3 4 KEDAR 22 ind" + "\n" + |
|
125 |
"1 4 0 Kinkz 7 ned" + "\n" + |
|
126 |
"1 4 1 UTEK 14 ina" + "\n" + |
|
127 |
"1 4 2 SJNT 23 ind" + "\n" + |
|
128 |
"1 4 3 ABCDEF89 24 vie" + "\n" + |
|
129 |
"1 4 4 SIJOYSIJ 27 ind" + "\n" + |
|
130 |
"1 5 0 SIJOYSIJ 40 ind" + "\n" + |
|
131 |
"1 5 1 UTEK 46 ina" + "\n" + |
|
132 |
"1 5 2 SJNT 54 ind" + "\n" + |
|
133 |
"1 5 3 FREDRIK 59 den" + "\n" + |
|
134 |
"1 5 4 YANY 64 arg" + "\n" + |
|
135 |
"1 6 0 UTEK 26 ina" + "\n" + |
|
136 |
"1 6 1 FLAVINHA 57 bra" + "\n" + |
|
137 |
"1 6 2 MILKMAN 57 fin" + "\n" + |
|
138 |
"1 6 3 MARIOEAGLE 59 ita" + "\n" + |
|
139 |
"1 6 4 LOLO766 85 fra" + "\n" + |
|
140 |
"1 7 0 UTEK 45 ina" + "\n" + |
|
141 |
"1 7 1 SEUA 157 vie" + "\n" + |
|
142 |
"1 7 2 FREDRIK 201 den" + "\n" + |
|
143 |
"1 7 3 ARMIN 205 rus" + "\n" + |
|
144 |
"1 7 4 ILXOM7 215 uzb" + "\n" + |
|
145 |
"1 8 0 SJNT 73 ind" + "\n" + |
|
146 |
"1 8 1 MILKOMANN 219 fin" + "\n" + |
|
147 |
"1 8 2 DEMONAIRE 288 uk" + "\n" + |
|
148 |
"1 8 3 SIJ 311 ind" + "\n" + |
|
149 |
"1 8 4 SIJOYSIJ 316 ind" + "\n" + |
|
150 |
"2 0 0 INEED7X7X7 1 rus" + "\n" + |
|
151 |
"2 0 1 HOMER0815 1 ger" + "\n" + |
|
152 |
"2 0 2 EIP 1 usa" + "\n" + |
|
153 |
"2 0 3 THEBIGBOSS 1 fra" + "\n" + |
|
154 |
"2 0 4 PHONG 1 vie" + "\n" + |
|
155 |
"2 1 0 SATERNSPY9 3 unk" + "\n" + |
|
156 |
"2 1 1 S13 4 usa" + "\n" + |
|
157 |
"2 1 2 ALSOELAN 4 usa" + "\n" + |
|
158 |
"2 1 3 NIKITOS 4 rus" + "\n" + |
|
159 |
"2 1 4 SEPIA6MIRA 4 unk" + "\n" + |
|
160 |
"2 2 0 STEVE123 9 irl" + "\n" + |
|
161 |
"2 2 1 NIKITOS 9 rus" + "\n" + |
|
162 |
"2 2 2 SEPIA6MIRA 9 unk" + "\n" + |
|
163 |
"2 2 3 INEED7X7X7 10 rus" + "\n" + |
|
164 |
"2 2 4 S13 10 usa" + "\n" + |
|
165 |
"2 3 0 NIKITOS 22 rus" + "\n" + |
|
166 |
"2 3 1 RUBIK123 24 lit" + "\n" + |
|
167 |
"2 3 2 NONAME 24 fin" + "\n" + |
|
168 |
"2 3 3 ABB0 26 ind" + "\n" + |
|
169 |
"2 3 4 NOYS 27 mex" + "\n" + |
|
170 |
"2 4 0 NIKITOS 37 rus" + "\n" + |
|
171 |
"2 4 1 INEED7X7X7 45 rus" + "\n" + |
|
172 |
"2 4 2 ILXOM7 50 uzb" + "\n" + |
|
173 |
"2 4 3 NOYS 52 mex" + "\n" + |
|
174 |
"2 4 4 MikeK 57 ger" + "\n" + |
|
175 |
"2 5 0 NIKITOS 62 rus" + "\n" + |
|
176 |
"2 5 1 LOLO766 70 fra" + "\n" + |
|
177 |
"2 5 2 HUBBUB 87 swe" + "\n" + |
|
178 |
"2 5 3 TETRAULT 90 usa" + "\n" + |
|
179 |
"2 5 4 NOYS 115 mex" + "\n" + |
|
180 |
"2 6 0 LOLO766 128 fra" + "\n" + |
|
181 |
"2 6 1 KAN 193 unk" + "\n" + |
|
182 |
"2 6 2 MEECMEEC 195 uk" + "\n" + |
|
183 |
"2 6 3 HUBBUB 197 swe" + "\n" + |
|
184 |
"2 6 4 PTOR 238 kyr" + "\n" + |
|
185 |
"2 7 0 CHRISTA 268 za" + "\n" + |
|
186 |
"2 7 1 MUZAFFER 288 tur" + "\n" + |
|
187 |
"2 7 2 INEED7X7X7 323 rus" + "\n" + |
|
188 |
"2 7 3 HECTOR58 360 mex" + "\n" + |
|
189 |
"2 7 4 CABC 391 rus" + "\n" + |
|
190 |
"2 8 0 CABC 245 rus" + "\n" + |
|
191 |
"2 8 1 SIRWALTR 289 arg" + "\n" + |
|
192 |
"2 8 2 NAMIT 558 ind" + "\n" + |
|
193 |
"2 8 3 HDH580702 602 mex" + "\n" + |
|
194 |
"2 8 4 HECTOR58 959 mex" + "\n" + |
|
195 |
"3 0 0 JARO 1 ger" + "\n" + |
|
196 |
"3 0 1 INEED7X7X7 1 rus" + "\n" + |
|
197 |
"3 0 2 MDR04 1 ita" + "\n" + |
|
198 |
"3 0 3 SAMW 1 uk" + "\n" + |
|
199 |
"3 0 4 MOKAI88 1 den" + "\n" + |
|
200 |
"3 1 0 MDR04G 3 ita" + "\n" + |
|
201 |
"3 1 1 INEED7X7X7 4 rus" + "\n" + |
|
202 |
"3 1 2 S13 4 usa" + "\n" + |
|
203 |
"3 1 3 KARAVAN 4 rus" + "\n" + |
|
204 |
"3 1 4 AWSOME897 4 usa" + "\n" + |
|
205 |
"3 2 0 INEED7X7X7 8 rus" + "\n" + |
|
206 |
"3 2 1 KARAVAN 8 rus" + "\n" + |
|
207 |
"3 2 2 S13 9 usa" + "\n" + |
|
208 |
"3 2 3 ALSOELAN 9 usa" + "\n" + |
|
209 |
"3 2 4 ROBERT04 9 unk" + "\n" + |
|
210 |
"3 3 0 NIKITOS 23 rus" + "\n" + |
|
211 |
"3 3 1 THISNAVIS 23 usa" + "\n" + |
|
212 |
"3 3 2 INEED7X7X7 24 rus" + "\n" + |
|
213 |
"3 3 3 RUBIK123 30 lit" + "\n" + |
|
214 |
"3 3 4 SKY16 31 usa" + "\n" + |
|
215 |
"3 4 0 NIKITOS 37 rus" + "\n" + |
|
216 |
"3 4 1 6969696 43 usa" + "\n" + |
|
217 |
"3 4 2 ALFREDOPVV 45 bra" + "\n" + |
|
218 |
"3 4 3 HIEU 48 vie" + "\n" + |
|
219 |
"3 4 4 INEED7X7X7 52 rus" + "\n" + |
|
220 |
"3 5 0 ILXOM707 63 uzb" + "\n" + |
|
221 |
"3 5 1 PHOENIX 77 fin" + "\n" + |
|
222 |
"3 5 2 Nargiza 82 unk" + "\n" + |
|
223 |
"3 5 3 NIKITOS 83 rus" + "\n" + |
|
224 |
"3 5 4 ILXOM7 83 uzb" + "\n" + |
|
225 |
"3 6 0 ILXOM7 81 uzb" + "\n" + |
|
226 |
"3 6 1 ILXOM707 140 uzb" + "\n" + |
|
227 |
"3 6 2 INEED7X7X7 143 rus" + "\n" + |
|
228 |
"3 6 3 KAN 143 unk" + "\n" + |
|
229 |
"3 6 4 RUBIK123 177 lit" + "\n" + |
|
230 |
"3 7 0 ILXOM707 238 uzb" + "\n" + |
|
231 |
"3 7 1 LOLO766 283 fra" + "\n" + |
|
232 |
"3 7 2 INEED7X7X7 293 rus" + "\n" + |
|
233 |
"3 7 3 RUBIK123 313 lit" + "\n" + |
|
234 |
"3 7 4 SIRWALTR 343 arg" + "\n" + |
|
235 |
"3 8 0 CABC 312 rus" + "\n" + |
|
236 |
"3 8 1 HDH580702 411 mex" + "\n" + |
|
237 |
"3 8 2 RUBIK123 558 lit" + "\n" + |
|
238 |
"3 8 3 MUZAFFER 568 tur" + "\n" + |
|
239 |
"3 8 4 NOYS 649 mex"; |
|
240 |
} |
|
29 | 241 |
} |
src/main/java/org/distorted/magic/RubikScoresViewPager.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.magic; |
21 | 21 |
|
22 |
import android.content.Context; |
|
23 | 22 |
import android.support.annotation.NonNull; |
23 |
import android.support.v4.app.FragmentActivity; |
|
24 | 24 |
import android.support.v4.view.PagerAdapter; |
25 | 25 |
import android.support.v4.view.ViewPager; |
26 |
import android.view.LayoutInflater; |
|
27 | 26 |
import android.view.View; |
28 | 27 |
import android.view.ViewGroup; |
29 | 28 |
|
30 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | 30 |
|
32 |
class RubikScoresViewPager extends PagerAdapter |
|
31 |
class RubikScoresViewPager extends PagerAdapter implements RubikScores.ScoresReceiver
|
|
33 | 32 |
{ |
34 |
private Context mContext;
|
|
33 |
private FragmentActivity mAct;
|
|
35 | 34 |
|
36 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
37 | 36 |
|
38 |
RubikScoresViewPager(Context context, ViewPager viewPager)
|
|
37 |
RubikScoresViewPager(FragmentActivity act, ViewPager viewPager)
|
|
39 | 38 |
{ |
40 |
mContext = context;
|
|
39 |
mAct = act;
|
|
41 | 40 |
viewPager.setAdapter(this); |
42 | 41 |
viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 ); |
43 | 42 |
} |
44 | 43 |
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
// TODO |
|
46 |
|
|
47 |
public void receive(String scores) |
|
48 |
{ |
|
49 |
|
|
50 |
} |
|
51 |
|
|
45 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 53 |
|
47 | 54 |
@Override |
48 | 55 |
@NonNull |
49 | 56 |
public Object instantiateItem(@NonNull ViewGroup collection, int position) |
50 | 57 |
{ |
51 |
int scoresTab= RubikSize.getSize(position).getLayout(); |
|
52 |
LayoutInflater inflater = LayoutInflater.from(mContext); |
|
53 |
ViewGroup layout = (ViewGroup) inflater.inflate(scoresTab, collection, false); |
|
54 |
collection.addView(layout); |
|
58 |
RubikScoresView view = new RubikScoresView(mAct,position); |
|
59 |
collection.addView(view); |
|
55 | 60 |
|
56 |
return layout;
|
|
61 |
return view;
|
|
57 | 62 |
} |
58 | 63 |
|
59 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikSize.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
public enum RubikSize |
25 | 25 |
{ |
26 |
SIZE2 ( R.id.rubikSize2, R.drawable.button2, R.layout.scores_tab2 ),
|
|
27 |
SIZE3 ( R.id.rubikSize3, R.drawable.button3, R.layout.scores_tab3 ),
|
|
28 |
SIZE4 ( R.id.rubikSize4, R.drawable.button4, R.layout.scores_tab4 ),
|
|
29 |
SIZE5 ( R.id.rubikSize5, R.drawable.button5, R.layout.scores_tab5 ),
|
|
26 |
SIZE2 ( 2, R.drawable.button2 ),
|
|
27 |
SIZE3 ( 3, R.drawable.button3 ),
|
|
28 |
SIZE4 ( 4, R.drawable.button4 ),
|
|
29 |
SIZE5 ( 5, R.drawable.button5 ),
|
|
30 | 30 |
; |
31 | 31 |
|
32 |
static final int DEFAULT_SIZE = 3; |
|
32 | 33 |
static final int LENGTH = values().length; |
33 |
private final int mImageButtonID, mIconID, mLayoutID;
|
|
34 |
private final int mCubeSize, mIconID;
|
|
34 | 35 |
private static final RubikSize[] sizes; |
35 | 36 |
|
36 | 37 |
static |
... | ... | |
54 | 55 |
|
55 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 57 |
|
57 |
RubikSize(int imageID, int iconID, int layoutID)
|
|
58 |
RubikSize(int size, int iconID)
|
|
58 | 59 |
{ |
59 |
mImageButtonID= imageID; |
|
60 |
mIconID = iconID; |
|
61 |
mLayoutID = layoutID; |
|
60 |
mCubeSize = size; |
|
61 |
mIconID = iconID; |
|
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 65 |
|
66 |
int getImageButton() |
|
67 |
{ |
|
68 |
return mImageButtonID; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
int getIcon() |
|
66 |
int getIconID() |
|
74 | 67 |
{ |
75 | 68 |
return mIconID; |
76 | 69 |
} |
77 | 70 |
|
78 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
79 | 72 |
|
80 |
int getLayout()
|
|
73 |
int getCubeSize()
|
|
81 | 74 |
{ |
82 |
return mLayoutID;
|
|
75 |
return mCubeSize;
|
|
83 | 76 |
} |
84 | 77 |
} |
src/main/res/layout/main.xml | ||
---|---|---|
43 | 43 |
android:layout_weight="1" /> |
44 | 44 |
|
45 | 45 |
<LinearLayout |
46 |
android:id="@+id/sizeLayout" |
|
46 | 47 |
android:layout_width="match_parent" |
47 | 48 |
android:layout_height="wrap_content" |
48 |
android:gravity="center" > |
|
49 |
|
|
50 |
<ImageButton |
|
51 |
android:id="@+id/rubikSize2" |
|
52 |
android:layout_width="64dp" |
|
53 |
android:layout_height="64dp" |
|
54 |
android:onClick="setSize" |
|
55 |
android:paddingLeft="3dp" |
|
56 |
android:paddingRight="3dp" |
|
57 |
android:src="@drawable/button2" /> |
|
58 |
|
|
59 |
<ImageButton |
|
60 |
android:id="@+id/rubikSize3" |
|
61 |
android:layout_width="64dp" |
|
62 |
android:layout_height="64dp" |
|
63 |
android:onClick="setSize" |
|
64 |
android:paddingLeft="3dp" |
|
65 |
android:paddingRight="3dp" |
|
66 |
android:src="@drawable/button3" /> |
|
67 |
|
|
68 |
<ImageButton |
|
69 |
android:id="@+id/rubikSize4" |
|
70 |
android:layout_width="64dp" |
|
71 |
android:layout_height="64dp" |
|
72 |
android:onClick="setSize" |
|
73 |
android:paddingLeft="3dp" |
|
74 |
android:paddingRight="3dp" |
|
75 |
android:src="@drawable/button4" /> |
|
76 |
|
|
77 |
<ImageButton |
|
78 |
android:id="@+id/rubikSize5" |
|
79 |
android:layout_width="64dp" |
|
80 |
android:layout_height="64dp" |
|
81 |
android:onClick="setSize" |
|
82 |
android:paddingLeft="3dp" |
|
83 |
android:paddingRight="3dp" |
|
84 |
android:src="@drawable/button5" /> |
|
49 |
android:gravity="center" |
|
50 |
android:orientation="horizontal"> |
|
85 | 51 |
</LinearLayout> |
86 | 52 |
|
87 | 53 |
<LinearLayout |
src/main/res/layout/scores_downloading.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 | 2 |
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
3 |
android:id="@+id/downloading_text" |
|
3 | 4 |
android:layout_width="match_parent" |
4 | 5 |
android:layout_height="match_parent" |
5 | 6 |
android:textSize="32sp" |
src/main/res/layout/scores_tab.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<ScrollView |
|
8 |
android:id="@+id/tabScrollView" |
|
9 |
android:layout_width="match_parent" |
|
10 |
android:layout_height="match_parent" |
|
11 |
android:background="@color/grey"> |
|
12 |
|
|
13 |
<LinearLayout |
|
14 |
android:id="@+id/tabLayout" |
|
15 |
android:layout_width="match_parent" |
|
16 |
android:layout_height="wrap_content" |
|
17 |
android:orientation="vertical" > |
|
18 |
</LinearLayout> |
|
19 |
|
|
20 |
</ScrollView> |
|
21 |
|
|
22 |
</LinearLayout> |
src/main/res/layout/scores_tab2.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<ScrollView |
|
8 |
android:id="@+id/tabScrollView2" |
|
9 |
android:layout_width="match_parent" |
|
10 |
android:layout_height="match_parent"> |
|
11 |
|
|
12 |
<LinearLayout |
|
13 |
android:id="@+id/tabLayout2" |
|
14 |
android:layout_width="match_parent" |
|
15 |
android:layout_height="wrap_content" |
|
16 |
android:orientation="vertical" > |
|
17 |
</LinearLayout> |
|
18 |
|
|
19 |
</ScrollView> |
|
20 |
|
|
21 |
</LinearLayout> |
src/main/res/layout/scores_tab3.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<ScrollView |
|
8 |
android:id="@+id/tabScrollView3" |
|
9 |
android:layout_width="match_parent" |
|
10 |
android:layout_height="match_parent"> |
|
11 |
|
|
12 |
<LinearLayout |
|
13 |
android:id="@+id/tabLayout3" |
|
14 |
android:layout_width="match_parent" |
|
15 |
android:layout_height="wrap_content" |
|
16 |
android:orientation="vertical" > |
|
17 |
</LinearLayout> |
|
18 |
|
|
19 |
</ScrollView> |
|
20 |
|
|
21 |
</LinearLayout> |
src/main/res/layout/scores_tab4.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<ScrollView |
|
8 |
android:id="@+id/tabScrollView4" |
|
9 |
android:layout_width="match_parent" |
|
10 |
android:layout_height="match_parent"> |
|
11 |
|
|
12 |
<LinearLayout |
|
13 |
android:id="@+id/tabLayout4" |
|
14 |
android:layout_width="match_parent" |
|
15 |
android:layout_height="wrap_content" |
|
16 |
android:orientation="vertical" > |
|
17 |
</LinearLayout> |
|
18 |
|
|
19 |
</ScrollView> |
|
20 |
|
|
21 |
</LinearLayout> |
src/main/res/layout/scores_tab5.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<ScrollView |
|
8 |
android:id="@+id/tabScrollView5" |
|
9 |
android:layout_width="match_parent" |
|
10 |
android:layout_height="match_parent"> |
|
11 |
|
|
12 |
<LinearLayout |
|
13 |
android:id="@+id/tabLayout5" |
|
14 |
android:layout_width="match_parent" |
|
15 |
android:layout_height="wrap_content" |
|
16 |
android:orientation="vertical" > |
|
17 |
</LinearLayout> |
|
18 |
|
|
19 |
</ScrollView> |
|
20 |
|
|
21 |
</LinearLayout> |
Also available in: Unified diff
Improvements