Project

General

Profile

« Previous | Next » 

Revision 6a083c6a

Added by Leszek Koltunski about 3 years ago

- report the Graphics driver's Renderer and Version.
- new Diamond, Skewb2 and Skewb3 meshes.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogAbout.java
36 36
import android.view.LayoutInflater;
37 37
import android.view.View;
38 38
import android.view.Window;
39
import android.view.WindowManager;
40 39
import android.widget.Button;
41 40
import android.widget.TextView;
42 41

  
......
104 103
    else
105 104
      {
106 105
      text4.setVisibility(View.GONE);
106
      /*
107
      text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
108
      String version = DistortedLibrary.getDriverVersion();
109
      text4.setText(version);
110
      */
107 111
      }
108 112

  
109 113
    builder.setView(view);
src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
38 38
import org.distorted.main.R;
39 39
import org.distorted.main.RubikActivity;
40 40
import org.distorted.objects.ObjectList;
41
import org.distorted.scores.RubikScores;
41
import org.distorted.network.RubikScores;
42 42
import org.distorted.states.StateList;
43 43
import org.distorted.states.RubikStatePlay;
44 44

  
src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
31 31
import android.widget.LinearLayout;
32 32

  
33 33
import org.distorted.main.R;
34
import org.distorted.scores.RubikScores;
35
import org.distorted.scores.RubikScoresDownloader;
34
import org.distorted.network.RubikScores;
35
import org.distorted.network.RubikNetwork;
36 36
import org.distorted.objects.ObjectList;
37 37
import org.distorted.states.RubikStatePlay;
38 38

  
39 39
///////////////////////////////////////////////////////////////////////////////////////////////////
40 40

  
41
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver
41
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikNetwork.Receiver
42 42
  {
43 43
  private final FragmentActivity mAct;
44 44
  private final RubikDialogScores mDialog;
......
242 242

  
243 243
    if( allCreated )
244 244
      {
245
      RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
245
      RubikNetwork network = RubikNetwork.getInstance();
246 246

  
247
      if( mIsSubmitting )  downloader.submit  ( this, mAct );
248
      else                 downloader.download( this, mAct );
247
      if( mIsSubmitting )  network.submit  ( this, mAct );
248
      else                 network.download( this, mAct );
249 249
      }
250 250

  
251 251
    return mViews[position];
src/main/java/org/distorted/dialogs/RubikDialogScoresView.java
34 34
import org.distorted.main.R;
35 35
import org.distorted.main.RubikActivity;
36 36
import org.distorted.objects.ObjectList;
37
import org.distorted.scores.RubikScores;
37
import org.distorted.network.RubikScores;
38 38

  
39
import static org.distorted.scores.RubikScoresDownloader.MAX_PLACES;
39
import static org.distorted.network.RubikNetwork.MAX_PLACES;
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
42 42

  
src/main/java/org/distorted/dialogs/RubikDialogSetName.java
41 41
import org.distorted.main.R;
42 42
import org.distorted.main.RubikActivity;
43 43
import org.distorted.objects.ObjectList;
44
import org.distorted.scores.RubikScores;
44
import org.distorted.network.RubikScores;
45 45
import org.distorted.states.StateList;
46 46
import org.distorted.states.RubikStatePlay;
47 47

  
src/main/java/org/distorted/main/RubikActivity.java
42 42
import org.distorted.library.main.DistortedLibrary;
43 43

  
44 44
import org.distorted.objects.TwistyObject;
45
import org.distorted.scores.RubikScores;
46
import org.distorted.scores.RubikScoresDownloader;
45
import org.distorted.network.RubikScores;
46
import org.distorted.network.RubikNetwork;
47 47
import org.distorted.objects.ObjectList;
48 48
import org.distorted.states.StateList;
49 49
import org.distorted.states.RubikStatePlay;
......
227 227
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
228 228
      view.onPause();
229 229
      DistortedLibrary.onPause(0);
230
      RubikScoresDownloader.onPause();
230
      RubikNetwork.onPause();
231 231
      savePreferences();
232 232
      }
233 233

  
src/main/java/org/distorted/main/RubikPreRender.java
41 41
import org.distorted.effects.scramble.ScrambleEffect;
42 42
import org.distorted.objects.TwistyObject;
43 43
import org.distorted.objects.ObjectList;
44
import org.distorted.scores.RubikScores;
44
import org.distorted.network.RubikScores;
45 45
import org.distorted.states.RubikStatePlay;
46 46
import org.distorted.states.StateList;
47 47
import org.distorted.states.RubikStateSolving;
src/main/java/org/distorted/main/RubikRenderer.java
29 29
import org.distorted.library.main.DistortedLibrary;
30 30
import org.distorted.library.main.DistortedScreen;
31 31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.network.RubikNetwork;
32 33

  
33 34
import javax.microedition.khronos.egl.EGLConfig;
34 35
import javax.microedition.khronos.opengles.GL10;
......
45 46
   private final DistortedScreen mScreen;
46 47
   private final Fps mFPS;
47 48
   private boolean mErrorShown;
49
   private boolean mDebugSent;
48 50

  
49 51
   private static class Fps
