Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPlay.java @ 71cda061

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( obj!=null && act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()==ScreenList.PLAY )
205
            {
206
            if( obj.isFree() )
207
              {
208
              RubikObjectList.setCurrObject(ordinal);
209
              act.changeObject(ordinal,true);
210
              if( mMenuPopup!=null ) setupLevelColors(act);
211
              mMovesController.clearMoves(act);
212
              }
213
            else
214
              {
215
              act.switchToPurchase(ordinal);
216
              }
217
            }
218

    
219
          if( mObjectPopup!=null ) mObjectPopup.dismiss();
220
          }
221
        });
222
      }
223

    
224
    mObjectPopup = new PopupWindow(act);
225
    mObjectPopup.setFocusable(true);
226
    mObjectPopup.setContentView(view);
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

    
231
  private void setupBottomLayout(final RubikActivity act, final RelativeLayout layout)
232
    {
233
    int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial);
234
    int iconD = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download);
235
    int iconI = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
236

    
237
    ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
238
    ImageButton buttonDow = layout.findViewById(R.id.buttonDow);
239
    ImageButton buttonInf = layout.findViewById(R.id.buttonInf);
240

    
241
    buttonTut.setImageResource(iconT);
242
    buttonDow.setImageResource(iconD);
243
    buttonInf.setImageResource(iconI);
244

    
245
    TypedValue outValue = new TypedValue();
246
    act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
247
    buttonTut.setBackgroundResource(outValue.resourceId);
248
    buttonDow.setBackgroundResource(outValue.resourceId);
249
    buttonInf.setBackgroundResource(outValue.resourceId);
250

    
251
    buttonTut.setOnClickListener( new View.OnClickListener()
252
      {
253
      @Override
254
      public void onClick(View v)
255
        {
256
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
257
        RubikDialogTutorial tDiag = new RubikDialogTutorial();
258
        tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
259
        }
260
      });
261

    
262
    buttonDow.setOnClickListener( new View.OnClickListener()
263
      {
264
      @Override
265
      public void onClick(View v)
266
        {
267
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
268
        RubikDialogUpdates uDiag = new RubikDialogUpdates();
269
        uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() );
270
        }
271
      });
272

    
273
    buttonInf.setOnClickListener( new View.OnClickListener()
274
      {
275
      @Override
276
      public void onClick(View v)
277
        {
278
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
279
        int currObject = RubikObjectList.getCurrObject();
280
        act.switchConfig(currObject);
281
        }
282
      });
283

    
284
    mBubbleUpdates = layout.findViewById(R.id.bubbleUpdates);
285
    mBubbleUpdates.setVisibility(View.INVISIBLE);
286

    
287
    RubikNetwork network = RubikNetwork.getInstance();
288
    network.signUpForUpdates(this);
289
    }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
  void setupSolveButton(final RubikActivity act)
294
    {
295
    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);
296
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
297
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
298

    
299
    mSolveButton.setOnClickListener( new View.OnClickListener()
300
      {
301
      @Override
302
      public void onClick(View v)
303
        {
304
        act.getControl().solveObject();
305
        mMovesController.clearMoves(act);
306
        }
307
      });
308
    }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

    
312
  private void setupScrambleButton(final RubikActivity act)
313
    {
314
    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);
315
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
316
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
317

    
318
    mScrambleButton.setOnClickListener( new View.OnClickListener()
319
      {
320
      @Override
321
      public void onClick(View v)
322
        {
323
        mShouldReactToEndOfScrambling = false;
324
        act.getControl().fastScrambleObject(RubikObject.FAST_SCRAMBLES);
325
        }
326
      });
327
    }
328

    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330

    
331
  private void setupMenuWindow(final RubikActivity act, final float width)
