Project

General

Profile

« Previous | Next » 

Revision 40c41d1e

Added by Leszek Koltunski about 4 years ago

Remove all traces of tutorials from the new 1.5.4.
This is a bigger job; tutorials will only come in 1.6.0.

View differences:

build.gradle
15 15
        applicationId "org.distorted.magic"
16 16
        minSdkVersion 21
17 17
        targetSdkVersion 29
18
        versionCode 21
19
        versionName "1.5.3"
18
        versionCode 22
19
        versionName "1.5.4"
20 20
    }
21 21

  
22 22
    buildTypes {
......
35 35

  
36 36
dependencies {
37 37
    implementation fileTree(dir: 'libs', include: ['*.jar'])
38
    implementation 'com.google.firebase:firebase-analytics:17.6.0'
38
    implementation 'com.google.firebase:firebase-analytics:18.0.0'
39 39
    implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
40
    implementation 'com.google.android.play:core:1.8.2'
40
    implementation 'com.google.android.play:core:1.8.3'
41 41

  
42 42
    api project(':distorted-library')
43 43
    implementation 'androidx.appcompat:appcompat:1.2.0'
src/main/java/org/distorted/dialogs/RubikDialogInfo.java
39 39
import org.distorted.main.R;
40 40
import org.distorted.main.RubikActivity;
41 41
import org.distorted.objects.TwistyObject;
42
import org.distorted.tutorial.TutorialActivity;
43 42

  
44 43
///////////////////////////////////////////////////////////////////////////////////////////////////
45 44

  
......
74 73
      @Override
75 74
      public void onClick(DialogInterface dialog, int which)
76 75
        {
77
        RubikActivity ract = (RubikActivity)getContext();
78
        Intent myIntent = new Intent(ract, TutorialActivity.class);
79
        //myIntent.putExtra("", value); //Optional parameters
80 76

  
81
        if( ract!=null ) ract.startActivity(myIntent);
82 77
        }
83 78
      });
84 79

  
src/main/java/org/distorted/states/RubikStateBase.java
133 133
    layoutLeft.addView(mPrevButton);
134 134
    setupLockButton(act,width);
135 135
    layoutMid.addView(mLockButton);
136
    /*
136 137
    setupInfoButton(act,width);
137 138
    layoutMid.addView(mInfoButton);
139
     */
138 140
    layoutRight.addView(button);
139 141

  
140 142
    layoutBot.addView(layoutLeft);
src/main/java/org/distorted/tutorial/TutorialActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.tutorial;
21

  
22
import android.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.View;
26
import android.view.ViewGroup;
27
import android.view.WindowManager;
28
import android.webkit.WebView;
29
import android.widget.LinearLayout;
30

  
31
import androidx.appcompat.app.AppCompatActivity;
32

  
33
import com.google.firebase.analytics.FirebaseAnalytics;
34

  
35
import org.distorted.dialogs.RubikDialogError;
36
import org.distorted.main.R;
37
import org.distorted.objects.ObjectList;
38
import org.distorted.objects.TwistyObject;
39
import org.distorted.states.RubikStatePlay;
40
import org.distorted.states.StateList;
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
public class TutorialActivity extends AppCompatActivity
45
{
46
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
47
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
48

  
49
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
50
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
51
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
52
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
53
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
54

  
55
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
56
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
57

  
58
    private boolean mIsLocked;
59
    private FirebaseAnalytics mFirebaseAnalytics;
60
    private static int mScreenWidth, mScreenHeight;
61
    private int mCurrentApiVersion;
62
    private WebView mWebView;
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

  
66
    @Override
67
    protected void onCreate(Bundle savedState)
68
      {
69
      super.onCreate(savedState);
70
      setTheme(R.style.CustomActivityThemeNoActionBar);
71
      setContentView(R.layout.tutorial);
72

  
73
      mIsLocked = false;
74
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
75

  
76
      DisplayMetrics displaymetrics = new DisplayMetrics();
77
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
78
      mScreenWidth =displaymetrics.widthPixels;
79
      mScreenHeight=displaymetrics.heightPixels;
80

  
81
      hideNavigationBar();
82
      cutoutHack();
83
      }
84

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

  
87
    private void hideNavigationBar()
88
      {
89
      mCurrentApiVersion = Build.VERSION.SDK_INT;
90

  
91
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
92
        {
93
        final View decorView = getWindow().getDecorView();
94

  
95
        decorView.setSystemUiVisibility(FLAGS);
96

  
97
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
98
          {
99
          @Override
100
          public void onSystemUiVisibilityChange(int visibility)
101
            {
102
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
103
              {
104
              decorView.setSystemUiVisibility(FLAGS);
105
              }
106
            }
107
          });
108
        }
109
      }
