Project

General

Profile

« Previous | Next » 

Revision 5a4d4fba

Added by Leszek Koltunski over 4 years ago

Convert the PostRender to a PreRender, called before we render.
This makes more sense as this way things are prepared for the very first render.

View differences:

src/main/java/org/distorted/effects/BaseEffect.java
29 29
import org.distorted.effects.win.WinEffect;
30 30
import org.distorted.library.main.DistortedScreen;
31 31
import org.distorted.main.R;
32
import org.distorted.main.RubikPostRender;
32
import org.distorted.main.RubikPreRender;
33 33

  
34 34
///////////////////////////////////////////////////////////////////////////////////////////////////
35 35

  
......
197 197

  
198 198
  ////////////////////////////////////////////////////////////////////////////////
199 199

  
200
    public long startEffect(DistortedScreen screen, RubikPostRender post) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
200
    public long startEffect(DistortedScreen screen, RubikPreRender pre) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
201 201
      {
202 202
      Method method1 = mClass.getDeclaredMethod("create", int.class);
203 203

  
204 204
      Object value1 = method1.invoke(null,mCurrentType);
205 205
      BaseEffect baseEffect = (BaseEffect)value1;
206 206

  
207
      Method method2 = mClass.getDeclaredMethod("start", int.class, DistortedScreen.class, RubikPostRender.class);
207
      Method method2 = mClass.getDeclaredMethod("start", int.class, DistortedScreen.class, RubikPreRender.class);
208 208

  
209 209
      Integer translated = translatePos(mCurrentPos)+1;
210
      Object value2 = method2.invoke(baseEffect,translated,screen,post);
210
      Object value2 = method2.invoke(baseEffect,translated,screen,pre);
211 211
      return (Long)value2;
212 212
      }
213 213

  
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.main.RubikPostRender;
27
import org.distorted.main.RubikPreRender;
28 28
import org.distorted.objects.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
......
224 224
///////////////////////////////////////////////////////////////////////////////////////////////////
225 225

  
226 226
  @SuppressWarnings("unused")
227
  public long start(int duration, DistortedScreen screen, RubikPostRender post)
227
  public long start(int duration, DistortedScreen screen, RubikPreRender pre)
228 228
    {
229 229
    mScreen   = screen;
230
    mObject[0]= post.getOldObject();
231
    mObject[1]= post.getObject();
232
    mListener = post;
230
    mObject[0]= pre.getOldObject();
231
    mObject[1]= pre.getObject();
232
    mListener = pre;
233 233
    mDuration = duration;
234 234

  
235 235
    if( mObject[0]!=null )
src/main/java/org/distorted/effects/scramble/ScrambleEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.main.RubikPostRender;
27
import org.distorted.main.RubikPreRender;
28 28
import org.distorted.objects.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
......
32 32

  
33 33
///////////////////////////////////////////////////////////////////////////////////////////////////
34 34

  
35
public abstract class ScrambleEffect extends BaseEffect implements EffectListener, RubikPostRender.ActionFinishedListener
35
public abstract class ScrambleEffect extends BaseEffect implements EffectListener, RubikPreRender.ActionFinishedListener
36 36
{
37 37
  public enum Type
38 38
    {
......
63 63
      }
64 64
    }
65 65

  
66
  private RubikPostRender mPostRender;
66
  private RubikPreRender mPreRender;
67 67
  private int mEffectReturned;
68 68
  private int mNumDoubleScramblesLeft, mNumScramblesLeft;
69 69
  private int mLastVector;
......
167 167
        android.util.Log.e("effect", "ERROR: "+mNumDoubleScramblesLeft);
168 168
        }
169 169

  
170
      mPostRender.addRotation(this, mLastVector, rowBitmap, angle*(360/mBasicAngle), durationMillis);
170
      mPreRender.addRotation(this, mLastVector, rowBitmap, angle*(360/mBasicAngle), durationMillis);
171 171
      }
172 172
    else
173 173
      {
......
175 175

  
176 176
      if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
177 177
        {
178
        mPostRender.effectFinished(FAKE_EFFECT_ID);
178
        mPreRender.effectFinished(FAKE_EFFECT_ID);
179 179
        }
180 180
      }
181 181
    }
......
279 279

  
280 280
          if( mNumScramblesLeft==0 )
281 281
            {
282
            mPostRender.effectFinished(FAKE_EFFECT_ID);
282
            mPreRender.effectFinished(FAKE_EFFECT_ID);
283 283
            }
284 284
          }
285 285

  
......
302 302

  
303 303
          if( mNumScramblesLeft==0 )
304 304
            {
305
            mPostRender.effectFinished(FAKE_EFFECT_ID);
305
            mPreRender.effectFinished(FAKE_EFFECT_ID);
306 306
            }
307 307
          }
308 308

  
......
314 314
///////////////////////////////////////////////////////////////////////////////////////////////////
315 315

  
316 316
  @SuppressWarnings("unused")
317
  public long start(int duration, DistortedScreen screen, RubikPostRender post)
317
  public long start(int duration, DistortedScreen screen, RubikPreRender pre)