50 52
     {
......
131 133
      BaseEffect.Type.enableEffects();
132 134

  
133 135
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
136

  
137
      if( !mDebugSent )
138
        {
139
        mDebugSent= true;
140
        RubikNetwork network = RubikNetwork.getInstance();
141
        network.debug( (RubikActivity)mView.getContext());
142
        }
134 143
      }
135 144

  
136 145
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/network/RubikNetwork.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.network;
21

  
22
import android.app.Activity;
23
import android.content.pm.PackageInfo;
24
import android.content.pm.PackageManager;
25

  
26
import androidx.appcompat.app.AppCompatActivity;
27
import androidx.fragment.app.FragmentActivity;
28

  
29
import org.distorted.library.main.DistortedLibrary;
30
import org.distorted.objects.ObjectList;
31

  
32
import java.io.InputStream;
33
import java.net.HttpURLConnection;
34
import java.net.URL;
35
import java.net.UnknownHostException;
36
import java.security.MessageDigest;
37
import java.security.NoSuchAlgorithmException;
38

  
39
import static org.distorted.objects.ObjectList.MAX_LEVEL;
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
public class RubikNetwork implements Runnable
44
  {
45
  public interface Receiver
46
    {
47
    void receive(String[][][] country, String[][][] name, float[][][] time);
48
    void message(String mess);
49
    void error(String error);
50
    }
51

  
52
  public static final int MAX_PLACES = 10;
53

  
54
  private static final int DOWNLOAD   = 0;
55
  private static final int SUBMIT     = 1;
56
  private static final int DEBUG      = 2;
57
  private static final int IDLE       = 3;
58

  
59
  private final String[] hex = {
60
    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
61
    "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
62
    "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
63
    "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
64
    "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
65
    "%28", "%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f",
66
    "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
67
    "%38", "%39", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f",
68
    "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
69
    "%48", "%49", "%4a", "%4b", "%4c", "%4d", "%4e", "%4f",
70
    "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
71
    "%58", "%59", "%5a", "%5b", "%5c", "%5d", "%5e", "%5f",
72
    "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
73
    "%68", "%69", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f",
74
    "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
75
    "%78", "%79", "%7a", "%7b", "%7c", "%7d", "%7e", "%7f",
76
    "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
77
    "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
78
    "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
79
    "%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
80
    "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
81
    "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
82
    "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
83
    "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf",
84
    "%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7",
85
    "%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf",
86
    "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
87
    "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
88
    "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7",
89
    "%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef",
90
    "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
91
    "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
92
    };
93

  
94
  private static final int mTotal = ObjectList.getTotal();
95
  private static final String[][][] mCountry = new String[mTotal][MAX_LEVEL][MAX_PLACES];
96
  private static final String[][][] mName    = new String[mTotal][MAX_LEVEL][MAX_PLACES];
97
  private static final  float[][][] mTime    = new  float[mTotal][MAX_LEVEL][MAX_PLACES];
98
  private static final int[][] mPlaces = new int[mTotal][MAX_LEVEL];
99

  
100
  private static RubikNetwork mThis;
101
  private static String mScores = "";
102
  private static boolean mRunning = false;
103
  private static int mMode = IDLE;
104
  private static Receiver mReceiver;
105
  private static String mVersion;
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
109
  private static String computeHash(String stringToHash, byte[] salt)
110
    {
111
    String generatedPassword;
112

  
113
    try
114
      {
115
      MessageDigest md = MessageDigest.getInstance("MD5");
116
      md.update(salt);
117
      byte[] bytes = md.digest(stringToHash.getBytes());
118
      StringBuilder sb = new StringBuilder();
119

  
120
      for (byte aByte : bytes)
121
        {
122
        sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1));
123
        }
124

  
125
      generatedPassword = sb.toString();
126
      }
127
    catch (NoSuchAlgorithmException e)
128
      {
129
      return "NoSuchAlgorithm";
130
      }
131

  
132
    return generatedPassword;
133
    }
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

  
137
  private boolean fillValues()
138
    {
139
    int begin=-1 ,end, len = mScores.length();
140
    String row;
141

  
142
    if( len==0 )
143
      {
144
      mReceiver.error("1");
145
      return false;
146
      }
147
    else if( len<=2 )
148
      {
149
      mReceiver.error(mScores);
150
      return false;
151
      }
152

  
153
    for(int i=0; i<mTotal; i++)
154
      for(int j=0; j<MAX_LEVEL; j++)
155
        {
156
        mPlaces[i][j] = 0;
157
        }
158

  
159
    while( begin<len )
160
      {
161
      end = mScores.indexOf('\n', begin+1);
162
      if( end<0 ) end = len;
163

  
164
      try
165
        {
166
        row = mScores.substring(begin+1,end);
167
        fillRow(row);
168
        }
169
      catch(Exception ex)
170
        {
171
        // faulty row - ignore
172
        }
173

  
174
      begin = end;
175
      }
176

  
177
    return true;
178
    }
179

  
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

  
182
  private void fillRow(String row)