110

  
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

  
113
    @Override
114
    public void onAttachedToWindow()
115
      {
116
      super.onAttachedToWindow();
117

  
118
      final float RATIO = 0.10f;
119
      float width = getScreenWidthInPixels();
120
      LinearLayout layout = findViewById(R.id.rightBar);
121
      ViewGroup.LayoutParams params = layout.getLayoutParams();
122
      params.width = (int)(width*RATIO);
123
      layout.setLayoutParams(params);
124
      }
125

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// do not avoid cutouts
128

  
129
    private void cutoutHack()
130
      {
131
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
132
        {
133
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
134
        }
135
      }
136

  
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

  
139
    @Override
140
    public void onWindowFocusChanged(boolean hasFocus)
141
      {
142
      super.onWindowFocusChanged(hasFocus);
143

  
144
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
145
        {
146
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
147
        }
148
      }
149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
    
152
    @Override
153
    protected void onPause() 
154
      {
155
      super.onPause();
156
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
157
      view.onPause();
158
      }
159

  
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
    
162
    @Override
163
    protected void onResume() 
164
      {
165
      super.onResume();
166
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
167
      view.onResume();
168
      view.initialize();
169

  
170
      boolean success = false;
171
      RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
172
      int object = play.getObject();
173
      int size   = play.getSize();
174

  
175
      if( object>=0 && object< ObjectList.NUM_OBJECTS )
176
        {
177
        ObjectList obj = ObjectList.getObject(object);
178
        int[] sizes = obj.getSizes();
179
        int sizeIndex = ObjectList.getSizeIndex(object,size);
180

  
181
        if( sizeIndex>=0 && sizeIndex<sizes.length )
182
          {
183
          success = true;
184
          view.getPreRender().changeObject(obj,size);
185
          }
186
        }
187
/*
188
      if( !success )
189
        {
190
        ObjectList obj = ObjectList.getObject(RubikStatePlay.DEF_OBJECT);
191
        int s = RubikStatePlay.DEF_SIZE;
192

  
193
        play.setObjectAndSize(this,obj,s);
194
        view.getPreRender().changeObject(obj,s);
195
        }
196
 */
197
      }
198
    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200
    
201
    @Override
202
    protected void onDestroy() 
203
      {
204
      super.onDestroy();
205
      }
206

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

  
209
    void OpenGLError()
210
      {
211
      RubikDialogError errDiag = new RubikDialogError();
212
      errDiag.show(getSupportFragmentManager(), null);
213
      }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
// PUBLIC API
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

  
219
    public FirebaseAnalytics getAnalytics()
220
      {
221
      return mFirebaseAnalytics;
222
      }
223

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

  
226
    public TwistyObject getObject()
227
      {
228
      TutorialSurfaceView view = findViewById(R.id.rubikSurfaceView);
229
      TutorialPreRender pre = view.getPreRender();
230
      return pre.getObject();
231
      }
232

  
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

  
235
    public int getScreenWidthInPixels()
236
      {
237
      return mScreenWidth;
238
      }
239

  
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

  
242
    public int getScreenHeightInPixels()
243
      {
244
      return mScreenHeight;
245
      }
246

  
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

  
249
    public TutorialPreRender getPreRender()
250
      {
251
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
252
      return view.getPreRender();
253
      }
254

  
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

  
257
    public static int getDrawableSize()
258
      {
259
      if( mScreenHeight<1000 )
260
        {
261
        return 0;
262
        }
263
      if( mScreenHeight<1600 )
264
        {
265
        return 1;
266
        }
267
      if( mScreenHeight<1900 )
268
        {
269
        return 2;
270
        }
271

  
272
      return 3;
273
      }
274

  
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

  
277
    public static int getDrawable(int small, int medium, int big, int huge)
278
      {
279
      int size = getDrawableSize();
280

  
281
      switch(size)
282
        {
283
        case 0 : return small;
284
        case 1 : return medium;
285
        case 2 : return big;
286
        default: return huge;
287
        }
288
      }
289

  
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

  
292
    public boolean isVertical()
293
      {
294
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
295
      return view.isVertical();
296
      }
297

  
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

  
300
    public void toggleLock()
301
      {
302
      mIsLocked = !mIsLocked;
303
      }
304

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

  
307
    public boolean isLocked()
308
      {
309
      StateList state = StateList.getCurrentState();
310

  
311
      if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
312
        {
313
        return mIsLocked;
314
        }
315

  
316
      return false;
317
      }