318 318
    {
319
    mObject     = post.getObject();
320
    mPostRender = post;
319
    mObject     = pre.getObject();
320
    mPreRender  = pre;
321 321
    mRowChances = mObject.getRowChances();
322 322

  
323 323
    mObject.solve();
......
325 325
    mNumAxis    = mObject.getRotationAxis().length;
326 326
    mBasicAngle = mObject.getBasicAngle();
327 327

  
328
    int numScrambles = post.getNumScrambles();
328
    int numScrambles = pre.getNumScrambles();
329 329
    int dura = (int)(duration*Math.pow(numScrambles,0.6f));
330 330
    createBaseEffects(dura,numScrambles);
331 331
    createEffects    (dura,numScrambles);
src/main/java/org/distorted/effects/solve/SolveEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.main.RubikPostRender;
27
import org.distorted.main.RubikPreRender;
28 28
import org.distorted.objects.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
......
197 197
///////////////////////////////////////////////////////////////////////////////////////////////////
198 198

  
199 199
  @SuppressWarnings("unused")
200
  public long start(int duration, DistortedScreen screen, RubikPostRender post)
200
  public long start(int duration, DistortedScreen screen, RubikPreRender pre)
201 201
    {
202 202
    mScreen   = screen;
203
    mObject   = post.getObject();
204
    mListener = post;
203
    mObject   = pre.getObject();
204
    mListener = pre;
205 205
    mDuration = duration;
206 206

  
207 207
    createEffectsPhase0(mDuration);
src/main/java/org/distorted/effects/win/WinEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.main.RubikPostRender;
27
import org.distorted.main.RubikPreRender;
28 28
import org.distorted.objects.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
......
163 163
///////////////////////////////////////////////////////////////////////////////////////////////////
164 164

  
165 165
  @SuppressWarnings("unused")
166
  public long start(int duration, DistortedScreen screen, RubikPostRender post)
166
  public long start(int duration, DistortedScreen screen, RubikPreRender pre)
167 167
    {
168 168
    mScreen   = screen;
169
    mObject   = post.getObject();
170
    mListener = post;
169
    mObject   = pre.getObject();
170
    mListener = pre;
171 171
    mDuration = duration;
172 172

  
173 173
    createEffects(mDuration);
src/main/java/org/distorted/main/RubikActivity.java
107 107
        if( sizeIndex>=0 && sizeIndex<sizes.length )
108 108
          {
109 109
          success = true;
110
          view.getPostRender().changeObject(obj,size);
110
          view.getPreRender().changeObject(obj,size);
111 111
          }
112 112

  
113 113
        }
......
118 118
        int s = RubikStatePlay.DEF_SIZE;
119 119

  
120 120
        play.setObjectAndSize(this,obj,s);
121
        view.getPostRender().changeObject(obj,s);
121
        view.getPreRender().changeObject(obj,s);
122 122
        }
123 123
      }
124 124
    
......
150 150

  
151 151
      RubikState.savePreferences(editor);
152 152
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
153
      view.getPostRender().savePreferences(editor);
153
      view.getPreRender().savePreferences(editor);
154 154

  
155 155
      editor.apply();
156 156
      }
......
174 174
      RubikState.restorePreferences(preferences);
175 175

  
176 176
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
177
      view.getPostRender().restorePreferences(preferences);
177
      view.getPreRender().restorePreferences(preferences);
178 178
      }
179 179

  
180 180
///////////////////////////////////////////////////////////////////////////////////////////////////
......
203 203
    public RubikObject getObject()
204 204
      {
205 205
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
206
      RubikPostRender post = view.getPostRender();
207
      return post.getObject();
206
      RubikPreRender pre = view.getPreRender();
207
      return pre.getObject();
208 208
      }
209 209

  
210 210
///////////////////////////////////////////////////////////////////////////////////////////////////
211 211

  
212
    public RubikPostRender getPostRender()
212
    public RubikPreRender getPreRender()
213 213
      {
214 214
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
215
      return view.getPostRender();
215
      return view.getPreRender();
216 216
      }
217 217

  
218 218
///////////////////////////////////////////////////////////////////////////////////////////////////
......
220 220
    public void changeObject(RubikObjectList object, int size)
221 221
      {
222 222
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
223
      RubikPostRender post = view.getPostRender();
224
      post.changeObject(object,size);
223
      RubikPreRender pre = view.getPreRender();
224
      pre.changeObject(object,size);
225 225
      }
226 226

  
227 227
///////////////////////////////////////////////////////////////////////////////////////////////////
......
229 229
    public void setupObject(RubikObjectList object, int size, int[][] moves)
230 230
      {
231 231
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
232
      RubikPostRender post = view.getPostRender();
233
      post.setupObject(object,size,moves);
232
      RubikPreRender pre = view.getPreRender();
233
      pre.setupObject(object,size,moves);
234 234
      }
