Revision 1c90c64a
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 47 |
|
48 |
public void receive(final String[][][] country, final String[][][] name, final String[][][] time)
|
|
48 |
public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
|
|
49 | 49 |
{ |
50 | 50 |
prepareView(); |
51 | 51 |
|
52 | 52 |
int c = mViewPager.getCurrentItem(); |
53 | 53 |
|
54 |
addPage(mViews[c],country[c],name[c],time[c]); |
|
54 |
addPage(c, mViews[c],country[c],name[c],time[c]);
|
|
55 | 55 |
|
56 | 56 |
for(int i=0; i<mNumTabs; i++) |
57 | 57 |
{ |
58 | 58 |
if( i==c ) continue; |
59 | 59 |
|
60 |
addPage(mViews[i],country[i],name[i],time[i]); |
|
60 |
addPage(i, mViews[i],country[i],name[i],time[i]);
|
|
61 | 61 |
} |
62 | 62 |
} |
63 | 63 |
|
... | ... | |
88 | 88 |
|
89 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
90 | 90 |
|
91 |
private void addPage(final RubikDialogScoresView view, final String[][] country, final String[][] name, final String[][] time)
|
|
91 |
private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time)
|
|
92 | 92 |
{ |
93 | 93 |
for(int i=0; i<MAX_SCRAMBLE; i++) |
94 | 94 |
{ |
95 |
final LinearLayout section = view.createSection(mAct, i, country[i], name[i], time[i]); |
|
95 |
final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]);
|
|
96 | 96 |
|
97 | 97 |
mAct.runOnUiThread(new Runnable() |
98 | 98 |
{ |
src/main/java/org/distorted/dialog/RubikDialogScoresView.java | ||
---|---|---|
30 | 30 |
import android.widget.TextView; |
31 | 31 |
|
32 | 32 |
import org.distorted.magic.R; |
33 |
import org.distorted.object.RubikObjectList; |
|
34 |
import org.distorted.scores.RubikScores; |
|
35 |
|
|
33 | 36 |
import static org.distorted.scores.RubikScoresDownloader.MAX_PLACES; |
34 | 37 |
|
35 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
64 | 67 |
|
65 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
66 | 69 |
|
67 |
LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
|
|
70 |
LinearLayout createSection(FragmentActivity act, int tab, int scramble, final String[] country, final String[] name, final float[] time)
|
|
68 | 71 |
{ |
69 | 72 |
LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null); |
70 | 73 |
TextView text = level.findViewById(R.id.scoresScrambleTitle); |
... | ... | |
73 | 76 |
Resources res = act.getResources(); |
74 | 77 |
String packageName = act.getPackageName(); |
75 | 78 |
|
76 |
for(int j=0; j<MAX_PLACES; j++) |
|
77 |
{ |
|
78 |
if( name[j] != null ) |
|
79 |
{ |
|
80 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
81 |
|
|
82 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
83 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
84 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
79 |
int object = RubikObjectList.unpackObject(tab); |
|
80 |
int size = RubikObjectList.unpackSize(tab); |
|
81 |
RubikScores scores = RubikScores.getInstance(); |
|
85 | 82 |
|
86 |
int resID = res.getIdentifier( country[j], "drawable", packageName); |
|
83 |
boolean inserted = false; |
|
84 |
long myRecordInSeconds = scores.getRecord(object, size, scramble); |
|
85 |
String myName = scores.getName(); |
|
86 |
int myCountryID = scores.getCountryID(); |
|
87 |
String myRecord = ( myRecordInSeconds<RubikScores.NO_RECORD ) ? Float.toString((myRecordInSeconds/100)/10.0f) : "??"; |
|
88 |
String theirTime; |
|
89 |
int theirCountryID; |
|
87 | 90 |
|
88 |
imgCoun.setImageResource(resID!=0 ? resID : R.drawable.unk); |
|
89 |
textName.setText(name[j]); |
|
90 |
textTime.setText(time[j]); |
|
91 |
int white = res.getColor(R.color.white); |
|
92 |
int red = res.getColor(R.color.red); |
|
91 | 93 |
|
94 |
for(int j=0; j<MAX_PLACES-1; j++) |
|
95 |
{ |
|
96 |
if( name[j] != null ) |
|
97 |
{ |
|
98 |
if( myRecordInSeconds<time[j] && !inserted ) |
|
99 |
{ |
|
100 |
inserted = true; |
|
101 |
View row = createRow(act, myCountryID, myName, myRecord, red); |
|
102 |
level.addView(row); |
|
103 |
} |
|
104 |
|
|
105 |
theirCountryID = res.getIdentifier( country[j], "drawable", packageName); |
|
106 |
theirTime = Float.toString(time[j]); |
|
107 |
View row = createRow(act, theirCountryID, name[j], theirTime, white); |
|
92 | 108 |
level.addView(row); |
93 | 109 |
} |
94 | 110 |
} |
95 | 111 |
|
112 |
if( !inserted ) |
|
113 |
{ |
|
114 |
View row = createRow(act, myCountryID, myName, myRecord, red); |
|
115 |
level.addView(row); |
|
116 |
} |
|
117 |
|
|
96 | 118 |
return level; |
97 | 119 |
} |
98 | 120 |
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
private View createRow(FragmentActivity act, int countryID, String name, String time, int color) |
|
124 |
{ |
|
125 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
126 |
|
|
127 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
128 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
129 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
130 |
|
|
131 |
imgCoun.setImageResource(countryID!=0 ? countryID : R.drawable.unk); |
|
132 |
textName.setText(name); |
|
133 |
textTime.setText(time); |
|
134 |
|
|
135 |
textName.setTextColor(color); |
|
136 |
textTime.setTextColor(color); |
|
137 |
|
|
138 |
return row; |
|
139 |
} |
|
140 |
|
|
99 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 142 |
// needs to run on UI thread |
101 | 143 |
|
src/main/java/org/distorted/scores/RubikScores.java | ||
---|---|---|
20 | 20 |
package org.distorted.scores; |
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 |
|
|
24 |
import org.distorted.magic.R; |
|
23 | 25 |
import org.distorted.object.RubikObjectList; |
24 | 26 |
|
25 | 27 |
import static org.distorted.object.RubikObjectList.MAX_SIZE; |
... | ... | |
31 | 33 |
|
32 | 34 |
public class RubikScores |
33 | 35 |
{ |
34 |
private static final long NO_RECORD = Integer.MAX_VALUE;
|
|
36 |
public static final long NO_RECORD = Long.MAX_VALUE;
|
|
35 | 37 |
private static RubikScores mThis; |
36 | 38 |
|
37 | 39 |
private long[][][] mRecords; |
... | ... | |
39 | 41 |
private boolean mNameIsVerified; |
40 | 42 |
private int mNumRuns; |
41 | 43 |
private int mNumPlays; |
44 |
private int mCountryID; |
|
42 | 45 |
|
43 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 47 |
|
... | ... | |
53 | 56 |
mRecords[i][j][k] = NO_RECORD; |
54 | 57 |
} |
55 | 58 |
|
56 |
mName = ""; |
|
59 |
mName = "YOU";
|
|
57 | 60 |
mNameIsVerified = false; |
58 | 61 |
mNumPlays= -1; |
59 | 62 |
mNumRuns = -1; |
63 |
mCountryID = R.drawable.unk; |
|
60 | 64 |
} |
61 | 65 |
|
62 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
116 | 120 |
{ |
117 | 121 |
String recordStr, subStr, nameStr, sizeStr, timeStr; |
118 | 122 |
int start, end, equals, underscore; |
119 |
int object, size, time; |
|
123 |
int object, size; |
|
124 |
long time; |
|
120 | 125 |
|
121 | 126 |
for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++) |
122 | 127 |
{ |
... | ... | |
143 | 148 |
|
144 | 149 |
object = RubikObjectList.getOrdinal(nameStr); |
145 | 150 |
size = RubikObjectList.getSize(object,Integer.parseInt(sizeStr)); |
146 |
time = Integer.parseInt(timeStr);
|
|
151 |
time = Long.parseLong(timeStr);
|
|
147 | 152 |
|
148 | 153 |
if( object>=0 && object< NUM_OBJECTS && size>=0 && size<MAX_SIZE ) |
149 | 154 |
{ |
150 | 155 |
mRecords[object][size][scramble] = time; |
151 | 156 |
|
152 |
if( time<Integer.MAX_VALUE )
|
|
157 |
if( time<NO_RECORD )
|
|
153 | 158 |
{ |
154 | 159 |
android.util.Log.e("solv", "Set record for: object="+object+" size="+size+" scramble="+scramble+" time: "+time); |
155 | 160 |
} |
... | ... | |
162 | 167 |
} |
163 | 168 |
} |
164 | 169 |
|
165 |
mName = preferences.getString("scores_name" , "");
|
|
170 |
mName = preferences.getString("scores_name" , "YOU" );
|
|
166 | 171 |
mNameIsVerified = preferences.getBoolean("scores_isVerified", false); |
167 | 172 |
mNumPlays = preferences.getInt("scores_numPlays", 0); |
168 | 173 |
mNumRuns = preferences.getInt("scores_numRuns" , 0); |
... | ... | |
199 | 204 |
} |
200 | 205 |
|
201 | 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
207 |
// TODO |
|
202 | 208 |
|
203 | 209 |
public void setName(String newName) |
204 | 210 |
{ |
... | ... | |
206 | 212 |
} |
207 | 213 |
|
208 | 214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 |
// TODO |
|
209 | 216 |
|
210 | 217 |
public void verifyName() |
211 | 218 |
{ |
212 | 219 |
mNameIsVerified = true; |
213 | 220 |
} |
214 | 221 |
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
// TODO |
|
224 |
|
|
225 |
public void setCountry(int country) |
|
226 |
{ |
|
227 |
mCountryID = country; |
|
228 |
} |
|
229 |
|
|
215 | 230 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
216 | 231 |
|
217 | 232 |
public long getRecord(int object, int size, int scramble) |
218 | 233 |
{ |
219 | 234 |
int maxsize = RubikObjectList.getObject(object).getSizes().length; |
220 | 235 |
|
221 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=1 && scramble<=MAX_SCRAMBLE )
|
|
236 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
|
|
222 | 237 |
{ |
223 | 238 |
return mRecords[object][size][scramble]; |
224 | 239 |
} |
... | ... | |
227 | 242 |
} |
228 | 243 |
|
229 | 244 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
245 |
// TODO |
|
246 |
|
|
247 |
public boolean isVerified() |
|
248 |
{ |
|
249 |
return mNameIsVerified; |
|
250 |
} |
|
251 |
|
|
252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
253 |
// TODO |
|
230 | 254 |
|
231 | 255 |
public int getNumPlays() |
232 | 256 |
{ |
... | ... | |
249 | 273 |
|
250 | 274 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
251 | 275 |
|
252 |
public boolean isVerified()
|
|
276 |
public int getCountryID()
|
|
253 | 277 |
{ |
254 |
return mNameIsVerified;
|
|
278 |
return mCountryID;
|
|
255 | 279 |
} |
256 | 280 |
} |
src/main/java/org/distorted/scores/RubikScoresDownloader.java | ||
---|---|---|
34 | 34 |
{ |
35 | 35 |
public interface Receiver |
36 | 36 |
{ |
37 |
void receive(String[][][] country, String[][][] name, String[][][] time);
|
|
37 |
void receive(String[][][] country, String[][][] name, float[][][] time);
|
|
38 | 38 |
void exception(String exception); |
39 | 39 |
} |
40 | 40 |
|
... | ... | |
91 | 91 |
private static String mScores = ""; |
92 | 92 |
private static String[][][] mCountry = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES]; |
93 | 93 |
private static String[][][] mName = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES]; |
94 |
private static String[][][] mTime = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
|
|
94 |
private static float[][][] mTime = new float[mTotal][MAX_SCRAMBLE][MAX_PLACES];
|
|
95 | 95 |
|
96 | 96 |
private static int[][] mPlaces = new int[mTotal][MAX_SCRAMBLE]; |
97 | 97 |
|
... | ... | |
138 | 138 |
String name = row.substring(s3+1, s4); |
139 | 139 |
int time = Integer.parseInt( row.substring(s4+1,s5) ); |
140 | 140 |
String country = row.substring(s5+1, s6); |
141 |
String realTime= String.valueOf(time/10.0f); |
|
142 | 141 |
|
143 | 142 |
if(level>=0 && level<MAX_SCRAMBLE && place>=0 && place<MAX_PLACES) |
144 | 143 |
{ |
... | ... | |
149 | 148 |
|
150 | 149 |
mCountry[size][level][place] = country; |
151 | 150 |
mName [size][level][place] = name; |
152 |
mTime [size][level][place] = realTime;
|
|
151 |
mTime [size][level][place] = ((float)time)/10.0f;
|
|
153 | 152 |
} |
154 | 153 |
} |
155 | 154 |
} |
src/main/res/layout/dialog_scores_scramble_row.xml | ||
---|---|---|
12 | 12 |
android:layout_height="match_parent" |
13 | 13 |
android:layout_weight="1.5" |
14 | 14 |
android:textSize="20sp" |
15 |
android:gravity="left"
|
|
15 |
android:gravity="start"
|
|
16 | 16 |
android:background="@color/black" |
17 |
android:paddingLeft="0dp"/>
|
|
17 |
android:paddingStart="0dp"/>
|
|
18 | 18 |
|
19 | 19 |
<TextView |
20 | 20 |
android:id="@+id/scoresScrambleRowName" |
... | ... | |
22 | 22 |
android:layout_height="match_parent" |
23 | 23 |
android:layout_weight="1" |
24 | 24 |
android:textSize="20sp" |
25 |
android:gravity="left"
|
|
25 |
android:gravity="start"
|
|
26 | 26 |
android:background="@color/black" |
27 | 27 |
/> |
28 | 28 |
|
... | ... | |
32 | 32 |
android:layout_height="match_parent" |
33 | 33 |
android:layout_weight="1.5" |
34 | 34 |
android:textSize="20sp" |
35 |
android:gravity="right"
|
|
35 |
android:gravity="end"
|
|
36 | 36 |
android:background="@color/black" |
37 |
android:paddingRight="5dp"
|
|
37 |
android:paddingEnd="5dp"
|
|
38 | 38 |
/> |
39 | 39 |
</LinearLayout> |
src/main/res/values/colors.xml | ||
---|---|---|
6 | 6 |
<color name="red">#ffff0000</color> |
7 | 7 |
<color name="grey">#ff333333</color> |
8 | 8 |
<color name="black">#ff010101</color> |
9 |
<color name="white">#ffffffff</color> |
|
9 | 10 |
</resources> |
Also available in: Unified diff
Incorporate myRecords into the Scores dialog.