318

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

  
321
    public boolean retLocked()
322
      {
323
      return mIsLocked;
324
      }
325
}
src/main/java/org/distorted/tutorial/TutorialPreRender.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.tutorial;
21

  
22
import android.content.Context;
23
import android.content.res.Resources;
24

  
25
import org.distorted.effects.BaseEffect;
26
import org.distorted.effects.EffectController;
27
import org.distorted.objects.ObjectList;
28
import org.distorted.objects.TwistyObject;
29
import org.distorted.main.RubikPreRender.ActionFinishedListener;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
public class TutorialPreRender implements EffectController
34
  {
35
  private ActionFinishedListener mAddActionListener;
36
  private TutorialSurfaceView mView;
37
  private boolean mFinishRotation, mRemoveRotation, mAddRotation,
38
                  mSetQuat, mChangeObject, mSetupObject, mSolveObject,
39
                  mInitializeObject, mResetAllTextureMaps, mRemovePatternRotation;
40
  private boolean mCanPlay;
41
  private boolean mIsSolved;
42
  private ObjectList mNextObject;
43
  private int mNextSize;
44
  private long mRotationFinishedID;
45
  private int mScreenWidth;
46
  private int[][] mNextMoves;
47
  private TwistyObject mOldObject, mNewObject;
48
  private int mAddRotationAxis, mAddRotationRowBitmap, mAddRotationAngle;
49
  private long mAddRotationDuration;
50
  private long mAddRotationID, mRemoveRotationID;
51
  private int mNearestAngle;
52

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

  
55
  TutorialPreRender(TutorialSurfaceView view)
56
    {
57
    mView = view;
58

  
59
    mFinishRotation = false;
60
    mRemoveRotation = false;
61
    mAddRotation    = false;
62
    mSetQuat        = false;
63
    mChangeObject   = false;
64
    mSetupObject    = false;
65
    mSolveObject    = false;
66
    mCanPlay        = true;
67
    mOldObject      = null;
68
    mNewObject      = null;
69
    mScreenWidth    = 0;
70

  
71
    mRemovePatternRotation= false;
72
    }
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  private void createObjectNow(ObjectList object, int size, int[][] moves)
77
    {
78
    if( mOldObject!=null ) mOldObject.releaseResources();
79
    mOldObject = mNewObject;
80

  
81
    Context con = mView.getContext();
82
    Resources res = con.getResources();
83

  
84
    mNewObject = object.create(size, mView.getQuat(), moves, res, mScreenWidth);
85

  
86
    if( mNewObject!=null )
87
      {
88
      mNewObject.createTexture();
89
      mView.setMovement(object.getObjectMovementClass());
90

  
91
      if( mScreenWidth!=0 )
92
        {
93
        mNewObject.recomputeScaleFactor(mScreenWidth);
94
        }
95

  
96
      mIsSolved = mNewObject.isSolved();
97
      }
98
    }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  private void doEffectNow(BaseEffect.Type type)
103
    {
104
    try
105
      {
106
      type.startEffect(mView.getRenderer().getScreen(),this);
107
      }
108
    catch( Exception ex )
109
      {
110
      mCanPlay= true;
111
      }
112
    }
113

  
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

  
116
  private void removePatternRotation()
117
    {
118
    mRemovePatternRotation = true;
119
    }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
  private void removePatternRotationNow()
124
    {
125
    mRemovePatternRotation=false;
126
    mNewObject.removeRotationNow();
127
    mAddActionListener.onActionFinished(mRemoveRotationID);
128
    }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
  private void removeRotationNow()
133
    {
134
    mRemoveRotation=false;
135
    mNewObject.removeRotationNow();
136

  
137
    boolean solved = mNewObject.isSolved();
138

  
139
    if( solved && !mIsSolved )
140
      {
141
      doEffectNow( BaseEffect.Type.WIN );
142
      }
143
    else
144
      {
145
      mCanPlay = true;
146
      }
147

  
148
    mIsSolved = solved;
149
    }
150

  
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

  
153
  private void removeRotation()
154
    {
155
    mRemoveRotation = true;
156
    }
157

  
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

  
160
  private void addRotationNow()
161
    {
162
    mAddRotation = false;
163
    mAddRotationID = mNewObject.addNewRotation( mAddRotationAxis, mAddRotationRowBitmap,
164
                                                mAddRotationAngle, mAddRotationDuration, this);
165
    }
166

  
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

  
169
  private void finishRotationNow()
170
    {
171
    mFinishRotation = false;
172
    mCanPlay        = false;
173
    mRotationFinishedID = mNewObject.finishRotationNow(this, mNearestAngle);
174

  
175
    if( mRotationFinishedID==0 ) // failed to add effect - should never happen
176
      {
177
      mCanPlay   = true;
178
      }
179
    }
180

  
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

  
183
  private void changeObjectNow()
184
    {
185
    mChangeObject = false;
186

  
187
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize)
188
      {
189
      mCanPlay  = false;
190
      createObjectNow(mNextObject, mNextSize, null);
191
      doEffectNow( BaseEffect.Type.SIZECHANGE );
192
      }
193
    }