235 235

  
236 236
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/main/RubikPostRender.java
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.SharedPreferences;
23
import android.os.Bundle;
24

  
25
import org.distorted.dialogs.RubikDialogNewRecord;
26
import org.distorted.dialogs.RubikDialogSolved;
27
import org.distorted.effects.BaseEffect;
28
import org.distorted.library.message.EffectListener;
29
import org.distorted.objects.RubikObject;
30
import org.distorted.objects.RubikObjectList;
31
import org.distorted.scores.RubikScores;
32
import org.distorted.states.RubikState;
33
import org.distorted.states.RubikStateSolving;
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
public class RubikPostRender implements EffectListener
38
  {
39
  public interface ActionFinishedListener
40
    {
41
    void onActionFinished(long effectID);
42
    }
43

  
44
  private RubikSurfaceView mView;
45
  private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
46
                  mSetQuatCurrent, mSetQuatAccumulated, mChangeObject, mSetupObject, mSolveObject,
47
                  mScrambleObject, mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
48
  private boolean mCanRotate, mCanPlay;
49
  private boolean mIsSolved;
50
  private RubikObjectList mNextObject;
51
  private int mNextSize;
52
  private long mRotationFinishedID;
53
  private long[] mEffectID;
54
  private boolean mIsNewRecord;
55
  private long mNewRecord;
56
  private int mScreenWidth, mScreenHeight;
57
  private SharedPreferences mPreferences;
58
  private int[][] mNextMoves;
59
  private RubikObject mOldObject, mNewObject;
60
  private int mScrambleObjectNum;
61
  private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
62
  private long mAddRotationDuration;
63
  private ActionFinishedListener mAddActionListener;
64
  private long mAddRotationID, mRemoveRotationID;
65
  private int mCubit, mFace, mNewColor;
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  RubikPostRender(RubikSurfaceView view)
70
    {
71
    mView = view;
72

  
73
    mFinishRotation       = false;
74
    mRemoveRotation       = false;
75
    mRemovePatternRotation= false;
76
    mAddRotation          = false;
77
    mSetQuatCurrent       = false;
78
    mSetQuatAccumulated   = false;
79
    mChangeObject         = false;
80
    mSetupObject          = false;
81
    mSolveObject          = false;
82
    mScrambleObject       = false;
83

  
84
    mCanRotate = true;
85
    mCanPlay   = true;
86

  
87
    mOldObject = null;
88
    mNewObject = null;
89

  
90
    mScreenWidth = mScreenHeight = 0;
91
    mScrambleObjectNum = 0;
92

  
93
    mEffectID = new long[BaseEffect.Type.LENGTH];
94
    }
95

  
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
  private void createObjectNow(RubikObjectList object, int size, int[][] moves)
99
    {
100
    boolean firstTime = (mNewObject==null);
101

  
102
    if( mOldObject!=null ) mOldObject.releaseResources();
103
    mOldObject = mNewObject;
104

  
105
    mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves);
106

  
107
    if( mNewObject!=null )
108
      {
109
      mNewObject.createTexture();
110
      mView.setMovement(object.getObjectMovementClass());
111

  
112
      if( firstTime ) mNewObject.restorePreferences(mPreferences);
113

  
114
      if( mScreenWidth!=0 )
115
        {
116
        mNewObject.recomputeScaleFactor(mScreenWidth, mScreenHeight);
117
        }
118

  
119
      mIsSolved = mNewObject.isSolved();
120
      }
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
// do all 'adjustable' effects (SizeChange, Solve, Scramble)
125

  
126
  private void doEffectNow(BaseEffect.Type type)
127
    {
128
    int index = type.ordinal();
129

  
130
    try
131
      {
132
      mEffectID[index] = type.startEffect(mView.getRenderer().getScreen(),this);
133
      }
134
    catch( Exception ex )
135
      {
136
      android.util.Log.e("renderer", "exception starting effect: "+ex.getMessage());
137

  
138
      mCanPlay   = true;
139
      mCanRotate = true;
140
      }
141
    }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
  private void removeRotationNow()
146
    {
147
    mRemoveRotation=false;
148
    mNewObject.removeRotationNow();
149

  
150
    boolean solved = mNewObject.isSolved();
151

  
152
    if( solved && !mIsSolved )
153
      {
154
      if( RubikState.getCurrentState()==RubikState.SOLV )
155
        {
156
        RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
157
        mNewRecord = solving.getRecord();
158

  
159
        if( mNewRecord< 0 )
160
          {
161
          mNewRecord = -mNewRecord;
162
          mIsNewRecord = false;
163
          }
164
        else
165
          {
166
          mIsNewRecord = true;
167
          }
168
        }
169

  
170
      mCanRotate = false;
171
      mCanPlay = false;
172
      doEffectNow( BaseEffect.Type.WIN );
173
      }
174
    else
175
      {
176
      mCanRotate = true;
177
      mCanPlay = true;
178
      }
179

  
180
    mIsSolved = solved;
181
    }
182

  
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

  
185
  private void removeRotation()
186
    {
187
    mRemoveRotation = true;
188
    }
189

  
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

  
192
  private void removePatternRotation()
193
    {
194
    mRemovePatternRotation = true;
195
    }
196

  
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

  
199
  private void removePatternRotationNow()
200
    {
201
    mRemovePatternRotation=false;
202
    mNewObject.removeRotationNow();
203
    mAddActionListener.onActionFinished(mRemoveRotationID);
204
    }
205

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

  
208
  private void addRotationNow()
209
    {
210
    mAddRotation = false;
211
    mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap,
212
                                                mAddRotationAngle, mAddRotationDuration, this);
213
    }