332
    {
333
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
334
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
335

    
336
    mMenuPopup = new PopupWindow(act);
337
    mMenuPopup.setContentView(layout);
338
    mMenuPopup.setFocusable(true);
339
    int padding = (int)(width*RubikActivity.MEDIUM_MARGIN);
340

    
341
    mMenuLayoutWidth = (int)(width*0.65f);
342
    mMenuLayoutHeight= padding + NUM_BUTTONS*(mMenuButtonHeight+padding) + 4*mMenuButtonHeight+6*padding;
343

    
344
    layout.setPadding(padding,0,padding,0);
345

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

    
364
    Button prettyPatterns = layout.findViewById(R.id.menuPrettyPatterns);
365
    prettyPatterns.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
366
    prettyPatterns.setOnClickListener( new View.OnClickListener()
367
        {
368
        @Override
369
        public void onClick(View v)
370
          {
371
          mMenuPopup.dismiss();
372
          RubikDialogPattern pDiag = new RubikDialogPattern();
373
          pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
374
          }
375
        });
376

    
377
    Button solver = layout.findViewById(R.id.menuSolver);
378
    solver.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
379
    solver.setOnClickListener( new View.OnClickListener()
380
        {
381
        @Override
382
        public void onClick(View v)
383
          {
384
          mMenuPopup.dismiss();
385
          ScreenList.switchScreen(act, ScreenList.SVER);
386
          }
387
        });
388

    
389
    Button tutorials = layout.findViewById(R.id.menuTutorials);
390
    tutorials.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
391
    tutorials.setOnClickListener( new View.OnClickListener()
392
        {
393
        @Override
394
        public void onClick(View v)
395
          {
396
          mMenuPopup.dismiss();
397
          RubikDialogTutorial tDiag = new RubikDialogTutorial();
398
          tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
399
          }
400
        });
401

    
402
    Button bandaged = layout.findViewById(R.id.menuBandaged);
403
    bandaged.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
404
    bandaged.setOnClickListener( new View.OnClickListener()
405
        {
406
        @Override
407
        public void onClick(View v)
408
          {
409
          mMenuPopup.dismiss();
410
          act.switchToBandagedCreator();
411
          }
412
        });
413

    
414
    Button about = layout.findViewById(R.id.menuAbout);
415
    about.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
416
    about.setOnClickListener( new View.OnClickListener()
417
        {
418
        @Override
419
        public void onClick(View v)
420
          {
421
          mMenuPopup.dismiss();
422
          RubikDialogAbout aDiag = new RubikDialogAbout();
423
          aDiag.show(act.getSupportFragmentManager(), null);
424
          }
425
        });
426

    
427
    TextView levels = layout.findViewById(R.id.menuLevels);
428
    levels.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
429

    
430
    setupLevelButtons(act,layout,padding);
431
    }
432

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

    
435
  private void setupLevelButtons(RubikActivity act, View layout, int padding)
