Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPlay.java @ 59cc16ae

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

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

    
38
import org.distorted.objectlib.main.ObjectControl;
39

    
40
import org.distorted.main.R;
41
import org.distorted.main.RubikActivity;
42
import org.distorted.dialogs.RubikDialogAbout;
43
import org.distorted.dialogs.RubikDialogPattern;
44
import org.distorted.dialogs.RubikDialogScores;
45
import org.distorted.dialogs.RubikDialogTutorial;
46
import org.distorted.helpers.TransparentButton;
47
import org.distorted.helpers.TransparentImageButton;
48
import org.distorted.network.RubikScores;
49
import org.distorted.objects.RubikObject;
50
import org.distorted.objects.RubikObjectList;
51

    
52
import static android.view.View.inflate;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
public class RubikScreenPlay extends RubikScreenBase
57
  {
58
  public static final int NUM_COLUMNS  = 4;
59
  public static final int LEVELS_SHOWN = 10;
60

    
61
  private static final int[] BUTTON_LABELS = { R.string.scores,
62
                                               R.string.patterns,
63
                                               R.string.solver,
64
                                               R.string.tutorials,
65
                                               R.string.about };
66

    
67
  private static final int NUM_BUTTONS = BUTTON_LABELS.length;
68
  private static final float LAST_BUTTON = 1.5f;
69
  private static final int[] mLocation = new int[2];
70

    
71
  private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
72
  private TransparentButton mPlayButton;
73
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
74
  private LinearLayout mPlayLayout;
75
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
76
  private int mLevelValue;
77
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
78
  private int mColCount, mRowCount, mMaxRowCount;
79
  private int mUpperBarHeight;
80
  private boolean mShouldReactToEndOfScrambling;
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  void leaveScreen(RubikActivity act)
85
    {
86

    
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  void enterScreen(final RubikActivity act)
92
    {
93
    int numObjects = RubikObjectList.getNumObjects();
94
    float width = act.getScreenWidthInPixels();
95
    mUpperBarHeight = act.getHeightUpperBar();
96

    
97
    mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
98
    mButtonSize   = width*RubikActivity.BUTTON_TEXT_SIZE;
99
    mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
100

    
101
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
102
    mColCount = NUM_COLUMNS;
103

    
104
    // TOP ////////////////////////////
105
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
106
    layoutTop.removeAllViews();
107

    
108
    setupObjectButton(act,width);
109
    layoutTop.addView(mObjButton);
110

    
111
    setupMenuButton(act,width);
112
    layoutTop.addView(mMenuButton);
113

    
114
    setupPlayButton(act,width);
115
    layoutTop.addView(mPlayButton);
116

    
117
    setupSolveButton(act);
118
    setupScrambleButton(act);
119
    createBottomPane(act,mSolveButton,mScrambleButton);
120
    }
121

    
122
//////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  private void setupObjectButton(final RubikActivity act, final float width)
125
    {
126
    final int margin  = (int)(width*RubikActivity.MARGIN);
127
    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);
128
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
129
    mObjButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
130

    
131
    mObjButton.setOnClickListener( new View.OnClickListener()
132
      {
133
      @Override
134
      public void onClick(View view)
135
        {
136
        if( mObjectPopup==null )
137
          {
138
          float width = act.getScreenWidthInPixels();
139
          float height= act.getScreenHeightInPixels();
140
          setupObjectWindow(act,width,height);
141
          }
142

    
143
        if( act.getControl().isUINotBlocked())
144
          {
145
          int rowCount = Math.min(mMaxRowCount,mRowCount);
146
          View popupView = mObjectPopup.getContentView();
147
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
148
          displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount,margin,margin);
149
          }
150
        }
151
      });
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  private void setupPlayButton(final RubikActivity act, final float width)
157
    {
158
    final int margin = (int)(width*RubikActivity.MARGIN);
159

    
160
    mPlayButton = new TransparentButton(act, R.string.play, mButtonSize);
161

    
162
    mPlayButton.setOnClickListener( new View.OnClickListener()
163
      {
164
      @Override
165
      public void onClick(View view)
166
        {
167
         if( mPlayPopup==null )
168
          {
169
          float width = act.getScreenWidthInPixels();
170
          setupPlayWindow(act,width);
171
          }
172

    
173
        if( act.getControl().isUINotBlocked())
174
          {
175
          float height= act.getScreenHeightInPixels();
176
          final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) );
177
          View popupView = mPlayPopup.getContentView();
178
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
179
          final int object  = RubikObjectList.getCurrObject();
180
          final int dbLevel = RubikObjectList.getDBLevel(object);
181
          final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
182
          final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
183
          final int realHeight = Math.min(popupHeight,maxHeight);
184
          displayPopup(act,view,mPlayPopup,mPlayLayoutWidth,realHeight,margin,margin);
185
          }
186
        }
187
      });
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  private void setupMenuButton(final RubikActivity act, final float width)
193
    {
194
    final int margin = (int)(width*RubikActivity.MARGIN);
195
    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);