214

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

  
217
  private void finishRotationNow()
218
    {
219
    mFinishRotation = false;
220
    mCanRotate      = false;
221
    mCanPlay        = false;
222
    mRotationFinishedID = mNewObject.finishRotationNow(this);
223

  
224
    if( mRotationFinishedID==0 ) // failed to add effect - should never happen
225
      {
226
      mCanRotate = true;
227
      mCanPlay   = true;
228
      }
229
    }
230

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

  
233
  private void changeObjectNow()
234
    {
235
    mChangeObject = false;
236

  
237
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getSize()!=mNextSize)
238
      {
239
      mCanRotate= false;
240
      mCanPlay  = false;
241
      createObjectNow(mNextObject, mNextSize, null);
242
      doEffectNow( BaseEffect.Type.SIZECHANGE );
243
      }
244
    }
245

  
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

  
248
  private void setupObjectNow()
249
    {
250
    mSetupObject = false;
251

  
252
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getSize()!=mNextSize)
253
      {
254
      mCanRotate= false;
255
      mCanPlay  = false;
256
      createObjectNow(mNextObject, mNextSize, mNextMoves);
257
      doEffectNow( BaseEffect.Type.SIZECHANGE );
258
      }
259
    else
260
      {
261
      mNewObject.initializeObject(mNextMoves);
262
      }
263
    }
264

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

  
267
  private void scrambleObjectNow()
268
    {
269
    mScrambleObject = false;
270
    mCanRotate      = false;
271
    mCanPlay        = false;
272
    mIsSolved       = false;
273
    RubikScores.getInstance().incrementNumPlays();
274
    doEffectNow( BaseEffect.Type.SCRAMBLE );
275
    }
276

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

  
279
  private void solveObjectNow()
280
    {
281
    mSolveObject = false;
282
    mCanRotate   = false;
283
    mCanPlay     = false;
284
    doEffectNow( BaseEffect.Type.SOLVE );
285
    }
286

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

  
289
  private void initializeObjectNow()
290
    {
291
    mInitializeObject = false;
292
    mNewObject.initializeObject(mNextMoves);
293
    }
294

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

  
297
  private void setTextureMapNow()
298
    {
299
    mSetTextureMap = false;
300

  
301
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
302
    }
303

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

  
306
  private void resetAllTextureMapsNow()
307
    {
308
    mResetAllTextureMaps = false;
309

  
310
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
311
    }
312

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

  
315
  private void setQuatCurrentNow()
316
    {
317
    mSetQuatCurrent = false;
318
    mView.setQuatCurrent();
319
    }
320

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

  
323
  private void setQuatAccumulatedNow()
324
    {
325
    mSetQuatAccumulated = false;
326
    mView.setQuatAccumulated();
327
    }
328

  
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
//
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

  
333
  void setScreenSize(int width, int height)
334
    {
335
    if( mNewObject!=null )
336
      {
337
      mNewObject.createTexture();
338
      mNewObject.recomputeScaleFactor(width,height);
339
      }
340

  
341
    mScreenHeight = height;
342
    mScreenWidth  = width;
343
    }
344

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

  
347
  void savePreferences(SharedPreferences.Editor editor)
348
    {
349
    if( mNewObject!=null )
350
      {
351
      mNewObject.savePreferences(editor);
352
      }
353
    }
354

  
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

  
357
  void restorePreferences(SharedPreferences preferences)
358
    {
359
    mPreferences = preferences;
360
    }
361

  
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

  
364
  void finishRotation()
365
    {
366
    mFinishRotation = true;
367
    }
368

  
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

  
371
  void changeObject(RubikObjectList object, int size)
372
    {
373
    if( size>0 )
374
      {
375
      mChangeObject = true;
376
      mNextObject = object;
377
      mNextSize   = size;
378
      }
379
    }
380

  
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

  
383
  void setupObject(RubikObjectList object, int size, int[][] moves)
384
    {
385
    if( size>0 )
386
      {
387
      mSetupObject= true;
388
      mNextObject = object;
389
      mNextSize   = size;
390
      mNextMoves  = moves;
391
      }
392
    }
393

  
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

  
396
  void setTextureMap(int cubit, int face, int newColor)
397
    {
398
    mSetTextureMap = true;
399

  
400
    mCubit    = cubit;
401
    mFace     = face;
402
    mNewColor = newColor;
403
    }
404

  
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

  
407
  boolean canRotate()
408
    {
409
    return mCanRotate;
410
    }
411

  
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

  
414
  public boolean canPlay()
415
    {
416
    return mCanPlay;
417
    }
418

  
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

  
421
  void setQuatCurrentOnNextRender()
422
    {
423
    mSetQuatCurrent = true;
424
    }
425

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

  
428
  void setQuatAccumulatedOnNextRender()
429
    {
430
    mSetQuatAccumulated = true;
431
    }