194

  
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

  
197
  private void setupObjectNow()
198
    {
199
    mSetupObject = false;
200

  
201
    if ( mNewObject==null || mNewObject.getObjectList()!=mNextObject || mNewObject.getNumLayers()!=mNextSize)
202
      {
203
      mCanPlay  = false;
204
      createObjectNow(mNextObject, mNextSize, mNextMoves);
205
      doEffectNow( BaseEffect.Type.SIZECHANGE );
206
      }
207
    else
208
      {
209
      mNewObject.initializeObject(mNextMoves);
210
      }
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  private void solveObjectNow()
216
    {
217
    mSolveObject = false;
218
    mCanPlay     = false;
219
    doEffectNow( BaseEffect.Type.SOLVE );
220
    }
221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

  
224
  private void initializeObjectNow()
225
    {
226
    mInitializeObject = false;
227
    mNewObject.initializeObject(mNextMoves);
228
    }
229

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

  
232
  private void resetAllTextureMapsNow()
233
    {
234
    mResetAllTextureMaps = false;
235

  
236
    if( mNewObject!=null ) mNewObject.resetAllTextureMaps();
237
    }
238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

  
241
  private void setQuatNow()
242
    {
243
    mSetQuat = false;
244
    mView.setQuat();
245
    }
246

  
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
//
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

  
251
  void setScreenSize(int width)
252
    {
253
    if( mNewObject!=null )
254
      {
255
      mNewObject.createTexture();
256
      mNewObject.recomputeScaleFactor(width);
257
      }
258

  
259
    mScreenWidth  = width;
260
    }
261

  
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

  
264
  void finishRotation(int nearestAngle)
265
    {
266
    mNearestAngle   = nearestAngle;
267
    mFinishRotation = true;
268
    }
269

  
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

  
272
  void changeObject(ObjectList object, int size)
273
    {
274
    if( size>0 )
275
      {
276
      mChangeObject = true;
277
      mNextObject = object;
278
      mNextSize   = size;
279
      }
280
    }
281

  
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

  
284
  void setQuatOnNextRender()
285
    {
286
    mSetQuat = true;
287
    }
288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
  void preRender()
292
    {
293
    if( mSetQuat               ) setQuatNow();
294
    if( mFinishRotation        ) finishRotationNow();
295
    if( mRemoveRotation        ) removeRotationNow();
296
    if( mChangeObject          ) changeObjectNow();
297
    if( mSetupObject           ) setupObjectNow();
298
    if( mSolveObject           ) solveObjectNow();
299
    if( mAddRotation           ) addRotationNow();
300
    if( mInitializeObject      ) initializeObjectNow();
301
    if( mResetAllTextureMaps   ) resetAllTextureMapsNow();
302
    if( mRemovePatternRotation ) removePatternRotationNow();
303
    }
304

  
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306
// PUBLIC API
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

  
309
  public void addRotation(ActionFinishedListener listener, int axis, int rowBitmap, int angle, long duration)
310
    {
311
    mAddRotation = true;
312

  
313
    mAddActionListener    = listener;
314
    mAddRotationAxis      = axis;
315
    mAddRotationRowBitmap = rowBitmap;
316
    mAddRotationAngle     = angle;
317
    mAddRotationDuration  = duration;
318
    }
319

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

  
322
  public void initializeObject(int[][] moves)
323
    {
324
    mInitializeObject = true;
325
    mNextMoves = moves;
326
    }
327

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

  
330
  public int getNumScrambles()
331
    {
332
    return 0;
333
    }
334

  
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336

  
337
  public void solveObject()
338
    {
339
    if( mCanPlay )
340
      {
341
      mSolveObject = true;
342
      }
343
    }
344

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

  
347
  public void resetAllTextureMaps()
348
    {
349
    mResetAllTextureMaps = true;
350
    }
351

  
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

  
354
  public TwistyObject getObject()
355
    {
356
    return mNewObject;
357
    }
358

  
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360

  
361
  public TwistyObject getOldObject()
362
    {
363
    return null;
364
    }
365

  
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

  
368
  public void effectFinished(final long effectID)
369
    {
370
    if( effectID == mRotationFinishedID )
371
      {
372
      mRotationFinishedID = 0;
373
      removeRotation();
374
      }
375
    else if( effectID == mAddRotationID )
376
      {
377
      mAddRotationID = 0;
378
      mRemoveRotationID = effectID;
379
      removePatternRotation();
380
      }
381
    else
382
      {
383
      mCanPlay   = true;
384
      }
385
    }
386
  }