196
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
197
    mMenuButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
198

    
199
    mMenuButton.setOnClickListener( new View.OnClickListener()
200
      {
201
      @Override
202
      public void onClick(View view)
203
        {
204
        if( mMenuPopup==null )
205
          {
206
          float width = act.getScreenWidthInPixels();
207
          setupMenuWindow(act,width);
208
          }
209

    
210
        if( act.getControl().isUINotBlocked())
211
          {
212
          View popupView = mMenuPopup.getContentView();
213
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
214
          displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-width/12),margin);
215
          }
216
        }
217
      });
218
    }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
  private void setupObjectWindow(final RubikActivity act, final float width, final float height)
223
    {
224
    int icon = RubikActivity.getDrawable(R.drawable.cube_2s,R.drawable.cube_2m, R.drawable.cube_2b, R.drawable.cube_2h);
225

    
226
    Resources res = act.getResources();
227
    BitmapDrawable bd = (BitmapDrawable)res.getDrawable(icon);
228
    int cubeWidth = bd.getIntrinsicWidth();
229
    int margin = (int)(width*RubikActivity.LARGE_MARGIN);
230
    mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
231
    mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize);
232

    
233
    LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null);
234
    GridLayout objectGrid = view.findViewById(R.id.objectGrid);
235

    
236
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
237
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
238

    
239
    objectGrid.setColumnCount(mColCount);
240
    objectGrid.setRowCount(mRowCount);
241

    
242
    LinearLayout bottomLayout = view.findViewById(R.id.bottomLayout);
243
    setupBottomLayout(act,bottomLayout,2*mObjectSize);
244

    
245
    mObjectPopup = new PopupWindow(act);
246
    mObjectPopup.setFocusable(true);
247
    mObjectPopup.setContentView(view);
248

    
249
    int[] nextInRow = new int[mRowCount];
250

    
251
    for(int row=0; row<mRowCount; row++)
252
      {
253
      rowSpecs[row] = GridLayout.spec(row);
254
      nextInRow[row]= 0;
255
      }
256
    for(int col=0; col<mColCount; col++)
257
      {
258
      colSpecs[col] = GridLayout.spec(col);
259
      }
260

    
261
    int numObjects = RubikObjectList.getNumObjects();
262

    
263
    for(int object=0; object<numObjects; object++)
264
      {
265
      final RubikObject robject = RubikObjectList.getObject(object);
266
      int iconSize = RubikActivity.getDrawableSize();
267
      int icons = robject==null ? 0 : robject.getIconID(iconSize);
268
      int row = object/NUM_COLUMNS;
269
      final int ordinal = robject==null ? 0 : robject.getOrdinal();
270

    
271
      ImageButton button = new ImageButton(act);
272
      button.setBackgroundResource(icons);
273
      button.setOnClickListener( new View.OnClickListener()
274
        {
275
        @Override
276
        public void onClick(View v)
277
          {
278
          if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
279
            {
280
            RubikObjectList.setCurrObject(act,ordinal);
281
            act.changeObject(ordinal,true);
282
            if( mPlayLayout!=null ) adjustLevels(act);
283
            mMovesController.clearMoves(act);
284
            }
285

    
286
          mObjectPopup.dismiss();
287
          }
288
        });
289

    
290
      GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
291
      params.bottomMargin = margin;
292
      params.topMargin    = margin;
293
      params.leftMargin   = margin;
294
      params.rightMargin  = margin;
295

    
296
      nextInRow[row]++;
297

    
298
      objectGrid.addView(button, params);
299
      }