432

  
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

  
435
  void postRender()
436
    {
437
    if( mSetQuatCurrent        ) setQuatCurrentNow();
438
    if( mSetQuatAccumulated    ) setQuatAccumulatedNow();
439
    if( mFinishRotation        ) finishRotationNow();
440
    if( mRemoveRotation        ) removeRotationNow();
441
    if( mRemovePatternRotation ) removePatternRotationNow();
442
    if( mChangeObject          ) changeObjectNow();
443
    if( mSetupObject           ) setupObjectNow();
444
    if( mSolveObject           ) solveObjectNow();
445
    if( mScrambleObject        ) scrambleObjectNow();
446
    if( mAddRotation           ) addRotationNow();
447
    if( mInitializeObject      ) initializeObjectNow();
448
    if( mResetAllTextureMaps   ) resetAllTextureMapsNow();
449
    if( mSetTextureMap         ) setTextureMapNow();
450
    }
451

  
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
// PUBLIC API
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

  
456
  public void addRotation(ActionFinishedListener listener, int axis, int rowBitmap, int angle, long duration)
457
    {
458
    mAddRotation = true;
459

  
460
    mAddActionListener    = listener;
461
    mAddRotationAxis      = axis;
462
    mAddRotationRowBitmap = rowBitmap;
463
    mAddRotationAngle     = angle;
464
    mAddRotationDuration  = duration;
465
    }
466

  
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

  
469
  public void initializeObject(int[][] moves)
470
    {
471
    mInitializeObject = true;
472
    mNextMoves = moves;
473
    }
474

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

  
477
  public void scrambleObject(int num)
478
    {
479
    if( mCanPlay )
480
      {
481
      mScrambleObject = true;
482
      mScrambleObjectNum = num;
483
      }
484
    }
485

  
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

  
488
  public void solveObject()
489
    {
490
    if( mCanPlay )
491
      {
492
      mSolveObject = true;
493
      }
494
    }
495

  
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

  
498
  public void resetAllTextureMaps()
499
    {
500
    mResetAllTextureMaps = true;
501
    }
502

  
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

  
505
  public RubikObject getObject()
506
    {
507
    return mNewObject;
508
    }
509

  
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

  
512
  public RubikObject getOldObject()
513
    {
514
    return mOldObject;
515
    }
516

  
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

  
519
  public int getNumScrambles()
520
    {
521
    return mScrambleObjectNum;
522
    }
523

  
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

  
526
  public void effectFinished(final long effectID)
527
    {
528
    if( effectID == mRotationFinishedID )
529
      {
530
      mRotationFinishedID = 0;
531
      removeRotation();
532
      }
533
    else if( effectID == mAddRotationID )
534
      {
535
      mAddRotationID = 0;
536
      mRemoveRotationID = effectID;
537
      removePatternRotation();
538
      }
539
    else
540
      {
541
      for(int i=0; i<BaseEffect.Type.LENGTH; i++)
542
        {
543
        if( effectID == mEffectID[i] )
544
          {
545
          mCanRotate = true;
546
          mCanPlay   = true;
547

  
548
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
549
            {
550
            final RubikActivity act = (RubikActivity)mView.getContext();
551

  
552
            act.runOnUiThread(new Runnable()
553
              {
554
              @Override
555
              public void run()
556
                {
557
                RubikState.switchState( act, RubikState.READ);
558
                }
559
              });
560
            }
561

  
562
          if( i==BaseEffect.Type.WIN.ordinal() )
563
            {
564
            if( RubikState.getCurrentState()==RubikState.SOLV )
565
              {
566
              final RubikActivity act = (RubikActivity)mView.getContext();
567
              Bundle bundle = new Bundle();
568
              bundle.putLong("time", mNewRecord );
569

  
570
              if( mIsNewRecord )
571
                {
572
                RubikDialogNewRecord dialog = new RubikDialogNewRecord();
573
                dialog.setArguments(bundle);
574
                dialog.show( act.getSupportFragmentManager(), null);
575
                }
576
              else
577
                {
578
                RubikDialogSolved dialog = new RubikDialogSolved();
579
                dialog.setArguments(bundle);
580
                dialog.show( act.getSupportFragmentManager(), null);
581
                }
582

  
583
              act.runOnUiThread(new Runnable()
584
                {
585
                @Override
586
                public void run()
587
                  {
588
                  RubikState.switchState( act, RubikState.DONE);
589
                  }
590
                });
591
              }
592
            }
593

  
594
          break;
595
          }
596
        }
597
      }
598
    }
599
  }