src/main/java/org/distorted/tutorial/TutorialRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.tutorial;
21

  
22
import android.opengl.GLSurfaceView;
23

  
24
import org.distorted.library.main.DistortedScreen;
25

  
26
import javax.microedition.khronos.egl.EGLConfig;
27
import javax.microedition.khronos.opengles.GL10;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
public class TutorialRenderer implements GLSurfaceView.Renderer
32
{
33
   private TutorialSurfaceView mView;
34
   private DistortedScreen mScreen;
35

  
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

  
38
   TutorialRenderer(TutorialSurfaceView v)
39
     {
40
     final float BRIGHTNESS = 0.30f;
41

  
42
     mView = v;
43
     mScreen = new DistortedScreen();
44
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
45
     }
46

  
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

  
49
   @Override
50
   public void onDrawFrame(GL10 glUnused)
51
     {
52
     long time = System.currentTimeMillis();
53
     mView.getPreRender().preRender();
54
     mScreen.render(time);
55
     }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
   @Override
60
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
61
      {
62
      mScreen.resize(width,height);
63
      mView.setScreenSize(width,height);
64
      mView.getPreRender().setScreenSize(width);
65
      }
66

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

  
69
   @Override
70
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
71
      {
72

  
73
      }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
   DistortedScreen getScreen()
78
     {
79
     return mScreen;
80
     }
81
}
src/main/java/org/distorted/tutorial/TutorialSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.tutorial;
21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLES30;
26
import android.opengl.GLSurfaceView;
27
import android.util.AttributeSet;
28
import android.util.DisplayMetrics;
29
import android.view.MotionEvent;
30

  
31
import com.google.firebase.crashlytics.FirebaseCrashlytics;
32

  
33
import org.distorted.library.type.Static2D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.objects.Movement;
36
import org.distorted.objects.TwistyObject;
37
import org.distorted.states.RubikStateSolving;
38
import org.distorted.states.StateList;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
public class TutorialSurfaceView extends GLSurfaceView
43
{
44
    private static final int NUM_SPEED_PROBES = 10;
45
    private static final int INVALID_POINTER_ID = -1;
46

  
47
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
48
    // given face by SWIPING_SENSITIVITY/2 degrees.
49
    private final static int SWIPING_SENSITIVITY  = 240;
50
    // Moving the finger by 0.3 of an inch will start a Rotation.
51
    private final static float ROTATION_SENSITIVITY = 0.3f;
52

  
53
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 1, 0);
54

  
55
    private TutorialRenderer mRenderer;
56
    private TutorialPreRender mPreRender;
57
    private Movement mMovement;
58
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
59
    private int mScreenWidth, mScreenHeight, mScreenMin;
60

  
61
    private float mRotAngle, mInitDistance;
62
    private int mPtrID1, mPtrID2;
63
    private float mX, mY;
64
    private float mStartRotX, mStartRotY;
65
    private float mAxisX, mAxisY;
66
    private float mRotationFactor;
67
    private int mCurrentAxis, mCurrentRow;
68
    private float mCurrentAngle, mCurrRotSpeed;
69
    private float[] mLastX;
70
    private float[] mLastY;
71
    private long[] mLastT;
72
    private int mFirstIndex, mLastIndex;
73
    private int mDensity;
74

  
75
    private static Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
76
    private static Static4D mTemp= new Static4D(0,0,0,1);
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
    void setScreenSize(int width, int height)
81
      {
82
      mScreenWidth = width;
83
      mScreenHeight= height;
84

  
85
      mScreenMin = Math.min(width, height);
86
      }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
    boolean isVertical()
91
      {
92
      return mScreenHeight>mScreenWidth;
93
      }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
    TutorialRenderer getRenderer()
98
      {
99
      return mRenderer;
100
      }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

  
104
    TutorialPreRender getPreRender()
105
      {
106
      return mPreRender;
107
      }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
    void setQuat()
112
      {
113
      mQuat.set(mTemp);
114
      }
115

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

  
118
    Static4D getQuat()
119
      {
120
      return mQuat;
121
      }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
    void setMovement(Movement movement)
126
      {
127
      mMovement = movement;
128
      }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
    private Static4D quatFromDrag(float dragX, float dragY)
