Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPlay.java @ 302c76a0

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.screens;
11

    
12
import java.lang.ref.WeakReference;
13

    
14
import android.app.Activity;
15
import android.content.Context;
16
import android.content.SharedPreferences;
17
import android.content.res.ColorStateList;
18
import android.content.res.Resources;
19
import android.os.Build;
20
import android.os.Bundle;
21
import android.util.TypedValue;
22
import android.view.Gravity;
23
import android.view.LayoutInflater;
24
import android.view.View;
25
import android.widget.Button;
26
import android.widget.GridLayout;
27
import android.widget.ImageButton;
28
import android.widget.LinearLayout;
29
import android.widget.PopupWindow;
30
import android.widget.RelativeLayout;
31
import android.widget.TextView;
32

    
33
import org.distorted.dialogs.RubikDialogUpdates;
34
import org.distorted.external.RubikNetwork;
35
import org.distorted.external.RubikScores;
36
import org.distorted.external.RubikUpdates;
37

    
38
import org.distorted.helpers.PopupCreator;
39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
41
import org.distorted.dialogs.RubikDialogAbout;
42
import org.distorted.dialogs.RubikDialogPattern;
43
import org.distorted.dialogs.RubikDialogScores;
44
import org.distorted.dialogs.RubikDialogTutorial;
45
import org.distorted.helpers.TransparentImageButton;
46
import org.distorted.objectlib.main.ObjectControl;
47
import org.distorted.objects.RubikObject;
48
import org.distorted.objects.RubikObjectList;
49

    
50
import static android.view.View.inflate;
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee
55
  {
56
  public static final int NUM_COLUMNS  = 5;
57
  public static final int LEVELS_SHOWN = 8;
58
  private static final int NUM_BUTTONS = 6;
59
  private static final int[] mLocation = new int[2];
60

    
61
  private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
62
  private PopupWindow mObjectPopup, mMenuPopup;
63
  private WeakReference<RubikActivity> mWeakAct;
64
  private TextView mBubbleUpdates;
65
  private Button[] mLevel;
66
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mMenuButtonHeight, mMenuTextSize;
67
  private int mLevelValue;
68
  private int mColCount, mRowCount, mMaxRowCount;
69
  private int mUpperBarHeight;
70
  private boolean mShouldReactToEndOfScrambling;
71
  private float mScreenWidth;
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  void leaveScreen(RubikActivity act)
76
    {
77

    
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  void enterScreen(final RubikActivity act)
83
    {
84
    mWeakAct = new WeakReference<>(act);
85
    mScreenWidth = act.getScreenWidthInPixels();
86
    mUpperBarHeight = act.getHeightUpperBar();
87

    
88
    mMenuButtonHeight = (int)(mScreenWidth*RubikActivity.MENU_BUTTON_HEIGHT);
89
    mMenuTextSize     = (int)(mScreenWidth*RubikActivity.MENU_MAIN_TEXT_SIZE);
90

    
91
    mObjectPopup = null;
92

    
93
    // TOP ////////////////////////////
94
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
95
    layoutTop.removeAllViews();
96

    
97
    setupSolveButton(act);
98
    layoutTop.addView(mSolveButton);
99
    setupMenuButton(act,mScreenWidth);
100
    layoutTop.addView(mMenuButton);
101
    setupScrambleButton(act);
102
    layoutTop.addView(mScrambleButton);
103

    
104
    // BOTTOM /////////////////////////
105
    setupObjectButton(act,mScreenWidth);
106
    createBottomPane(act,mObjButton,null);
107
    }
108

    
109
//////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  private void setupObjectButton(final RubikActivity act, final float width)
112
    {
113
    final int margin  = (int)(width*RubikActivity.SMALL_MARGIN);
114
    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);
115
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
116
    mObjButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
117

    
118
    mObjButton.setOnClickListener( new View.OnClickListener()
119
      {
120
      @Override
121
      public void onClick(View view)
122
        {
123
        if( mObjectPopup==null )
124
          {
125
          float width = act.getScreenWidthInPixels();
126
          float height= act.getScreenHeightInPixels();
127
          setupObjectWindow(act,width,height);
128
          }
129

    
130
        if( act.getControl().isUINotBlocked())
131
          {
132
          int rowCount = Math.min(mMaxRowCount,mRowCount);
133
          View popupView = mObjectPopup.getContentView();
134
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
135
          displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount+5*margin,margin,margin);
136
          }
137
        }
138
      });
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  private void setupMenuButton(final RubikActivity act, final float width)
144
    {
145
    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);
146
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
147
    mMenuButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
148

    
149
    mMenuButton.setOnClickListener( new View.OnClickListener()
150
      {
151
      @Override
152
      public void onClick(View view)
153
        {
154
        if( mMenuPopup==null )
155
          {
156
          float width = act.getScreenWidthInPixels();
157
          setupMenuWindow(act,width);
158
          }
159

    
160
        if( act.getControl().isUINotBlocked())
161
          {
162
          View popupView = mMenuPopup.getContentView();
163
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
164
          setupLevelColors(act);
165
          displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-mMenuLayoutWidth/2 + width/6),0);
166
          }
167
        }
168
      });
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  private void setupObjectWindow(final RubikActivity act, final float width, final float height)
174
    {
175
    int numObjects = RubikObjectList.getNumObjects();
176
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
177
    mColCount = NUM_COLUMNS;
178

    
179
    int cubeSize = (int)(width/9);
180
    int margin   = (int)(width*RubikActivity.LARGE_MARGIN);
181
    int padding  = (int)(width*RubikActivity.POPUP_PADDING);
182
    mObjectSize  = (int)(cubeSize + 2*margin + 0.5f);
183
    mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize);