src/main/java/org/distorted/main/RubikPreRender.java
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.SharedPreferences;
23
import android.os.Bundle;
24

  
25
import org.distorted.dialogs.RubikDialogNewRecord;
26
import org.distorted.dialogs.RubikDialogSolved;
27
import org.distorted.effects.BaseEffect;
28
import org.distorted.library.message.EffectListener;
29
import org.distorted.objects.RubikObject;
30
import org.distorted.objects.RubikObjectList;
31
import org.distorted.scores.RubikScores;
32
import org.distorted.states.RubikState;
33
import org.distorted.states.RubikStateSolving;
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
public class RubikPreRender implements EffectListener
38
  {
39
  public interface ActionFinishedListener
40
    {
41
    void onActionFinished(long effectID);
42
    }
43

  
44
  private RubikSurfaceView mView;
45
  private boolean mFinishRotation, mRemoveRotation, mRemovePatternRotation, mAddRotation,
46
                  mSetQuatCurrent, mSetQuatAccumulated, mChangeObject, mSetupObject, mSolveObject,
47
                  mScrambleObject, mInitializeObject, mSetTextureMap, mResetAllTextureMaps;
48
  private boolean mCanRotate, mCanPlay;
49
  private boolean mIsSolved;
50
  private RubikObjectList mNextObject;
51
  private int mNextSize;
52
  private long mRotationFinishedID;
53
  private long[] mEffectID;
54
  private boolean mIsNewRecord;
55
  private long mNewRecord;
56
  private int mScreenWidth, mScreenHeight;
57
  private SharedPreferences mPreferences;
58
  private int[][] mNextMoves;
59
  private RubikObject mOldObject, mNewObject;
60
  private int mScrambleObjectNum;
61
  private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
62
  private long mAddRotationDuration;
63
  private ActionFinishedListener mAddActionListener;
64
  private long mAddRotationID, mRemoveRotationID;
65
  private int mCubit, mFace, mNewColor;
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  RubikPreRender(RubikSurfaceView view)
70
    {
71
    mView = view;
72

  
73
    mFinishRotation       = false;
74
    mRemoveRotation       = false;
75
    mRemovePatternRotation= false;
76
    mAddRotation          = false;
77
    mSetQuatCurrent       = false;
78
    mSetQuatAccumulated   = false;
79
    mChangeObject         = false;
80
    mSetupObject          = false;
81
    mSolveObject          = false;
82
    mScrambleObject       = false;
83

  
84
    mCanRotate = true;
85
    mCanPlay   = true;
86

  
87
    mOldObject = null;
88
    mNewObject = null;
89

  
90
    mScreenWidth = mScreenHeight = 0;
91
    mScrambleObjectNum = 0;
92

  
93
    mEffectID = new long[BaseEffect.Type.LENGTH];
94
    }
95

  
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
  private void createObjectNow(RubikObjectList object, int size, int[][] moves)
99
    {
100
    boolean firstTime = (mNewObject==null);
101

  
102
    if( mOldObject!=null ) mOldObject.releaseResources();
103
    mOldObject = mNewObject;
104

  
105
    mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves);
106

  
107
    if( mNewObject!=null )
108
      {
109
      mNewObject.createTexture();
110
      mView.setMovement(object.getObjectMovementClass());
111

  
112
      if( firstTime ) mNewObject.restorePreferences(mPreferences);
113

  
114
      if( mScreenWidth!=0 )
115
        {
116
        mNewObject.recomputeScaleFactor(mScreenWidth, mScreenHeight);
117
        }
118

  
119
      mIsSolved = mNewObject.isSolved();
120
      }
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
// do all 'adjustable' effects (SizeChange, Solve, Scramble)
125

  
126
  private void doEffectNow(BaseEffect.Type type)
127
    {
128
    int index = type.ordinal();
129

  
130
    try
131
      {
132
      mEffectID[index] = type.startEffect(mView.getRenderer().getScreen(),this);
133
      }
134
    catch( Exception ex )
135
      {
136
      android.util.Log.e("renderer", "exception starting effect: "+ex.getMessage());
137

  
138
      mCanPlay   = true;
139
      mCanRotate = true;
140
      }
141
    }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
  private void removeRotationNow()
146
    {
147
    mRemoveRotation=false;
148
    mNewObject.removeRotationNow();
149

  
150
    boolean solved = mNewObject.isSolved();
151

  
152
    if( solved && !mIsSolved )
153
      {
154
      if( RubikState.getCurrentState()==RubikState.SOLV )
155
        {
156
        RubikStateSolving solving = (RubikStateSolving)RubikState.SOLV.getStateClass();
157
        mNewRecord = solving.getRecord();
158

  
159
        if( mNewRecord< 0 )
160
          {
161
          mNewRecord = -mNewRecord;
162
          mIsNewRecord = false;
163
          }
164
        else
165
          {
166
          mIsNewRecord = true;
167
          }
168
        }
169

  
170
      mCanRotate = false;
171
      mCanPlay = false;
172
      doEffectNow( BaseEffect.Type.WIN );
173
      }
174
    else
175
      {
176
      mCanRotate = true;
177
      mCanPlay = true;
178
      }
179

  
180
    mIsSolved = solved;
181
    }
182

  
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

  
185
  private void removeRotation()
186
    {
187
    mRemoveRotation = true;
188
    }
189

  
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

  
192
  private void removePatternRotation()
193
    {
194
    mRemovePatternRotation = true;
195
    }
196

  
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

  
199
  private void removePatternRotationNow()
200
    {
201
    mRemovePatternRotation=false;
202
    mNewObject.removeRotationNow();
203
    mAddActionListener.onActionFinished(mRemoveRotationID);
204
    }
205

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

  
208
  private void addRotationNow()
209
    {
210
    mAddRotation = false;
211
    mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap,
212
                                                mAddRotationAngle, mAddRotationDuration, this);
213
    }