133
      {
134
      float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
135
      float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
136
      float axisZ = 0;
137
      float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
138

  
139
      if( axisL>0 )
140
        {
141
        axisX /= axisL;
142
        axisY /= axisL;
143
        axisZ /= axisL;
144

  
145
        float ratio = axisL;
146
        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
147

  
148
        float cosA = (float)Math.cos(Math.PI*ratio);
149
        float sinA = (float)Math.sqrt(1-cosA*cosA);
150

  
151
        return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
152
        }
153

  
154
      return new Static4D(0f, 0f, 0f, 1f);
155
      }
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
159
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
160

  
161
    private void computeCurrentAxis(Static4D axis)
162
      {
163
      Static4D result = rotateVectorByQuat(axis, mQuat);
164

  
165
      mAxisX =result.get0();
166
      mAxisY =result.get1();
167

  
168
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
169
      mAxisX /= len;
170
      mAxisY /= len;
171
      }
172

  
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
// return quat1*quat2
175

  
176
    public static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
177
      {
178
      float qx = quat1.get0();
179
      float qy = quat1.get1();
180
      float qz = quat1.get2();
181
      float qw = quat1.get3();
182

  
183
      float rx = quat2.get0();
184
      float ry = quat2.get1();
185
      float rz = quat2.get2();
186
      float rw = quat2.get3();
187

  
188
      float tx = rw*qx - rz*qy + ry*qz + rx*qw;
189
      float ty = rw*qy + rz*qx + ry*qw - rx*qz;
190
      float tz = rw*qz + rz*qw - ry*qx + rx*qy;
191
      float tw = rw*qw - rz*qz - ry*qy - rx*qx;
192

  
193
      return new Static4D(tx,ty,tz,tw);
194
      }
195

  
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197
// rotate 'vector' by quat  ( i.e. return quat*vector*(quat^-1) )
198

  
199
    public static Static4D rotateVectorByQuat(Static4D vector, Static4D quat)
200
      {
201
      float qx = quat.get0();
202
      float qy = quat.get1();
203
      float qz = quat.get2();
204
      float qw = quat.get3();
205

  
206
      Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw);
207
      Static4D tmp = quatMultiply(quat,vector);
208

  
209
      return quatMultiply(tmp,quatInverted);
210
      }
211

  
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
214

  
215
    public static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat)
216
      {
217
      float qx = quat.get0();
218
      float qy = quat.get1();
219
      float qz = quat.get2();
220
      float qw = quat.get3();
221

  
222
      Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw);
223
      Static4D tmp = quatMultiply(quatInverted,vector);
224

  
225
      return quatMultiply(tmp,quat);
226
      }
227

  
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

  
230
    private void addSpeedProbe(float x, float y)
231
      {
232
      long currTime = System.currentTimeMillis();
233
      boolean theSame = mLastIndex==mFirstIndex;
234

  
235
      mLastIndex++;
236
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
237

  
238
      mLastT[mLastIndex] = currTime;
239
      mLastX[mLastIndex] = x;
240
      mLastY[mLastIndex] = y;
241

  
242
      if( mLastIndex==mFirstIndex)
243
        {
244
        mFirstIndex++;
245
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
246
        }
247

  
248
      if( theSame )
249
        {
250
        mLastT[mFirstIndex] = currTime;
251
        mLastX[mFirstIndex] = x;
252
        mLastY[mFirstIndex] = y;
253
        }
254
      }
255

  
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

  
258
    private void computeCurrentSpeedInInchesPerSecond()
259
      {
260
      long firstTime = mLastT[mFirstIndex];
261
      long lastTime  = mLastT[mLastIndex];
262
      float fX = mLastX[mFirstIndex];
263
      float fY = mLastY[mFirstIndex];
264
      float lX = mLastX[mLastIndex];
265
      float lY = mLastY[mLastIndex];
266

  
267
      long timeDiff = lastTime-firstTime;
268

  
269
      mLastIndex = 0;
270
      mFirstIndex= 0;
271

  
272
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
273
      }
274

  
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

  
277
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
278
      {
279
      float xDist = mScreenWidth*(xFrom-xTo);
280
      float yDist = mScreenHeight*(yFrom-yTo);
281
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
282

  
283
      return distInPixels/mDensity;
284
      }
285

  
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

  
288
    private void setUpDragOrRotate(float x, float y)
289
      {
290
        Static4D touchPoint = new Static4D(x, y, 0, 0);
291
        Static4D rotatedTouchPoint= rotateVectorByInvertedQuat(touchPoint, mQuat);
292
        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
293

  
294
        if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera) )