300
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  private void setupBottomLayout(final RubikActivity act, final LinearLayout layout, int width)
305
    {
306
    int iconD = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
307
    int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial);
308

    
309
    ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
310
         Button buttonNul = layout.findViewById(R.id.buttonNul);
311
    ImageButton buttonDet = layout.findViewById(R.id.buttonDet);
312

    
313
    buttonTut.setImageResource(iconT);
314
    buttonDet.setImageResource(iconD);
315
    buttonNul.setVisibility(View.INVISIBLE);
316

    
317
    buttonNul.setWidth(width);
318

    
319
    TypedValue outValue = new TypedValue();
320
    act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
321
    buttonTut.setBackgroundResource(outValue.resourceId);
322
    buttonDet.setBackgroundResource(outValue.resourceId);
323

    
324
    buttonTut.setOnClickListener( new View.OnClickListener()
325
      {
326
      @Override
327
      public void onClick(View v)
328
        {
329
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
330
        RubikDialogTutorial tDiag = new RubikDialogTutorial();
331
        tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
332
        }
333
      });
334

    
335
    buttonDet.setOnClickListener( new View.OnClickListener()
336
      {
337
      @Override
338
      public void onClick(View v)
339
        {
340
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
341
        int currObject = RubikObjectList.getCurrObject();
342
        act.switchConfig(currObject);
343
        }
344
      });
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

    
349
  private void setupMenuWindow(final RubikActivity act, final float width)
350
    {
351
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
352
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
353
    LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
354

    
355
    mMenuPopup = new PopupWindow(act);
356
    mMenuPopup.setContentView(layout);
357
    mMenuPopup.setFocusable(true);
358
    int margin  = (int)(width*RubikActivity.MARGIN);
359
    int padding = (int)(width*RubikActivity.PADDING);
360

    
361
    mMenuLayoutWidth = (int)(width/2);
362
    mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
363

    
364
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
365

    
366
    for(int i=0; i<NUM_BUTTONS; i++)
367
      {
368
      final int but = i;
369
      Button button = new Button(act);
370
      button.setLayoutParams(p);
371
      button.setText(BUTTON_LABELS[i]);
372
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
373

    
374
      button.setOnClickListener( new View.OnClickListener()
375
        {
376
        @Override
377
        public void onClick(View v)
378
          {
379
          mMenuPopup.dismiss();
380
          MenuAction(act,but);
381
          }
382
        });
383

    
384
      menuLayout.addView(button);
385
      }
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  private void setupPlayWindow(final RubikActivity act, final float width)
391
    {
392
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
393
    final View layout = layoutInflater.inflate(R.layout.popup_play, null);
394
    mPlayLayout = layout.findViewById(R.id.playGrid);
395

    
396
    mPlayLayoutWidth = (int)(width*0.4f);
397

    
398
    mPlayPopup = new PopupWindow(act);
399
    mPlayPopup.setContentView(layout);
400
    mPlayPopup.setFocusable(true);
401

    
402
    adjustLevels(act);
403
    }
404

    
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

    
407
  private void MenuAction(RubikActivity act, int button)
408
    {
409
    switch(button)
410
      {
411
      case 0: Bundle sBundle = new Bundle();
412
              int currObject = RubikObjectList.getCurrObject();
413
              sBundle.putInt("tab", currObject );
414
              sBundle.putBoolean("submitting", false);
415
              RubikDialogScores scores = new RubikDialogScores();
416
              scores.setArguments(sBundle);
417
              scores.show(act.getSupportFragmentManager(), null);
418
              break;
419
      case 1: RubikDialogPattern pDiag = new RubikDialogPattern();
420
              pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
421
              break;
422
      case 2: ScreenList.switchScreen(act, ScreenList.SVER);
423
              break;
424
      case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
425
              tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
426
              break;
427
      case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
428
              aDiag.show(act.getSupportFragmentManager(), null);
429
              break;
430
      }
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  void setupSolveButton(final RubikActivity act)
436
    {
437
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve_new,R.drawable.ui_medium_cube_solve_new, R.drawable.ui_big_cube_solve_new, R.drawable.ui_huge_cube_solve_new);
438
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
439
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_END,params);
440

    
441
    mSolveButton.setOnClickListener( new View.OnClickListener()
442
      {
443
      @Override
444
      public void onClick(View v)
445
        {
446
        act.getControl().solveObject();
447
        mMovesController.clearMoves(act);
448
        }
449
      });
450
    }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453

    
