Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikPreRender.java @ 3f7a4363

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

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

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

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

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

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

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

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

    
170
    boolean solved = mNewObject.isSolved();
171

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

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

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

    
198
    mIsSolved = solved;
199
    }
200

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

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

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

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

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

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

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

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

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

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

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

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

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

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

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

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

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

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

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

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

    
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

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

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

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

    
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

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

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

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

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

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

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

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

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

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

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

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

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

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

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

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

    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

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

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

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

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

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

    
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

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

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

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

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461
//
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

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

    
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

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

    
479
    mScreenWidth  = width;
480
    }
481

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

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

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

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

    
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

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

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508

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

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520

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

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533

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

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

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

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

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

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

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

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

    
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568

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

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

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

    
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586

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

    
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594

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

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

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

    
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609

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

    
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628
// PUBLIC API
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630

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

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

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

    
647
///////////////////////////////////////////////////////////////////////////////////////////////////
648

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

    
655
///////////////////////////////////////////////////////////////////////////////////////////////////
656

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

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

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

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

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

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

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

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

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

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

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

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

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

    
715
///////////////////////////////////////////////////////////////////////////////////////////////////
716

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

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

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

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

    
763
              reportRecord();
764
              requestReview();
765

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

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

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