295
          {
296
          mDragging           = false;
297
          mContinuingRotation = false;
298
          mBeginningRotation  = true;
299
          }
300
        else
301
          {
302
          final TutorialActivity act = (TutorialActivity)getContext();
303
          mDragging           = !act.isLocked();
304
          mContinuingRotation = false;
305
          mBeginningRotation  = false;
306
          }
307
      }
308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

  
311
    private void drag(MotionEvent event, float x, float y)
312
      {
313
      if( mPtrID1!=INVALID_POINTER_ID && mPtrID2!=INVALID_POINTER_ID)
314
        {
315
        int pointer = event.findPointerIndex(mPtrID2);
316
        float pX,pY;
317

  
318
        try
319
          {
320
          pX = event.getX(pointer);
321
          pY = event.getY(pointer);
322
          }
323
        catch(IllegalArgumentException ex)
324
          {
325
          mPtrID1=INVALID_POINTER_ID;
326
          mPtrID2=INVALID_POINTER_ID;
327

  
328
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
329
          crashlytics.setCustomKey("DragError", "pointer="+pointer );
330
          crashlytics.recordException(ex);
331

  
332
          return;
333
          }
334

  
335
        float x2 = (pX - mScreenWidth*0.5f)/mScreenMin;
336
        float y2 = (mScreenHeight*0.5f -pY)/mScreenMin;
337

  
338
        float angleNow = getAngle(x,y,x2,y2);
339
        float angleDiff = angleNow-mRotAngle;
340
        float sinA =-(float)Math.sin(angleDiff);
341
        float cosA = (float)Math.cos(angleDiff);
342

  
343
        Static4D dragQuat = quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
344
        mTemp.set(dragQuat);
345

  
346
        mRotAngle = angleNow;
347

  
348
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
349
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
350
        mInitDistance = distNow;
351

  
352
        TwistyObject object = mPreRender.getObject();
353
        if( object!=null ) object.setObjectRatio(distQuot);
354
        }
355
      else
356
        {
357
        Static4D dragQuat = quatMultiply(quatFromDrag(mX-x,y-mY), mQuat);
358
        mTemp.set(dragQuat);
359
        }
360

  
361
      mPreRender.setQuatOnNextRender();
362
      mX = x;
363
      mY = y;
364
      }
365

  
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

  
368
    private void finishRotation()
369
      {
370
      computeCurrentSpeedInInchesPerSecond();
371
      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAngle, mCurrRotSpeed);
372
      mPreRender.finishRotation(angle);
373

  
374
////////////
375
// TODO
376
      if( angle!=0 )
377
        {
378
        if( StateList.getCurrentState()== StateList.SOLV )
379
          {
380
          RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
381
          solving.addMove(mCurrentAxis, mCurrentRow, angle);
382
          }
383
        }
384
///////////
385

  
386
      mContinuingRotation = false;
387
      mBeginningRotation  = false;
388
      mDragging           = true;
389
      }
390

  
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

  
393
    private void continueRotation(float x, float y)
394
      {
395
      float dx = x-mStartRotX;
396
      float dy = y-mStartRotY;
397
      float alpha = dx*mAxisX + dy*mAxisY;
398
      float x2 = dx - alpha*mAxisX;
399
      float y2 = dy - alpha*mAxisY;
400

  
401
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
402

  
403
      // we have the length of 1D vector 'angle', now the direction:
404
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
405

  
406
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
407
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
408
      mPreRender.getObject().continueRotation(mCurrentAngle);
409

  
410
      addSpeedProbe(x2,y2);
411
      }
412

  
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

  
415
    private void beginRotation(float x, float y)
416
      {
417
      mStartRotX = x;
418
      mStartRotY = y;
419

  
420
      TwistyObject object = mPreRender.getObject();
421
      int numLayers = object.getNumLayers();
422

  
423
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
424
      Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuat);
425
      Static2D res = mMovement.newRotation(numLayers,rotatedTouchPoint2);
426

  
427
      mCurrentAxis = (int)res.get0();
428
      mCurrentRow  = (int)res.get1();
429

  
430
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
431
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
432

  
433
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
434

  
435
      addSpeedProbe(x,y);
436

  
437
      mBeginningRotation = false;
438
      mContinuingRotation= true;
439
      }
440

  
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

  
443
    private float getAngle(float x1, float y1, float x2, float y2)
444
      {
445
      return (float) Math.atan2(y1-y2, x1-x2);
446
      }
447

  
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

  
450
    private void actionMove(MotionEvent event)