184

    
185
    LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null);
186
    GridLayout objectGrid = view.findViewById(R.id.objectGrid);
187
    RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout);
188
    setupBottomLayout(act,bottomLayout);
189

    
190
    PopupCreator.createObjectGrid(objectGrid,act,mRowCount,mColCount,numObjects,margin,cubeSize,padding);
191

    
192
    for(int child=0; child<numObjects; child++)
193
      {
194
      final RubikObject obj = RubikObjectList.getObject(child);
195
      View v = objectGrid.getChildAt(child);
196
      ImageButton button = PopupCreator.getButton(obj,v);
197
      final int ordinal = child;
198

    
199
      button.setOnClickListener( new View.OnClickListener()
200
        {
201
        @Override
202
        public void onClick(View v)
203
          {
204
          if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
205
            {
206
            RubikObjectList.setCurrObject(ordinal);
207
            act.changeObject(ordinal,true);
208
            if( mMenuPopup!=null ) setupLevelColors(act);
209
            mMovesController.clearMoves(act);
210
            }
211

    
212
          if( mObjectPopup!=null ) mObjectPopup.dismiss();
213
          }
214
        });
215
      }
216

    
217
    mObjectPopup = new PopupWindow(act);
218
    mObjectPopup.setFocusable(true);
219
    mObjectPopup.setContentView(view);
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  private void setupBottomLayout(final RubikActivity act, final RelativeLayout layout)
225
    {
226
    int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial);
227
    int iconD = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download);
228
    int iconI = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
229

    
230
    ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
231
    ImageButton buttonDow = layout.findViewById(R.id.buttonDow);
232
    ImageButton buttonInf = layout.findViewById(R.id.buttonInf);
233

    
234
    buttonTut.setImageResource(iconT);
235
    buttonDow.setImageResource(iconD);
236
    buttonInf.setImageResource(iconI);
237

    
238
    TypedValue outValue = new TypedValue();
239
    act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
240
    buttonTut.setBackgroundResource(outValue.resourceId);
241
    buttonDow.setBackgroundResource(outValue.resourceId);
242
    buttonInf.setBackgroundResource(outValue.resourceId);
243

    
244
    buttonTut.setOnClickListener( new View.OnClickListener()
245
      {
246
      @Override
247
      public void onClick(View v)
248
        {
249
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
250
        RubikDialogTutorial tDiag = new RubikDialogTutorial();
251
        tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
252
        }
253
      });
254

    
255
    buttonDow.setOnClickListener( new View.OnClickListener()
256
      {
257
      @Override
258
      public void onClick(View v)
259
        {
260
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
261
        RubikDialogUpdates uDiag = new RubikDialogUpdates();
262
        uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() );
263
        }
264
      });
265

    
266
    buttonInf.setOnClickListener( new View.OnClickListener()
267
      {
268
      @Override
269
      public void onClick(View v)
270
        {
271
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
272
        int currObject = RubikObjectList.getCurrObject();
273
        act.switchConfig(currObject);
274
        }
275
      });
276

    
277
    mBubbleUpdates = layout.findViewById(R.id.bubbleUpdates);
278
    mBubbleUpdates.setVisibility(View.INVISIBLE);
279

    
280
    RubikNetwork network = RubikNetwork.getInstance();
281
    network.signUpForUpdates(this);
282
    }
283

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

    
286
  void setupSolveButton(final RubikActivity act)
287
    {
288
    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);
289
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
290
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
291

    
292
    mSolveButton.setOnClickListener( new View.OnClickListener()
293
      {
294
      @Override
295
      public void onClick(View v)
296
        {
297
        act.getControl().solveObject();
298
        mMovesController.clearMoves(act);
299
        }
300
      });
301
    }
302

    
303
///////////////////////////////////////////////////////////////////////////////////////////////////
304

    
305
  private void setupScrambleButton(final RubikActivity act)
