Project

General

Profile

Download (24 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / states / RubikStatePlay.java @ 6a76f80a

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.states;
21

    
22
import android.content.Context;
23
import android.content.SharedPreferences;
24
import android.graphics.drawable.BitmapDrawable;
25
import android.os.Bundle;
26
import android.util.TypedValue;
27
import android.view.LayoutInflater;
28
import android.view.View;
29
import android.widget.Button;
30
import android.widget.GridLayout;
31
import android.widget.ImageButton;
32
import android.widget.LinearLayout;
33
import android.widget.PopupWindow;
34

    
35
import org.distorted.dialogs.RubikDialogAbout;
36
import org.distorted.dialogs.RubikDialogScores;
37
import org.distorted.main.R;
38
import org.distorted.main.RubikActivity;
39
import org.distorted.main.RubikPreRender;
40
import org.distorted.objects.TwistyObject;
41
import org.distorted.objects.ObjectList;
42
import org.distorted.scores.RubikScores;
43

    
44
import java.util.ArrayList;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
public class RubikStatePlay extends RubikStateAbstract implements RubikPreRender.ActionFinishedListener
49
  {
50
  private static final int DURATION_MILLIS = 750;
51
  private static final int LEVELS_SHOWN = 10;
52
  public  static final int DEF_OBJECT= ObjectList.CUBE.ordinal();
53
  public  static final int DEF_SIZE  =  3;
54

    
55
  private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about };
56
  private static final int NUM_BUTTONS = BUTTON_LABELS.length;
57

    
58
  private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton, mLockButton;
59
  private Button mPlayButton;
60
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
61
  private int mObject = DEF_OBJECT;
62
  private int mSize   = DEF_SIZE;
63
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
64
  private int mLevelValue;
65
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
66
  private int mColCount, mRowCount;
67
  private LinearLayout mPlayLayout;
68

    
69
  private ArrayList<Move> mMoves;
70
  private boolean mCanPrevMove;
71

    
72
  private static class Move
73
    {
74
    private int mAxis, mRow, mAngle;
75

    
76
    Move(int axis, int row, int angle)
77
      {
78
      mAxis = axis;
79
      mRow  = row;
80
      mAngle= angle;
81
      }
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  void leaveState(RubikActivity act)
87
    {
88

    
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  void enterState(final RubikActivity act)
94
    {
95
    float width = act.getScreenWidthInPixels();
96
    mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
97
    mButtonSize   = width*RubikActivity.BUTTON_TEXT_SIZE;
98
    mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
99

    
100
    mCanPrevMove = true;
101

    
102
    if( mMoves==null ) mMoves = new ArrayList<>();
103
    else               mMoves.clear();
104

    
105
    mRowCount = ObjectList.getRowCount();
106
    mColCount = ObjectList.getColumnCount();
107

    
108
    // TOP ////////////////////////////
109
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
110
    layoutTop.removeAllViews();
111

    
112
    setupObjectWindow(act,width);
113
    setupObjectButton(act,width);
114
    layoutTop.addView(mObjButton);
115

    
116
    setupMenuWindow(act,width);
117
    setupMenuButton(act,width);
118
    layoutTop.addView(mMenuButton);
119

    
120
    setupPlayWindow(act,width);
121
    setupPlayButton(act,width);
122
    layoutTop.addView(mPlayButton);
123

    
124
    // BOT ////////////////////////////
125
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
126
    layoutBot.removeAllViews();
127

    
128
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
129

    
130
    LinearLayout layoutLeft = new LinearLayout(act);
131
    layoutLeft.setLayoutParams(params);
132
    LinearLayout layoutMid = new LinearLayout(act);
133
    layoutMid.setLayoutParams(params);
134
    LinearLayout layoutRight = new LinearLayout(act);
135
    layoutRight.setLayoutParams(params);
136

    
137
    setupPrevButton(act,width);
138
    layoutLeft.addView(mPrevButton);
139
    setupLockButton(act,width);
140
    layoutMid.addView(mLockButton);
141
    setupSolveButton(act,width);
142
    layoutRight.addView(mSolveButton);
143

    
144
    layoutBot.addView(layoutLeft);
145
    layoutBot.addView(layoutMid);
146
    layoutBot.addView(layoutRight);
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  private void setupObjectButton(final RubikActivity act, final float width)
152
    {
153
    final int margin  = (int)(width*RubikActivity.MARGIN);
154
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
155
    mObjButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
156

    
157
    mObjButton.setOnClickListener( new View.OnClickListener()
158
      {
159
      @Override
160
      public void onClick(View view)
161
        {
162
        if( act.getPreRender().canPlay() )
163
          {
164
          if( mObjectPopup==null )
165
            {
166
            // I completely don't understand it, but Firebase says occasionally mObjectPopup is null here. Recreate.
167
            float width = act.getScreenWidthInPixels();
168
            setupObjectWindow(act,width);
169
            }
170

    
171
          mObjectPopup.setFocusable(false);
172
          mObjectPopup.update();
173

    
174
          View popupView = mObjectPopup.getContentView();
175
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
176

    
177
          mObjectPopup.showAsDropDown(view, margin, margin);
178
          mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);
179

    
180
          mObjectPopup.setFocusable(true);
181
          mObjectPopup.update();
182
          }
183
        }
184
      });
185
    }
186

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

    
189
  private void setupPlayButton(final RubikActivity act, final float width)
190
    {
191
    final int margin  = (int)(width*RubikActivity.MARGIN);
192
    mPlayButton = new TransparentButton(act, R.string.play, mButtonSize, width);
193

    
194
    mPlayButton.setOnClickListener( new View.OnClickListener()
195
      {
196
      @Override
197
      public void onClick(View view)
198
        {
199
        if( act.getPreRender().canPlay() )
200
          {
201
          if( mPlayPopup==null )
202
            {
203
            // I completely don't understand it, but Firebase says occasionally mPlayPopup is null here. Recreate.
204
            float width = act.getScreenWidthInPixels();
205
            setupPlayWindow(act,width);
206
            }
207

    
208
          mPlayPopup.setFocusable(false);
209
          mPlayPopup.update();
210

    
211
          View popupView = mPlayPopup.getContentView();
212
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
213

    
214
          final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
215
          final int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
216
          final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);
217

    
218
          mPlayPopup.showAsDropDown(view, margin, margin);
219
          mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin));
220

    
221
          mPlayPopup.setFocusable(true);
222
          mPlayPopup.update();
223
          }
224
        }
225
      });
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  private void setupMenuButton(final RubikActivity act, final float width)
231
    {
232
    final int margin  = (int)(width*RubikActivity.MARGIN);
233
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);
234
    mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
235

    
236
    mMenuButton.setOnClickListener( new View.OnClickListener()
237
      {
238
      @Override
239
      public void onClick(View view)
240
        {
241
        if( act.getPreRender().canPlay() )
242
          {
243
          if( mMenuPopup==null )
244
            {
245
            // I completely don't understand it, but Firebase says occasionally mMenuPopup is null here. Recreate.
246
            float width = act.getScreenWidthInPixels();
247
            setupMenuWindow(act,width);
248
            }
249

    
250
          mMenuPopup.setFocusable(false);
251
          mMenuPopup.update();
252

    
253
          View popupView = mMenuPopup.getContentView();
254
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
255

    
256
          mMenuPopup.showAsDropDown(view, (int)(-width/12), margin);
257
          mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight);
258

    
259
          mMenuPopup.setFocusable(true);
260
          mMenuPopup.update();
261
          }
262
        }
263
      });
264
    }
265

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

    
268
  private void setupSolveButton(final RubikActivity act, final float width)
269
    {
270
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
271
    mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
272

    
273
    mSolveButton.setOnClickListener( new View.OnClickListener()
274
      {
275
      @Override
276
      public void onClick(View v)
277
        {
278
        act.getPreRender().solveObject();
279
        mMoves.clear();
280
        }
281
      });
282
    }
283

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

    
286
  private void setupLockButton(final RubikActivity act, final float width)
287
    {
288
    final int icon = getLockIcon(act);
289
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
290

    
291
    mLockButton.setOnClickListener( new View.OnClickListener()
292
      {
293
      @Override
294
      public void onClick(View v)
295
        {
296
        toggleLock(act);
297
        }
298
      });
299
    }
300

    
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

    
303
  private void setupPrevButton(final RubikActivity act, final float width)
304
    {
305
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back);
306
    mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
307

    
308
    mPrevButton.setOnClickListener( new View.OnClickListener()
309
      {
310
      @Override
311
      public void onClick(View v)
312
        {
313
        RubikPreRender pre = act.getPreRender();
314
        backMove(pre);
315
        }
316
      });
317
    }
318

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

    
321
  private void setupObjectWindow(final RubikActivity act, final float width)
322
    {
323
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
324
    final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
325
    GridLayout objectGrid = layout.findViewById(R.id.objectGrid);
326

    
327
    int[] indices = ObjectList.getIndices();
328

    
329
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
330
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
331

    
332
    objectGrid.setColumnCount(mColCount);
333
    objectGrid.setRowCount(mRowCount);
334

    
335
    int[] nextInColumn = new int[mColCount];
336

    
337
    for(int row=0; row<mRowCount; row++)
338
      {
339
      rowSpecs[row] = GridLayout.spec(row);
340
      }
341
    for(int col=0; col<mColCount; col++)
342
      {
343
      colSpecs[col] = GridLayout.spec(col);
344
      nextInColumn[col] =0;
345
      }
346

    
347
    mObjectPopup = new PopupWindow(act);
348
    mObjectPopup.setContentView(layout);
349
    mObjectPopup.setFocusable(true);
350
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);
351

    
352
    BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
