Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikPreRender.java @ 8fa39aa6

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

    
22
import android.content.Context;
23
import android.content.SharedPreferences;
24
import android.content.res.Resources;
25
import android.os.Bundle;
26

    
27
import androidx.annotation.NonNull;
28

    
29
import com.google.android.play.core.review.ReviewInfo;
30
import com.google.android.play.core.review.ReviewManager;
31
import com.google.android.play.core.review.ReviewManagerFactory;
32
import com.google.android.play.core.tasks.OnCompleteListener;
33
import com.google.android.play.core.tasks.OnFailureListener;
34
import com.google.android.play.core.tasks.Task;
35
import com.google.firebase.analytics.FirebaseAnalytics;
36

    
37
import org.distorted.dialogs.RubikDialogNewRecord;
38
import org.distorted.dialogs.RubikDialogSolved;
39
import org.distorted.effects.BaseEffect;
40
import org.distorted.effects.EffectController;
41
import org.distorted.effects.scramble.ScrambleEffect;
42
import org.distorted.helpers.BlockController;
43
import org.distorted.helpers.MovesFinished;
44
import org.distorted.helpers.TwistyPreRender;
45
import org.distorted.objects.TwistyObject;
46
import org.distorted.objects.ObjectList;
47
import org.distorted.network.RubikScores;
48
import org.distorted.screens.RubikScreenPlay;
49
import org.distorted.screens.ScreenList;
50
import org.distorted.screens.RubikScreenSolving;
51

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

    
54
public class RubikPreRender implements EffectController, TwistyPreRender
55
  {
56
  private final RubikSurfaceView mView;
57
  private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
58
                  mSetQuat, mChangeObject, mSetupObject, mSolveObject, mScrambleObject,
59
                  mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
60
  private boolean mUIBlocked, mTouchBlocked;
61
  private boolean mIsSolved;
62
  private ObjectList mNextObject;
63
  private int mNextSize;
64
  private long mRotationFinishedID;
65
  private final long[] mEffectID;
66
  private boolean mIsNewRecord;
67
  private long mNewRecord;
68
  private int mScreenWidth;
69
  private SharedPreferences mPreferences;
70
  private int[][] mNextMoves;
71
  private TwistyObject mOldObject, mNewObject;
72
  private int mScrambleObjectNum;
73
  private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
74
  private long mAddRotationDuration;
75
  private MovesFinished mAddActionListener;
76
  private long mAddRotationID, mRemoveRotationID;
77
  private int mCubit, mFace, mNewColor;
78
  private int mNearestAngle;
79
  private String mDebug;
80
  private long mDebugStartTime;
81
  private final BlockController mBlockController;
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  RubikPreRender(RubikSurfaceView view)
86
    {
87
    mView = view;
88

    
89
    mFinishRotation       = false;
90
    mRemoveRotation       = false;
91
    mRemovePatternRotation= false;
92
    mAddRotation          = false;
93
    mSetQuat              = false;
94
    mChangeObject         = false;
95
    mSetupObject          = false;
96
    mSolveObject          = false;
97
    mScrambleObject       = false;
98

    
99
    mOldObject = null;
100
    mNewObject = null;
101

    
102
    mScreenWidth = 0;
103
    mScrambleObjectNum = 0;
104

    
105
    mEffectID = new long[BaseEffect.Type.LENGTH];
106

    
107
    mDebug = "";
108

    
109
    RubikActivity act = (RubikActivity)mView.getContext();
110
    mBlockController = new BlockController(act);
111
    unblockEverything();
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  private void createObjectNow(ObjectList object, int size, int[][] moves)
117
    {
118
    boolean firstTime = (mNewObject==null);
119

    
120
    if( mOldObject!=null ) mOldObject.releaseResources();
121
    mOldObject = mNewObject;
122

    
123
    Context con = mView.getContext();
124
    Resources res = con.getResources();
125

    
126
    mNewObject = object.create(size, mView.getQuat(), moves, res, mScreenWidth);
127

    
128
    if( mNewObject!=null )
129
      {
130
      mNewObject.createTexture();
131
      mView.setMovement(object.getObjectMovementClass());
132

    
133
      if( firstTime ) mNewObject.restorePreferences(mPreferences);
134

    
135
      if( mScreenWidth!=0 )
136
        {
137
        mNewObject.recomputeScaleFactor(mScreenWidth);
138
        }
139

    
140
      mIsSolved = mNewObject.isSolved();
141
      }
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
// do all 'adjustable' effects (SizeChange, Solve, Scramble)
146

    
147
  private void doEffectNow(BaseEffect.Type type)
148
    {
149
    try
150
      {
151
      int index = type.ordinal();
152
      mEffectID[index] = type.startEffect(mView.getRenderer().getScreen(),this);
153
      }
154
    catch( Exception ex )
155
      {
156
      android.util.Log.e("renderer", "exception starting effect: "+ex.getMessage());
157
      unblockEverything();
158
      }
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  private void removeRotationNow()
164
    {
165
    mRemoveRotation=false;
166
    mNewObject.removeRotationNow();
167

    
168
    boolean solved = mNewObject.isSolved();
169

    
170
    if( solved && !mIsSolved )
171
      {
172
      if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
173
        {
174
        RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
175
        mNewRecord = solving.getRecord();
176

    
177
        if( mNewRecord< 0 )
178
          {
179
          mNewRecord = -mNewRecord;
180
          mIsNewRecord = false;
181
          }
182
        else
183
          {
184
          mIsNewRecord = true;
185
          }
186
        }
187

    
188
      unblockEverything();
189
      doEffectNow( BaseEffect.Type.WIN );
190
      }
191
    else
192
      {
193
      unblockEverything();
194
      }
195

    
196
    mIsSolved = solved;
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  private void removeRotation()
202
    {
203
    mRemoveRotation = true;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  private void removePatternRotation()
209
    {
210
    mRemovePatternRotation = true;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  private void removePatternRotationNow()
216
    {
217
    mRemovePatternRotation=false;
218
    mNewObject.removeRotationNow();
219
    mAddActionListener.onActionFinished(mRemoveRotationID);
220
    }
221

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

    
224
  private void addRotationNow()
225
    {
226
    mAddRotation = false;
227
    mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap,
228
                                                mAddRotationAngle, mAddRotationDuration, this);
229

    
230
    if( mAddRotationID==0 ) // failed to add effect - should never happen
231
      {
232
      unblockEverything();
233
      }
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
  private void finishRotationNow()
239
    {
240
    mFinishRotation = false;
241
    blockEverything(BlockController.RUBIK_PLACE_0);
242
    mRotationFinishedID = mNewObject.finishRotationNow(this, mNearestAngle);
243

    
244
    if( mRotationFinishedID==0 ) // failed to add effect - should never happen
245
      {
246
      unblockEverything();
247
      }
248
    }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
  private void changeObjectNow()
253
    {
254
    mChangeObject = false;
255

    
256
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize)
257
      {
258
      blockEverything(BlockController.RUBIK_PLACE_1);
259
      createObjectNow(mNextObject, mNextSize, null);
260
      doEffectNow( BaseEffect.Type.SIZECHANGE );
261
      }
262
    }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

    
266
  private void setupObjectNow()
267
    {
268
    mSetupObject = false;
269

    
270
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize)
271
      {
272
      blockEverything(BlockController.RUBIK_PLACE_2);
273
      createObjectNow(mNextObject, mNextSize, mNextMoves);
274
      doEffectNow( BaseEffect.Type.SIZECHANGE );
275
      }
276
    else
277
      {
278
      mNewObject.initializeObject(mNextMoves);
279
      }
280
    }
281

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

    
284
  private void scrambleObjectNow()
285
    {
286
    mScrambleObject = false;
287
    mIsSolved       = false;
288
    blockEverything(BlockController.RUBIK_PLACE_3);
289
    RubikScores.getInstance().incrementNumPlays();
290
    doEffectNow( BaseEffect.Type.SCRAMBLE );
291
    }
292

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294

    
295
  private void solveObjectNow()
296
    {
297
    mSolveObject = false;
298
    blockEverything(BlockController.RUBIK_PLACE_4);
299
    doEffectNow( BaseEffect.Type.SOLVE );
300
    }
301

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

    
304
  private void initializeObjectNow()
305
    {
306
    mInitializeObject = false;
307
    mNewObject.initializeObject(mNextMoves);
308
    }
309

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

    
312
  private void setTextureMapNow()
313
    {
314
    mSetTextureMap = false;
315

    
316
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
317
    }
318

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

    
321
  private void resetAllTextureMapsNow()
322
    {
323
    mResetAllTextureMaps = false;
324

    
325
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
326
    }
327

    
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329

    
330
  private void setQuatNow()
331
    {
332
    mSetQuat = false;
333
    mView.setQuat();
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  private void reportRecord()
339
    {
340
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
341
    RubikScores scores = RubikScores.getInstance();
342

    
343
    int object      = play.getObject();
344
    int size        = play.getSize();
345
    int level       = play.getLevel();
346
    ObjectList list = ObjectList.getObject(object);
347
    String name     = scores.getName();
348

    
349
    String record = list.name()+"_"+size+" level "+level+" time "+mNewRecord+" isNew: "+mIsNewRecord+" scrambleNum: "+mScrambleObjectNum;
350

    
351
    if( BuildConfig.DEBUG )
352
       {
353
       android.util.Log.e("pre", mDebug);
354
       android.util.Log.e("pre", name);
355
       android.util.Log.e("pre", record);
356
       }
357
    else
358
      {
359
      final RubikActivity act = (RubikActivity)mView.getContext();
360
      FirebaseAnalytics analytics = act.getAnalytics();
361

    
362
      if( analytics!=null )
363
        {
364
        Bundle bundle = new Bundle();
365
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, mDebug);
366
        bundle.putString(FirebaseAnalytics.Param.CHARACTER, name);
367
        bundle.putString(FirebaseAnalytics.Param.LEVEL, record);
368
        analytics.logEvent(FirebaseAnalytics.Event.LEVEL_UP, bundle);
369
        }
370
      }
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  private void requestReview()
376
    {
377
    final RubikScores scores = RubikScores.getInstance();
378
    int numWins = scores.incrementNumWins();
379

    
380
    if( numWins==7 || numWins==30 || numWins==100 || numWins==200)
381
      {
382
      final long timeBegin = System.currentTimeMillis();
383
      final RubikActivity act = (RubikActivity)mView.getContext();
384
      final ReviewManager manager = ReviewManagerFactory.create(act);
385
      Task<ReviewInfo> request = manager.requestReviewFlow();
386

    
387
      request.addOnCompleteListener(new OnCompleteListener<ReviewInfo>()
388
        {
389
        @Override
390
        public void onComplete (@NonNull Task<ReviewInfo> task)
391
          {
392
          if (task.isSuccessful())
393
            {
394
            final String name = scores.getName();
395
            ReviewInfo reviewInfo = task.getResult();
396
            Task<Void> flow = manager.launchReviewFlow(act, reviewInfo);
397

    
398
            flow.addOnFailureListener(new OnFailureListener()
399
              {
400
              @Override
401
              public void onFailure(Exception e)
402
                {
403
                analyticsReport(act,"Failed", name, timeBegin);
404
                }
405
              });
406

    
407
            flow.addOnCompleteListener(new OnCompleteListener<Void>()
408
              {
409
              @Override
410
              public void onComplete(@NonNull Task<Void> task)
411
                {
412
                analyticsReport(act,"Complete", name, timeBegin);
413
                }
414
              });
415
            }
416
          else
417
            {
418
            String name = scores.getName();
419
            analyticsReport(act,"Not Successful", name, timeBegin);
420
            }
421
          }
422
        });
423
      }
424
    }
425

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

    
428
  private void analyticsReport(RubikActivity act, String message, String name, long timeBegin)
429
    {
430
    long elapsed = System.currentTimeMillis() - timeBegin;
431
    String msg = message+" startTime: "+timeBegin+" elapsed: "+elapsed+" name: "+name;
432

    
433
    if( BuildConfig.DEBUG )
434
       {
435
       android.util.Log.d("pre", msg);
436
       }
437
    else
438
      {
439
      FirebaseAnalytics analytics = act.getAnalytics();
440

    
441
      if( analytics!=null )
442
        {
443
        Bundle bundle = new Bundle();
444
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, msg);
445
        analytics.logEvent(FirebaseAnalytics.Event.SHARE, bundle);
446
        }
447
      }
448
    }
449

    
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451
//
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453

    
454
  void rememberMove(int axis, int row, int angle)
455
    {
456
    mDebug += (" (m "+axis+" "+(1<<row)+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

    
461
  void setScreenSize(int width)
462
    {
463
    if( mNewObject!=null )
464
      {
465
      mNewObject.createTexture();
466
      mNewObject.recomputeScaleFactor(width);
467
      }
468

    
469
    mScreenWidth  = width;
470
    }
471

    
472
///////////////////////////////////////////////////////////////////////////////////////////////////
473

    
474
  void savePreferences(SharedPreferences.Editor editor)
475
    {
476
    if( mNewObject!=null )
477
      {
478
      mNewObject.savePreferences(editor);
479
      }
480
    }
481

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

    
484
  void restorePreferences(SharedPreferences preferences)
485
    {
486
    mPreferences = preferences;
487
    }
488

    
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

    
491
  void finishRotation(int nearestAngle)
492
    {
493
    mNearestAngle   = nearestAngle;
494
    mFinishRotation = true;
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498

    
499
  void changeObject(ObjectList object, int size)
500
    {
501
    if( size>0 )
502
      {
503
      mChangeObject = true;
504
      mNextObject = object;
505
      mNextSize   = size;
506
      }
507
    }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
  void setupObject(ObjectList object, int size, int[][] moves)
512
    {
513
    if( size>0 )
514
      {
515
      mSetupObject= true;
516
      mNextObject = object;
517
      mNextSize   = size;
518
      mNextMoves  = moves;
519
      }
520
    }
521

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

    
524
  void setTextureMap(int cubit, int face, int newColor)
525
    {
526
    mSetTextureMap = true;
527

    
528
    mCubit    = cubit;
529
    mFace     = face;
530
    mNewColor = newColor;
531
    }
532

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534

    
535
  public boolean isTouchBlocked()
536
    {
537
    return mTouchBlocked;
538
    }
539

    
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541

    
542
  public boolean isUINotBlocked()
543
    {
544
    return !mUIBlocked;
545
    }
546

    
547
///////////////////////////////////////////////////////////////////////////////////////////////////
548

    
549
  public void blockEverything(int place)
550
    {
551
    mUIBlocked   = true;
552
    mTouchBlocked= true;
553
    mBlockController.touchBlocked(place);
554
    mBlockController.uiBlocked(place);
555
    }
556

    
557
///////////////////////////////////////////////////////////////////////////////////////////////////
558

    
559
  public void blockTouch(int place)
560
    {
561
    mTouchBlocked= true;
562
    mBlockController.touchBlocked(place);
563
    }
564

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

    
567
  public void unblockEverything()
568
    {
569
    mUIBlocked   = false;
570
    mTouchBlocked= false;
571
    mBlockController.touchUnblocked();
572
    mBlockController.uiUnblocked();
573
    }
574

    
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576

    
577
  public void unblockTouch()
578
    {
579
    mTouchBlocked= false;
580
    mBlockController.touchUnblocked();
581
    }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584

    
585
  public void unblockUI()
586
    {
587
    mUIBlocked= false;
588
    mBlockController.uiUnblocked();
589
    }
590

    
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592

    
593
  void setQuatOnNextRender()
594
    {
595
    mSetQuat = true;
596
    }
597

    
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599

    
600
  void preRender()
601
    {
602
    if( mSetQuat               ) setQuatNow();
603
    if( mFinishRotation        ) finishRotationNow();
604
    if( mRemoveRotation        ) removeRotationNow();
605
    if( mRemovePatternRotation ) removePatternRotationNow();
606
    if( mChangeObject          ) changeObjectNow();
607
    if( mSetupObject           ) setupObjectNow();
608
    if( mSolveObject           ) solveObjectNow();
609
    if( mScrambleObject        ) scrambleObjectNow();
610
    if( mAddRotation           ) addRotationNow();
611
    if( mInitializeObject      ) initializeObjectNow();
612
    if( mResetAllTextureMaps   ) resetAllTextureMapsNow();
613
    if( mSetTextureMap         ) setTextureMapNow();
614
    }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617
// PUBLIC API
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

    
620
  public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration)
621
    {
622
    mAddRotation = true;
623

    
624
    mAddActionListener    = listener;
625
    mAddRotationAxis      = axis;
626
    mAddRotationRowBitmap = rowBitmap;
627
    mAddRotationAngle     = angle;
628
    mAddRotationDuration  = duration;
629

    
630
    if( listener instanceof ScrambleEffect )
631
      {
632
      mDebug += (" (a "+axis+" "+rowBitmap+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
633
      }
634
    }
635

    
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637

    
638
  public void initializeObject(int[][] moves)
639
    {
640
    mInitializeObject = true;
641
    mNextMoves = moves;
642
    }
643

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

    
646
  public void scrambleObject(int num)
647
    {
648
    if( !mUIBlocked )
649
      {
650
      mScrambleObject = true;
651
      mScrambleObjectNum = num;
652
      mDebug = "";
653
      mDebugStartTime = System.currentTimeMillis();
654
      }
655
    }
656

    
657
///////////////////////////////////////////////////////////////////////////////////////////////////
658

    
659
  public void solveObject()
660
    {
661
    if( !mUIBlocked )
662
      {
663
      mSolveObject = true;
664
      }
665
    }
666

    
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668

    
669
  public void resetAllTextureMaps()
670
    {
671
    mResetAllTextureMaps = true;
672
    }
673

    
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675

    
676
  public TwistyObject getObject()
677
    {
678
    return mNewObject;
679
    }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

    
683
  public TwistyObject getOldObject()
684
    {
685
    return mOldObject;
686
    }
687

    
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689

    
690
  public int getNumScrambles()
691
    {
692
    return mScrambleObjectNum;
693
    }
694

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696

    
697
  public void effectFinished(final long effectID)
698
    {
699
    if( effectID == mRotationFinishedID )
700
      {
701
      mRotationFinishedID = 0;
702
      removeRotation();
703
      }
704
    else if( effectID == mAddRotationID )
705
      {
706
      mAddRotationID = 0;
707
      mRemoveRotationID = effectID;
708
      removePatternRotation();
709
      }
710
    else
711
      {
712
      for(int i=0; i<BaseEffect.Type.LENGTH; i++)
713
        {
714
        if( effectID == mEffectID[i] )
715
          {
716
          if( i!=BaseEffect.Type.WIN.ordinal() )
717
            {
718
            unblockEverything();
719
            }
720

    
721
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
722
            {
723
            final RubikActivity act = (RubikActivity)mView.getContext();
724

    
725
            act.runOnUiThread(new Runnable()
726
              {
727
              @Override
728
              public void run()
729
                {
730
                ScreenList.switchScreen( act, ScreenList.READ);
731
                }
732
              });
733
            }
734

    
735
          if( i==BaseEffect.Type.WIN.ordinal() )
736
            {
737
            if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
738
              {
739
              final RubikActivity act = (RubikActivity)mView.getContext();
740
              Bundle bundle = new Bundle();
741
              bundle.putLong("time", mNewRecord );
742

    
743
              reportRecord();
744
              requestReview();
745

    
746
              if( mIsNewRecord )
747
                {
748
                RubikDialogNewRecord dialog = new RubikDialogNewRecord();
749
                dialog.setArguments(bundle);
750
                dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() );
751
                }
752
              else
753
                {
754
                RubikDialogSolved dialog = new RubikDialogSolved();
755
                dialog.setArguments(bundle);
756
                dialog.show( act.getSupportFragmentManager(), RubikDialogSolved.getDialogTag() );
757
                }
758

    
759
              act.runOnUiThread(new Runnable()
760
                {
761
                @Override
762
                public void run()
763
                  {
764
                  ScreenList.switchScreen( act, ScreenList.DONE);
765
                  }
766
                });
767
              }
768
            }
769

    
770
          break;
771
          }
772
        }
773
      }
774
    }
775
  }
(2-2/4)