Project

General

Profile

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

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

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.Gravity;
28
import android.view.LayoutInflater;
29
import android.view.View;
30
import android.widget.Button;
31
import android.widget.GridLayout;
32
import android.widget.ImageButton;
33
import android.widget.LinearLayout;
34
import android.widget.PopupWindow;
35

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

    
45
import java.util.ArrayList;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

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

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

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

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

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

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  void leaveState(RubikActivity act)
88
    {
89

    
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

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

    
101
    mCanPrevMove = true;
102

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

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

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

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

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

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

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

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

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

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

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

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

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

    
158
    mObjButton.setOnClickListener( new View.OnClickListener()
159
      {
160
      @Override
161
      public void onClick(View view)
162
        {
163
        if( act.getPreRender().canPlay() )
164
          {
165
          mObjectPopup.setFocusable(false);
166
          mObjectPopup.update();
167

    
168
          View popupView = mObjectPopup.getContentView();
169
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
170

    
171
          mObjectPopup.showAsDropDown(view, margin, margin, Gravity.LEFT);
172
          mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount);
173

    
174
          mObjectPopup.setFocusable(true);
175
          mObjectPopup.update();
176
          }
177
        }
178
      });
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  private void setupPlayButton(final RubikActivity act, final float width)
184
    {
185
    final int margin  = (int)(width*RubikActivity.MARGIN);
186
    mPlayButton = new TransparentButton(act, R.string.play, mButtonSize, width);
187

    
188
    mPlayButton.setOnClickListener( new View.OnClickListener()
189
      {
190
      @Override
191
      public void onClick(View view)
192
        {
193
        mPlayPopup.setFocusable(false);
194
        mPlayPopup.update();
195

    
196
        View popupView = mPlayPopup.getContentView();
197
        popupView.setSystemUiVisibility(RubikActivity.FLAGS);
198

    
199
        final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
200
        final int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
201
        final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);
202

    
203
        mPlayPopup.showAsDropDown(view, margin, margin, Gravity.RIGHT);
204
        mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin));
205

    
206
        mPlayPopup.setFocusable(true);
207
        mPlayPopup.update();
208
        }
209
      });
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  private void setupMenuButton(final RubikActivity act, final float width)
215
    {
216
    final int margin  = (int)(width*RubikActivity.MARGIN);
217
    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);
218
    mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
219

    
220
    mMenuButton.setOnClickListener( new View.OnClickListener()
221
      {
222
      @Override
223
      public void onClick(View view)
224
        {
225
        if( act.getPreRender().canPlay() )
226
          {
227
          mMenuPopup.setFocusable(false);
228
          mMenuPopup.update();
229

    
230
          View popupView = mMenuPopup.getContentView();
231
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
232

    
233
          mMenuPopup.showAsDropDown(view, (int)(-width/12), margin, Gravity.CENTER);
234
          mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight);
235

    
236
          mMenuPopup.setFocusable(true);
237
          mMenuPopup.update();
238
          }
239
        }
240
      });
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  private void setupSolveButton(final RubikActivity act, final float width)
246
    {
247
    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);
248
    mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
249

    
250
    mSolveButton.setOnClickListener( new View.OnClickListener()
251
      {
252
      @Override
253
      public void onClick(View v)
254
        {
255
        act.getPreRender().solveObject();
256
        mMoves.clear();
257
        }
258
      });
259
    }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

    
263
  private void setupLockButton(final RubikActivity act, final float width)
264
    {
265
    final int icon = getLockIcon(act);
266
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
267

    
268
    mLockButton.setOnClickListener( new View.OnClickListener()
269
      {
270
      @Override
271
      public void onClick(View v)
272
        {
273
        toggleLock(act);
274
        }
275
      });
276
    }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
  private void setupPrevButton(final RubikActivity act, final float width)
281
    {
282
    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);
283
    mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
284

    
285
    mPrevButton.setOnClickListener( new View.OnClickListener()
286
      {
287
      @Override
288
      public void onClick(View v)
289
        {
290
        RubikPreRender pre = act.getPreRender();
291
        backMove(pre);
292
        }
293
      });
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  private void setupObjectWindow(final RubikActivity act, final float width)
299
    {
300
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
301
    final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
302
    GridLayout objectGrid = layout.findViewById(R.id.objectGrid);
303

    
304
    int[] indices = ObjectList.getIndices();
305

    
306
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
307
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
308

    
309
    objectGrid.setColumnCount(mColCount);
310
    objectGrid.setRowCount(mRowCount);
311

    
312
    int[] nextInColumn = new int[mColCount];
313

    
314
    for(int row=0; row<mRowCount; row++)
315
      {
316
      rowSpecs[row] = GridLayout.spec(row);
317
      }
318
    for(int col=0; col<mColCount; col++)
319
      {
320
      colSpecs[col] = GridLayout.spec(col);
321
      nextInColumn[col] =0;
322
      }
323

    
324
    mObjectPopup = new PopupWindow(act);
325
    mObjectPopup.setContentView(layout);
326
    mObjectPopup.setFocusable(true);
327
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);
328

    
329
    BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
