| 20 |
20 |
package org.distorted.patterns;
|
| 21 |
21 |
|
| 22 |
22 |
import java.util.Vector;
|
| 23 |
|
import android.graphics.Paint;
|
| 24 |
23 |
|
| 25 |
24 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 26 |
25 |
|
| ... | ... | |
| 31 |
30 |
public static final int NUM_CUBES = MAX_CUBE-MIN_CUBE+1;
|
| 32 |
31 |
|
| 33 |
32 |
private int[] numCategories = new int[NUM_CUBES];
|
| 34 |
|
private static String buffer="";
|
| 35 |
|
private static Paint mPaint = new Paint();
|
| 36 |
|
private static int mWidth;
|
| 37 |
|
|
| 38 |
33 |
private Vector<Category>[] mCategories;
|
| 39 |
|
|
| 40 |
34 |
private static RubikPattern mThis;
|
| 41 |
35 |
|
| 42 |
36 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| ... | ... | |
| 159 |
153 |
private static class Pattern
|
| 160 |
154 |
{
|
| 161 |
155 |
private String name;
|
| 162 |
|
private String shortname=null;
|
| 163 |
156 |
private String moves;
|
| 164 |
|
private int curmove;
|
| 165 |
|
private int nummove;
|
|
157 |
private int curMove;
|
|
158 |
private int numMove;
|
| 166 |
159 |
|
| 167 |
160 |
/////////////////////////////////////////////////////////////
|
| 168 |
161 |
|
| ... | ... | |
| 170 |
163 |
{
|
| 171 |
164 |
name=n;
|
| 172 |
165 |
moves=m;
|
| 173 |
|
nummove = moves.length()/4;
|
| 174 |
|
curmove=nummove;
|
|
166 |
numMove = moves.length()/4;
|
|
167 |
curMove=numMove;
|
| 175 |
168 |
}
|
| 176 |
169 |
|
| 177 |
170 |
/////////////////////////////////////////////////////////////
|
| 178 |
171 |
|
| 179 |
172 |
String getName()
|
| 180 |
173 |
{
|
| 181 |
|
if( shortname==null ) shortname=cutPatternName(name);
|
| 182 |
|
return shortname;
|
|
174 |
return name;
|
| 183 |
175 |
}
|
| 184 |
176 |
|
| 185 |
177 |
/////////////////////////////////////////////////////////////
|
| 186 |
178 |
|
| 187 |
179 |
int getNumMove()
|
| 188 |
180 |
{
|
| 189 |
|
return nummove;
|
|
181 |
return numMove;
|
| 190 |
182 |
}
|
| 191 |
183 |
|
| 192 |
184 |
/////////////////////////////////////////////////////////////
|
| 193 |
185 |
|
| 194 |
186 |
int getCurMove()
|
| 195 |
187 |
{
|
| 196 |
|
return curmove;
|
|
188 |
return curMove;
|
| 197 |
189 |
}
|
| 198 |
190 |
|
| 199 |
191 |
/////////////////////////////////////////////////////////////
|
| 200 |
192 |
|
| 201 |
193 |
String retNextMove()
|
| 202 |
194 |
{
|
| 203 |
|
curmove++;
|
|
195 |
curMove++;
|
| 204 |
196 |
|
| 205 |
|
if( curmove>nummove)
|
|
197 |
if( curMove>numMove)
|
| 206 |
198 |
{
|
| 207 |
|
curmove= 0;
|
|
199 |
curMove= 0;
|
| 208 |
200 |
return retInitializationString();
|
| 209 |
201 |
}
|
| 210 |
202 |
else
|
| 211 |
203 |
{
|
| 212 |
|
curmove--;
|
| 213 |
|
return moves.substring(4*curmove-4,4*curmove);
|
|
204 |
curMove--;
|
|
205 |
return moves.substring(4*curMove-4,4*curMove);
|
| 214 |
206 |
}
|
| 215 |
207 |
}
|
| 216 |
208 |
|
| ... | ... | |
| 218 |
210 |
|
| 219 |
211 |
String retPrevMove()
|
| 220 |
212 |
{
|
| 221 |
|
curmove--;
|
|
213 |
curMove--;
|
| 222 |
214 |
|
| 223 |
|
if( curmove<0)
|
|
215 |
if( curMove<0)
|
| 224 |
216 |
{
|
| 225 |
|
curmove=nummove;
|
|
217 |
curMove=numMove;
|
| 226 |
218 |
return retInitializationString();
|
| 227 |
219 |
}
|
| 228 |
220 |
else
|
| 229 |
221 |
{
|
| 230 |
|
curmove++;
|
| 231 |
|
return moves.substring(4*curmove,4*curmove+4);
|
|
222 |
curMove++;
|
|
223 |
return moves.substring(4*curMove,4*curMove+4);
|
| 232 |
224 |
}
|
| 233 |
225 |
}
|
| 234 |
226 |
|
| ... | ... | |
| 236 |
228 |
|
| 237 |
229 |
String retInitializationString()
|
| 238 |
230 |
{
|
| 239 |
|
return moves.substring(0,4*curmove);
|
|
231 |
return moves.substring(0,4*curMove);
|
| 240 |
232 |
}
|
| 241 |
233 |
}
|
| 242 |
234 |
|
| ... | ... | |
| 244 |
236 |
|
| 245 |
237 |
private RubikPattern()
|
| 246 |
238 |
{
|
| 247 |
|
mPaint.setTextSize(24);
|
| 248 |
|
mWidth = 300;
|
| 249 |
239 |
mCategories = new Vector[NUM_CUBES];
|
| 250 |
240 |
|
| 251 |
241 |
initializeCategories(0, RubikPatternData2.patterns);
|
| ... | ... | |
| 286 |
276 |
}
|
| 287 |
277 |
}
|
| 288 |
278 |
|
| 289 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 290 |
|
|
| 291 |
|
private static String cutPatternName(String n)
|
| 292 |
|
{
|
| 293 |
|
int len1 = (int)mPaint.measureText(n);
|
| 294 |
|
|
| 295 |
|
if( len1>mWidth )
|
| 296 |
|
{
|
| 297 |
|
int l = n.length();
|
| 298 |
|
|
| 299 |
|
while( l>=2 && len1>mWidth )
|
| 300 |
|
{
|
| 301 |
|
l--;
|
| 302 |
|
buffer = n.substring(0,l);
|
| 303 |
|
len1 = (int)mPaint.measureText(buffer);
|
| 304 |
|
}
|
| 305 |
|
|
| 306 |
|
return buffer+"...";
|
| 307 |
|
}
|
| 308 |
|
|
| 309 |
|
return n;
|
| 310 |
|
}
|
| 311 |
|
|
| 312 |
279 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 313 |
280 |
// PUBLIC API
|
| 314 |
281 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Minor.