454
  private void setupScrambleButton(final RubikActivity act)
455
    {
456
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble_new,R.drawable.ui_medium_cube_scramble_new, R.drawable.ui_big_cube_scramble_new, R.drawable.ui_huge_cube_scramble_new);
457
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
458
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_START, params);
459

    
460
    mScrambleButton.setOnClickListener( new View.OnClickListener()
461
      {
462
      @Override
463
      public void onClick(View v)
464
        {
465
        int currObject = RubikObjectList.getCurrObject();
466
        RubikObject object = RubikObjectList.getObject(currObject);
467
        int numScrambles = object==null ? 0 : object.getNumScramble();
468
        mShouldReactToEndOfScrambling = false;
469
        act.getControl().scrambleObject(numScrambles);
470
        }
471
      });
472
    }
473

    
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still
476
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not
477
// going to be called)
478
// An reference to the old instance of RubikActivity will cause all sorts of strange issues.
479

    
480
  public void savePreferences(SharedPreferences.Editor editor)
481
    {
482
    if( mObjectPopup!=null )
483
      {
484
      mObjectPopup.dismiss();
485
      mObjectPopup = null;
486
      }
487

    
488
    if( mMenuPopup!=null )
489
      {
490
      mMenuPopup.dismiss();
491
      mMenuPopup = null;
492
      }
493

    
494
    if( mPlayPopup!=null )
495
      {
496
      mPlayPopup.dismiss();
497
      mPlayPopup = null;
498
      }
499
    }
500

    
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502

    
503
  public void restorePreferences(SharedPreferences preferences)
504
    {
505

    
506
    }
507

    
508
///////////////////////////////////////////////////////////////////////////////////////////////////
509

    
510
  public void setCurrObject(RubikActivity act)
511
    {
512
    if( mPlayLayout!=null ) adjustLevels(act);
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
517

    
518
  private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
519
    {
520
    View topLayout = act.findViewById(R.id.relativeLayout);
521
    boolean isFullScreen;
522

    
523
    if( topLayout!=null )
524
      {
525
      topLayout.getLocationOnScreen(mLocation);
526
      isFullScreen = (mLocation[1]==0);
527
      }
528
    else
529
      {
530
      isFullScreen = true;
531
      }
532

    
533
    try
534
      {
535
      // if on Android 11 or we are fullscreen
536
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || isFullScreen )
537
        {
538
        window.showAsDropDown(view, xoff, yoff, Gravity.CENTER);
539
        window.update(view, w, h);
540
        }
541
      else  // Android 10 or below in pop-up mode or split-screen mode
542
        {
543
        view.getLocationOnScreen(mLocation);
544
        int width  = view.getWidth();
545
        int height = view.getHeight();
546
        int x = mLocation[0]+(width-w)/2;
547
        int y = mLocation[1]+height+yoff;
548

    
549
        window.showAsDropDown(view);
550
        window.update(x,y,w,h);
551
        }
552
      }
553
    catch( IllegalArgumentException iae )
554
      {
555
      // ignore, this means window is 'not attached to window manager' -
556
      // which most probably is because we are already exiting the app.
557
      }
558
    }