306
    {
307
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
308
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
309
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
310

    
311
    mScrambleButton.setOnClickListener( new View.OnClickListener()
312
      {
313
      @Override
314
      public void onClick(View v)
315
        {
316
        mShouldReactToEndOfScrambling = false;
317
        act.getControl().fastScrambleObject(RubikObject.FAST_SCRAMBLES);
318
        }
319
      });
320
    }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
  private void setupMenuWindow(final RubikActivity act, final float width)
325
    {
326
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
327
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
328

    
329
    mMenuPopup = new PopupWindow(act);
330
    mMenuPopup.setContentView(layout);
331
    mMenuPopup.setFocusable(true);
332
    int padding = (int)(width*RubikActivity.MEDIUM_MARGIN);
333

    
334
    mMenuLayoutWidth = (int)(width*0.6f);
335
    mMenuLayoutHeight= padding + NUM_BUTTONS*(mMenuButtonHeight+padding) + 4*mMenuButtonHeight+6*padding;
336

    
337
    layout.setPadding(padding,0,padding,0);
338

    
339
    Button highScores = layout.findViewById(R.id.menuHighScores);
340
    highScores.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
341
    highScores.setOnClickListener( new View.OnClickListener()
342
        {
343
        @Override
344
        public void onClick(View v)
345
          {
346
          mMenuPopup.dismiss();
347
          Bundle sBundle = new Bundle();
348
          int currObject = RubikObjectList.getCurrObject();
349
          sBundle.putInt("tab", currObject );
350
          sBundle.putBoolean("submitting", false);
351
          RubikDialogScores scores = new RubikDialogScores();
352
          scores.setArguments(sBundle);
353
          scores.show(act.getSupportFragmentManager(), null);
354
          }
355
        });
356

    
357
    Button prettyPatterns = layout.findViewById(R.id.menuPrettyPatterns);
358
    prettyPatterns.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
359
    prettyPatterns.setOnClickListener( new View.OnClickListener()
360
        {
361
        @Override
362
        public void onClick(View v)
363
          {
364
          mMenuPopup.dismiss();
365
          RubikDialogPattern pDiag = new RubikDialogPattern();
366
          pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
367
          }
368
        });
369

    
370
    Button solver = layout.findViewById(R.id.menuSolver);
371
    solver.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
372
    solver.setOnClickListener( new View.OnClickListener()
373
        {
374
        @Override
375
        public void onClick(View v)
376
          {
377
          mMenuPopup.dismiss();
378
          ScreenList.switchScreen(act, ScreenList.SVER);
379
          }
380
        });
381

    
382
    Button tutorials = layout.findViewById(R.id.menuTutorials);
383
    tutorials.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
384
    tutorials.setOnClickListener( new View.OnClickListener()
385
        {
386
        @Override
387
        public void onClick(View v)
388
          {
389
          mMenuPopup.dismiss();
390
          RubikDialogTutorial tDiag = new RubikDialogTutorial();
391
          tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
392
          }
393
        });
394

    
395
    Button bandaged = layout.findViewById(R.id.menuBandaged);
396
    bandaged.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
397
    bandaged.setOnClickListener( new View.OnClickListener()
398
        {
399
        @Override
400
        public void onClick(View v)
401
          {
402
          mMenuPopup.dismiss();
403
          act.switchToBandagedCreator();
404
          }
405
        });
406

    
407
    Button about = layout.findViewById(R.id.menuAbout);
408
    about.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
409
    about.setOnClickListener( new View.OnClickListener()
410
        {
411
        @Override
412
        public void onClick(View v)
413
          {
414
          mMenuPopup.dismiss();
415
          RubikDialogAbout aDiag = new RubikDialogAbout();
416
          aDiag.show(act.getSupportFragmentManager(), null);
417
          }
418
        });
419

    
420
    TextView levels = layout.findViewById(R.id.menuLevels);
421
    levels.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
422

    
423
    setupLevelButtons(act,layout,padding);
424
    }
425

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

    
428
  private void setupLevelButtons(RubikActivity act, View layout, int padding)
