Project

General

Profile

« Previous | Next » 

Revision 329c0aeb

Added by Leszek Koltunski almost 5 years ago

Many small improvements.

View differences:

src/main/java/org/distorted/dialog/RubikDialogAbout.java
75 75

  
76 76
    final View view = inflater.inflate(R.layout.dialog_about, null);
77 77
    TextView text = view.findViewById(R.id.about_version);
78
    text.setText(R.string.app_version);
78
    String appName = getString(R.string.app_name);
79
    String appVers = getString(R.string.app_version);
80
    text.setText(getString(R.string.ap_placeholder,appName, appVers));
79 81
    builder.setView(view);
80 82

  
81 83
    return builder.create();
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
162 162
    if( allCreated )
163 163
      {
164 164
      RubikScoresDownloader downloader = new RubikScoresDownloader();
165
      downloader.download(this, "distorted", 1);                        // TODO
165
      downloader.download(this, "distorted", "1.0.0", 1);                        // TODO
166 166
      }
167 167

  
168 168
    return mViews[position];
src/main/java/org/distorted/network/RubikScoresDownloader.java
24 24
import java.net.URL;
25 25
import java.net.UnknownHostException;
26 26

  
27
import org.distorted.magic.R;
28

  
29 27
import static org.distorted.object.RubikObject.LENGTH;
30 28
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
31 29

  
......
85 83
  private static boolean mRunning = false;
86 84
  private static int mMode = IDLE;
87 85
  private static Receiver mReceiver;
88
  private static String mUserName;
86
  private static String mUserName, mVersion;
89 87
  private static int mNumRuns;
90 88

  
91 89
  private static String mScores = "";
......
93 91
  private static String[][][] mName    = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
94 92
  private static String[][][] mTime    = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
95 93

  
94
  private static int[][] mPlaces = new int[LENGTH][MAX_SCRAMBLE];
95

  
96 96
///////////////////////////////////////////////////////////////////////////////////////////////////
97 97

  
98 98
  private void fillValues()