353
    int cubeWidth = bd.getIntrinsicWidth();
354
    int margin = (int)(width*RubikActivity.LARGE_MARGIN);
355
    mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
356

    
357
    for(int object = 0; object< ObjectList.NUM_OBJECTS; object++)
358
      {
359
      final ObjectList list = ObjectList.getObject(object);
360
      final int[] sizes = list.getSizes();
361
      int[] icons = list.getIconIDs();
362
      int len = sizes.length;
363
      final int obj = object;
364
      int col = indices[object];
365

    
366
      for(int i=0; i<len; i++)
367
        {
368
        final int index = i;
369

    
370
        ImageButton button = new ImageButton(act);
371
        button.setBackgroundResource(icons[i]);
372
        button.setOnClickListener( new View.OnClickListener()
373
          {
374
          @Override
375
          public void onClick(View v)
376
            {
377
            if( act.getPreRender().canPlay() && StateList.getCurrentState()== StateList.PLAY )
378
              {
379
              mObject = obj;
380
              mSize   = sizes[index];
381
              act.changeObject(list,sizes[index], true);
382
              adjustLevels(act);
383
              mMoves.clear();
384
              }
385

    
386
            mObjectPopup.dismiss();
387
            }
388
          });
389

    
390
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[nextInColumn[col]],colSpecs[col]);
391
        params.bottomMargin = margin;
392
        params.topMargin    = margin;
393
        params.leftMargin   = margin;
394
        params.rightMargin  = margin;
395

    
396
        nextInColumn[col]++;
397

    
398
        objectGrid.addView(button, params);
399
        }
400
      }
401
    }
402

    
403
///////////////////////////////////////////////////////////////////////////////////////////////////
404

    
405
  private void setupMenuWindow(final RubikActivity act, final float width)