183
    {
184
    int s1 = row.indexOf(' ');
185
    int s2 = row.indexOf(' ',s1+1);
186
    int s3 = row.indexOf(' ',s2+1);
187
    int s4 = row.indexOf(' ',s3+1);
188
    int s5 = row.length();
189

  
190
    if( s5>s4 && s4>s3 && s3>s2 && s2>s1 && s1>0 )
191
      {
192
      int object = ObjectList.unpackObjectFromString( row.substring(0,s1) );
193

  
194
      if( object>=0 && object<mTotal )
195
        {
196
        int level      = Integer.parseInt( row.substring(s1+1,s2) );
197
        String name    = row.substring(s2+1, s3);
198
        int time       = Integer.parseInt( row.substring(s3+1,s4) );
199
        String country = row.substring(s4+1, s5);
200

  
201
        if( country.equals("do") ) country = "dm"; // see RubikScores.setCountry()
202

  
203
        if(level>=0 && level<MAX_LEVEL)
204
          {
205
          int p = mPlaces[object][level];
206
          mPlaces[object][level]++;
207

  
208
          mCountry[object][level][p] = country;
209
          mName   [object][level][p] = name;
210
          mTime   [object][level][p] = ((float)(time/10))/100.0f;
211
          }
212
        }
213
      }
214
    else
215
      {
216
      tryDoCommand(row);
217
      }
218
    }
219

  
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

  
222
  private void tryDoCommand(String row)
223
    {
224
    if( row.startsWith("comm") )
225
      {
226
      int colon = row.indexOf(':');
227

  
228
      if( colon>0 )
229
        {
230
        String commandNumber = row.substring(4,colon);
231
        int number;
232

  
233
        try
234
          {
235
          number = Integer.parseInt(commandNumber);
236
          }
237
        catch(NumberFormatException ex)
238
          {
239
          number=0;
240
          }
241

  
242
        if(number==1)
243
          {
244
          String country = row.substring(colon+1);
245
          RubikScores scores = RubikScores.getInstance();
246
          scores.setCountry(country);
247
          }
248
        }
249
      }
250
    }
251

  
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

  
254
  private String URLencode(String s)
255
    {
256
    StringBuilder sbuf = new StringBuilder();
257
    int len = s.length();
258

  
259
    for (int i = 0; i < len; i++)
260
      {
261
      int ch = s.charAt(i);
262

  
263
           if ('A' <= ch && ch <= 'Z') sbuf.append((char)ch);
264
      else if ('a' <= ch && ch <= 'z') sbuf.append((char)ch);
265
      else if ('0' <= ch && ch <= '9') sbuf.append((char)ch);
266
      else if (ch == ' '             ) sbuf.append('+');
267
      else if (ch == '-' || ch == '_'
268
            || ch == '.' || ch == '!'
269
            || ch == '~' || ch == '*'
270
            || ch == '\'' || ch == '('
271
            || ch == ')'             ) sbuf.append((char)ch);
272
      else if (ch <= 0x007f)           sbuf.append(hex[ch]);
273
      else if (ch <= 0x07FF)
274
        {
275
        sbuf.append(hex[0xc0 | (ch >> 6)]);
276
        sbuf.append(hex[0x80 | (ch & 0x3F)]);
277
        }
278
      else
279
        {
280
        sbuf.append(hex[0xe0 | (ch >> 12)]);
281
        sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]);
282
        sbuf.append(hex[0x80 | (ch & 0x3F)]);
283
        }
284
      }
285

  
286
    return sbuf.toString();
287
    }
288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
  private void sendDebug()
292
    {
293
    String url = constructDebugURL();
294

  
295
    try
296
      {
297
      java.net.URL connectURL = new URL(url);
298
      HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
299

  
300
      conn.setDoInput(true);
301
      conn.setDoOutput(true);
302
      conn.setUseCaches(false);
303
      conn.setRequestMethod("GET");
304
      conn.connect();
305
      conn.getOutputStream().flush();
306
      conn.getInputStream();
307
      }
308
    catch( final Exception e )
309
      {
310
      // ignore
311
      }
312
    }
313

  
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

  
316
  private boolean network(String url)
317
    {
318
    try
319
      {
320
      java.net.URL connectURL = new URL(url);
321
      HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
322

  
323
      conn.setDoInput(true);
324
      conn.setDoOutput(true);
325
      conn.setUseCaches(false);
326
      conn.setRequestMethod("GET");
327
      conn.connect();
328
      conn.getOutputStream().flush();
329

  
330
      try( InputStream is = conn.getInputStream() )
331
        {
332
        int ch;
333
        StringBuilder sb = new StringBuilder();
334
        while( ( ch = is.read() ) != -1 )
335
          {
336
          sb.append( (char)ch );
337
          }
338
        mScores = sb.toString();
339
        }
340
      catch( final Exception e)
341
        {
342
        mReceiver.message("Failed to get an answer from the High Scores server");
343
        return false;
344
        }
345
      }
346
    catch( final UnknownHostException e )
347
      {
348
      mReceiver.message("No access to Internet");
349
      return false;
350
      }
351
    catch( final SecurityException e )
352
      {
353
      mReceiver.message("Application not authorized to connect to the Internet");
354
      return false;
355
      }
356
    catch( final Exception e )
357
      {
358
      mReceiver.message(e.getMessage());
359
      return false;
360
      }
361

  
362
    if( mScores.length()==0 )
363
      {
364
      mReceiver.message("Failed to download scores");
365
      return false;
366
      }
367

  
368
    return true;
369
    }
370

  
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

  
373
  private String constructDebugURL()