99 99
    {
100 100
    int begin=-1 ,end, len = mScores.length();
101 101

  
102
    for(int i=0; i<LENGTH; i++)
103
      for(int j=0; j<MAX_SCRAMBLE; j++)
104
        {
105
        mPlaces[i][j] = 0;
106
        }
107

  
102 108
    while( begin<len )
103 109
      {
104 110
      end = mScores.indexOf('\n', begin+1);
......
134 140

  
135 141
        if(level>=0 && level<MAX_SCRAMBLE && place>=0 && place<MAX_PLACES)
136 142
          {
143
          int p = mPlaces[size][level];
144
          mPlaces[size][level]++;
145

  
146
          if( p!=place ) android.util.Log.e("downloader", "size="+size+" level="+level+" p="+p+" place="+place);
147

  
137 148
          mCountry[size][level][place] = country;
138 149
          mName   [size][level][place] = name;
139 150
          mTime   [size][level][place] = realTime;
......
183 194

  
184 195
  private boolean doDownload()
185 196
    {
186
    String version = R.string.app_version+"d";
187
    String message=URL+"/download.cgi?n="+URLencode(mUserName)+"&r="+mNumRuns+"&e="+version;
197
    String message=URL+"/download.cgi?n="+URLencode(mUserName)+"&r="+mNumRuns+"&e="+mVersion+"d";
188 198

  
189 199
    try
190 200
      {
......
230 240
      return false;
231 241
      }
232 242

  
243
    if( mScores.length()==0 )
244
      {
245
      mReceiver.exception("Failed to download scores");
246
      return false;
247
      }
248

  
233 249
    return true;
234 250
    }
235 251

  
......
280 296

  
281 297
///////////////////////////////////////////////////////////////////////////////////////////////////
282 298

  
283
  public void download(Receiver receiver, String userName, int numRuns)
299
  public void download(Receiver receiver, String userName, String version, int numRuns)
284 300
    {
285 301
    mReceiver = receiver;
286 302
    mMode     = DOWNLOAD;
287 303
    mUserName = userName;
304
    mVersion  = version;
288 305
    mNumRuns  = numRuns;
289 306

  
290 307
    Thread networkThrd = new Thread(this);
src/main/java/org/distorted/uistate/RubikStateAbstract.java
28 28
  {
29 29
  public static final int BUTTON_ID_BACK= 1023;
30 30

  
31
  public abstract void enterState(RubikActivity act);
32
  public abstract void leaveState(RubikActivity act);
31
  abstract void enterState(RubikActivity act);
32
  abstract void leaveState(RubikActivity act);
33 33
  public abstract void savePreferences(SharedPreferences.Editor editor);
34 34
  public abstract void restorePreferences(SharedPreferences preferences);
35 35
  }
src/main/java/org/distorted/uistate/RubikStateMain.java
37 37

  
38 38
public class RubikStateMain extends RubikStateAbstract
39 39
  {
40
  public void leaveState(RubikActivity act)
40
  void leaveState(RubikActivity act)
41 41
    {
42 42
    FragmentManager mana = act.getSupportFragmentManager();
43 43
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
......
54 54

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

  
57
  public void enterState(RubikActivity act)
57
  void enterState(RubikActivity act)
58 58
    {
59 59
    FragmentManager mana = act.getSupportFragmentManager();
60 60
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
src/main/java/org/distorted/uistate/RubikStatePlay.java
51 51

  
52 52
///////////////////////////////////////////////////////////////////////////////////////////////////
53 53

  
54
  public void leaveState(RubikActivity act)
54
  void leaveState(RubikActivity act)
55 55
    {
56 56
    mPickerValue = mPicker.getValue();
57 57
    }
58 58

  
59 59
///////////////////////////////////////////////////////////////////////////////////////////////////
60 60

  
61
  public void enterState(RubikActivity act)
61
  void enterState(RubikActivity act)
62 62
    {
63 63
    LayoutInflater inflater = act.getLayoutInflater();
64 64

  
src/main/java/org/distorted/uistate/RubikStateSolving.java
33 33
import java.util.TimerTask;
34 34

  
35 35
import static android.view.View.INVISIBLE;
36
import static org.distorted.object.RubikObject.LENGTH;
37
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
36 38

  
37 39
///////////////////////////////////////////////////////////////////////////////////////////////////
38 40

  
39 41
public class RubikStateSolving extends RubikStateAbstract
40 42
  {
43
  private static final int NO_RECORD = Integer.MAX_VALUE;
44

  
41 45
  private TextView mTime;
42 46
  private Timer mTimer;
43 47
  private long mStartTime;
44 48
  private boolean mRunning;
45 49

  
50
  private long[][] mRecords;
51

  
46 52
///////////////////////////////////////////////////////////////////////////////////////////////////
47 53

  
48
  public void leaveState(RubikActivity act)
54
  RubikStateSolving()
55
    {
56
    mRecords = new long[LENGTH][MAX_SCRAMBLE];
57

  
58
    for(int i=0; i<LENGTH; i++)
59
      for(int j=0; j<MAX_SCRAMBLE; j++)
60
        {
61
        mRecords[i][j] = NO_RECORD;
62
        }
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  void leaveState(RubikActivity act)
49 68
    {
50 69
    stopCounting();
51 70
    }
52 71

  
53 72
///////////////////////////////////////////////////////////////////////////////////////////////////
54 73

  
55
  public void enterState(RubikActivity act)
74
  void enterState(RubikActivity act)
56 75
    {
57 76
    LayoutInflater inflater = act.getLayoutInflater();
58 77

  
......
96 115

  
97 116
  public void savePreferences(SharedPreferences.Editor editor)
98 117
    {
99

  
118
    for(int i=0; i<LENGTH; i++)
119
      for(int j=0; j<MAX_SCRAMBLE; j++)
120
        {
121
        if( mRecords[i][j]!=NO_RECORD)
122
          {
123
          editor.putLong("record_"+i+"_"+j, mRecords[i][j]);
124
          }
125
        }
100 126
    }
101 127

  
102 128
///////////////////////////////////////////////////////////////////////////////////////////////////
103 129

  
104 130
  public void restorePreferences(SharedPreferences preferences)
105 131
    {
106

  
132
    for(int i=0; i<LENGTH; i++)
133
      for(int j=0; j<MAX_SCRAMBLE; j++)
134
        {
135
        mRecords[i][j] = preferences.getInt("record_"+i+"_"+j, NO_RECORD );
136
        }
107 137
    }
108 138

  
109 139
///////////////////////////////////////////////////////////////////////////////////////////////////
......
148 178
        }
149 179
      mRunning = false;
150 180

  
151
      return System.currentTimeMillis()-mStartTime;
181
      long timeTaken = System.currentTimeMillis()-mStartTime;
182

  
183
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
184
      int object  = play.getButton();
185
      int scramble= play.getPicker();
186

  
187
      if( object>=0 && object<LENGTH && scramble>=0 && scramble<MAX_SCRAMBLE )
188
        {
189
        if( mRecords[object][scramble]> timeTaken )
190
          {
191
          mRecords[object][scramble] = timeTaken;
192
          android.util.Log.e("solv","new record!");
193
          }
194
        }
195

  
196
      return timeTaken;
152 197
      }
153 198

  
154 199
    return 0;
src/main/res/values/strings.xml
1 1
<resources>
2 2
    <string name="app_name">Magic Cube</string>
3
    <string name="app_version">Magic Cube v1.0.0</string>
3
    <string name="app_version">1.0.0</string>
4 4
    <string name="distorted">DISTORTED</string>
5 5
    <string name="scramble">Scramble</string>
6 6
    <string name="solve">Solve</string>
......
26 26
    <string name="ms_placeholder">%1$d ms</string>
27 27
    <string name="sc_placeholder">Scramble %1$d</string>
28 28
    <string name="tm_placeholder">%1$02d:%2$02d</string>
29
    <string name="ap_placeholder">%1$s %2$s</string>
29 30
</resources>

Also available in: Unified diff