429
    {
430
    int sizeW = (mMenuLayoutWidth-4*padding)/3;
431
    int sizeH = (int)(sizeW*0.8f);
432
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(sizeW,sizeH);
433
    params.setMargins(padding/2,0,padding/2,0);
434

    
435
    mLevel = new Button[LEVELS_SHOWN+1];
436

    
437
    mLevel[0] = layout.findViewById(R.id.level1);
438
    mLevel[1] = layout.findViewById(R.id.level2);
439
    mLevel[2] = layout.findViewById(R.id.level3);
440
    mLevel[3] = layout.findViewById(R.id.level4);
441
    mLevel[4] = layout.findViewById(R.id.level5);
442
    mLevel[5] = layout.findViewById(R.id.level6);
443
    mLevel[6] = layout.findViewById(R.id.level7);
444
    mLevel[7] = layout.findViewById(R.id.level8);
445
    mLevel[8] = layout.findViewById(R.id.levelM);
446

    
447
    for(int i=0; i<=LEVELS_SHOWN; i++)
448
      {
449
      final int ii = i;
450
      mLevel[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
451
      mLevel[i].setLayoutParams(params);
452
      mLevel[i].setOnClickListener( new View.OnClickListener()
453
        {
454
        @Override
455
        public void onClick(View v)
456
          {
457
          ObjectControl control = act.getControl();
458

    
459
          if(control.isUINotBlocked())
460
            {
461
            if( mMenuPopup!=null ) mMenuPopup.dismiss();
462

    
463
            int currObject = RubikObjectList.getCurrObject();
464
            RubikObject object = RubikObjectList.getObject(currObject);
465
            final int scrambles = ii<LEVELS_SHOWN ? ii+1 : (object==null ? 0 : object.getNumScramble());
466
            mLevelValue = ii+1;
467
            mShouldReactToEndOfScrambling = true;
468
            control.scrambleObject(scrambles);
469
            }
470
          }
471
        });
472
      }
473
    }
474

    
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476

    
477
  private void setupLevelColors(RubikActivity act)
478
    {
479
    int currObject = RubikObjectList.getCurrObject();
480
    RubikScores scores = RubikScores.getInstance();
481
    Resources res = act.getResources();
482
    ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
483
    ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
484

    
485
    for(int level=0; level<=LEVELS_SHOWN; level++)
486
      {
487
      boolean isSolved = scores.isSolved(currObject,level);
488
      mLevel[level].setBackgroundTintList( isSolved ? colorG : colorD);
489
      }
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still
494
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not
495
// going to be called)
496
// An reference to the old instance of RubikActivity will cause all sorts of strange issues.
497

    
498
  public void savePreferences(SharedPreferences.Editor editor)
499
    {
500
    editor.putInt("play_LevelValue", mLevelValue );
501

    
502
    if( mObjectPopup!=null )
503
      {
504
      mObjectPopup.dismiss();
505
      mObjectPopup = null;
506
      }
507

    
508
    if( mMenuPopup!=null )
509
      {
510
      mMenuPopup.dismiss();
511
      mMenuPopup = null;
512
      }
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516

    
517
  public void restorePreferences(SharedPreferences preferences)
518
    {
519
    mLevelValue = preferences.getInt("play_LevelValue", 0);
520
    }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
524

    
525
  private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
526
    {
527
    View topLayout = act.findViewById(R.id.relativeLayout);
528
    boolean isFullScreen;
529

    
530
    if( topLayout!=null )
531
      {
532
      topLayout.getLocationOnScreen(mLocation);
533
      isFullScreen = (mLocation[1]==0);
534
      }
535
    else
536
      {
537
      isFullScreen = true;
538
      }
539

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

    
556
        window.showAsDropDown(view);
557
        window.update(x,y,w,h);
558
        }
559
      }
560
    catch( IllegalArgumentException iae )
561
      {
562
      // ignore, this means window is 'not attached to window manager' -
563
      // which most probably is because we are already exiting the app.
564
      }
565
    }
566

    
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568

    
569
  public int getLevel()
570
    {
571
    return mLevelValue;
572
    }
573

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

    
576
  public void recreatePopup()
577
    {
578
    mObjectPopup = null;
579
    }
580

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

    
583
  public boolean shouldReactToEndOfScrambling()
584
    {
585
    return mShouldReactToEndOfScrambling;
586
    }
587

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

    
590
  public void receiveUpdate(RubikUpdates updates)
591
    {
592
    Activity act = mWeakAct.get();
593

    
594
    if( act!=null )
595
      {
596
      act.runOnUiThread(new Runnable()
597
        {
598
        @Override
599
        public void run()
600
          {
601
          int num = updates.getCompletedNumber();
602

    
603
          if( num>0 )
604
            {
605
            String shownNum = String.valueOf(num);
606
            mBubbleUpdates.setText(shownNum);
607
            mBubbleUpdates.setVisibility(View.VISIBLE);
608
            int height = (int)(0.05f*mScreenWidth);
609
            mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
610
            }
611
         else
612
            {
613
            mBubbleUpdates.setVisibility(View.INVISIBLE);
614
            }
615
          }
616
        });
617
      }
618
    }
619

    
620
///////////////////////////////////////////////////////////////////////////////////////////////////
621

    
622
  public void errorUpdate()
623
    {
624
    android.util.Log.e("D", "Screen: Error receiving update");
625
    }
626
  }
(5-5/10)