330
    int cubeWidth = bd.getIntrinsicWidth();
331
    int margin = (int)(width*RubikActivity.LARGE_MARGIN);
332
    mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
333

    
334
    for(int object = 0; object< ObjectList.NUM_OBJECTS; object++)
335
      {
336
      final ObjectList list = ObjectList.getObject(object);
337
      final int[] sizes = list.getSizes();
338
      int[] icons = list.getIconIDs();
339
      int len = sizes.length;
340
      final int obj = object;
341
      int col = indices[object];
342

    
343
      for(int i=0; i<len; i++)
344
        {
345
        final int index = i;
346

    
347
        ImageButton button = new ImageButton(act);
348
        button.setBackgroundResource(icons[i]);
349
        button.setOnClickListener( new View.OnClickListener()
350
          {
351
          @Override
352
          public void onClick(View v)
353
            {
354
            if( act.getPreRender().canPlay() && StateList.getCurrentState()== StateList.PLAY )
355
              {
356
              mObject = obj;
357
              mSize   = sizes[index];
358
              act.changeObject(list,sizes[index], true);
359
              adjustLevels(act);
360
              mMoves.clear();
361
              }
362

    
363
            mObjectPopup.dismiss();
364
            }
365
          });
366

    
367
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[nextInColumn[col]],colSpecs[col]);
368
        params.bottomMargin = margin;
369
        params.topMargin    = margin;
370
        params.leftMargin   = margin;
371
        params.rightMargin  = margin;
372

    
373
        nextInColumn[col]++;
374

    
375
        objectGrid.addView(button, params);
376
        }
377
      }
378
    }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381

    
382
  private void setupMenuWindow(final RubikActivity act, final float width)