214

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

  
217
  private void finishRotationNow()
218
    {
219
    mFinishRotation = false;
220
    mCanRotate      = false;
221
    mCanPlay        = false;
222
    mRotationFinishedID = mNewObject.finishRotationNow(this);
223

  
224
    if( mRotationFinishedID==0 ) // failed to add effect - should never happen
225
      {
226
      mCanRotate = true;
227
      mCanPlay   = true;
228
      }
229
    }
230

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

  
233
  private void changeObjectNow()
234
    {
235
    mChangeObject = false;
236

  
237
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getSize()!=mNextSize)
238
      {
239
      mCanRotate= false;
240
      mCanPlay  = false;
241
      createObjectNow(mNextObject, mNextSize, null);
242
      doEffectNow( BaseEffect.Type.SIZECHANGE );
243
      }
244
    }
245

  
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

  
248
  private void setupObjectNow()
249
    {
250
    mSetupObject = false;
251

  
252
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getSize()!=mNextSize)
253
      {
254
      mCanRotate= false;
255
      mCanPlay  = false;
256
      createObjectNow(mNextObject, mNextSize, mNextMoves);
257
      doEffectNow( BaseEffect.Type.SIZECHANGE );
258
      }
259
    else
260
      {
261
      mNewObject.initializeObject(mNextMoves);
262
      }
263
    }
264

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

  
267
  private void scrambleObjectNow()
268
    {
269
    mScrambleObject = false;
270
    mCanRotate      = false;
271
    mCanPlay        = false;
272
    mIsSolved       = false;
273
    RubikScores.getInstance().incrementNumPlays();
274
    doEffectNow( BaseEffect.Type.SCRAMBLE );
275
    }
276

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

  
279
  private void solveObjectNow()
280
    {
281
    mSolveObject = false;
282
    mCanRotate   = false;
283
    mCanPlay     = false;
284
    doEffectNow( BaseEffect.Type.SOLVE );
285
    }
286

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

  
289
  private void initializeObjectNow()
290
    {
291
    mInitializeObject = false;
292
    mNewObject.initializeObject(mNextMoves);
293
    }
294

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

  
297
  private void setTextureMapNow()
298
    {
299
    mSetTextureMap = false;
300

  
301
    if( mNewObject!=null ) mNewObject.setTextureMap(mCubit,mFace,mNewColor);
302
    }
303

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

  
306
  private void resetAllTextureMapsNow()
307
    {
308
    mResetAllTextureMaps = false;
309

  
310
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
311
    }
312

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

  
315
  private void setQuatCurrentNow()
316
    {
317
    mSetQuatCurrent = false;
318
    mView.setQuatCurrent();
319
    }
320

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

  
323
  private void setQuatAccumulatedNow()
324
    {
325
    mSetQuatAccumulated = false;
326
    mView.setQuatAccumulated();
327
    }
328

  
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
//
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

  
333
  void setScreenSize(int width, int height)
334
    {
335
    if( mNewObject!=null )
336
      {
337
      mNewObject.createTexture();
338
      mNewObject.recomputeScaleFactor(width,height);
339
      }
340

  
341
    mScreenHeight = height;
342
    mScreenWidth  = width;
343
    }
344

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

  
347
  void savePreferences(SharedPreferences.Editor editor)
348
    {
349
    if( mNewObject!=null )
350
      {
351
      mNewObject.savePreferences(editor);
352
      }
353
    }
354

  
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

  
357
  void restorePreferences(SharedPreferences preferences)
358
    {
359
    mPreferences = preferences;
360
    }
361

  
362
///////////////////////////////////////////////////////////////////////////////////////////////////
363

  
364
  void finishRotation()
365
    {
366
    mFinishRotation = true;
367
    }
368

  
369
///////////////////////////////////////////////////////////////////////////////////////////////////
370

  
371
  void changeObject(RubikObjectList object, int size)
372
    {
373
    if( size>0 )
374
      {
375
      mChangeObject = true;
376
      mNextObject = object;
377
      mNextSize   = size;
378
      }
379
    }
380

  
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

  
383
  void setupObject(RubikObjectList object, int size, int[][] moves)
384
    {
385
    if( size>0 )
386
      {
387
      mSetupObject= true;
388
      mNextObject = object;
389
      mNextSize   = size;
390
      mNextMoves  = moves;
391
      }
392
    }
393

  
394
///////////////////////////////////////////////////////////////////////////////////////////////////
395

  
396
  void setTextureMap(int cubit, int face, int newColor)
397
    {
398
    mSetTextureMap = true;
399

  
400
    mCubit    = cubit;
401
    mFace     = face;
402
    mNewColor = newColor;
403
    }
404

  
405
///////////////////////////////////////////////////////////////////////////////////////////////////
406

  
407
  boolean canRotate()
408
    {
409
    return mCanRotate;
410
    }