374
    {
375
    RubikScores scores = RubikScores.getInstance();
376
    String name = URLencode(scores.getName());
377
    int numRuns = scores.getNumRuns();
378
    int numPlay = scores.getNumPlays();
379
    String country = scores.getCountry();
380
    String renderer = DistortedLibrary.getDriverRenderer();
381
    String version  = DistortedLibrary.getDriverVersion();
382

  
383
    renderer = URLencode(renderer);
384
    version  = URLencode(version);
385

  
386
    String url="https://distorted.org/magic/cgi-bin/debugs.cgi";
387
    url += "?n="+name+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion+"d"+"&d="+renderer+"&v="+version;
388

  
389
    return url;
390
    }
391

  
392
///////////////////////////////////////////////////////////////////////////////////////////////////
393

  
394
  private String constructDownloadURL()
395
    {
396
    RubikScores scores = RubikScores.getInstance();
397
    String name = URLencode(scores.getName());
398
    String veri = scores.isVerified() ? name : "";
399
    int numRuns = scores.getNumRuns();
400
    int numPlay = scores.getNumPlays();
401
    String country = scores.getCountry();
402

  
403
    String url="https://distorted.org/magic/cgi-bin/download.cgi";
404
    url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&c="+country+"&e="+mVersion+"d";
405
    url += "&o="+ ObjectList.getObjectList()+"&min=0&max="+MAX_LEVEL+"&l="+MAX_PLACES;
406

  
407
    return url;
408
    }
409

  
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411

  
412
  private String constructSubmitURL()
413
    {
414
    RubikScores scores = RubikScores.getInstance();
415
    String name = URLencode(scores.getName());
416
    String veri = scores.isVerified() ? name : "";
417
    int numRuns = scores.getNumRuns();
418
    int numPlay = scores.getNumPlays();
419
    int deviceID= scores.getDeviceID();
420
    String reclist = scores.getRecordList("&o=","&l=","&t=");
421
    String country = scores.getCountry();
422
    long epoch = System.currentTimeMillis();
423
    String salt = "cuboid";
424

  
425
    String url1="https://distorted.org/magic/cgi-bin/submit.cgi";
426
    String url2 = "n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d";
427
    url2 += reclist+"&c="+country+"&f="+epoch+"&oo="+ ObjectList.getObjectList();
428
    url2 += "&min=0&max="+MAX_LEVEL+"&lo="+MAX_PLACES;
429
    String hash = computeHash( url2, salt.getBytes() );
430

  
431
    return url1 + "?" + url2 + "&h=" + hash;
432
    }
433

  
434
///////////////////////////////////////////////////////////////////////////////////////////////////
435

  
436
  private boolean gottaDownload()
437
    {
438
    return ((mScores.length()==0) && !mRunning);
439
    }
440

  
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

  
443
  @Override
444
  public void run()
445
    {
446
    boolean receiveValues=true;
447

  
448
    try
449
      {
450
      if( mMode==DOWNLOAD && gottaDownload() )
451
        {
452
        mRunning = true;
453
        receiveValues = network(constructDownloadURL());
454
        }
455
      if( mMode==SUBMIT )
456
        {
457
        mRunning = true;
458

  
459
        if( RubikScores.getInstance().thereAreUnsubmittedRecords() )
460
          {
461
          receiveValues = network(constructSubmitURL());
462
          }
463
        }
464
      if( mMode==DEBUG )
465
        {
466
        sendDebug();
467
        receiveValues = false;
468
        mRunning = false;
469
        }
470
      }
471
    catch( Exception e )
472
      {
473
      if( mReceiver!=null ) mReceiver.message("Exception downloading records: "+e.getMessage() );
474
      }
475

  
476
    if( mRunning )
477
      {
478
      receiveValues = fillValues();
479
      mRunning = false;
480
      }
481

  
482
    if( receiveValues )
483
      {
484
      if( mReceiver!=null ) mReceiver.receive(mCountry, mName, mTime);
485

  
486
      if( mMode==SUBMIT )
487
        {
488
        RubikScores.getInstance().successfulSubmit();
489
        }
490
      }
491
    }
492

  
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

  
495
  private RubikNetwork()
496
    {
497

  
498
    }
499

  
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501
// PUBLIC API
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

  
504
  public static void onPause()
505
    {
506
    mRunning = false;
507
    }
508

  
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

  
511
  public static RubikNetwork getInstance()
512
    {
513
    if( mThis==null )
514
      {
515
      mThis = new RubikNetwork();
516
      }
517

  
518
    return mThis;
519
    }
520

  
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

  
523
  private void start(Receiver receiver, Activity act, int mode)
524
    {
525
    mReceiver = receiver;
526
    mMode     = mode;
527

  
528
    try
529
      {
530
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
531
      mVersion = pInfo.versionName;
532
      }
533
    catch (PackageManager.NameNotFoundException e)
534
      {
535
      mVersion = "0.9.2";
536
      }
537

  
538
    Thread networkThrd = new Thread(this);
539
    networkThrd.start();
540
    }
541

  
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

  
544
  public void download(Receiver receiver, FragmentActivity act)
545
    {
546
    start(receiver, act, DOWNLOAD);
547
    }
548

  
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550

  
551
  public void submit(Receiver receiver, FragmentActivity act)