383
    {
384
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
385
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
386
    LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
387

    
388
    mMenuPopup = new PopupWindow(act);
389
    mMenuPopup.setContentView(layout);
390
    mMenuPopup.setFocusable(true);
391
    int margin  = (int)(width*RubikActivity.MARGIN);
392
    int padding = (int)(width*RubikActivity.PADDING);
393

    
394
    mMenuLayoutWidth = (int)(width/2);
395
    mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
396

    
397
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
398
    pT.setMargins(margin, 0, margin, margin);
399
    LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
400
    pM.setMargins(margin, margin, margin, margin);
401
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
402
    pB.setMargins(margin, margin, margin, 2*margin);
403

    
404
    for(int i=0; i<NUM_BUTTONS; i++)
405
      {
406
      final int but = i;
407
      Button button = new Button(act);
408
      button.setLayoutParams(pT);//i==0 ? pT : (i==NUM_BUTTONS-1 ? pB : pM));
409
      button.setText(BUTTON_LABELS[i]);
410
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
411

    
412
      button.setOnClickListener( new View.OnClickListener()
413
        {
414
        @Override
415
        public void onClick(View v)
416
          {
417
          mMenuPopup.dismiss();
418
          MenuAction(act,but);
419
          }
420
        });
421

    
422
      menuLayout.addView(button);
423
      }
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
  private void setupPlayWindow(final RubikActivity act, final float width)
429
    {
430
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
431
    final View layout = layoutInflater.inflate(R.layout.popup_play, null);
432
    mPlayLayout = layout.findViewById(R.id.playGrid);
433

    
434
    mPlayLayoutWidth = (int)(width*0.4f);
435

    
436
    mPlayPopup = new PopupWindow(act);
437
    mPlayPopup.setContentView(layout);
438
    mPlayPopup.setFocusable(true);
439

    
440
    adjustLevels(act);
441
    }
442

    
443
///////////////////////////////////////////////////////////////////////////////////////////////////
444

    
445
  private void backMove(RubikPreRender pre)
446
    {
447
    if( mCanPrevMove )
448
      {
449
      int numMoves = mMoves.size();
450

    
451
      if( numMoves>0 )
452
        {
453
        Move move = mMoves.remove(numMoves-1);
454
        TwistyObject object = pre.getObject();
455

    
456
        int axis  = move.mAxis;
457
        int row   = (1<<move.mRow);
458
        int angle = move.mAngle;
459
        int numRot= Math.abs(angle*object.getBasicAngle()/360);
460

    
461
        if( angle!=0 )
462
          {
463
          mCanPrevMove = false;
464
          pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS);
465
          }
466
        else
467
          {
468
          android.util.Log.e("solution", "error: trying to back move of angle 0");
469
          }
470
        }
471
      }
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

    
476
  private void MenuAction(RubikActivity act, int button)
477
    {
478
    switch(button)
479
      {
480
      case 0: RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
481
              int object = play.getObject();
482
              int size   = play.getSize();
483
              int sizeIndex = ObjectList.getSizeIndex(object,size);
484

    
485
              Bundle bundle = new Bundle();
486
              bundle.putInt("tab", ObjectList.pack(object,sizeIndex) );
487
              bundle.putBoolean("submitting", false);
488

    
489
              RubikDialogScores scores = new RubikDialogScores();
490
              scores.setArguments(bundle);
491
              scores.show(act.getSupportFragmentManager(), null);
492
              break;
493
      case 1: StateList.switchState(act, StateList.PATT);
494
              break;
495
      case 2: StateList.switchState(act, StateList.SVER);
496
              break;
497
      case 3: RubikDialogAbout diag = new RubikDialogAbout();
498
              diag.show(act.getSupportFragmentManager(), null);
499
              break;
500
      }
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  private void toggleLock(RubikActivity act)
506
    {
507
    act.toggleLock();
508
    mLockButton.setImageResource(getLockIcon(act));
509
    }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
  private int getLockIcon(RubikActivity act)
514
    {
515
    if( act.retLocked() )
516
      {
517
      return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
518
      }
519
    else
520
      {
521
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
522
      }
523
    }
524

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

    
527
  public void savePreferences(SharedPreferences.Editor editor)
528
    {
529
    editor.putInt("statePlay_object", mObject);
530
    editor.putInt("statePlay_size"  , mSize);
531

    
532
    if( mObjectPopup!=null )
533
      {
534
      mObjectPopup.dismiss();
535
      mObjectPopup = null;
536
      }
537

    
538
    if( mMenuPopup!=null )
539
      {
540
      mMenuPopup.dismiss();
541
      mMenuPopup = null;
542
      }
543

    
544
    if( mPlayPopup!=null )
545
      {
546
      mPlayPopup.dismiss();
547
      mPlayPopup = null;
548
      }
549
    }
550

    
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552

    
553
  public void restorePreferences(SharedPreferences preferences)
554
    {
555
    mObject     = preferences.getInt("statePlay_object", DEF_OBJECT);
556
    mSize       = preferences.getInt("statePlay_size"  , DEF_SIZE  );
557
    }
558

    
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560

    
561
  public boolean setObjectAndSize(RubikActivity act, ObjectList obj, int size)
562
    {
563
    if( mObject!=obj.ordinal() || mSize != size )
564
      {
565
      boolean success = false;
566

    
567
      for( int s: obj.getSizes() )
568
        if( s==size )
569
          {
570
          success = true;
571
          break;
572
          }
573

    
574
      if( success )
575
        {
576
        mObject = obj.ordinal();
577
        mSize   = size;
578

    
579
        if( mPlayLayout!=null ) adjustLevels(act);
580
        }
581

    
582
      return success;
583
      }
584

    
585
    return true;
586
    }
587

    
588
///////////////////////////////////////////////////////////////////////////////////////////////////
589

    
590
  private void adjustLevels(final RubikActivity act)
591
    {
592
    int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
593
    int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex);
594
    String[] levels = new String[maxLevel];
595

    
596
    for(int i=0; i<maxLevel; i++)
597
      {
598
      levels[i] = act.getString(R.string.lv_placeholder,i+1);
599
      }
600

    
601
    if( mLevelValue>maxLevel ) mLevelValue=1;
602

    
603
    float width = act.getScreenWidthInPixels();
604
    int margin  = (int)(width*RubikActivity.MARGIN);
605
    int padding = (int)(width*RubikActivity.PADDING);
606

    
607
    LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
608
    pM.setMargins(margin, 0, margin, margin);
609
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
610
    pT.setMargins(margin, margin, margin, margin);
611
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( mPlayLayoutWidth - 2*padding, (int)mMenuItemSize);
612
    pB.setMargins(margin, margin, margin, 2*margin);
613

    
614
    mPlayLayout.removeAllViews();
615

    
616
    int realSize= ObjectList.getSizeIndex(mObject,mSize);
617
    RubikScores scores = RubikScores.getInstance();
618

    
619
    for(int i=0; i<maxLevel; i++)
620
      {
621
      final int but = i;
622
      Button button = new Button(act);
623
      button.setLayoutParams(i==0 ? pT : (i==maxLevel-1 ? pB : pM));
624
      button.setText(levels[i]);
625
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
626

    
627
      int icon = scores.isSolved(mObject, realSize, i) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
628
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
629

    
630
      button.setOnClickListener( new View.OnClickListener()
631
        {
632
        @Override
633
        public void onClick(View v)
634
          {
635
          mPlayPopup.dismiss();
636
          mLevelValue = but+1;
637
          act.getPreRender().scrambleObject(mLevelValue);
638
          }
639
        });
640

    
641
      mPlayLayout.addView(button);
642
      }
643
    }
644

    
645
///////////////////////////////////////////////////////////////////////////////////////////////////
646

    
647
  public int getLevel()
648
    {
649
    return mLevelValue;
650
    }
651

    
652
///////////////////////////////////////////////////////////////////////////////////////////////////
653

    
654
  public void addMove(int axis, int row, int angle)
655
    {
656
    mMoves.add(new Move(axis,row,angle));
657
    }
658

    
659
///////////////////////////////////////////////////////////////////////////////////////////////////
660

    
661
  public int getObject()
662
    {
663
    return mObject;
664
    }
665

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

    
668
  public int getSize()
669
    {
670
    return mSize;
671
    }
672

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

    
675
  public void onActionFinished(final long effectID)
676
    {
677
    mCanPrevMove = true;
678
    }
679
  }
(4-4/9)