Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikPreRender.java @ 318c0a7d

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.ObjectType;
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 ObjectType mNextObject;
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(ObjectType object, 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(mView.getQuat(), moves, res, mScreenWidth);
128

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

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

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

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

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

    
162
    boolean solved = mNewObject.isSolved();
163

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

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

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

    
190
    mIsSolved = solved;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

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

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

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

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

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

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

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

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

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

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

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

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

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

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

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

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

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

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

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

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

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

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

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

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

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

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

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

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

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

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

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

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

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

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

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

    
345
    int object      = play.getObject();
346
    int level       = play.getLevel();
347
    ObjectType list = ObjectType.getObject(object);
348
    String name     = scores.getName();
349

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

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

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

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

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

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

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

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

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

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

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

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

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452
//
453
///////////////////////////////////////////////////////////////////////////////////////////////////
454

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

    
460
///////////////////////////////////////////////////////////////////////////////////////////////////
461

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

    
470
    mScreenWidth  = width;
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

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

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

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

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

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

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

    
500
  void changeObject(ObjectType object)
501
    {
502
    mChangeObject = true;
503
    mNextObject = object;
504
    }
505

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

    
508
  void setupObject(ObjectType object, int[][] moves)
509
    {
510
    mSetupObject= true;
511
    mNextObject = object;
512
    mNextMoves  = moves;
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516

    
517
  void setTextureMap(int cubit, int face, int newColor)
518
    {
519
    mSetTextureMap = true;
520

    
521
    mCubit    = cubit;
522
    mFace     = face;
523
    mNewColor = newColor;
524
    }
525

    
526
///////////////////////////////////////////////////////////////////////////////////////////////////
527

    
528
  public boolean isTouchBlocked()
529
    {
530
    return mTouchBlocked;
531
    }
532

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

    
535
  public boolean isUINotBlocked()
536
    {
537
    return !mUIBlocked;
538
    }
539

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

    
542
  public void blockEverything(int place)
543
    {
544
    mUIBlocked   = true;
545
    mTouchBlocked= true;
546
    mBlockController.touchBlocked(place);
547
    mBlockController.uiBlocked(place);
548
    }
549

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

    
552
  public void blockTouch(int place)
553
    {
554
    mTouchBlocked= true;
555
    mBlockController.touchBlocked(place);
556
    }
557

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559

    
560
  public void unblockEverything()
561
    {
562
    mUIBlocked   = false;
563
    mTouchBlocked= false;
564
    mBlockController.touchUnblocked();
565
    mBlockController.uiUnblocked();
566
    }
567

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

    
570
  public void unblockTouch()
571
    {
572
    mTouchBlocked= false;
573
    mBlockController.touchUnblocked();
574
    }
575

    
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577

    
578
  public void unblockUI()
579
    {
580
    mUIBlocked= false;
581
    mBlockController.uiUnblocked();
582
    }
583

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

    
586
  void setQuatOnNextRender()
587
    {
588
    mSetQuat = true;
589
    }
590

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

    
593
  void preRender()
594
    {
595
    if( mSolve                 ) solveNow();
596
    if( mSetQuat               ) setQuatNow();
597
    if( mFinishRotation        ) finishRotationNow();
598
    if( mRemoveRotation        ) removeRotationNow();
599
    if( mRemovePatternRotation ) removePatternRotationNow();
600
    if( mChangeObject          ) changeObjectNow();
601
    if( mSetupObject           ) setupObjectNow();
602
    if( mSolveObject           ) solveObjectNow();
603
    if( mScrambleObject        ) scrambleObjectNow();
604
    if( mAddRotation           ) addRotationNow();
605
    if( mInitializeObject      ) initializeObjectNow();
606
    if( mResetAllTextureMaps   ) resetAllTextureMapsNow();
607
    if( mSetTextureMap         ) setTextureMapNow();
608
    }
609

    
610
///////////////////////////////////////////////////////////////////////////////////////////////////
611
// PUBLIC API
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613

    
614
  public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration)
615
    {
616
    mAddRotation = true;
617

    
618
    mAddActionListener    = listener;
619
    mAddRotationAxis      = axis;
620
    mAddRotationRowBitmap = rowBitmap;
621
    mAddRotationAngle     = angle;
622
    mAddRotationDuration  = duration;
623

    
624
    if( listener instanceof ScrambleEffect )
625
      {
626
      mDebug += (" (a "+axis+" "+rowBitmap+" "+angle+" "+(System.currentTimeMillis()-mDebugStartTime)+")");
627
      }
628
    }
629

    
630
///////////////////////////////////////////////////////////////////////////////////////////////////
631

    
632
  public void initializeObject(int[][] moves)
633
    {
634
    mInitializeObject = true;
635
    mNextMoves = moves;
636
    }
637

    
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639

    
640
  public void scrambleObject(int num)
641
    {
642
    if( !mUIBlocked )
643
      {
644
      mScrambleObject = true;
645
      mScrambleObjectNum = num;
646
      mDebug = "";
647
      mDebugStartTime = System.currentTimeMillis();
648
      }
649
    }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652
// this starts the Solve Effect
653

    
654
  public void solveObject()
655
    {
656
    if( !mUIBlocked )
657
      {
658
      mSolveObject = true;
659
      }
660
    }
661

    
662
///////////////////////////////////////////////////////////////////////////////////////////////////
663
// this only sets the cubits state to solved
664

    
665
  public void solve()
666
    {
667
    mSolve = true;
668
    }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
  public void resetAllTextureMaps()
673
    {
674
    mResetAllTextureMaps = true;
675
    }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678

    
679
  public TwistyObject getObject()
680
    {
681
    return mNewObject;
682
    }
683

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685

    
686
  public TwistyObject getOldObject()
687
    {
688
    return mOldObject;
689
    }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
  public int getNumScrambles()
694
    {
695
    return mScrambleObjectNum;
696
    }
697

    
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

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

    
724
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
725
            {
726
            final RubikActivity act = (RubikActivity)mView.getContext();
727

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

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

    
746
              reportRecord();
747
              requestReview();
748

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

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

    
773
          break;
774
          }
775
        }
776
      }
777
    }
778
  }
(2-2/4)