552
    {
553
    start(receiver, act, SUBMIT);
554
    }
555

  
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557

  
558
  public void debug(AppCompatActivity act)
559
    {
560
    start(null, act, DEBUG);
561
    }
562
}
src/main/java/org/distorted/network/RubikScores.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.network;
21

  
22
import android.content.Context;
23
import android.content.SharedPreferences;
24
import android.telephony.TelephonyManager;
25

  
26
import com.google.firebase.crashlytics.FirebaseCrashlytics;
27

  
28
import org.distorted.main.BuildConfig;
29
import org.distorted.objects.ObjectList;
30

  
31
import java.util.UUID;
32

  
33
import static org.distorted.objects.ObjectList.MAX_NUM_OBJECTS;
34
import static org.distorted.objects.ObjectList.NUM_OBJECTS;
35
import static org.distorted.objects.ObjectList.MAX_LEVEL;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
// hold my own scores, and some other statistics.
39

  
40
public class RubikScores
41
  {
42
  public static final long NO_RECORD = Long.MAX_VALUE;
43
  private static RubikScores mThis;
44

  
45
  private final long[][][] mRecords;
46
  private final int [][][] mSubmitted;
47

  
48
  private String mName, mCountry;
49
  private boolean mNameIsVerified;
50
  private int mNumRuns;
51
  private int mNumPlays;
52
  private int mNumWins;
53
  private int mDeviceID;
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  private RubikScores()
58
    {
59
    mRecords   = new long[NUM_OBJECTS][MAX_NUM_OBJECTS][MAX_LEVEL];
60
    mSubmitted = new int [NUM_OBJECTS][MAX_NUM_OBJECTS][MAX_LEVEL];
61

  
62
    for(int i=0; i<NUM_OBJECTS; i++)
63
      for(int j=0; j<MAX_NUM_OBJECTS; j++)
64
        for(int k=0; k<MAX_LEVEL; k++)
65
          {
66
          mRecords[i][j][k]   = NO_RECORD;
67
          mSubmitted[i][j][k] = 0;
68
          }
69

  
70
    mName = "";
71
    mCountry = "un";
72

  
73
    mNameIsVerified = false;
74

  
75
    mNumPlays= -1;
76
    mNumRuns = -1;
77
    mDeviceID= -1;
78
    mNumWins =  0;
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  private int privateGetDeviceID()
84
    {
85
    int id;
86

  
87
    try
88
      {
89
      String s = UUID.randomUUID().toString();
90
      id = s.hashCode();
91
      }
92
    catch(Exception ex)
93
      {
94
      id = 0;
95
      android.util.Log.e("scores", "Exception in getDeviceID()");
96
      }
97

  
98
    return id<0 ? -id : id;
99
    }
100

  
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

  
103
  synchronized void successfulSubmit()
104
    {
105
    mNameIsVerified = true;
106

  
107
    for(int i=0; i<NUM_OBJECTS; i++)
108
      for(int j=0; j<MAX_NUM_OBJECTS; j++)
109
        for(int k=0; k<MAX_LEVEL; k++)
110
          {
111
          mSubmitted[i][j][k]=1;
112
          }
113
    }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
  int getDeviceID()
118
    {
119
    return mDeviceID;
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
  synchronized boolean thereAreUnsubmittedRecords()
125
    {
126
    ObjectList list;
127
    int length;
128

  
129
    for(int object=0; object<NUM_OBJECTS; object++)
130
      {
131
      list = ObjectList.getObject(object);
132
      length = list.getSizes().length;
133

  
134
      for(int size=0; size<length; size++)
135
        for(int level=0; level<MAX_LEVEL; level++)
136
          {
137
          if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
138
            {
139
            return true;
140
            }
141
          }
142
      }
143

  
144
    return false;
145
    }
146

  
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

  
149
  synchronized String getRecordList(String strObj, String strLvl, String strTim)
150
    {
151
    ObjectList list;
152
    StringBuilder builderObj = new StringBuilder();
153
    StringBuilder builderLvl = new StringBuilder();
154
    StringBuilder builderTim = new StringBuilder();
155
    boolean first = true;
156
    int[] sizes;
157
    int length;
158

  
159
    for(int object=0; object<NUM_OBJECTS; object++)
160
      {
161
      list = ObjectList.getObject(object);
162
      sizes = list.getSizes();
163
      length = sizes.length;
164

  
165
      for(int size=0; size<length; size++)
166
        {
167
        for(int level=0; level<MAX_LEVEL; level++)
168
          {
169
          if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
170
            {
171
            if( !first )
172
              {
173
              builderObj.append(',');
174
              builderLvl.append(',');
175
              builderTim.append(',');
176
              }
177
            else
178
              {
179
              first=false;
180
              }
181

  
182
            builderObj.append(list.name());
183
            builderObj.append("_");
184
            builderObj.append(sizes[size]);
185
            builderLvl.append(level);
186
            builderTim.append(mRecords[object][size][level]);
187
            }
188
          }
189
        }
190
      }
191

  
192
    return strObj+builderObj.toString()+strLvl+builderLvl.toString()+strTim+builderTim.toString();
193
    }
194

  
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
// Public API
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

  
199
  public synchronized long getRecord(int object, int size, int level)
200
    {
201
    int maxsize = ObjectList.getObject(object).getSizes().length;
202

  
203
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=0 && level<MAX_LEVEL )
204
      {
205
      return mRecords[object][size][level];
206
      }
207

  
208
    return -1;
209
    }
210

  
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

  
213
  public synchronized boolean isSubmitted(int object, int size, int level)
214
    {
215
    int maxsize = ObjectList.getObject(object).getSizes().length;
216

  
217
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=0 && level<MAX_LEVEL )
218
      {
219
      return mSubmitted[object][size][level]==1;
220
      }
221

  
222
    return false;
223
    }
224

  
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

  
227
  public boolean isVerified()
228
    {
229
    return mNameIsVerified;
230
    }
231

  
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

  
234
  public int getNumPlays()
235
    {
236
    return mNumPlays;
237
    }
238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

  
241
  public int getNumRuns()
242
    {
243
    return mNumRuns;
244
    }
245

  
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

  
248
  public String getName()
249
    {
250
    return mName;
251
    }
252

  
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

  
255
  public String getCountry()
256
    {
257
    return mCountry;
258
    }
259

  
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

  
262
  public void incrementNumPlays()
263
    {
264
    mNumPlays++;
265
    }
266

  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

  
269
  public void incrementNumRuns()
270
    {
271
    mNumRuns++;
272
    }
273

  
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

  
276
  public int incrementNumWins()
277
    {
278
    mNumWins++;
279
    return mNumWins;
280
    }
281

  
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

  
284
  public void setName(String newName)
285
    {
286
    mName = newName;
287
    }
288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
  public synchronized boolean isSolved(int object, int size, int level)
292
    {
293
    int maxsize = ObjectList.getObject(object).getSizes().length;
294

  
295
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=0 && level<MAX_LEVEL )
296
      {
297
      return mRecords[object][size][level]<NO_RECORD;
298
      }
299

  
300
    return false;
301
    }