411

  
412
///////////////////////////////////////////////////////////////////////////////////////////////////
413

  
414
  public boolean canPlay()
415
    {
416
    return mCanPlay;
417
    }
418

  
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420

  
421
  void setQuatCurrentOnNextRender()
422
    {
423
    mSetQuatCurrent = true;
424
    }
425

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

  
428
  void setQuatAccumulatedOnNextRender()
429
    {
430
    mSetQuatAccumulated = true;
431
    }
432

  
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

  
435
  void preRender()
436
    {
437
    if( mSetQuatCurrent        ) setQuatCurrentNow();
438
    if( mSetQuatAccumulated    ) setQuatAccumulatedNow();
439
    if( mFinishRotation        ) finishRotationNow();
440
    if( mRemoveRotation        ) removeRotationNow();
441
    if( mRemovePatternRotation ) removePatternRotationNow();
442
    if( mChangeObject          ) changeObjectNow();
443
    if( mSetupObject           ) setupObjectNow();
444
    if( mSolveObject           ) solveObjectNow();
445
    if( mScrambleObject        ) scrambleObjectNow();
446
    if( mAddRotation           ) addRotationNow();
447
    if( mInitializeObject      ) initializeObjectNow();
448
    if( mResetAllTextureMaps   ) resetAllTextureMapsNow();
449
    if( mSetTextureMap         ) setTextureMapNow();
450
    }
451

  
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
// PUBLIC API
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455

  
456
  public void addRotation(ActionFinishedListener listener, int axis, int rowBitmap, int angle, long duration)
457
    {
458
    mAddRotation = true;
459

  
460
    mAddActionListener    = listener;
461
    mAddRotationAxis      = axis;
462
    mAddRotationRowBitmap = rowBitmap;
463
    mAddRotationAngle     = angle;
464
    mAddRotationDuration  = duration;
465
    }
466

  
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468

  
469
  public void initializeObject(int[][] moves)
470
    {
471
    mInitializeObject = true;
472
    mNextMoves = moves;
473
    }
474

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

  
477
  public void scrambleObject(int num)
478
    {
479
    if( mCanPlay )
480
      {
481
      mScrambleObject = true;
482
      mScrambleObjectNum = num;
483
      }
484
    }
485

  
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

  
488
  public void solveObject()
489
    {
490
    if( mCanPlay )
491
      {
492
      mSolveObject = true;
493
      }
494
    }
495

  
496
///////////////////////////////////////////////////////////////////////////////////////////////////
497

  
498
  public void resetAllTextureMaps()
499
    {
500
    mResetAllTextureMaps = true;
501
    }
502

  
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

  
505
  public RubikObject getObject()
506
    {
507
    return mNewObject;
508
    }
509

  
510
///////////////////////////////////////////////////////////////////////////////////////////////////
511

  
512
  public RubikObject getOldObject()
513
    {
514
    return mOldObject;
515
    }
516

  
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

  
519
  public int getNumScrambles()
520
    {
521
    return mScrambleObjectNum;
522
    }
523

  
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

  
526
  public void effectFinished(final long effectID)
527
    {
528
    if( effectID == mRotationFinishedID )
529
      {
530
      mRotationFinishedID = 0;
531
      removeRotation();
532
      }
533
    else if( effectID == mAddRotationID )
534
      {
535
      mAddRotationID = 0;
536
      mRemoveRotationID = effectID;
537
      removePatternRotation();
538
      }
539
    else
540
      {
541
      for(int i=0; i<BaseEffect.Type.LENGTH; i++)
542
        {
543
        if( effectID == mEffectID[i] )
544
          {
545
          mCanRotate = true;
546
          mCanPlay   = true;
547

  
548
          if( i==BaseEffect.Type.SCRAMBLE.ordinal() )
549
            {
550
            final RubikActivity act = (RubikActivity)mView.getContext();
551

  
552
            act.runOnUiThread(new Runnable()
553
              {
554
              @Override
555
              public void run()
556
                {
557
                RubikState.switchState( act, RubikState.READ);
558
                }
559
              });
560
            }
561

  
562
          if( i==BaseEffect.Type.WIN.ordinal() )
563
            {
564
            if( RubikState.getCurrentState()==RubikState.SOLV )
565
              {
566
              final RubikActivity act = (RubikActivity)mView.getContext();
567
              Bundle bundle = new Bundle();
568
              bundle.putLong("time", mNewRecord );
569

  
570
              if( mIsNewRecord )
571
                {
572
                RubikDialogNewRecord dialog = new RubikDialogNewRecord();
573
                dialog.setArguments(bundle);
574
                dialog.show( act.getSupportFragmentManager(), null);
575
                }
576
              else
577
                {
578
                RubikDialogSolved dialog = new RubikDialogSolved();
579
                dialog.setArguments(bundle);
580
                dialog.show( act.getSupportFragmentManager(), null);
581
                }
582

  
583
              act.runOnUiThread(new Runnable()
584
                {
585
                @Override
586
                public void run()
587
                  {
588
                  RubikState.switchState( act, RubikState.DONE);
589
                  }
590
                });
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff