Project

General

Profile

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

magiccube / src / main / java / org / distorted / states / RubikStatePlay.java @ fd0b901a

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 static int mSafeInsetTop;
59

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

    
71
  private ArrayList<Move> mMoves;
72
  private boolean mCanPrevMove;
73

    
74
  private static class Move
75
    {
76
    private int mAxis, mRow, mAngle;
77

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

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  void leaveState(RubikActivity act)
89
    {
90

    
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

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

    
102
    mCanPrevMove = true;
103

    
104
    if( mMoves==null ) mMoves = new ArrayList<>();
105
    else               mMoves.clear();
106

    
107
    mRowCount = ObjectList.getRowCount();
108
    mColCount = ObjectList.getColumnCount();
109

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

    
114
    setupObjectWindow(act,width);
115
    setupObjectButton(act,width);
116
    layoutTop.addView(mObjButton);
117

    
118
    setupMenuWindow(act,width);
119
    setupMenuButton(act,width);
120
    layoutTop.addView(mMenuButton);
121

    
122
    setupPlayWindow(act,width);
123
    setupPlayButton(act,width);
124
    layoutTop.addView(mPlayButton);
125

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

    
130
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
131

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

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

    
146
    layoutBot.addView(layoutLeft);
147
    layoutBot.addView(layoutMid);
148
    layoutBot.addView(layoutRight);
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  private void setupObjectButton(final RubikActivity act, final float width)
154
    {
155
    final int margin  = (int)(width*RubikActivity.MARGIN);
156
    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);
157
    mObjButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
158

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

    
173
          mObjectPopup.setFocusable(false);
174
          mObjectPopup.update();
175

    
176
          View popupView = mObjectPopup.getContentView();
177
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
178

    
179
          mObjectPopup.showAsDropDown(view, margin, margin + mSafeInsetTop);
180
          mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);
181

    
182
          mObjectPopup.setFocusable(true);
183
          mObjectPopup.update();
184
          }
185
        }
186
      });
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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

    
196
    mPlayButton.setOnClickListener( new View.OnClickListener()
197
      {
198
      @Override
199
      public void onClick(View view)
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 + mSafeInsetTop);
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
  private void setupMenuButton(final RubikActivity act, final float width)
230
    {
231
    final int margin  = (int)(width*RubikActivity.MARGIN);
232
    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);
233
    mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
234

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

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

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

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

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

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  private void setupSolveButton(final RubikActivity act, final float width)
268
    {
269
    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);
270
    mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
271

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

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

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

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

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
  private void setupPrevButton(final RubikActivity act, final float width)
303
    {
304
    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);
305
    mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
306

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

    
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

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

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

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

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

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

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

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

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

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

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

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

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

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

    
395
        nextInColumn[col]++;
396

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

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

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

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

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

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

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

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

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

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

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

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

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

    
462
    adjustLevels(act);
463
    }
464

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

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

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

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

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

    
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

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

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

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

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

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

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534

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

    
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548

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

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

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

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

    
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574

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

    
581
///////////////////////////////////////////////////////////////////////////////////////////////////
582

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

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

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

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

    
604
      return success;
605
      }
606

    
607
    return true;
608
    }
609

    
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611

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

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

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

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

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

    
636
    mPlayLayout.removeAllViews();
637

    
638
    RubikScores scores = RubikScores.getInstance();
639

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

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

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

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

    
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667

    
668
  public static void setSafeInsetTop(int top)
669
    {
670
    mSafeInsetTop = top;
671
    }
672

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674

    
675
  public int getLevel()
676
    {
677
    return mLevelValue;
678
    }
679

    
680
///////////////////////////////////////////////////////////////////////////////////////////////////
681

    
682
  public void addMove(int axis, int row, int angle)
683
    {
684
    mMoves.add(new Move(axis,row,angle));
685
    }
686

    
687
///////////////////////////////////////////////////////////////////////////////////////////////////
688

    
689
  public int getObject()
690
    {
691
    return mObject;
692
    }
693

    
694
///////////////////////////////////////////////////////////////////////////////////////////////////
695

    
696
  public int getSize()
697
    {
698
    return mSize;
699
    }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

    
703
  public void onActionFinished(final long effectID)
704
    {
705
    mCanPrevMove = true;
706
    }
707
  }
(4-4/9)