Project

General

Profile

« Previous | Next » 

Revision 85b09df4

Added by Leszek Koltunski over 4 years ago

Reorganize UI of the Play state.

View differences:

src/main/java/org/distorted/component/HorizontalNumberPicker.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.component;
21

  
22
import android.content.Context;
23
import android.support.annotation.Nullable;
24
import android.util.AttributeSet;
25
import android.view.View;
26
import android.widget.Button;
27
import android.widget.LinearLayout;
28
import android.widget.TextView;
29

  
30
import org.distorted.main.R;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class HorizontalNumberPicker extends LinearLayout
35
{
36
  private TextView mNumber;
37
  private int mMin, mMax;
38

  
39
  private class AddHandler implements OnClickListener
40
    {
41
    final int diff;
42

  
43
    AddHandler(int diff)
44
      {
45
      this.diff = diff;
46
      }
47

  
48
    @Override
49
    public void onClick(View v)
50
      {
51
      int newValue = getValue() + diff;
52

  
53
      if (newValue < mMin)
54
        {
55
        newValue = mMin;
56
        }
57
      else if (newValue > mMax)
58
        {
59
        newValue = mMax;
60
        }
61
      setValue(newValue);
62
      }
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
// PUBLIC API
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  public HorizontalNumberPicker(Context context, @Nullable AttributeSet attrs)
70
    {
71
    super(context, attrs);
72

  
73
    mMin = 0;
74
    mMax = 5;
75

  
76
    inflate(context, R.layout.numberpicker, this);
77

  
78
    mNumber = findViewById(R.id.textNumber);
79

  
80
    final Button btn_less = findViewById(R.id.buttonLess);
81
    btn_less.setOnClickListener(new AddHandler(-1));
82

  
83
    final Button btn_more = findViewById(R.id.buttonMore);
84
    btn_more.setOnClickListener(new AddHandler( 1));
85
    }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
  public int getValue()
90
    {
91
    if(mNumber != null)
92
      {
93
      try
94
        {
95
        final String value = mNumber.getText().toString();
96
        return Integer.parseInt(value);
97
        }
98
      catch(NumberFormatException ex)
99
        {
100
        android.util.Log.e("HorizontalNumberPicker", ex.toString());
101
        }
102
      }
103
    return 0;
104
    }
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
  public void setValue(final int value)
109
    {
110
    if (mNumber != null)
111
      {
112
      mNumber.setText(String.valueOf(value));
113
      }
114
    }
115

  
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

  
118
  public void setMin(int min)
119
    {
120
    mMin = min;
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  public void setMax(int max)
126
    {
127
    mMax = max;
128
    }
129
}
src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
32 32
import org.distorted.scores.RubikScoresDownloader;
33 33
import org.distorted.objects.RubikObjectList;
34 34

  
35
import static org.distorted.states.RubikStatePlay.MAX_SCRAMBLE;
35
import static org.distorted.states.RubikStatePlay.MAX_LEVEL;
36 36

  
37 37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 38

  
......
136 136

  
137 137
  private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time)
138 138
    {
139
    for(int i=0; i<MAX_SCRAMBLE; i++)
139
    for(int i=0; i<MAX_LEVEL; i++)
140 140
      {
141 141
      final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]);
142 142

  
src/main/java/org/distorted/dialogs/RubikDialogScoresView.java
69 69

  
70 70
///////////////////////////////////////////////////////////////////////////////////////////////////
71 71

  
72
  LinearLayout createSection(FragmentActivity act, int tab, int scramble, final String[] country, final String[] name, final float[] time)
72
  LinearLayout createSection(FragmentActivity act, int tab, int level, final String[] country, final String[] name, final float[] time)
73 73
    {
74
    LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
75
    TextView text = level.findViewById(R.id.scoresScrambleTitle);
76
    text.setText(act.getString(R.string.sc_placeholder,(scramble+1)));
74
    LinearLayout levelLayout = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
75
    TextView text = levelLayout.findViewById(R.id.scoresScrambleTitle);
76
    text.setText(act.getString(R.string.lv_placeholder,level+1));
77 77

  
78 78
    Resources res = act.getResources();
79 79
    String packageName = act.getPackageName();
......
83 83
    RubikScores scores = RubikScores.getInstance();
84 84

  
85 85
    boolean inserted = false;
86
    long myRecordInMillis = scores.getRecord(object, size, scramble);
86
    long myRecordInMillis = scores.getRecord(object, size, level);
87 87
    float myRecordInSeconds = (myRecordInMillis/100)/10.0f;
88
    boolean mySubmitted = scores.isSubmitted(object, size, scramble);
88
    boolean mySubmitted = scores.isSubmitted(object, size, level);
89 89
    String myName = scores.getName();
90 90
    if( myName.length()==0 ) myName = act.getString(R.string.you);
91 91
    int myCountryID = res.getIdentifier( scores.getCountry(), "drawable", packageName);
......
105 105
          {
106 106
          inserted = true;
107 107
          View row = createRow(act, myCountryID, myName, myRecord, red);
108
          level.addView(row);
108
          levelLayout.addView(row);
109 109
          }
110 110

  
111 111
        equals = name[j].equals(myName);
......
116 116
          theirCountryID = res.getIdentifier( country[j], "drawable", packageName);
117 117
          theirTime = Float.toString(time[j]);
118 118
          View row = createRow(act, theirCountryID, name[j], theirTime, equals ? red:white);
119
          level.addView(row);
119
          levelLayout.addView(row);
120 120
          }
121 121
        }