302

  
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

  
305
  public void setCountry(Context context)
306
    {
307
    TelephonyManager tM =((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
308

  
309
    if( tM!=null )
310
      {
311
      mCountry = tM.getSimCountryIso();
312

  
313
      if( mCountry==null || mCountry.length()<=1 )
314
        {
315
        mCountry = tM.getNetworkCountryIso();
316
        }
317
      }
318

  
319
    // Special case: Dominicana. Its ISO-3166-alpha-2 country code is 'do' which we can't have here
320
    // because we later on map this to a resource name (the flag) and 'do' is a reserved Java keyword
321
    // and can't be a resource name.
322

  
323
    if( mCountry.equals("do") ) mCountry = "dm";
324
    }
325

  
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

  
328
  public void setCountry(String country)
329
    {
330
    mCountry = country;
331

  
332
    if( mCountry.equals("do") ) mCountry = "dm";  // see above
333
    }
334

  
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

  
337
  public static RubikScores getInstance()
338
    {
339
    if( mThis==null )
340
      {
341
      mThis = new RubikScores();
342
      }
343

  
344
    return mThis;
345
    }
346

  
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

  
349
  public synchronized void savePreferences(SharedPreferences.Editor editor)
350
    {
351
    StringBuilder builder = new StringBuilder();
352
    ObjectList list;
353
    int[] sizes;
354
    int length;
355

  
356
    for(int level=0; level<MAX_LEVEL; level++)
357
      {
358
      builder.setLength(0);
359

  
360
      for(int object=0; object<NUM_OBJECTS; object++)
361
        {
362
        list = ObjectList.getObject(object);
363
        sizes = list.getSizes();
364
        length = sizes.length;
365

  
366
        for(int size=0; size<length; size++)
367
          {
368
          builder.append(list.name());
369
          builder.append("_");
370
          builder.append(sizes[size]);
371
          builder.append("=");
372
          builder.append(mRecords[object][size][level]);
373
          builder.append(",");
374
          builder.append(mSubmitted[object][size][level]);
375
          builder.append(" ");
376
          }
377
        }
378

  
379
      editor.putString("scores_record"+level, builder.toString());
380
      }
381

  
382
    editor.putString("scores_name"  , mName  );
383
    editor.putBoolean("scores_isVerified", mNameIsVerified);
384
    editor.putInt("scores_numPlays", mNumPlays);
385
    editor.putInt("scores_numRuns" , mNumRuns );
386
    editor.putInt("scores_deviceid", mDeviceID);
387
    editor.putInt("scores_review"  , mNumWins );
388
    }
389

  
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391

  
392
  public synchronized void restorePreferences(SharedPreferences preferences)
393
    {
394
    String recordStr, subStr, nameStr, sizeStr, timeStr, submStr, errorStr="";
395
    int start, end, equals, underscore, comma;
396
    int object, sizeIndex, subm;
397
    long time;
398
    boolean thereWasError = false;
399

  
400
    for(int level=0; level<MAX_LEVEL; level++)
401
      {
402
      start = end = 0;
403
      recordStr = preferences.getString("scores_record"+level, "");
404

  
405
      while( end!=-1 )
406
        {
407
        end = recordStr.indexOf(" ", start);
408

  
409
        if( end==-1 ) subStr = recordStr.substring(start);
410
        else          subStr = recordStr.substring(start,end);
411

  
412
        start = end+1;
413

  
414
        underscore = subStr.indexOf("_");
415
        equals = subStr.indexOf("=");
416
        comma = subStr.indexOf(",");
417

  
418
        if( underscore>=0 && equals>=0 && comma>=0 )
419
          {
420
          nameStr = subStr.substring(0,underscore);
421
          sizeStr = subStr.substring(underscore+1, equals);
422
          timeStr = subStr.substring(equals+1,comma);
423
          submStr = subStr.substring(comma+1);
424

  
425
          object = ObjectList.getOrdinal(nameStr);
426

  
427
          if( object>=0 && object< NUM_OBJECTS )
428
            {
429
            sizeIndex = ObjectList.getSizeIndex(object,Integer.parseInt(sizeStr));
430
            time = Long.parseLong(timeStr);
431
            subm = Integer.parseInt(submStr);
432

  
433
            if( sizeIndex>=0 && sizeIndex<MAX_NUM_OBJECTS && subm>=0 && subm<=1 )
434
              {
435
              mRecords  [object][sizeIndex][level] = time;
436
              mSubmitted[object][sizeIndex][level] = subm;
437
              }
438
            else
439
              {
440
              errorStr += ("error1: size="+sizeIndex+" subm="+subm+" obj: "+nameStr+" size: "+sizeStr+"\n");
441
              thereWasError= true;
442
              }
443
            }
444
          else
445
            {
446
            errorStr += ("error2: object="+object+" obj: "+nameStr+" size: "+sizeStr+"\n");
447
            thereWasError = true;
448
            }
449
          }
450
        }
451
      }
452

  
453
    mName           = preferences.getString("scores_name"  , "" );
454
    mNameIsVerified = preferences.getBoolean("scores_isVerified", false);
455
    mNumPlays       = preferences.getInt("scores_numPlays", 0);
456
    mNumRuns        = preferences.getInt("scores_numRuns" , 0);
457
    mDeviceID       = preferences.getInt("scores_deviceid",-1);
458
    mNumWins        = preferences.getInt("scores_review"  , 0);
459

  
460
    if( mDeviceID==-1 ) mDeviceID = privateGetDeviceID();
461

  
462
    if( thereWasError ) recordDBError(errorStr);
463
    }
464

  
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

  
467
  public void recordDBError(String message)
468
    {
469
    if( BuildConfig.DEBUG )
470
      {
471
      android.util.Log.e("scores", message);
472
      }
473
    else
474
      {
475
      Exception ex = new Exception(message);
476
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
477
      crashlytics.setCustomKey("scores" , message);
478
      crashlytics.recordException(ex);
479
      }
480
    }
481

  
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

  
484
  public synchronized boolean setRecord(int object, int size, int level, long timeTaken)
485
    {
486
    int maxsize = ObjectList.getObject(object).getSizes().length;
487

  
488
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=1 && level<=MAX_LEVEL )
489
      {
490
      if( mRecords[object][size][level-1]> timeTaken )
491
        {
492
        mRecords  [object][size][level-1] = timeTaken;
493
        mSubmitted[object][size][level-1] = 0;
494
        return true;
495
        }
496
      }
497

  
498
    return false;
499
    }
500
  }