559

    
560
///////////////////////////////////////////////////////////////////////////////////////////////////
561

    
562
  public void adjustSolvedIcons()
563
    {
564
    if( mPlayLayout!=null )
565
      {
566
      int currObject = RubikObjectList.getCurrObject();
567
      int dbLevel = RubikObjectList.getDBLevel(currObject);
568
      int numLevel= Math.min(dbLevel, LEVELS_SHOWN);
569
      RubikScores scores = RubikScores.getInstance();
570

    
571
      for(int i=0; i<numLevel; i++)
572
        {
573
        int level = i<numLevel-1 ? i+1 : dbLevel;
574
        Button button = (Button)mPlayLayout.getChildAt(i);
575
        int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
576
        button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
577
        }
578
      }
579
    }
580

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

    
583
  private void adjustLevels(final RubikActivity act)
584
    {
585
    int currObject = RubikObjectList.getCurrObject();
586
    int dbLevel = RubikObjectList.getDBLevel(currObject);
587
    RubikObject object = RubikObjectList.getObject(currObject);
588
    int numScrambles = object==null ? 0 : object.getNumScramble();
589
    int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
590
    String[] levels = new String[numLevel];
591

    
592
    for(int i=0; i<numLevel-1; i++)
593
      {
594
      levels[i] = act.getString(R.string.lv_placeholder,i+1);
595
      }
596

    
597
    if( numLevel>0 )
598
      {
599
      levels[numLevel-1] = act.getString(R.string.level_full);
600
      }
601

    
602
    if( mLevelValue>dbLevel || mLevelValue<1 ||
603
       (mLevelValue<dbLevel || mLevelValue>LEVELS_SHOWN ) )
604
      {
605
      mLevelValue=1;
606
      }
607

    
608
    float width  = act.getScreenWidthInPixels();
609
    int margin   = (int)(width*RubikActivity.MARGIN);
610
    int padding  = (int)(width*RubikActivity.PADDING);
611
    int butWidth = mPlayLayoutWidth - 2*padding;
612
    int butHeight= (int)mMenuItemSize;
613
    int lastButH = (int)(mMenuItemSize*LAST_BUTTON) ;
614

    
615
    LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( butWidth, butHeight );
616
    pM.setMargins(margin, 0, margin, margin);
617
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( butWidth, butHeight );
618
    pT.setMargins(margin, margin, margin, margin);
619
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( butWidth, lastButH  );
620
    pB.setMargins(margin, margin, margin, 2*margin);
621

    
622
    mPlayLayout.removeAllViews();
623

    
624
    RubikScores scores = RubikScores.getInstance();
625

    
626
    for(int i=0; i<numLevel; i++)
627
      {
628
      final int level     = i<numLevel-1 ? i+1 : dbLevel;
629
      final int scrambles = i<numLevel-1 ? i+1 : numScrambles;
630
      Button button = new Button(act);
631
      button.setLayoutParams(i==0 ? pT : (i==numLevel-1 ? pB : pM));
632
      button.setText(levels[i]);
633
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
634

    
635
      int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
636
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
637

    
638
      button.setOnClickListener( new View.OnClickListener()
639
        {
640
        @Override
641
        public void onClick(View v)
642
          {
643
          ObjectControl control = act.getControl();
644

    
645
          if(control.isUINotBlocked())
646
            {
647
            if( mPlayPopup!=null ) mPlayPopup.dismiss();
648
            mLevelValue = level;
649
            mShouldReactToEndOfScrambling = true;
650
            control.scrambleObject(scrambles);
651
            }
652
          }
653
        });
654

    
655
      mPlayLayout.addView(button);
656
      }
657
    }
658

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

    
661
  public int getLevel()
662
    {
663
    return mLevelValue;
664
    }
665

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

    
668
  public boolean shouldReactToEndOfScrambling()
669
    {
670
    return mShouldReactToEndOfScrambling;
671
    }
672
  }
(5-5/10)