122 122
      }
......
124 124
    if( !inserted )
125 125
      {
126 126
      View row = createRow(act, myCountryID, myName, myRecord, red);
127
      level.addView(row);
127
      levelLayout.addView(row);
128 128
      }
129 129

  
130
    return level;
130
    return levelLayout;
131 131
    }
132 132

  
133 133
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/main/RubikActivity.java
262 262
      RubikDialogAbout diag = new RubikDialogAbout();
263 263
      diag.show(getSupportFragmentManager(), null);
264 264
      }
265

  
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

  
268
    public void Scramble(View v)
269
      {
270
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
271
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
272
      int scramble = play.getPicker();
273
      view.getPostRender().scrambleObject(scramble);
274
      }
275

  
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
    public void Solve(View v)
279
      {
280
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
281
      view.getPostRender().solveObject();
282
      }
283 265
}
src/main/java/org/distorted/main/RubikPostRender.java
361 361

  
362 362
///////////////////////////////////////////////////////////////////////////////////////////////////
363 363

  
364
  void scrambleObject(int num)
364
  void setTextureMap(int cubit, int face, int newColor)
365 365
    {
366
    if( mCanPlay )
367
      {
368
      mScrambleObject = true;
369
      mScrambleObjectNum = num;
370
      }
371
    }
372

  
373
///////////////////////////////////////////////////////////////////////////////////////////////////
366
    mSetTextureMap = true;
374 367

  
375
  void solveObject()
376
    {
377
    if( mCanPlay )
378
      {
379
      mSolveObject = true;
380
      }
368
    mCubit    = cubit;
369
    mFace     = face;
370
    mNewColor = newColor;
381 371
    }
382 372

  
383 373
///////////////////////////////////////////////////////////////////////////////////////////////////
......
451 441

  
452 442
///////////////////////////////////////////////////////////////////////////////////////////////////
453 443

  
454
  void setTextureMap(int cubit, int face, int newColor)
444
  public void scrambleObject(int num)
455 445
    {
456
    mSetTextureMap = true;
446
    if( mCanPlay )
447
      {
448
      mScrambleObject = true;
449
      mScrambleObjectNum = num;
450
      }
451
    }
457 452

  
458
    mCubit    = cubit;
459
    mFace     = face;