src/main/java/org/distorted/objects/TwistyDino4.java
106 106

  
107 107
  public boolean isSolved()
108 108
    {
109
android.util.Log.e("D",
110

  
111
CUBITS[ 0].mQuatIndex+" "+
112
CUBITS[ 1].mQuatIndex+" "+
113
CUBITS[ 2].mQuatIndex+" "+
114
CUBITS[ 3].mQuatIndex+" "+
115
CUBITS[ 4].mQuatIndex+" "+
116
CUBITS[ 5].mQuatIndex+" "+
117
CUBITS[ 6].mQuatIndex+" "+
118
CUBITS[ 7].mQuatIndex+" "+
119
CUBITS[ 8].mQuatIndex+" "+
120
CUBITS[ 9].mQuatIndex+" "+
121
CUBITS[10].mQuatIndex+" "+
122
CUBITS[11].mQuatIndex
123

  
124
);
125

  
109 126
    int redX = CUBITS[0].mQuatIndex;
110 127
    int bluX = CUBITS[2].mQuatIndex;
111 128
    int yelX = CUBITS[8].mQuatIndex;
......
114 131
        CUBITS[1].mQuatIndex == bluX && CUBITS[5].mQuatIndex == bluX &&
115 132
        CUBITS[9].mQuatIndex == yelX && CUBITS[4].mQuatIndex == yelX  ) return true;
116 133

  
117
    if (CUBITS[3].mQuatIndex != mulQuat(redX,2)) return false;
118
    if (CUBITS[7].mQuatIndex != mulQuat(redX,8)) return false;
119
    if (CUBITS[1].mQuatIndex != mulQuat(bluX,2)) return false;
120
    if (CUBITS[5].mQuatIndex != mulQuat(bluX,8)) return false;
121
    if (CUBITS[9].mQuatIndex != mulQuat(yelX,2)) return false;
122
    if (CUBITS[4].mQuatIndex != mulQuat(yelX,8)) return false;
134
    if (CUBITS[3].mQuatIndex != mulQuat(redX,2))
135
      {
136
      android.util.Log.e("D", "FALSE 1");
137
      return false;
138
      }
