Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikPreRender.java @ fdb5f389

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.objectlib.main.TwistyObject;
38
import org.distorted.objectlib.main.ObjectList;
39

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

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

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

    
101
    mOldObject = null;
102
    mNewObject = null;
103

    
104
    mScreenWidth = 0;
105
    mScrambleObjectNum = 0;
106

    
107
    mEffectID = new long[BaseEffect.Type.LENGTH];
108

    
109
    mDebug = "";
110

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

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

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

    
122
    if( mOldObject!=null ) mOldObject.releaseResources();
123
    mOldObject = mNewObject;
124

    
125
    Context con = mView.getContext();
126
    Resources res = con.getResources();
127

    
128
    mNewObject = object.create(size, mView.getQuat(), moves, res, mScreenWidth);
129

    
130
    if( mNewObject!=null )
131
      {
132
      mNewObject.createTexture();
133
      mView.setMovement(mNewObject.getMovement());
134
      if( firstTime ) mNewObject.restorePreferences(mPreferences);
135
      mIsSolved = mNewObject.isSolved();
136
      }
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140
// do all 'adjustable' effects (SizeChange, Solve, Scramble)
141

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

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  private void removeRotationNow()
159
    {
160
    mRemoveRotation=false;
161
    mNewObject.removeRotationNow();
162

    
163
    boolean solved = mNewObject.isSolved();
164

    
165
    if( solved && !mIsSolved )
166
      {
167
      if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
168
        {
169
        RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
170
        mNewRecord = solving.getRecord();
171

    
172
        if( mNewRecord< 0 )
173
          {
174
          mNewRecord = -mNewRecord;
175
          mIsNewRecord = false;
176
          }
177
        else
178
          {
179
          mIsNewRecord = true;
180
          }
181
        }
182

    
183
      unblockEverything();
184
      doEffectNow( BaseEffect.Type.WIN );
185
      }
186
    else
187
      {
188
      unblockEverything();
189
      }
190

    
191
    mIsSolved = solved;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  private void removeRotation()
197
    {
198
    mRemoveRotation = true;
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  private void removePatternRotation()
204
    {
205
    mRemovePatternRotation = true;
206
    }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

    
210
  private void removePatternRotationNow()
211
    {
212
    mRemovePatternRotation=false;
213
    mNewObject.removeRotationNow();
214
    mAddActionListener.onActionFinished(mRemoveRotationID);
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  private void addRotationNow()
220
    {
221
    mAddRotation = false;
222
    mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap,
223
                                                mAddRotationAngle, mAddRotationDuration, this);
224

    
225
    if( mAddRotationID==0 ) // failed to add effect - should never happen
226
      {
227
      unblockEverything();
228
      }
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

    
233
  private void finishRotationNow()
234
    {
235
    mFinishRotation = false;
236
    blockEverything(BlockController.RUBIK_PLACE_0);
237
    mRotationFinishedID = mNewObject.finishRotationNow(this, mNearestAngle);
238

    
239
    if( mRotationFinishedID==0 ) // failed to add effect - should never happen
240
      {
241
      unblockEverything();
242
      }
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
  private void changeObjectNow()
248
    {
249
    mChangeObject = false;
250

    
251
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize)
252
      {
253
      blockEverything(BlockController.RUBIK_PLACE_1);
254
      createObjectNow(mNextObject, mNextSize, null);
255
      doEffectNow( BaseEffect.Type.SIZECHANGE );
256
      }
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  private void setupObjectNow()
262
    {
263
    mSetupObject = false;
264

    
265
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize)
266
      {
267
      blockEverything(BlockController.RUBIK_PLACE_2);
268
      createObjectNow(mNextObject, mNextSize, mNextMoves);
269
      doEffectNow( BaseEffect.Type.SIZECHANGE );
270
      }
271
    else
272
      {
273
      mNewObject.initializeObject(mNextMoves);
274
      }
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

    
279
  private void scrambleObjectNow()
280
    {
281
    mScrambleObject = false;
282
    mIsSolved       = false;
283
    blockEverything(BlockController.RUBIK_PLACE_3);
284
    RubikScores.getInstance().incrementNumPlays();
285
    doEffectNow( BaseEffect.Type.SCRAMBLE );
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

    
290
  private void solveObjectNow()
291
    {
292
    mSolveObject = false;
293
    blockEverything(BlockController.RUBIK_PLACE_4);
294
    doEffectNow( BaseEffect.Type.SOLVE );
295
    }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

    
299
  private void solveNow()
300
    {
301
    mSolve = false;
302
    mNewObject.solve();
303
    }
304

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

    
307
  private void initializeObjectNow()
308
    {
309
    mInitializeObject = false;
310
    mNewObject.initializeObject(mNextMoves);
311
    }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

    
315
  private void setTextureMapNow()
316
    {
317
    mSetTextureMap = false;
318

    
319
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
320
    }
321

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

    
324
  private void resetAllTextureMapsNow()
325
    {
326
    mResetAllTextureMaps = false;
327

    
328
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  private void setQuatNow()
334
    {
335
    mSetQuat = false;
336
    mView.setQuat();
337
    }
338

    
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

    
341
  private void reportRecord()
342
    {
343
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
344
    RubikScores scores = RubikScores.getInstance();
345

    
346
    int object      = play.getObject();
347
    int size        = play.getSize();
348
    int level       = play.getLevel();
349
    ObjectList list = ObjectList.getObject(object);
350
    String name     = scores.getName();
351

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

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

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

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377

    
378
  private void requestReview()
379
    {
380
    final RubikScores scores = RubikScores.getInstance();
381
    int numWins = scores.incrementNumWins();
382

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

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

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

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

    
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

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

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

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

    
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454
//
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

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

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

    
464
  void setScreenSize(int width)
465
    {
466
    if( mNewObject!=null )
467
      {
468
      mNewObject.createTexture();
469
      mNewObject.recomputeScaleFactor(width);
470
      }
471

    
472
    mScreenWidth  = width;
473
    }
474

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

    
477
  void savePreferences(SharedPreferences.Editor editor)
478
    {
479
    if( mNewObject!=null )
480
      {
481
      mNewObject.savePreferences(editor);
482
      }
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  void restorePreferences(SharedPreferences preferences)
488
    {
489
    mPreferences = preferences;
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493

    
494
  void finishRotation(int nearestAngle)
495
    {
496
    mNearestAngle   = nearestAngle;
497
    mFinishRotation = true;
498
    }
499

    
500
///////////////////////////////////////////////////////////////////////////////////////////////////
501

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

    
512
///////////////////////////////////////////////////////////////////////////////////////////////////
513

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

    
525
///////////////////////////////////////////////////////////////////////////////////////////////////
526

    
527
  void setTextureMap(int cubit, int face, int newColor)
528
    {
529
    mSetTextureMap = true;
530

    
531
    mCubit    = cubit;
532
    mFace     = face;
533
    mNewColor = newColor;
534
    }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

    
538
  public boolean isTouchBlocked()
539
    {
540
    return mTouchBlocked;
541
    }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

    
545
  public boolean isUINotBlocked()
546
    {
547
    return !mUIBlocked;
548
    }
549

    
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551

    
552
  public void blockEverything(int place)
553
    {
554
    mUIBlocked   = true;
555
    mTouchBlocked= true;
556
    mBlockController.touchBlocked(place);
557
    mBlockController.uiBlocked(place);
558
    }
559

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

    
562
  public void blockTouch(int place)
563
    {
564
    mTouchBlocked= true;
565
    mBlockController.touchBlocked(place);
566
    }
567

    
568
///////////////////////////////////////////////////////////////////////////////////////////////////
569

    
570
  public void unblockEverything()
571
    {
572
    mUIBlocked   = false;
573
    mTouchBlocked= false;
574
    mBlockController.touchUnblocked();
575
    mBlockController.uiUnblocked();
576
    }
577

    
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579

    
580
  public void unblockTouch()
581
    {
582
    mTouchBlocked= false;
583
    mBlockController.touchUnblocked();
584
    }
585

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

    
588
  public void unblockUI()
589
    {
590
    mUIBlocked= false;
591
    mBlockController.uiUnblocked();
592
    }
593

    
594
///////////////////////////////////////////////////////////////////////////////////////////////////
595

    
596
  void setQuatOnNextRender()
597
    {
598
    mSetQuat = true;
599
    }
600

    
601
///////////////////////////////////////////////////////////////////////////////////////////////////
602

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

    
620
///////////////////////////////////////////////////////////////////////////////////////////////////
621
// PUBLIC API
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623

    
624
  public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration)
625
    {
626
    mAddRotation = true;
627

    
628
    mAddActionListener    = listener;
629
    mAddRotationAxis      = axis;
630
    mAddRotationRowBitmap = rowBitmap;
631
    mAddRotationAngle     = angle;
632
    mAddRotationDuration  = duration;
633

    
634
    if( listener instanceof ScrambleEffect )
635
      {
636
      mDebug += (" (a "+axis+" "+rowBitmap+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
637
      }
638
    }
639

    
640
///////////////////////////////////////////////////////////////////////////////////////////////////
641

    
642
  public void initializeObject(int[][] moves)
643
    {
644
    mInitializeObject = true;
645
    mNextMoves = moves;
646
    }
647

    
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649

    
650
  public void scrambleObject(int num)
651
    {
652
    if( !mUIBlocked )
653
      {
654
      mScrambleObject = true;
655
      mScrambleObjectNum = num;
656
      mDebug = "";
657
      mDebugStartTime = System.currentTimeMillis();
658
      }
659
    }
660

    
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662
// this starts the Solve Effect
663

    
664
  public void solveObject()
665
    {
666
    if( !mUIBlocked )
667
      {
668
      mSolveObject = true;
669
      }
670
    }
671

    
672
///////////////////////////////////////////////////////////////////////////////////////////////////
673
// this only sets the cubits state to solved
674

    
675
  public void solve()
676
    {
677
    mSolve = true;
678
    }
679

    
680
///////////////////////////////////////////////////////////////////////////////////////////////////
681

    
682
  public void resetAllTextureMaps()
683
    {
684
    mResetAllTextureMaps = true;
685
    }
686

    
687
///////////////////////////////////////////////////////////////////////////////////////////////////
688

    
689
  public TwistyObject getObject()
690
    {
691
    return mNewObject;
692
    }
693

    
694
///////////////////////////////////////////////////////////////////////////////////////////////////
695

    
696
  public TwistyObject getOldObject()
697
    {
698
    return mOldObject;
699
    }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

    
703
  public int getNumScrambles()
704
    {
705
    return mScrambleObjectNum;
706
    }
707

    
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709

    
710
  public void effectFinished(final long effectID)
711
    {
712
    if( effectID == mRotationFinishedID )
713
      {
714
      mRotationFinishedID = 0;
715
      removeRotation();
716
      }
717
    else if( effectID == mAddRotationID )
718
      {
719
      mAddRotationID = 0;
720
      mRemoveRotationID = effectID;
721
      removePatternRotation();
722
      }
723
    else
724
      {
725
      for(int i=0; i<BaseEffect.Type.LENGTH; i++)
726
        {
727
        if( effectID == mEffectID[i] )
728
          {
729
          if( i!=BaseEffect.Type.WIN.ordinal() )
730
            {
731
            unblockEverything();
732
            }
733

    
734
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
735
            {
736
            final RubikActivity act = (RubikActivity)mView.getContext();
737

    
738
            act.runOnUiThread(new Runnable()
739
              {
740
              @Override
741
              public void run()
742
                {
743
                ScreenList.switchScreen( act, ScreenList.READ);
744
                }
745
              });
746
            }
747

    
748
          if( i==BaseEffect.Type.WIN.ordinal() )
749
            {
750
            if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
751
              {
752
              final RubikActivity act = (RubikActivity)mView.getContext();
753
              Bundle bundle = new Bundle();
754
              bundle.putLong("time", mNewRecord );
755

    
756
              reportRecord();
757
              requestReview();
758

    
759
              if( mIsNewRecord )
760
                {
761
                RubikDialogNewRecord dialog = new RubikDialogNewRecord();
762
                dialog.setArguments(bundle);
763
                dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() );
764
                }
765
              else
766
                {
767
                RubikDialogSolved dialog = new RubikDialogSolved();
768
                dialog.setArguments(bundle);
769
                dialog.show( act.getSupportFragmentManager(), RubikDialogSolved.getDialogTag() );
770
                }
771

    
772
              act.runOnUiThread(new Runnable()
773
                {
774
                @Override
775
                public void run()
776
                  {
777
                  ScreenList.switchScreen( act, ScreenList.DONE);
778
                  }
779
                });
780
              }
781
            }
782

    
783
          break;
784
          }
785
        }
786
      }
787
    }
788
  }
(2-2/4)