460
    mNewColor = newColor;
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

  
455
  public void solveObject()
456
    {
457
    if( mCanPlay )
458
      {
459
      mSolveObject = true;
460
      }
461 461
    }
462 462

  
463 463
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/scores/RubikScores.java
29 29

  
30 30
import static org.distorted.objects.RubikObjectList.MAX_SIZE;
31 31
import static org.distorted.objects.RubikObjectList.NUM_OBJECTS;
32
import static org.distorted.states.RubikStatePlay.MAX_SCRAMBLE;
32
import static org.distorted.states.RubikStatePlay.MAX_LEVEL;
33 33

  
34 34
///////////////////////////////////////////////////////////////////////////////////////////////////
35 35
// hold my own scores, and some other statistics.
......
52 52

  
53 53
  private RubikScores()
54 54
    {
55
    mRecords   = new long[NUM_OBJECTS][MAX_SIZE][MAX_SCRAMBLE];
56
    mSubmitted = new int [NUM_OBJECTS][MAX_SIZE][MAX_SCRAMBLE];
55
    mRecords   = new long[NUM_OBJECTS][MAX_SIZE][MAX_LEVEL];
56
    mSubmitted = new int [NUM_OBJECTS][MAX_SIZE][MAX_LEVEL];
57 57

  
58 58
    for(int i=0; i<NUM_OBJECTS; i++)
59 59
      for(int j=0; j<MAX_SIZE; j++)
60
        for(int k=0; k<MAX_SCRAMBLE; k++)
60
        for(int k=0; k<MAX_LEVEL; k++)
61 61
          {
62 62
          mRecords[i][j][k]   = NO_RECORD;
63 63
          mSubmitted[i][j][k] = 0;
......
111 111

  
112 112
      for(int size=0; size<length; size++)
113 113
        {
114
        for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
114
        for(int scramble=0; scramble<MAX_LEVEL; scramble++)
115 115
          {
116 116
          if( mSubmitted[object][size][scramble]==0 && mRecords[object][size][scramble]<NO_RECORD )
117 117
            {
......
160 160
    int[] sizes;
161 161
    int length;
162 162

  
163
    for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
163
    for(int scramble=0; scramble<MAX_LEVEL; scramble++)
164 164
      {
165 165
      builder.setLength(0);
166 166

  
......
202 202
    int object, sizeIndex, subm;
203 203
    long time;
204 204

  
205
    for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
205
    for(int scramble=0; scramble<MAX_LEVEL; scramble++)
206 206
      {
207 207
      start = end = 0;
208 208
      recordStr = preferences.getString("scores_record"+scramble, "");
......
268 268
    {
269 269
    int maxsize = RubikObjectList.getObject(object).getSizes().length;
270 270

  
271
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=1 && scramble<=MAX_SCRAMBLE )
271
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=1 && scramble<=MAX_LEVEL )
272 272
      {
273 273
      if( mRecords[object][size][scramble-1]> timeTaken )
274 274
        {
......
310 310

  
311 311
    for(int i=0; i<NUM_OBJECTS; i++)
312 312
      for(int j=0; j<MAX_SIZE   ; j++)
313
        for(int k=0; k<MAX_SCRAMBLE; k++)
313
        for(int k=0; k<MAX_LEVEL; k++)
314 314
          {
315 315
          mSubmitted[i][j][k]=1;
316 316
          }
......
345 345
    {
346 346
    int maxsize = RubikObjectList.getObject(object).getSizes().length;
347 347

  
348
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
348
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_LEVEL )
349 349
      {
350 350
      return mRecords[object][size][scramble];
351 351
      }
......
359 359
    {
360 360
    int maxsize = RubikObjectList.getObject(object).getSizes().length;
361 361

  
362
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
362
    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_LEVEL )
363 363
      {
364 364
      return mSubmitted[object][size][scramble]==1;
365 365
      }
......
422 422
      length = list.getSizes().length;
423 423

  
424 424
      for(int size=0; size<length; size++)
425
        for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
425
        for(int scramble=0; scramble<MAX_LEVEL; scramble++)
426 426
          {
427 427
          if( mSubmitted[object][size][scramble]==0 && mRecords[object][size][scramble]<NO_RECORD )
428 428
            {
src/main/java/org/distorted/scores/RubikScoresDownloader.java
29 29
import java.net.URL;
30 30
import java.net.UnknownHostException;
31 31

  
32
import static org.distorted.states.RubikStatePlay.MAX_SCRAMBLE;
32
import static org.distorted.states.RubikStatePlay.MAX_LEVEL;
33 33

  
34 34
///////////////////////////////////////////////////////////////////////////////////////////////////
35 35

  
......
90 90

  
91 91
  private static int mTotal = RubikObjectList.getTotal();
92 92
  private static String mScores = "";
93
  private static String[][][] mCountry = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
94
  private static String[][][] mName    = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
95
  private static  float[][][] mTime    = new  float[mTotal][MAX_SCRAMBLE][MAX_PLACES];
93
  private static String[][][] mCountry = new String[mTotal][MAX_LEVEL][MAX_PLACES];
94
  private static String[][][] mName    = new String[mTotal][MAX_LEVEL][MAX_PLACES];
95
  private static  float[][][] mTime    = new  float[mTotal][MAX_LEVEL][MAX_PLACES];
96 96

  
97
  private static int[][] mPlaces = new int[mTotal][MAX_SCRAMBLE];
97
  private static int[][] mPlaces = new int[mTotal][MAX_LEVEL];
98 98
  private static RubikScoresDownloader mThis;
99 99

  
100 100
///////////////////////////////////////////////////////////////////////////////////////////////////
......
143 143
      }
144 144

  
145 145
    for(int i=0; i<mTotal; i++)
146
      for(int j=0; j<MAX_SCRAMBLE; j++)
146
      for(int j=0; j<MAX_LEVEL; j++)
147 147
        {
148 148
        mPlaces[i][j] = 0;
149 149
        }
......
190 190
        int time       = Integer.parseInt( row.substring(s3+1,s4) );
191 191
        String country = row.substring(s4+1, s5);
192 192

  
193
        if(scramble>=0 && scramble<MAX_SCRAMBLE)
193
        if(scramble>=0 && scramble<MAX_LEVEL)
194 194
          {
195 195
          int p = mPlaces[object][scramble];
196 196
          mPlaces[object][scramble]++;
......
311 311

  
312 312
    String url="https://distorted.org/magic/cgi-bin/download.cgi";
313 313
    url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&e="+mVersion+"d";
314
    url += "&o="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&l="+MAX_PLACES;
314
    url += "&o="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_LEVEL+"&l="+MAX_PLACES;
315 315

  
316 316
    return url;
317 317
    }
......
335 335
    String url="https://distorted.org/magic/cgi-bin/submit.cgi";
336 336
    url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d";
337 337
    url += "&o="+objlist+"&l="+lvllist+"&t="+timlist+"&c="+country+"&h="+hash;
338
    url += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_SCRAMBLE+"&lo="+MAX_PLACES;
338
    url += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_LEVEL+"&lo="+MAX_PLACES;
339 339

  
340 340
    return url;
341 341
    }
src/main/java/org/distorted/states/RubikStatePlay.java
26 26
import android.view.Gravity;
27 27
import android.view.LayoutInflater;
28 28
import android.view.View;
29
import android.widget.AdapterView;
30
import android.widget.ArrayAdapter;
29 31
import android.widget.Button;
30 32
import android.widget.ImageButton;
31 33
import android.widget.LinearLayout;
32 34
import android.widget.PopupWindow;
35
import android.widget.Spinner;
33 36

  
34
import org.distorted.component.HorizontalNumberPicker;
35 37
import org.distorted.main.R;
36 38
import org.distorted.main.RubikActivity;
37 39
import org.distorted.objects.RubikObjectList;
38 40

  
39 41
///////////////////////////////////////////////////////////////////////////////////////////////////
40 42

  
41
public class RubikStatePlay extends RubikStateAbstract
43
public class RubikStatePlay extends RubikStateAbstract implements AdapterView.OnItemSelectedListener
42 44
  {
43
  private static final int MIN_SCRAMBLE =  1;
44
  private static final int DEF_SCRAMBLE =  1;
45
  public  static final int MAX_SCRAMBLE = 18;
46
  public  static final int DEF_OBJECT   = RubikObjectList.CUBE.ordinal();
47
  public  static final int DEF_SIZE     =  3;
45
  private static final int DEF_LEVEL =  1;
46
  public  static final int MAX_LEVEL = 18;
47
  public  static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal();
48
  public  static final int DEF_SIZE  =  3;
48 49

  
49 50
  private ImageButton mObjButton;
50
  private Button mBackButton;
51
  private Button mBackButton, mSolveButton, mPlayButton;
51 52
  private PopupWindow mPopup;
52
  private HorizontalNumberPicker mPicker;
53
  private int mPickerValue;
54 53
  private int mObject = DEF_OBJECT;
55 54
  private int mSize   = DEF_SIZE;
56
  private int mLayoutWidth, mLayoutHeight;
55
  private int mLayoutWidth;
57 56
  private LinearLayout mLayout;
57
  private Spinner mLevelSpinner;
58
  private int mLevelValue;
58 59

  
59 60
///////////////////////////////////////////////////////////////////////////////////////////////////
60 61

  
61 62
  void leaveState(RubikActivity act)
62 63
    {
63
    mPickerValue = mPicker.getValue();
64

  
64 65
    }
65 66

  
66 67
///////////////////////////////////////////////////////////////////////////////////////////////////
67 68

  
68 69
  void enterState(final RubikActivity act)
69 70
    {
70
    LayoutInflater inflater = act.getLayoutInflater();
71
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
72
    final float scale = metrics.density;
71 73

  
72 74
    // TOP ////////////////////////////
73
    final View viewTop = inflater.inflate(R.layout.play_title, null);
74

  
75 75
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
76 76
    layoutTop.removeAllViews();
77
    layoutTop.addView(viewTop);
77

  
78
    if( mObjButton   ==null ) setupObjectButton(act,scale);
79
    layoutTop.addView(mObjButton);
80
    if( mLevelSpinner==null ) setupLevelSpinner(act,scale);
81
    layoutTop.addView(mLevelSpinner);
82
    if( mPlayButton  ==null ) setupPlayButton(act,scale);
83
    layoutTop.addView(mPlayButton);
78 84

  
79 85
    // BOT ////////////////////////////
80
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
81
    final float scale = metrics.density;
82 86

  
83
    if( mObjButton==null ) setupObjectButton(act,scale);
87
    if( mSolveButton==null ) setupSolveButton(act,scale);
84 88

  
85 89
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
86 90
    layoutLeft.removeAllViews();
87
    layoutLeft.addView(mObjButton);
91
    layoutLeft.addView(mSolveButton);
88 92

  
89 93
    if( mBackButton==null ) setupBackButton(act,scale);
90 94

  
......
92 96
    layoutRight.removeAllViews();
93 97
    layoutRight.addView(mBackButton);
94 98

  
95
    mPicker = act.findViewById(R.id.rubikNumberPicker);
96
    mPicker.setMin(MIN_SCRAMBLE);
97
    mPicker.setMax(MAX_SCRAMBLE);
98
    mPicker.setValue(mPickerValue);
99

  
100 99
    if( mPopup==null ) setupPopupWindow(act, scale);
101 100
    }
102 101

  
......
122 121
          boolean vertical = act.isVertical();
123 122
          mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
124 123

  
125
          int height = view.getHeight();
126 124
          int width  = view.getWidth();
127 125
          int laywid = mLayoutWidth * (vertical? 1:total);
128
          int layhei = mLayoutHeight* (vertical? total:1);
129 126

  
130
          mPopup.showAsDropDown(view, (width-laywid)/2, -height-layhei, Gravity.LEFT);
127
          mPopup.showAsDropDown(view, (width-laywid)/2, 0, Gravity.LEFT);
131 128
          }
132 129
        }
133 130
      });
134 131
    }
135 132

  
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

  
135
  private void setupLevelSpinner(final RubikActivity act, final float scale)
136
    {
137
    int spinnerPadding = (int)(scale* 10 + 0.5f);
138
    int spinnerMargin  = (int)(scale*  3 + 0.5f);
139
    int spinnerLength  = (int)(scale*150 + 0.5f);
140
    LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(spinnerLength,LinearLayout.LayoutParams.MATCH_PARENT);
141
    spinnerLayoutParams.topMargin    =   spinnerMargin;
142
    spinnerLayoutParams.bottomMargin =   spinnerMargin;
143
    spinnerLayoutParams.leftMargin   =   spinnerMargin;
144
    spinnerLayoutParams.rightMargin  = 2*spinnerMargin;
145

  
146
    mLevelSpinner = new Spinner(act);
147
    mLevelSpinner.setLayoutParams(spinnerLayoutParams);
148
    mLevelSpinner.setPadding(spinnerPadding,0,spinnerPadding,0);
149
    mLevelSpinner.setBackgroundResource(R.drawable.spinner);
150
    mLevelSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
151

  
152
    mLevelSpinner.setOnItemSelectedListener(this);
153
    String[] levels = new String[MAX_LEVEL];
154

  
155
    for(int i=0; i<MAX_LEVEL; i++)
156
      {
157
      levels[i] = act.getString(R.string.lv_placeholder,i+1);
158
      }
159

  
160
    ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
161
    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
162
    mLevelSpinner.setAdapter(adapterType);
163
    mLevelSpinner.setSelection(mLevelValue-1);
164
    }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  private void setupPlayButton(final RubikActivity act, final float scale)
169
    {
170
    int padding = (int)(3*scale + 0.5f);
171
    LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
172
    mPlayButton = new Button(act);
173
    mPlayButton.setLayoutParams(backParams);
174
    mPlayButton.setPadding(padding,0,padding,0);
175
    mPlayButton.setText(R.string.play);
176

  
177
    mPlayButton.setOnClickListener( new View.OnClickListener()
178
      {
179
      @Override
180
      public void onClick(View v)
181
        {
182
        act.getPostRender().scrambleObject(mLevelValue);
183
        }
184
      });
185
    }
186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

  
189
  private void setupSolveButton(final RubikActivity act, final float scale)
190
    {
191
    int padding = (int)(3*scale + 0.5f);
192
    LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
193
    mSolveButton = new Button(act);
194
    mSolveButton.setLayoutParams(backParams);
195
    mSolveButton.setPadding(padding,0,padding,0);
196
    mSolveButton.setText(R.string.solve);
197

  
198
    mSolveButton.setOnClickListener( new View.OnClickListener()
199
      {
200
      @Override
201
      public void onClick(View v)
202
        {
203
        act.getPostRender().solveObject();
204
        }
205
      });
206
    }
207

  
136 208
///////////////////////////////////////////////////////////////////////////////////////////////////
137 209

  
138 210
  private void setupBackButton(final RubikActivity act, final float scale)
......
169 241

  
170 242
    BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2);
171 243
    int cubeWidth  = bd.getIntrinsicWidth();
172
    int cubeHeight = bd.getIntrinsicHeight();
173

  
174 244
    mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
175
    mLayoutHeight= (int)(cubeHeight+ 2*margin + 0.5f);
176 245

  
177 246
    for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
178 247
      {
......
217 286

  
218 287
  public void savePreferences(SharedPreferences.Editor editor)
219 288
    {
220
    if( mPicker!=null )
221
      {
222
      editor.putInt("statePlay_scramble", mPicker.getValue() );
223
      }
224

  
289
    editor.putInt("statePlay_level" , mLevelValue);
225 290
    editor.putInt("statePlay_object", mObject);
226 291
    editor.putInt("statePlay_size"  , mSize);
227 292

  
228
    mObjButton = null;
229
    mBackButton= null;
293
    mObjButton   = null;
294
    mBackButton  = null;
295
    mSolveButton = null;
296
    mPlayButton  = null;
297
    mLevelSpinner= null;
230 298

  
231 299
    if( mPopup!=null )
232 300
      {
......
239 307

  
240 308
  public void restorePreferences(SharedPreferences preferences)
241 309
    {
242
    mPickerValue= preferences.getInt("statePlay_scramble", DEF_SCRAMBLE);
243
    mObject     = preferences.getInt("statePlay_object"  , DEF_OBJECT  );
244
    mSize       = preferences.getInt("statePlay_size"    , DEF_SIZE    );
310
    mLevelValue = preferences.getInt("statePlay_level" , DEF_LEVEL );
311
    mObject     = preferences.getInt("statePlay_object", DEF_OBJECT);
312
    mSize       = preferences.getInt("statePlay_size"  , DEF_SIZE  );
245 313
    }
246 314

  
247 315
///////////////////////////////////////////////////////////////////////////////////////////////////
......
268 336

  
269 337
///////////////////////////////////////////////////////////////////////////////////////////////////
270 338

  
271
  public int getPicker()
339
  int getLevel()
272 340
    {
273
    return mPicker!=null ? mPicker.getValue() : 1;
341
    return mLevelValue;
274 342
    }
275 343

  
276 344
///////////////////////////////////////////////////////////////////////////////////////////////////
......
286 354
    {
287 355
    return mSize;
288 356
    }
357

  
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359

  
360
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
361
    {
362
    mLevelValue = pos+1;
363
    }
364

  
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

  
367
  public void onNothingSelected(AdapterView<?> parent) { }
289 368
  }
src/main/java/org/distorted/states/RubikStateSolving.java
172 172
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
173 173
      int object  = play.getObject();
174 174
      int size    = play.getSize();
175
      int scramble= play.getPicker();
175
      int level   = play.getLevel();
176 176
      int realSize= RubikObjectList.getSizeIndex(object,size);
177 177

  
178
      boolean isNew = mScores.setRecord(object, realSize, scramble, timeTaken);
178
      boolean isNew = mScores.setRecord(object, realSize, level, timeTaken);
179 179

  
180 180
      return isNew ? timeTaken : -timeTaken;
181 181
      }
src/main/res/layout/main.xml
7 7
    <LinearLayout
8 8
        android:id="@+id/upperBar"
9 9
        android:layout_width="fill_parent"
10
        android:layout_height="50dp"
10
        android:layout_height="52dp"
11 11
        android:gravity="center"
12 12
        android:orientation="horizontal">
13 13
    </LinearLayout>
......
20 20

  
21 21
    <LinearLayout
22 22
        android:layout_width="match_parent"
23
        android:layout_height="60dp"
23
        android:layout_height="55dp"
24 24
        android:orientation="horizontal">
25 25

  
26 26
        <LinearLayout
src/main/res/values/strings.xml
52 52
    <string name="solver_cube3_error9">Solver interrupted!</string>
53 53

  
54 54
    <string name="ms_placeholder">%1$d ms</string>
55
    <string name="sc_placeholder">Scramble %1$d</string>
55
    <string name="lv_placeholder">Level %1$d</string>
56 56
    <string name="tm_placeholder">%1$02d:%2$02d</string>
57 57
    <string name="ap_placeholder">%1$s %2$s</string>
58 58
    <string name="ti_placeholder">%1$.1f seconds</string>

Also available in: Unified diff