139
    if (CUBITS[7].mQuatIndex != mulQuat(redX,8))
140
      {
141
      android.util.Log.e("D", "FALSE 2");
142
      return false;
143
      }
144
    if (CUBITS[1].mQuatIndex != mulQuat(bluX,2))
145
      {
146
      android.util.Log.e("D", "FALSE 3");
147
      return false;
148
      }
149
    if (CUBITS[5].mQuatIndex != mulQuat(bluX,8))
150
      {
151
      android.util.Log.e("D", "FALSE 4");
152
      return false;
153
      }
154
    if (CUBITS[9].mQuatIndex != mulQuat(yelX,2))
155
      {
156
      android.util.Log.e("D", "FALSE 5");
157
      return false;
158
      }
159
    if (CUBITS[4].mQuatIndex != mulQuat(yelX,8))
160
      {
161
      android.util.Log.e("D", "FALSE 6");
162
      return false;
163
      }
123 164

  
124 165
    return true;
125 166
    }
src/main/java/org/distorted/scores/RubikScores.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.scores;
21

  
22
import android.content.Context;
23
import android.content.SharedPreferences;
24
import android.telephony.TelephonyManager;
25

  
26
import com.google.firebase.crashlytics.FirebaseCrashlytics;
27

  
28
import org.distorted.main.BuildConfig;
29
import org.distorted.objects.ObjectList;
30

  
31
import java.util.UUID;
32

  
33
import static org.distorted.objects.ObjectList.MAX_NUM_OBJECTS;
34
import static org.distorted.objects.ObjectList.NUM_OBJECTS;
35
import static org.distorted.objects.ObjectList.MAX_LEVEL;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
// hold my own scores, and some other statistics.
39

  
40
public class RubikScores
41
  {
42
  public static final long NO_RECORD = Long.MAX_VALUE;
43
  private static RubikScores mThis;
44

  
45
  private final long[][][] mRecords;
46
  private final int [][][] mSubmitted;
47

  
48
  private String mName, mCountry;
49
  private boolean mNameIsVerified;
50
  private int mNumRuns;
51
  private int mNumPlays;
52
  private int mNumWins;
53
  private int mDeviceID;
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  private RubikScores()
58
    {
59
    mRecords   = new long[NUM_OBJECTS][MAX_NUM_OBJECTS][MAX_LEVEL];
60
    mSubmitted = new int [NUM_OBJECTS][MAX_NUM_OBJECTS][MAX_LEVEL];
61

  
62
    for(int i=0; i<NUM_OBJECTS; i++)
63
      for(int j=0; j<MAX_NUM_OBJECTS; j++)
64
        for(int k=0; k<MAX_LEVEL; k++)
65
          {
66
          mRecords[i][j][k]   = NO_RECORD;
67
          mSubmitted[i][j][k] = 0;
68
          }
69

  
70
    mName = "";
71
    mCountry = "un";
72

  
73
    mNameIsVerified = false;
74

  
75
    mNumPlays= -1;
76
    mNumRuns = -1;
77
    mDeviceID= -1;
78
    mNumWins =  0;
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  private int privateGetDeviceID()
84
    {
85
    int id;
86

  
87
    try
88
      {
89
      String s = UUID.randomUUID().toString();
90
      id = s.hashCode();
91
      }
92
    catch(Exception ex)
93
      {
94
      id = 0;
95
      android.util.Log.e("scores", "Exception in getDeviceID()");
96
      }
97

  
98
    return id<0 ? -id : id;
99
    }
100

  
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

  
103
  synchronized void successfulSubmit()
104
    {
105
    mNameIsVerified = true;
106

  
107
    for(int i=0; i<NUM_OBJECTS; i++)
108
      for(int j=0; j<MAX_NUM_OBJECTS; j++)
109
        for(int k=0; k<MAX_LEVEL; k++)
110
          {
111
          mSubmitted[i][j][k]=1;
112
          }
113
    }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
  int getDeviceID()
118
    {
119
    return mDeviceID;
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
  synchronized boolean thereAreUnsubmittedRecords()
125
    {
126
    ObjectList list;
127
    int length;
128

  
129
    for(int object=0; object<NUM_OBJECTS; object++)
130
      {
131
      list = ObjectList.getObject(object);
132
      length = list.getSizes().length;
133

  
134
      for(int size=0; size<length; size++)
135
        for(int level=0; level<MAX_LEVEL; level++)
136
          {
137
          if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
138
            {
139
            return true;
140
            }
141
          }
142
      }
143

  
144
    return false;
145
    }
146

  
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

  
149
  synchronized String getRecordList(String strObj, String strLvl, String strTim)
150
    {
151
    ObjectList list;
152
    StringBuilder builderObj = new StringBuilder();
153
    StringBuilder builderLvl = new StringBuilder();
154
    StringBuilder builderTim = new StringBuilder();
155
    boolean first = true;
156
    int[] sizes;
157
    int length;
158

  
159
    for(int object=0; object<NUM_OBJECTS; object++)
160
      {
161
      list = ObjectList.getObject(object);
162
      sizes = list.getSizes();
163
      length = sizes.length;
164

  
165
      for(int size=0; size<length; size++)
166
        {
167
        for(int level=0; level<MAX_LEVEL; level++)
168
          {
169
          if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff