93 |
93 |
return id<0 ? -id : id;
|
94 |
94 |
}
|
95 |
95 |
|
96 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
98 |
|
private String getUnsubmittedList(int mode)
|
99 |
|
{
|
100 |
|
ObjectList list;
|
101 |
|
StringBuilder builder = new StringBuilder();
|
102 |
|
boolean first = true;
|
103 |
|
int[] sizes;
|
104 |
|
int length;
|
105 |
|
|
106 |
|
for(int object=0; object<NUM_OBJECTS; object++)
|
107 |
|
{
|
108 |
|
list = ObjectList.getObject(object);
|
109 |
|
sizes = list.getSizes();
|
110 |
|
length = sizes.length;
|
111 |
|
|
112 |
|
for(int size=0; size<length; size++)
|
113 |
|
{
|
114 |
|
for(int level=0; level<MAX_LEVEL; level++)
|
115 |
|
{
|
116 |
|
if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
|
117 |
|
{
|
118 |
|
if( !first ) builder.append(',');
|
119 |
|
else first=false;
|
120 |
|
|
121 |
|
switch(mode)
|
122 |
|
{
|
123 |
|
case 0: builder.append(list.name());
|
124 |
|
builder.append("_");
|
125 |
|
builder.append(sizes[size]);
|
126 |
|
break;
|
127 |
|
case 1: builder.append(level);
|
128 |
|
break;
|
129 |
|
case 2: builder.append(mRecords[object][size][level]);
|
130 |
|
break;
|
131 |
|
}
|
132 |
|
}
|
133 |
|
}
|
134 |
|
}
|
135 |
|
}
|
136 |
|
|
137 |
|
return builder.toString();
|
138 |
|
}
|
139 |
|
|
140 |
96 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
97 |
// PUBLIC API
|
142 |
98 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
153 |
109 |
|
154 |
110 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155 |
111 |
|
156 |
|
public void savePreferences(SharedPreferences.Editor editor)
|
|
112 |
public synchronized void savePreferences(SharedPreferences.Editor editor)
|
157 |
113 |
{
|
158 |
114 |
StringBuilder builder = new StringBuilder();
|
159 |
115 |
ObjectList list;
|
... | ... | |
195 |
151 |
|
196 |
152 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197 |
153 |
|
198 |
|
public void restorePreferences(SharedPreferences preferences)
|
|
154 |
public synchronized void restorePreferences(SharedPreferences preferences)
|
199 |
155 |
{
|
200 |
156 |
String recordStr, subStr, nameStr, sizeStr, timeStr, submStr;
|
201 |
157 |
int start, end, equals, underscore, comma;
|
... | ... | |
242 |
198 |
}
|
243 |
199 |
else
|
244 |
200 |
{
|
245 |
|
android.util.Log.e("solv", "error: size="+sizeIndex+" subm="+subm);
|
|
201 |
android.util.Log.e("scores", "error: size="+sizeIndex+" subm="+subm);
|
246 |
202 |
}
|
247 |
203 |
}
|
248 |
204 |
else
|
249 |
205 |
{
|
250 |
|
android.util.Log.e("solv", "error: object="+object);
|
|
206 |
android.util.Log.e("scores", "error: object="+object);
|
251 |
207 |
}
|
252 |
208 |
}
|
253 |
209 |
}
|
... | ... | |
264 |
220 |
|
265 |
221 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
266 |
222 |
|
267 |
|
public boolean setRecord(int object, int size, int level, long timeTaken)
|
|
223 |
public synchronized boolean setRecord(int object, int size, int level, long timeTaken)
|
268 |
224 |
{
|
269 |
225 |
int maxsize = ObjectList.getObject(object).getSizes().length;
|
270 |
226 |
|
... | ... | |
304 |
260 |
|
305 |
261 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
306 |
262 |
|
307 |
|
void successfulSubmit()
|
|
263 |
synchronized void successfulSubmit()
|
308 |
264 |
{
|
309 |
265 |
mNameIsVerified = true;
|
310 |
266 |
|
... | ... | |
350 |
306 |
|
351 |
307 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
352 |
308 |
|
353 |
|
public boolean isSolved(int object, int size, int level)
|
|
309 |
public synchronized boolean isSolved(int object, int size, int level)
|
354 |
310 |
{
|
355 |
311 |
int maxsize = ObjectList.getObject(object).getSizes().length;
|
356 |
312 |
|
... | ... | |
364 |
320 |
|
365 |
321 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366 |
322 |
|
367 |
|
public long getRecord(int object, int size, int level)
|
|
323 |
public synchronized long getRecord(int object, int size, int level)
|
368 |
324 |
{
|
369 |
325 |
int maxsize = ObjectList.getObject(object).getSizes().length;
|
370 |
326 |
|
... | ... | |
378 |
334 |
|
379 |
335 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
380 |
336 |
|
381 |
|
public boolean isSubmitted(int object, int size, int level)
|
|
337 |
public synchronized boolean isSubmitted(int object, int size, int level)
|
382 |
338 |
{
|
383 |
339 |
int maxsize = ObjectList.getObject(object).getSizes().length;
|
384 |
340 |
|
... | ... | |
434 |
390 |
|
435 |
391 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
436 |
392 |
|
437 |
|
boolean thereAreUnsubmittedRecords()
|
|
393 |
synchronized boolean thereAreUnsubmittedRecords()
|
438 |
394 |
{
|
439 |
395 |
ObjectList list;
|
440 |
396 |
int length;
|
... | ... | |
459 |
415 |
|
460 |
416 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
461 |
417 |
|
462 |
|
String getUnsubmittedObjlist()
|
|
418 |
synchronized String getRecordList(String strObj, String strLvl, String strTim)
|
463 |
419 |
{
|
464 |
|
return getUnsubmittedList(0);
|
465 |
|
}
|
|
420 |
ObjectList list;
|
|
421 |
StringBuilder builderObj = new StringBuilder();
|
|
422 |
StringBuilder builderLvl = new StringBuilder();
|
|
423 |
StringBuilder builderTim = new StringBuilder();
|
|
424 |
boolean first = true;
|
|
425 |
int[] sizes;
|
|
426 |
int length;
|
466 |
427 |
|
467 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
428 |
for(int object=0; object<NUM_OBJECTS; object++)
|
|
429 |
{
|
|
430 |
list = ObjectList.getObject(object);
|
|
431 |
sizes = list.getSizes();
|
|
432 |
length = sizes.length;
|
468 |
433 |
|
469 |
|
String getUnsubmittedLevellist()
|
470 |
|
{
|
471 |
|
return getUnsubmittedList(1);
|
472 |
|
}
|
|
434 |
for(int size=0; size<length; size++)
|
|
435 |
{
|
|
436 |
for(int level=0; level<MAX_LEVEL; level++)
|
|
437 |
{
|
|
438 |
if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
|
|
439 |
{
|
|
440 |
if( !first )
|
|
441 |
{
|
|
442 |
builderObj.append(',');
|
|
443 |
builderLvl.append(',');
|
|
444 |
builderTim.append(',');
|
|
445 |
}
|
|
446 |
else
|
|
447 |
{
|
|
448 |
first=false;
|
|
449 |
}
|
473 |
450 |
|
474 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
451 |
builderObj.append(list.name());
|
|
452 |
builderObj.append("_");
|
|
453 |
builderObj.append(sizes[size]);
|
|
454 |
builderLvl.append(level);
|
|
455 |
builderTim.append(mRecords[object][size][level]);
|
|
456 |
}
|
|
457 |
}
|
|
458 |
}
|
|
459 |
}
|
475 |
460 |
|
476 |
|
String getUnsubmittedTimelist()
|
477 |
|
{
|
478 |
|
return getUnsubmittedList(2);
|
|
461 |
return strObj+builderObj.toString()+strLvl+builderLvl.toString()+strTim+builderTim.toString();
|
479 |
462 |
}
|
480 |
463 |
}
|
Make the RubikScores class thread-safe.