451
      {
452
      int pointer = event.findPointerIndex(mPtrID1 != INVALID_POINTER_ID ? mPtrID1:mPtrID2);
453

  
454
      if( pointer<0 ) return;
455

  
456
      float pX = event.getX(pointer);
457
      float pY = event.getY(pointer);
458

  
459
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
460
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
461

  
462
      if( mBeginningRotation )
463
        {
464
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
465
          {
466
          beginRotation(x,y);
467
          }
468
        }
469
      else if( mContinuingRotation )
470
        {
471
        continueRotation(x,y);
472
        }
473
      else if( mDragging )
474
        {
475
        drag(event,x,y);
476
        }
477
      else
478
        {
479
        setUpDragOrRotate(x,y);
480
        }
481
      }
482

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

  
485
    private void actionDown(MotionEvent event)
486
      {
487
      mPtrID1 = event.getPointerId(0);
488

  
489
      float x = event.getX();
490
      float y = event.getY();
491

  
492
      mX = (x - mScreenWidth*0.5f)/mScreenMin;
493
      mY = (mScreenHeight*0.5f -y)/mScreenMin;
494

  
495
      setUpDragOrRotate(mX,mY);
496
      }
497

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

  
500
    private void actionUp(MotionEvent event)
501
      {
502
      mPtrID1 = INVALID_POINTER_ID;
503
      mPtrID2 = INVALID_POINTER_ID;
504

  
505
      if( mContinuingRotation )
506
        {
507
        finishRotation();
508
        }
509
      }
510

  
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

  
513
    private void actionDown2(MotionEvent event)
514
      {
515
      int index = event.getActionIndex();
516

  
517
      if( mPtrID1==INVALID_POINTER_ID )
518
        {
519
        mPtrID1 = event.getPointerId(index);
520
        float x = event.getX();
521
        float y = event.getY();
522

  
523
        if( mPtrID2 != INVALID_POINTER_ID )
524
          {
525
          int pointer = event.findPointerIndex(mPtrID2);
526

  
527
          try
528
            {
529
            float x2 = event.getX(pointer);
530
            float y2 = event.getY(pointer);
531

  
532
            mRotAngle = getAngle(x,-y,x2,-y2);
533
            mInitDistance = -1;
534
            }
535
          catch(IllegalArgumentException ex)
536
            {
537
            mPtrID1=INVALID_POINTER_ID;
538
            mPtrID2=INVALID_POINTER_ID;
539

  
540
            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
541
            crashlytics.setCustomKey("DragError", "pointer="+pointer );
542
            crashlytics.recordException(ex);
543

  
544
            return;
545
            }
546
          }
547

  
548
        mX = (x - mScreenWidth*0.5f)/mScreenMin;
549
        mY = (mScreenHeight*0.5f -y)/mScreenMin;
550
        }
551
      else if( mPtrID2==INVALID_POINTER_ID )
552
        {
553
        mPtrID2 = event.getPointerId(index);
554

  
555
        float x = event.getX();
556
        float y = event.getY();
557

  
558
        if( mPtrID2 != INVALID_POINTER_ID )
559
          {
560
          int pointer = event.findPointerIndex(mPtrID2);
561

  
562
          try
563
            {
564
            float x2 = event.getX(pointer);
565
            float y2 = event.getY(pointer);
566

  
567
            mRotAngle = getAngle(x,-y,x2,-y2);
568
            mInitDistance = -1;
569
            }
570
          catch(IllegalArgumentException ex)
571
            {
572
            mPtrID1=INVALID_POINTER_ID;
573
            mPtrID2=INVALID_POINTER_ID;
574

  
575
            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
576
            crashlytics.setCustomKey("DragError", "pointer="+pointer );
577
            crashlytics.recordException(ex);
578

  
579
            return;
580
            }
581
          }
582

  
583
        if( mBeginningRotation || mContinuingRotation )
584
          {
585
          mX = (x - mScreenWidth*0.5f)/mScreenMin;
586
          mY = (mScreenHeight*0.5f -y)/mScreenMin;
587
          }
588
        }
589

  
590
      if( mBeginningRotation )
591
        {
592
        mContinuingRotation = false;
593
        mBeginningRotation  = false;
594
        mDragging           = true;
595
        }
596
      else if( mContinuingRotation )
597
        {
598
        finishRotation();
599
        }
600
      }
601

  
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

  
604
    private void actionUp2(MotionEvent event)
605
      {
606
      int index = event.getActionIndex();
607

  
608
      if( index==event.findPointerIndex(mPtrID1) )
609
        {
610
        mPtrID1 = INVALID_POINTER_ID;
611
        int pointer = event.findPointerIndex(mPtrID2);
612

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff