Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikPreRender.java @ 771f6dfa

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, mSolve;
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
    mSolve                = false;
98
    mScrambleObject       = false;
99

    
100
    mOldObject = null;
101
    mNewObject = null;
102

    
103
    mScreenWidth = 0;
104
    mScrambleObjectNum = 0;
105

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

    
108
    mDebug = "";
109

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

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

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

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

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

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

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

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

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

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

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

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

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

    
169
    boolean solved = mNewObject.isSolved();
170

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

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

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

    
197
    mIsSolved = solved;
198
    }
199

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

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

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

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

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

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

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

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

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

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

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

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

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

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

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

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

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

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

    
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

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

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

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

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

    
305
  private void solveNow()
306
    {
307
    mSolve = false;
308
    mNewObject.solve();
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

    
313
  private void initializeObjectNow()
314
    {
315
    mInitializeObject = false;
316
    mNewObject.initializeObject(mNextMoves);
317
    }
318

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

    
321
  private void setTextureMapNow()
322
    {
323
    mSetTextureMap = false;
324

    
325
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
326
    }
327

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

    
330
  private void resetAllTextureMapsNow()
331
    {
332
    mResetAllTextureMaps = false;
333

    
334
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
335
    }
336

    
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

    
339
  private void setQuatNow()
340
    {
341
    mSetQuat = false;
342
    mView.setQuat();
343
    }
344

    
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

    
347
  private void reportRecord()
348
    {
349
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
350
    RubikScores scores = RubikScores.getInstance();
351

    
352
    int object      = play.getObject();
353
    int size        = play.getSize();
354
    int level       = play.getLevel();
355
    ObjectList list = ObjectList.getObject(object);
356
    String name     = scores.getName();
357

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

    
360
    if( BuildConfig.DEBUG )
361
       {
362
       android.util.Log.e("pre", mDebug);
363
       android.util.Log.e("pre", name);
364
       android.util.Log.e("pre", record);
365
       }
366
    else
367
      {
368
      final RubikActivity act = (RubikActivity)mView.getContext();
369
      FirebaseAnalytics analytics = act.getAnalytics();
370

    
371
      if( analytics!=null )
372
        {
373
        Bundle bundle = new Bundle();
374
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, mDebug);
375
        bundle.putString(FirebaseAnalytics.Param.CHARACTER, name);
376
        bundle.putString(FirebaseAnalytics.Param.LEVEL, record);
377
        analytics.logEvent(FirebaseAnalytics.Event.LEVEL_UP, bundle);
378
        }
379
      }
380
    }
381

    
382
///////////////////////////////////////////////////////////////////////////////////////////////////
383

    
384
  private void requestReview()
385
    {
386
    final RubikScores scores = RubikScores.getInstance();
387
    int numWins = scores.incrementNumWins();
388

    
389
    if( numWins==7 || numWins==30 || numWins==100 || numWins==200)
390
      {
391
      final long timeBegin = System.currentTimeMillis();
392
      final RubikActivity act = (RubikActivity)mView.getContext();
393
      final ReviewManager manager = ReviewManagerFactory.create(act);
394
      Task<ReviewInfo> request = manager.requestReviewFlow();
395

    
396
      request.addOnCompleteListener(new OnCompleteListener<ReviewInfo>()
397
        {
398
        @Override
399
        public void onComplete (@NonNull Task<ReviewInfo> task)
400
          {
401
          if (task.isSuccessful())
402
            {
403
            final String name = scores.getName();
404
            ReviewInfo reviewInfo = task.getResult();
405
            Task<Void> flow = manager.launchReviewFlow(act, reviewInfo);
406

    
407
            flow.addOnFailureListener(new OnFailureListener()
408
              {
409
              @Override
410
              public void onFailure(Exception e)
411
                {
412
                analyticsReport(act,"Failed", name, timeBegin);
413
                }
414
              });
415

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

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436

    
437
  private void analyticsReport(RubikActivity act, String message, String name, long timeBegin)
438
    {
439
    long elapsed = System.currentTimeMillis() - timeBegin;
440
    String msg = message+" startTime: "+timeBegin+" elapsed: "+elapsed+" name: "+name;
441

    
442
    if( BuildConfig.DEBUG )
443
       {
444
       android.util.Log.d("pre", msg);
445
       }
446
    else
447
      {
448
      FirebaseAnalytics analytics = act.getAnalytics();
449

    
450
      if( analytics!=null )
451
        {
452
        Bundle bundle = new Bundle();
453
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, msg);
454
        analytics.logEvent(FirebaseAnalytics.Event.SHARE, bundle);
455
        }
456
      }
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
//
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  void rememberMove(int axis, int row, int angle)
464
    {
465
    mDebug += (" (m "+axis+" "+(1<<row)+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
466
    }
467

    
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469

    
470
  void setScreenSize(int width)
471
    {
472
    if( mNewObject!=null )
473
      {
474
      mNewObject.createTexture();
475
      mNewObject.recomputeScaleFactor(width);
476
      }
477

    
478
    mScreenWidth  = width;
479
    }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

    
483
  void savePreferences(SharedPreferences.Editor editor)
484
    {
485
    if( mNewObject!=null )
486
      {
487
      mNewObject.savePreferences(editor);
488
      }
489
    }
490

    
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492

    
493
  void restorePreferences(SharedPreferences preferences)
494
    {
495
    mPreferences = preferences;
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499

    
500
  void finishRotation(int nearestAngle)
501
    {
502
    mNearestAngle   = nearestAngle;
503
    mFinishRotation = true;
504
    }
505

    
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507

    
508
  void changeObject(ObjectList object, int size)
509
    {
510
    if( size>0 )
511
      {
512
      mChangeObject = true;
513
      mNextObject = object;
514
      mNextSize   = size;
515
      }
516
    }
517

    
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519

    
520
  void setupObject(ObjectList object, int size, int[][] moves)
521
    {
522
    if( size>0 )
523
      {
524
      mSetupObject= true;
525
      mNextObject = object;
526
      mNextSize   = size;
527
      mNextMoves  = moves;
528
      }
529
    }
530

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532

    
533
  void setTextureMap(int cubit, int face, int newColor)
534
    {
535
    mSetTextureMap = true;
536

    
537
    mCubit    = cubit;
538
    mFace     = face;
539
    mNewColor = newColor;
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543

    
544
  public boolean isTouchBlocked()
545
    {
546
    return mTouchBlocked;
547
    }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550

    
551
  public boolean isUINotBlocked()
552
    {
553
    return !mUIBlocked;
554
    }
555

    
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557

    
558
  public void blockEverything(int place)
559
    {
560
    mUIBlocked   = true;
561
    mTouchBlocked= true;
562
    mBlockController.touchBlocked(place);
563
    mBlockController.uiBlocked(place);
564
    }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

    
568
  public void blockTouch(int place)
569
    {
570
    mTouchBlocked= true;
571
    mBlockController.touchBlocked(place);
572
    }
573

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

    
576
  public void unblockEverything()
577
    {
578
    mUIBlocked   = false;
579
    mTouchBlocked= false;
580
    mBlockController.touchUnblocked();
581
    mBlockController.uiUnblocked();
582
    }
583

    
584
///////////////////////////////////////////////////////////////////////////////////////////////////
585

    
586
  public void unblockTouch()
587
    {
588
    mTouchBlocked= false;
589
    mBlockController.touchUnblocked();
590
    }
591

    
592
///////////////////////////////////////////////////////////////////////////////////////////////////
593

    
594
  public void unblockUI()
595
    {
596
    mUIBlocked= false;
597
    mBlockController.uiUnblocked();
598
    }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601

    
602
  void setQuatOnNextRender()
603
    {
604
    mSetQuat = true;
605
    }
606

    
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608

    
609
  void preRender()
610
    {
611
    if( mSolve                 ) solveNow();
612
    if( mSetQuat               ) setQuatNow();
613
    if( mFinishRotation        ) finishRotationNow();
614
    if( mRemoveRotation        ) removeRotationNow();
615
    if( mRemovePatternRotation ) removePatternRotationNow();
616
    if( mChangeObject          ) changeObjectNow();
617
    if( mSetupObject           ) setupObjectNow();
618
    if( mSolveObject           ) solveObjectNow();
619
    if( mScrambleObject        ) scrambleObjectNow();
620
    if( mAddRotation           ) addRotationNow();
621
    if( mInitializeObject      ) initializeObjectNow();
622
    if( mResetAllTextureMaps   ) resetAllTextureMapsNow();
623
    if( mSetTextureMap         ) setTextureMapNow();
624
    }
625

    
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627
// PUBLIC API
628
///////////////////////////////////////////////////////////////////////////////////////////////////
629

    
630
  public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration)
631
    {
632
    mAddRotation = true;
633

    
634
    mAddActionListener    = listener;
635
    mAddRotationAxis      = axis;
636
    mAddRotationRowBitmap = rowBitmap;
637
    mAddRotationAngle     = angle;
638
    mAddRotationDuration  = duration;
639

    
640
    if( listener instanceof ScrambleEffect )
641
      {
642
      mDebug += (" (a "+axis+" "+rowBitmap+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
643
      }
644
    }
645

    
646
///////////////////////////////////////////////////////////////////////////////////////////////////
647

    
648
  public void initializeObject(int[][] moves)
649
    {
650
    mInitializeObject = true;
651
    mNextMoves = moves;
652
    }
653

    
654
///////////////////////////////////////////////////////////////////////////////////////////////////
655

    
656
  public void scrambleObject(int num)
657
    {
658
    if( !mUIBlocked )
659
      {
660
      mScrambleObject = true;
661
      mScrambleObjectNum = num;
662
      mDebug = "";
663
      mDebugStartTime = System.currentTimeMillis();
664
      }
665
    }
666

    
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668
// this starts the Solve Effect
669

    
670
  public void solveObject()
671
    {
672
    if( !mUIBlocked )
673
      {
674
      mSolveObject = true;
675
      }
676
    }
677

    
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679
// this only sets the cubits state to solved
680

    
681
  public void solve()
682
    {
683
    mSolve = true;
684
    }
685

    
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687

    
688
  public void resetAllTextureMaps()
689
    {
690
    mResetAllTextureMaps = true;
691
    }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
  public TwistyObject getObject()
696
    {
697
    return mNewObject;
698
    }
699

    
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701

    
702
  public TwistyObject getOldObject()
703
    {
704
    return mOldObject;
705
    }
706

    
707
///////////////////////////////////////////////////////////////////////////////////////////////////
708

    
709
  public int getNumScrambles()
710
    {
711
    return mScrambleObjectNum;
712
    }
713

    
714
///////////////////////////////////////////////////////////////////////////////////////////////////
715

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

    
740
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
741
            {
742
            final RubikActivity act = (RubikActivity)mView.getContext();
743

    
744
            act.runOnUiThread(new Runnable()
745
              {
746
              @Override
747
              public void run()
748
                {
749
                ScreenList.switchScreen( act, ScreenList.READ);
750
                }
751
              });
752
            }
753

    
754
          if( i==BaseEffect.Type.WIN.ordinal() )
755
            {
756
            if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
757
              {
758
              final RubikActivity act = (RubikActivity)mView.getContext();
759
              Bundle bundle = new Bundle();
760
              bundle.putLong("time", mNewRecord );
761

    
762
              reportRecord();
763
              requestReview();
764

    
765
              if( mIsNewRecord )
766
                {
767
                RubikDialogNewRecord dialog = new RubikDialogNewRecord();
768
                dialog.setArguments(bundle);
769
                dialog.show( act.getSupportFragmentManager(), RubikDialogNewRecord.getDialogTag() );
770
                }
771
              else
772
                {
773
                RubikDialogSolved dialog = new RubikDialogSolved();
774
                dialog.setArguments(bundle);
775
                dialog.show( act.getSupportFragmentManager(), RubikDialogSolved.getDialogTag() );
776
                }
777

    
778
              act.runOnUiThread(new Runnable()
779
                {
780
                @Override
781
                public void run()
782
                  {
783
                  ScreenList.switchScreen( act, ScreenList.DONE);
784
                  }
785
                });
786
              }
787
            }
788

    
789
          break;
790
          }
791
        }
792
      }
793
    }
794
  }
(2-2/4)