406
    {
407
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
408
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
409
    LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
410

    
411
    mMenuPopup = new PopupWindow(act);
412
    mMenuPopup.setContentView(layout);
413
    mMenuPopup.setFocusable(true);
414
    int margin  = (int)(width*RubikActivity.MARGIN);
415
    int padding = (int)(width*RubikActivity.PADDING);
416

    
417
    mMenuLayoutWidth = (int)(width/2);
418
    mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
419

    
420
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
421
    pT.setMargins(margin, 0, margin, margin);
422
    LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
423
    pM.setMargins(margin, margin, margin, margin);
424
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
425
    pB.setMargins(margin, margin, margin, 2*margin);
426

    
427
    for(int i=0; i<NUM_BUTTONS; i++)
428
      {
429
      final int but = i;
430
      Button button = new Button(act);
431
      button.setLayoutParams(pT);//i==0 ? pT : (i==NUM_BUTTONS-1 ? pB : pM));
432
      button.setText(BUTTON_LABELS[i]);
433
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
434

    
435
      button.setOnClickListener( new View.OnClickListener()
436
        {
437
        @Override
438
        public void onClick(View v)
439
          {
440
          mMenuPopup.dismiss();
441
          MenuAction(act,but);
442
          }
443
        });
444

    
445
      menuLayout.addView(button);
446
      }
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  private void setupPlayWindow(final RubikActivity act, final float width)
452
    {
453
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
454
    final View layout = layoutInflater.inflate(R.layout.popup_play, null);
455
    mPlayLayout = layout.findViewById(R.id.playGrid);
456

    
457
    mPlayLayoutWidth = (int)(width*0.4f);
458

    
459
    mPlayPopup = new PopupWindow(act);
460
    mPlayPopup.setContentView(layout);
461
    mPlayPopup.setFocusable(true);
462

    
463
    adjustLevels(act);
464
    }
465

    
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

    
468
  private void backMove(RubikPreRender pre)
469
    {
470
    if( mCanPrevMove )
471
      {
472
      int numMoves = mMoves.size();
473

    
474
      if( numMoves>0 )
475
        {
476
        Move move = mMoves.remove(numMoves-1);
477
        TwistyObject object = pre.getObject();
478

    
479
        int axis  = move.mAxis;
480
        int row   = (1<<move.mRow);
481
        int angle = move.mAngle;
482
        int numRot= Math.abs(angle*object.getBasicAngle()/360);
483

    
484
        if( angle!=0 )
485
          {
486
          mCanPrevMove = false;
487
          pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS);
488
          }
489
        else
490
          {
491
          android.util.Log.e("solution", "error: trying to back move of angle 0");
492
          }
493
        }
494
      }
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  private void MenuAction(RubikActivity act, int button)
500
    {
501
    switch(button)
502
      {
503
      case 0: RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
504
              int object = play.getObject();
505
              int size   = play.getSize();
506
              int sizeIndex = ObjectList.getSizeIndex(object,size);
507

    
508
              Bundle bundle = new Bundle();
509
              bundle.putInt("tab", ObjectList.pack(object,sizeIndex) );
510
              bundle.putBoolean("submitting", false);
511

    
512
              RubikDialogScores scores = new RubikDialogScores();
513
              scores.setArguments(bundle);
514
              scores.show(act.getSupportFragmentManager(), null);
515
              break;
516
      case 1: StateList.switchState(act, StateList.PATT);
517
              break;
518
      case 2: StateList.switchState(act, StateList.SVER);
519
              break;
520
      case 3: RubikDialogAbout diag = new RubikDialogAbout();
521
              diag.show(act.getSupportFragmentManager(), null);
522
              break;
523
      }
524
    }
525

    
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527

    
528
  private void toggleLock(RubikActivity act)
529
    {
530
    act.toggleLock();
531
    mLockButton.setImageResource(getLockIcon(act));
532
    }
533

    
534
///////////////////////////////////////////////////////////////////////////////////////////////////
535

    
536
  private int getLockIcon(RubikActivity act)
537
    {
538
    if( act.retLocked() )
539
      {
540
      return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
541
      }
542
    else
543
      {
544
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
545
      }
546
    }
547

    
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549

    
550
  public void savePreferences(SharedPreferences.Editor editor)
551
    {
552
    editor.putInt("statePlay_object", mObject);
553
    editor.putInt("statePlay_size"  , mSize);
554

    
555
    if( mObjectPopup!=null )
556
      {
557
      mObjectPopup.dismiss();
558
      mObjectPopup = null;
559
      }
560

    
561
    if( mMenuPopup!=null )
562
      {
563
      mMenuPopup.dismiss();
564
      mMenuPopup = null;
565
      }
566

    
567
    if( mPlayPopup!=null )
568
      {
569
      mPlayPopup.dismiss();
570
      mPlayPopup = null;
571
      }
572
    }
573

    
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575

    
576
  public void restorePreferences(SharedPreferences preferences)
577
    {
578
    mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
579
    mSize  = preferences.getInt("statePlay_size"  , DEF_SIZE  );
580
    }
581

    
582
///////////////////////////////////////////////////////////////////////////////////////////////////
583

    
584
  public boolean setObjectAndSize(RubikActivity act, ObjectList obj, int size)
585
    {
586
    if( mObject!=obj.ordinal() || mSize != size )
587
      {
588
      boolean success = false;
589

    
590
      for( int s: obj.getSizes() )
591
        if( s==size )
592
          {
593
          success = true;
594
          break;
595
          }
596

    
597
      if( success )
598
        {
599
        mObject = obj.ordinal();
600
        mSize   = size;
601

    
602
        if( mPlayLayout!=null ) adjustLevels(act);
603
        }
604

    
605
      return success;
606
      }
607

    
608
    return true;
609
    }
610

    
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612

    
613
  private void adjustLevels(final RubikActivity act)
614
    {
615
    int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
616
    int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
617
    String[] levels = new String[maxLevel];
618

    
619
    for(int i=0; i<maxLevel; i++)
620
      {
621
      levels[i] = act.getString(R.string.lv_placeholder,i+1);
622
      }
623

    
624
    if( mLevelValue>maxLevel ) mLevelValue=1;
625

    
626
    float width = act.getScreenWidthInPixels();
627
    int margin  = (int)(width*RubikActivity.MARGIN);
628
    int padding = (int)(width*RubikActivity.PADDING);
629

    
630
    LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
631
    pM.setMargins(margin, 0, margin, margin);
632
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
633
    pT.setMargins(margin, margin, margin, margin);
634
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
635
    pB.setMargins(margin, margin, margin, 2*margin);
636

    
637
    mPlayLayout.removeAllViews();
638

    
639
    RubikScores scores = RubikScores.getInstance();
640

    
641
    for(int i=0; i<maxLevel; i++)
642
      {
643
      final int but = i;
644
      Button button = new Button(act);
645
      button.setLayoutParams(i==0 ? pT : (i==maxLevel-1 ? pB : pM));
646
      button.setText(levels[i]);
647
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
648

    
649
      int icon = scores.isSolved(mObject, sizeIndex, i) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
650
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
651

    
652
      button.setOnClickListener( new View.OnClickListener()
653
        {
654
        @Override
655
        public void onClick(View v)
656
          {
657
          mPlayPopup.dismiss();
658
          mLevelValue = but+1;
659
          act.getPreRender().scrambleObject(mLevelValue);
660
          }
661
        });
662

    
663
      mPlayLayout.addView(button);
664
      }
665
    }
666

    
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668

    
669
  public int getLevel()
670
    {
671
    return mLevelValue;
672
    }
673

    
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675

    
676
  public void addMove(int axis, int row, int angle)
677
    {
678
    mMoves.add(new Move(axis,row,angle));
679
    }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

    
683
  public int getObject()
684
    {
685
    return mObject;
686
    }
687

    
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689

    
690
  public int getSize()
691
    {
692
    return mSize;
693
    }
694

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696

    
697
  public void onActionFinished(final long effectID)
698
    {
699
    mCanPrevMove = true;
700
    }
701
  }
(4-4/9)