436
    {
437
    int sizeW = (mMenuLayoutWidth-4*padding)/3;
438
    int sizeH = (int)(sizeW*0.8f);
439
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(sizeW,sizeH);
440
    params.setMargins(padding/2,0,padding/2,0);
441

    
442
    mLevel = new Button[LEVELS_SHOWN+1];
443

    
444
    mLevel[0] = layout.findViewById(R.id.level1);
445
    mLevel[1] = layout.findViewById(R.id.level2);
446
    mLevel[2] = layout.findViewById(R.id.level3);
447
    mLevel[3] = layout.findViewById(R.id.level4);
448
    mLevel[4] = layout.findViewById(R.id.level5);
449
    mLevel[5] = layout.findViewById(R.id.level6);
450
    mLevel[6] = layout.findViewById(R.id.level7);
451
    mLevel[7] = layout.findViewById(R.id.level8);
452
    mLevel[8] = layout.findViewById(R.id.levelM);
453

    
454
    for(int i=0; i<=LEVELS_SHOWN; i++)
455
      {
456
      final int ii = i;
457
      mLevel[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
458
      mLevel[i].setLayoutParams(params);
459
      mLevel[i].setOnClickListener( new View.OnClickListener()
460
        {
461
        @Override
462
        public void onClick(View v)
463
          {
464
          ObjectControl control = act.getControl();
465

    
466
          if(control.isUINotBlocked())
467
            {
468
            if( mMenuPopup!=null ) mMenuPopup.dismiss();
469

    
470
            int currObject = RubikObjectList.getCurrObject();
471
            RubikObject object = RubikObjectList.getObject(currObject);
472
            final int scrambles = ii<LEVELS_SHOWN ? ii+1 : (object==null ? 0 : object.getNumScramble());
473
            mLevelValue = ii+1;
474
            mShouldReactToEndOfScrambling = true;
475
            control.scrambleObject(scrambles);
476
            }
477
          }
478
        });
479
      }
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  private void setupLevelColors(RubikActivity act)
485
    {
486
    int currObject = RubikObjectList.getCurrObject();
487
    RubikScores scores = RubikScores.getInstance();
488
    Resources res = act.getResources();
489
    ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
490
    ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
491

    
492
    for(int level=0; level<=LEVELS_SHOWN; level++)
493
      {
494
      boolean isSolved = scores.isSolved(currObject,level);
495
      mLevel[level].setBackgroundTintList( isSolved ? colorG : colorD);
496
      }
497
    }
498

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still
501
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not
502
// going to be called)
503
// An reference to the old instance of RubikActivity will cause all sorts of strange issues.
504

    
505
  public void savePreferences(SharedPreferences.Editor editor)
506
    {
507
    editor.putInt("play_LevelValue", mLevelValue );
508

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

    
515
    if( mMenuPopup!=null )
516
      {
517
      mMenuPopup.dismiss();
518
      mMenuPopup = null;
519
      }
520
    }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523

    
524
  public void restorePreferences(SharedPreferences preferences)
525
    {
526
    mLevelValue = preferences.getInt("play_LevelValue", 0);
527
    }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
531

    
532
  private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
533
    {
534
    View topLayout = act.findViewById(R.id.relativeLayout);
535
    boolean isFullScreen;
536

    
537
    if( topLayout!=null )
538
      {
539
      topLayout.getLocationOnScreen(mLocation);
540
      isFullScreen = (mLocation[1]==0);
541
      }
542
    else
543
      {
544
      isFullScreen = true;
545
      }
546

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

    
563
        window.showAsDropDown(view);
564
        window.update(x,y,w,h);
565
        }
566
      }
567
    catch( IllegalArgumentException iae )
568
      {
569
      // ignore, this means window is 'not attached to window manager' -
570
      // which most probably is because we are already exiting the app.
571
      }
572
    }
573

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

    
576
  public int getLevel()
577
    {
578
    return mLevelValue;
579
    }
580

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

    
583
  public void recreatePopup()
584
    {
585
    mObjectPopup = null;
586
    }
587

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

    
590
  public boolean shouldReactToEndOfScrambling()
591
    {
592
    return mShouldReactToEndOfScrambling;
593
    }
594

    
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596

    
597
  public void receiveUpdate(RubikUpdates updates)
598
    {
599
    Activity act = mWeakAct.get();
600

    
601
    if( act!=null )
602
      {
603
      act.runOnUiThread(new Runnable()
604
        {
605
        @Override
606
        public void run()
607
          {
608
          int num = updates.getCompletedNumber();
609

    
610
          if( num>0 )
611
            {
612
            String shownNum = String.valueOf(num);
613
            mBubbleUpdates.setText(shownNum);
614
            mBubbleUpdates.setVisibility(View.VISIBLE);
615
            int height = (int)(0.05f*mScreenWidth);
616
            mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
617
            }
618
         else
619
            {
620
            mBubbleUpdates.setVisibility(View.INVISIBLE);
621
            }
622
          }
623
        });
624
      }
625
    }
626

    
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628

    
629
  public void errorUpdate()
630
    {
631
    android.util.Log.e("D", "Screen: Error receiving update");
632
    }
633
  }
(5-5/10)