Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPlay.java @ a88b947f

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
      View button = objectGrid.getChildAt(child);
195
      final int ordinal = child;
196

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

    
210
          if( mObjectPopup!=null ) mObjectPopup.dismiss();
211
          }
212
        });
213
      }
214

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

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

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

    
228
    ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
229
    ImageButton buttonDow = layout.findViewById(R.id.buttonDow);
230
    ImageButton buttonInf = layout.findViewById(R.id.buttonInf);
231

    
232
    buttonTut.setImageResource(iconT);
233
    buttonDow.setImageResource(iconD);
234
    buttonInf.setImageResource(iconI);
235

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

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

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

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

    
275
    mBubbleUpdates = layout.findViewById(R.id.bubbleUpdates);
276
    mBubbleUpdates.setVisibility(View.INVISIBLE);
277

    
278
    RubikNetwork network = RubikNetwork.getInstance();
279
    network.signUpForUpdates(this);
280
    }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

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

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

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

    
303
  private void setupScrambleButton(final RubikActivity act)
304
    {
305
    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);
306
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
307
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
308

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

    
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321

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

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

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

    
335
    layout.setPadding(padding,0,padding,0);
336

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

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

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

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

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

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

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

    
421
    setupLevelButtons(act,layout,padding);
422
    }
423

    
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425

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

    
433
    mLevel = new Button[LEVELS_SHOWN+1];
434

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

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

    
457
          if(control.isUINotBlocked())
458
            {
459
            if( mMenuPopup!=null ) mMenuPopup.dismiss();
460

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

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

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

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

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

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

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

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

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514

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

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

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

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

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

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

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566

    
567
  public int getLevel()
568
    {
569
    return mLevelValue;
570
    }
571

    
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573

    
574
  public void recreatePopup()
575
    {
576
    mObjectPopup = null;
577
    }
578

    
579
///////////////////////////////////////////////////////////////////////////////////////////////////
580

    
581
  public boolean shouldReactToEndOfScrambling()
582
    {
583
    return mShouldReactToEndOfScrambling;
584
    }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587

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

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

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

    
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

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