Project

General

Profile

« Previous | Next » 

Revision dd1a65c1

Added by Leszek Koltunski over 2 years ago

Move ObjectControl, the next big chunk of code, to objectlib.

View differences:

src/main/java/org/distorted/control/RubikControlWhole.java
281 281
    RubikSurfaceView view = mControl.getSurfaceView();
282 282
    float x = point1.get0() + mWidth*0.5f;
283 283
    float y = mHeight*0.5f - point1.get1();
284

  
285
    /*
284 286
    view.prepareDown();
285 287
    view.actionDown(x,y);
288

  
289
     */
286 290
    }
287 291

  
288 292
///////////////////////////////////////////////////////////////////////////////////////////////////
......
509 513
    float y2 = mHeight*0.5f - point2s.get1();
510 514

  
511 515
    RubikSurfaceView view = mControl.getSurfaceView();
516

  
517
    /*
512 518
    view.prepareDown();
513 519
    view.prepareDown2();
514 520
    view.actionDown(x1,y1);
515 521
    view.actionDown2(x1,y1,x2,y2);
522

  
523
     */
516 524
    }
517 525

  
518 526
///////////////////////////////////////////////////////////////////////////////////////////////////
......
920 928
                RubikSurfaceView view = mControl.getSurfaceView();
921 929
                float x1 = tmpBuffer[0]+mWidth*0.5f;
922 930
                float y1 = mHeight*0.5f-tmpBuffer[1];
923
                view.actionMove(x1,y1,0,0);
931
                //view.actionMove(x1,y1,0,0);
924 932
                }
925 933

  
926 934
              if( finished1 )
......
928 936
                if( mCurrentStage==3 )
929 937
                  {
930 938
                  RubikSurfaceView view = mControl.getSurfaceView();
931
                  view.prepareUp();
932
                  view.actionUp();
939
                  //view.prepareUp();
940
                  //view.actionUp();
933 941
                  }
934 942

  
935 943
                stageFinished(mCurrentStage);
......
947 955
                float y1 = mHeight*0.5f-tmpBuffer[1];
948 956
                float x2 = tmpBuffer[3]+mWidth*0.5f;
949 957
                float y2 = mHeight*0.5f-tmpBuffer[4];
950
                view.prepareMove(x1,y1,x2,y2);
951
                view.actionMove(x1,y1,x2,y2);
958
                //view.prepareMove(x1,y1,x2,y2);
959
                //view.actionMove(x1,y1,x2,y2);
952 960
                }
953 961

  
954 962
              if( finished2_1 && finished2_2 )
......
956 964
                 if( mCurrentStage==11 )
957 965
                  {
958 966
                  RubikSurfaceView view = mControl.getSurfaceView();
959
                  view.prepareUp();
960
                  view.actionUp2(true,0,0,false,0,0);
961
                  view.actionUp();
967
                  //view.prepareUp();
968
                  //view.actionUp2(true,0,0,false,0,0);
969
                  //view.actionUp();
962 970
                  }
963 971

  
964 972
                stageFinished(mCurrentStage);
src/main/java/org/distorted/helpers/LockController.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.helpers;
21

  
22
import java.util.Timer;
23
import java.util.TimerTask;
24

  
25
import android.view.View;
26
import android.widget.ImageButton;
27
import android.widget.LinearLayout;
28

  
29
import org.distorted.main.R;
30
import org.distorted.main.RubikActivity;
31
import org.distorted.objectlib.helpers.TwistyActivity;
32
import org.distorted.objectlib.main.ObjectPreRender;
33

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

  
36
public class LockController
37
  {
38
  private static final int LOCK_TIME = 300;
39

  
40
  private ObjectPreRender mPre;
41
  private ImageButton mLockButton;
42
  private long mLockTime;
43
  private Timer mTimer;
44
  private boolean mTimerRunning;
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
// PUBLIC API
48

  
49
  public LockController()
50
    {
51
    mTimerRunning= false;
52
    mLockTime    = 0;
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  public void toggleLock(TwistyActivity act)
58
    {
59
    act.toggleLock();
60
    mLockButton.setImageResource(getLockIcon(act,false));
61
    }
62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
  private int getLockIcon(TwistyActivity act, boolean red)
66
    {
67
    if( act.retLocked() )
68
      {
69
      if( red )
70
        {
71
        return RubikActivity.getDrawable(R.drawable.ui_small_locked_red,
72
                                         R.drawable.ui_medium_locked_red,
73
                                         R.drawable.ui_big_locked_red,
74
                                         R.drawable.ui_huge_locked_red);
75
        }
76
      else
77
        {
78
        return RubikActivity.getDrawable(R.drawable.ui_small_locked,
79
                                         R.drawable.ui_medium_locked,
80
                                         R.drawable.ui_big_locked,
81
                                         R.drawable.ui_huge_locked);
82
        }
83
      }
84
    else
85
      {
86
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,
87
                                       R.drawable.ui_medium_unlocked,
88
                                       R.drawable.ui_big_unlocked,
89
                                       R.drawable.ui_huge_unlocked);
90
      }
91
    }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
  private void changeIcon(TwistyActivity act, final boolean red)
96
    {
97
    act.runOnUiThread(new Runnable()
98
      {
99
      @Override
100
      public void run()
101
        {
102
        if( mLockButton!=null )
103
          mLockButton.setImageResource(getLockIcon(act,red));
104
        }
105
      });
106
    }
107

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  public void reddenLock(final TwistyActivity act)
111
    {
112
    mLockTime = System.currentTimeMillis();
113

  
114
    if( !mTimerRunning )
115
      {
116
      changeIcon(act,true);
117

  
118
      mTimerRunning = true;
119
      mTimer = new Timer();
120

  
121
      mTimer.scheduleAtFixedRate(new TimerTask()
122
        {
123
        @Override
124
        public void run()
125
          {
126
          act.runOnUiThread(new Runnable()
127
            {
128
            @Override
129
            public void run()
130
              {
131
              if( System.currentTimeMillis()-mLockTime > LOCK_TIME )
132
                {
133
                changeIcon(act,false);
134

  
135
                if( mTimer!=null )
136
                  {
137
                  mTimer.cancel();
138
                  mTimer = null;
139
                  }
140

  
141
                mTimerRunning = false;
142
                }
143
              }
144
            });
145
          }
146
        }, 0, LOCK_TIME);
147
      }
148
    }
149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

  
152
  public void setupButton(final TwistyActivity act, final float width)
153
    {
154
    final int icon = getLockIcon(act,false);
155
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
156

  
157
    mLockButton.setOnClickListener( new View.OnClickListener()
158
      {
159
      @Override
160
      public void onClick(View v)
161
        {
162
        toggleLock(act);
163
        }
164
      });
165
    }
166

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

  
169
  public void setState(final TwistyActivity act)
170
    {
171
    act.runOnUiThread(new Runnable()
172
      {
173
      @Override
174
      public void run()
175
        {
176
        if( mLockButton!=null )
177
          mLockButton.setImageResource(getLockIcon(act,false));
178
        }
179
      });
180
    }
181

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
  public ImageButton getButton()
185
    {
186
    return mLockButton;
187
    }
188
  }
src/main/java/org/distorted/helpers/MovesAndLockController.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.helpers;
21

  
22
import java.util.ArrayList;
23
import java.util.Timer;
24
import java.util.TimerTask;
25

  
26
import android.view.View;
27
import android.widget.ImageButton;
28
import android.widget.LinearLayout;
29

  
30
import org.distorted.main.R;
31
import org.distorted.main.RubikActivity;
32
import org.distorted.objectlib.helpers.BlockController;
33
import org.distorted.objectlib.helpers.MovesFinished;
34
import org.distorted.objectlib.helpers.TwistyActivity;
35
import org.distorted.objectlib.main.ObjectPreRender;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
public class MovesAndLockController implements MovesFinished
40
  {
41
  private static final int MILLIS_PER_DEGREE = 6;
42
  private static final int LOCK_TIME = 300;
43

  
44
  private static class Move
45
    {
46
    private final int mAxis, mRow, mAngle;
47

  
48
    Move(int axis, int row, int angle)
49
      {
50
      mAxis = axis;
51
      mRow  = row;
52
      mAngle= angle;
53
      }
54
    }
55

  
56
  private final ArrayList<Move> mMoves;
57
  private boolean mCanPrevMove;
58
  private ObjectPreRender mPre;
59
  private ImageButton mPrevButton, mLockButton;
60
  private long mLockTime;
61
  private Timer mTimer;
62
  private boolean mTimerRunning;
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
// PUBLIC API
66

  
67
  public MovesAndLockController()
68
    {
69
    mTimerRunning= false;
70
    mLockTime    = 0;
71
    mCanPrevMove = true;
72
    mMoves       = new ArrayList<>();
73
    }
74

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

  
77
  public void toggleLock(TwistyActivity act)
78
    {
79
    act.toggleLock();
80
    mLockButton.setImageResource(getLockIcon(act,false));
81
    }
82

  
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

  
85
  public int getLockIcon(TwistyActivity act, boolean red)
86
    {
87
    if( act.retLocked() )
88
      {
89
      if( red )
90
        {
91
        return RubikActivity.getDrawable(R.drawable.ui_small_locked_red,
92
                                         R.drawable.ui_medium_locked_red,
93
                                         R.drawable.ui_big_locked_red,
94
                                         R.drawable.ui_huge_locked_red);
95
        }
96
      else
97
        {
98
        return RubikActivity.getDrawable(R.drawable.ui_small_locked,
99
                                         R.drawable.ui_medium_locked,
100
                                         R.drawable.ui_big_locked,
101
                                         R.drawable.ui_huge_locked);
102
        }
103
      }
104
    else
105
      {
106
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,
107
                                       R.drawable.ui_medium_unlocked,
108
                                       R.drawable.ui_big_unlocked,
109
                                       R.drawable.ui_huge_unlocked);
110
      }
111
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

  
115
  public int getPrevIcon(boolean on)
116
    {
117
    if( on )
118
      {
119
      return RubikActivity.getDrawable(R.drawable.ui_small_cube_back,
120
                                       R.drawable.ui_medium_cube_back,
121
                                       R.drawable.ui_big_cube_back,
122
                                       R.drawable.ui_huge_cube_back);
123
      }
124
    else
125
      {
126
      return RubikActivity.getDrawable(R.drawable.ui_small_cube_grey,
127
                                       R.drawable.ui_medium_cube_grey,
128
                                       R.drawable.ui_big_cube_grey,
129
                                       R.drawable.ui_huge_cube_grey);
130
      }
131
    }
132

  
133
//////////////////////////////////////////////////////////////////////////////////////////////////
134

  
135
  public void backMove(TwistyActivity act)
136
    {
137
    if( mCanPrevMove )
138
      {
139
      int numMoves = mMoves.size();
140

  
141
      if( numMoves>0 )
142
        {
143
        Move move   = mMoves.remove(numMoves-1);
144
        int axis    = move.mAxis;
145
        int row     = (1<<move.mRow);
146
        int angle   = move.mAngle;
147
        int duration= Math.abs(angle)*MILLIS_PER_DEGREE;
148

  
149
        if( angle!=0 )
150
          {
151
          mCanPrevMove = false;
152
          mPre = act.getPreRender();
153
          mPre.blockTouch(BlockController.MOVES_PLACE_0);
154
          mPre.addRotation(this, axis, row, -angle, duration);
155
          }
156
        else
157
          {
158
          android.util.Log.e("solution", "error: trying to back move of angle 0");
159
          }
160

  
161
        if( numMoves==1 ) changeBackMove(act, false);
162
        }
163
      }
164
    }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  private void changeBackMove(TwistyActivity act, final boolean on)
169
    {
170
    act.runOnUiThread(new Runnable()
171
      {
172
      @Override
173
      public void run()
174
        {
175
        if( mPrevButton!=null )
176
          mPrevButton.setImageResource(getPrevIcon(on));
177
        }
178
      });
179
    }
180

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

  
183
  private void changeLockIcon(TwistyActivity act, final boolean red)
184
    {
185
    act.runOnUiThread(new Runnable()
186
      {
187
      @Override
188
      public void run()
189
        {
190
        if( mLockButton!=null )
191
          mLockButton.setImageResource(getLockIcon(act,red));
192
        }
193
      });
194
    }
195

  
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

  
198
  public void reddenLock(final TwistyActivity act)
199
    {
200
    mLockTime = System.currentTimeMillis();
201

  
202
    if( !mTimerRunning )
203
      {
204
      changeLockIcon(act,true);
205

  
206
      mTimerRunning = true;
207
      mTimer = new Timer();
208

  
209
      mTimer.scheduleAtFixedRate(new TimerTask()
210
        {
211
        @Override
212
        public void run()
213
          {
214
          act.runOnUiThread(new Runnable()
215
            {
216
            @Override
217
            public void run()
218
              {
219
              if( System.currentTimeMillis()-mLockTime > LOCK_TIME )
220
                {
221
                changeLockIcon(act,false);
222

  
223
                if( mTimer!=null )
224
                  {
225
                  mTimer.cancel();
226
                  mTimer = null;
227
                  }
228

  
229
                mTimerRunning = false;
230
                }
231
              }
232
            });
233
          }
234
        }, 0, LOCK_TIME);
235
      }
236
    }
237

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

  
240
  public void addMove(TwistyActivity act, int axis, int row, int angle)
241
    {
242
    if( mMoves.isEmpty() ) changeBackMove(act,true);
243
    mMoves.add(new Move(axis,row,angle));
244
    }
245

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

  
248
  public void onActionFinished(final long effectID)
249
    {
250
    mCanPrevMove = true;
251
    mPre.unblockTouch();
252
    }
253

  
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

  
256
  public void clearMoves(final TwistyActivity act)
257
    {
258
    mMoves.clear();
259
    changeBackMove(act,false);
260
    }
261

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

  
264
  public int getNumMoves()
265
    {
266
    return mMoves.size();
267
    }
268

  
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

  
271
  public void setupPrevButton(final TwistyActivity act, final float width)
272
    {
273
    final int icon = getPrevIcon( !mMoves.isEmpty() );
274
    mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
275

  
276
    mPrevButton.setOnClickListener( new View.OnClickListener()
277
      {
278
      @Override
279
      public void onClick(View v)
280
        {
281
        backMove(act);
282
        }
283
      });
284
    }
285

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

  
288
  public void setupLockButton(final TwistyActivity act, final float width)
289
    {
290
    final int icon = getLockIcon(act,false);
291
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
292

  
293
    mLockButton.setOnClickListener( new View.OnClickListener()
294
      {
295
      @Override
296
      public void onClick(View v)
297
        {
298
        toggleLock(act);
299
        }
300
      });
301
    }
302

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

  
305
  public void setLockState(final TwistyActivity act)
306
    {
307
    act.runOnUiThread(new Runnable()
308
      {
309
      @Override
310
      public void run()
311
        {
312
        if( mLockButton!=null )
313
          mLockButton.setImageResource(getLockIcon(act,false));
314
        }
315
      });
316
    }
317

  
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

  
320
  public ImageButton getPrevButton()
321
    {
322
    return mPrevButton;
323
    }
324

  
325
///////////////////////////////////////////////////////////////////////////////////////////////////
326

  
327
  public ImageButton getLockButton()
328
    {
329
    return mLockButton;
330
    }
331
  }
src/main/java/org/distorted/helpers/MovesController.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.helpers;
21

  
22
import java.util.ArrayList;
23

  
24
import android.view.View;
25
import android.widget.ImageButton;
26
import android.widget.LinearLayout;
27

  
28
import org.distorted.objectlib.helpers.BlockController;
29
import org.distorted.objectlib.helpers.MovesFinished;
30
import org.distorted.objectlib.helpers.TwistyActivity;
31
import org.distorted.objectlib.main.ObjectPreRender;
32

  
33
import org.distorted.main.R;
34
import org.distorted.main.RubikActivity;
35

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

  
38
public class MovesController implements MovesFinished
39
  {
40
  private static final int MILLIS_PER_DEGREE = 6;
41

  
42
  private static class Move
43
    {
44
    private final int mAxis, mRow, mAngle;
45

  
46
    Move(int axis, int row, int angle)
47
      {
48
      mAxis = axis;
49
      mRow  = row;
50
      mAngle= angle;
51
      }
52
    }
53

  
54
  private final ArrayList<Move> mMoves;
55
  private boolean mCanPrevMove;
56
  private ObjectPreRender mPre;
57
  private ImageButton mPrevButton;
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
// PUBLIC API
61

  
62
  public MovesController()
63
    {
64
    mCanPrevMove = true;
65
    mMoves       = new ArrayList<>();
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  private int getPrevIcon(boolean on)
71
    {
72
    if( on )
73
      {
74
      return RubikActivity.getDrawable(R.drawable.ui_small_cube_back,
75
                                       R.drawable.ui_medium_cube_back,
76
                                       R.drawable.ui_big_cube_back,
77
                                       R.drawable.ui_huge_cube_back);
78
      }
79
    else
80
      {
81
      return RubikActivity.getDrawable(R.drawable.ui_small_cube_grey,
82
                                       R.drawable.ui_medium_cube_grey,
83
                                       R.drawable.ui_big_cube_grey,
84
                                       R.drawable.ui_huge_cube_grey);
85
      }
86
    }
87

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

  
90
  public void backMove(TwistyActivity act)
91
    {
92
    if( mCanPrevMove )
93
      {
94
      int numMoves = mMoves.size();
95

  
96
      if( numMoves>0 )
97
        {
98
        Move move   = mMoves.remove(numMoves-1);
99
        int axis    = move.mAxis;
100
        int row     = (1<<move.mRow);
101
        int angle   = move.mAngle;
102
        int duration= Math.abs(angle)*MILLIS_PER_DEGREE;
103

  
104
        if( angle!=0 )
105
          {
106
          mCanPrevMove = false;
107
          mPre = act.getPreRender();
108
          mPre.blockTouch(BlockController.MOVES_PLACE_0);
109
          mPre.addRotation(this, axis, row, -angle, duration);
110
          }
111
        else
112
          {
113
          android.util.Log.e("solution", "error: trying to back move of angle 0");
114
          }
115

  
116
        if( numMoves==1 ) changeBackMove(act, false);
117
        }
118
      }
119
    }
120

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

  
123
  private void changeBackMove(TwistyActivity act, final boolean on)
124
    {
125
    act.runOnUiThread(new Runnable()
126
      {
127
      @Override
128
      public void run()
129
        {
130
        if( mPrevButton!=null )
131
          mPrevButton.setImageResource(getPrevIcon(on));
132
        }
133
      });
134
    }
135

  
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

  
138
  public void addMove(TwistyActivity act, int axis, int row, int angle)
139
    {
140
    if( mMoves.isEmpty() ) changeBackMove(act,true);
141
    mMoves.add(new Move(axis,row,angle));
142
    }
143

  
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

  
146
  public void onActionFinished(final long effectID)
147
    {
148
    mCanPrevMove = true;
149
    mPre.unblockTouch();
150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
  public void clearMoves(final TwistyActivity act)
155
    {
156
    mMoves.clear();
157
    changeBackMove(act,false);
158
    }
159

  
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

  
162
  public int getNumMoves()
163
    {
164
    return mMoves.size();
165
    }
166

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

  
169
  public void setupButton(final TwistyActivity act, final float width)
170
    {
171
    final int icon = getPrevIcon( !mMoves.isEmpty() );
172
    mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
173

  
174
    mPrevButton.setOnClickListener( new View.OnClickListener()
175
      {
176
      @Override
177
      public void onClick(View v)
178
        {
179
        backMove(act);
180
        }
181
      });
182
    }
183

  
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
  public ImageButton getButton()
187
    {
188
    return mPrevButton;
189
    }
190
  }
src/main/java/org/distorted/main/RubikObjectStateActioner.java
39 39
import org.distorted.dialogs.RubikDialogSolved;
40 40
import org.distorted.network.RubikScores;
41 41
import org.distorted.screens.RubikScreenPlay;
42
import org.distorted.screens.RubikScreenReady;
43
import org.distorted.screens.RubikScreenSolver;
42 44
import org.distorted.screens.RubikScreenSolving;
43 45
import org.distorted.screens.ScreenList;
46
import org.distorted.solvers.SolverMain;
44 47

  
45 48
///////////////////////////////////////////////////////////////////////////////////////////////////
46 49

  
......
217 220
       });
218 221
     }
219 222

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

  
225
   public void onFinishRotation(TwistyActivity act, int axis, int row, int angle)
226
     {
227
     if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
228
       {
229
       RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
230
       solv.addMove(act, axis, row, angle);
231
       }
232
     if( ScreenList.getCurrentScreen()== ScreenList.PLAY )
233
       {
234
       RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
235
       play.addMove(act, axis, row, angle);
236
       }
237
     }
238

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

  
241
   public void onBeginRotation(TwistyActivity act)
242
     {
243
     if( ScreenList.getCurrentScreen()== ScreenList.READ )
244
       {
245
       RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
246
       solving.resetElapsed();
247
       RubikActivity ract = (RubikActivity)act;
248

  
249
       ract.runOnUiThread(new Runnable()
250
         {
251
         @Override
252
         public void run()
253
           {
254
           ScreenList.switchScreen( ract, ScreenList.SOLV);
255
           }
256
         });
257
       }
258
     }
259

  
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

  
262
    public void failedToDrag(TwistyActivity act)
263
      {
264
      ScreenList curr = ScreenList.getCurrentScreen();
265

  
266
      if( curr==ScreenList.PLAY )
267
        {
268
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
269
        play.reddenLock(act);
270
        }
271
      else if( curr==ScreenList.READ )
272
        {
273
        RubikScreenReady read = (RubikScreenReady) ScreenList.READ.getScreenClass();
274
        read.reddenLock(act);
275
        }
276
      else if( curr==ScreenList.SOLV )
277
        {
278
        RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
279
        solv.reddenLock(act);
280
        }
281
      }
282

  
220 283
///////////////////////////////////////////////////////////////////////////////////////////////////
221 284

  
222 285
   public void onSolved()
......
237 300
          }
238 301
        }
239 302
     }
303

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

  
306
   public int getCurrentColor()
307
     {
308
     RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
309
     return solver.getCurrentColor();
310
     }
311

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

  
314
   public int cubitIsLocked(ObjectType type, int cubit)
315
     {
316
     return SolverMain.cubitIsLocked(type,cubit);
317
     }
240 318
}
src/main/java/org/distorted/main/RubikSurfaceView.java
25 25
import android.opengl.GLES30;
26 26
import android.opengl.GLSurfaceView;
27 27
import android.util.AttributeSet;
28
import android.util.DisplayMetrics;
29 28
import android.view.MotionEvent;
30 29

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

  
33 32
import org.distorted.library.main.DistortedScreen;
34
import org.distorted.library.type.Static2D;
35 33
import org.distorted.library.type.Static4D;
36
import org.distorted.library.main.QuatHelper;
37 34

  
38 35
import org.distorted.objectlib.helpers.ObjectSurfaceView;
39 36
import org.distorted.objectlib.helpers.TwistyActivity;
37
import org.distorted.objectlib.main.ObjectControl;
40 38
import org.distorted.objectlib.main.ObjectPreRender;
41
import org.distorted.objectlib.main.TwistyObject;
42 39
import org.distorted.objectlib.main.Movement;
43 40

  
44
import org.distorted.screens.RubikScreenReady;
45 41
import org.distorted.screens.ScreenList;
46
import org.distorted.screens.RubikScreenPlay;
47
import org.distorted.screens.RubikScreenSolver;
48
import org.distorted.screens.RubikScreenSolving;
49
import org.distorted.solvers.SolverMain;
50 42

  
51 43
///////////////////////////////////////////////////////////////////////////////////////////////////
52 44

  
53 45
public class RubikSurfaceView extends GLSurfaceView implements ObjectSurfaceView
54 46
{
55
    public static final int NUM_SPEED_PROBES = 10;
56
    public static final int INVALID_POINTER_ID = -1;
57

  
58
    public static final int MODE_ROTATE  = 0;
59
    public static final int MODE_DRAG    = 1;
60
    public static final int MODE_REPLACE = 2;
61

  
62
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
63
    // given face by SWIPING_SENSITIVITY/2 degrees.
64
    public final static int SWIPING_SENSITIVITY  = 240;
65
    // Moving the finger by 0.3 of an inch will start a Rotation.
66
    public final static float ROTATION_SENSITIVITY = 0.3f;
67

  
68
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
69

  
47
    private ObjectControl mObjectController;
70 48
    private RubikRenderer mRenderer;
71
    private ObjectPreRender mPreRender;
72
    private Movement mMovement;
73
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
74
    private int mScreenWidth, mScreenHeight, mScreenMin;
75

  
76
    private float mRotAngle, mInitDistance;
77
    private float mStartRotX, mStartRotY;
78
    private float mAxisX, mAxisY;
79
    private float mRotationFactor;
80
    private int mLastCubitColor, mLastCubitFace, mLastCubit;
81
    private int mCurrentAxis, mCurrentRow;
82
    private float mCurrentAngle, mCurrRotSpeed;
83
    private float[] mLastX;
84
    private float[] mLastY;
85
    private long[] mLastT;
86
    private int mFirstIndex, mLastIndex;
87
    private int mDensity;
88

  
89
    private int mPointer1, mPointer2;
90
    private float mX1, mY1, mX2, mY2, mX, mY;
91
    private boolean mIsAutomatic;
92

  
93
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
94
    private static final Static4D mTemp= new Static4D(0,0,0,1);
49
    private int mScreenWidth, mScreenHeight;
95 50

  
96 51
///////////////////////////////////////////////////////////////////////////////////////////////////
97 52

  
......
99 54
      {
100 55
      mScreenWidth = width;
101 56
      mScreenHeight= height;
102

  
103
      mScreenMin = Math.min(width, height);
57
      mObjectController.setScreenSize(width,height);
104 58
      }
105 59

  
106 60
///////////////////////////////////////////////////////////////////////////////////////////////////
......
121 75

  
122 76
    ObjectPreRender getPreRender()
123 77
      {
124
      return mPreRender;
125
      }
126

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

  
131
    private void computeCurrentAxis(Static4D axis)
132
      {
133
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
134

  
135
      mAxisX =result.get0();
136
      mAxisY =result.get1();
137

  
138
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
139
      mAxisX /= len;
140
      mAxisY /= len;
141
      }
142

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

  
145
    private void addSpeedProbe(float x, float y)
146
      {
147
      long currTime = System.currentTimeMillis();
148
      boolean theSame = mLastIndex==mFirstIndex;
149

  
150
      mLastIndex++;
151
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
152

  
153
      mLastT[mLastIndex] = currTime;
154
      mLastX[mLastIndex] = x;
155
      mLastY[mLastIndex] = y;
156

  
157
      if( mLastIndex==mFirstIndex)
158
        {
159
        mFirstIndex++;
160
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
161
        }
162

  
163
      if( theSame )
164
        {
165
        mLastT[mFirstIndex] = currTime;
166
        mLastX[mFirstIndex] = x;
167
        mLastY[mFirstIndex] = y;
168
        }
169
      }
170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
    private void computeCurrentSpeedInInchesPerSecond()
174
      {
175
      long firstTime = mLastT[mFirstIndex];
176
      long lastTime  = mLastT[mLastIndex];
177
      float fX = mLastX[mFirstIndex];
178
      float fY = mLastY[mFirstIndex];
179
      float lX = mLastX[mLastIndex];
180
      float lY = mLastY[mLastIndex];
181

  
182
      long timeDiff = lastTime-firstTime;
183

  
184
      mLastIndex = 0;
185
      mFirstIndex= 0;
186

  
187
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
188
      }
189

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

  
192
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
193
      {
194
      float xDist = mScreenWidth*(xFrom-xTo);
195
      float yDist = mScreenHeight*(yFrom-yTo);
196
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
197

  
198
      return distInPixels/mDensity;
199
      }
200

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

  
203
    private void setUpDragOrRotate(boolean down, float x, float y)
204
      {
205
      int mode = ScreenList.getMode();
206

  
207
      if( mode==MODE_DRAG )
208
        {
209
        mDragging           = true;
210
        mBeginningRotation  = false;
211
        mContinuingRotation = false;
212
        }
213
      else
214
        {
215
        TwistyObject object = mPreRender.getObject();
216
        CAMERA_POINT.set2( object==null ? 1.21f : object.getCameraDist() );
217

  
218
        Static4D touchPoint = new Static4D(x, y, 0, 0);
219
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
220
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
221

  
222
        if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
223
          {
224
          mDragging           = false;
225
          mContinuingRotation = false;
226

  
227
          if( mode==MODE_ROTATE )
228
            {
229
            mBeginningRotation= !mPreRender.isTouchBlocked();
230
            }
231
          else if( mode==MODE_REPLACE )
232
            {
233
            mBeginningRotation= false;
234

  
235
            if( down )
236
              {
237
              RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
238
              mLastCubitFace = mMovement.getTouchedFace();
239
              float[] point = mMovement.getTouchedPoint3D();
240
              int color = solver.getCurrentColor();
241
              mLastCubit = object.getCubit(point);
242
              mPreRender.setTextureMap( mLastCubit, mLastCubitFace, color );
243
              mLastCubitColor = SolverMain.cubitIsLocked(object.getObjectType(), mLastCubit);
244
              }
245
            }
246
          }
247
        else
248
          {
249
          final RubikActivity act = (RubikActivity)getContext();
250
          final boolean locked= act.isLocked();
251
          mDragging           = (!locked || mIsAutomatic);
252
          mBeginningRotation  = false;
253
          mContinuingRotation = false;
254
          if( !mDragging ) reddenLockIcon(act);
255
          }
256
        }
257
      }
258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

  
261
    private void reddenLockIcon(RubikActivity act)
262
      {
263
      ScreenList curr = ScreenList.getCurrentScreen();
264

  
265
      if( curr==ScreenList.PLAY )
266
        {
267
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
268
        play.reddenLock(act);
269
        }
270
      else if( curr==ScreenList.READ )
271
        {
272
        RubikScreenReady read = (RubikScreenReady) ScreenList.READ.getScreenClass();
273
        read.reddenLock(act);
274
        }
275
      else if( curr==ScreenList.SOLV )
276
        {
277
        RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
278
        solv.reddenLock(act);
279
        }
280
      }
281

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

  
284
    private void drag(float x, float y)
285
      {
286
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
287
        {
288
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
289
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
290

  
291
        float angleNow = getAngle(x,y,x2,y2);
292
        float angleDiff = angleNow-mRotAngle;
293
        float sinA =-(float)Math.sin(angleDiff);
294
        float cosA = (float)Math.cos(angleDiff);
295

  
296
        Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
297
        mTemp.set(dragQuat);
298

  
299
        mRotAngle = angleNow;
300

  
301
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
302
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
303
        mInitDistance = distNow;
304
        TwistyObject object = mPreRender.getObject();
305
        if( object!=null ) object.setObjectRatio(distQuot);
306
        }
307
      else
308
        {
309
        Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
310
        mTemp.set(dragQuat);
311
        }
312

  
313
      mPreRender.setQuatOnNextRender();
314
      mX = x;
315
      mY = y;
316
      }
317

  
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319

  
320
    private void finishRotation()
321
      {
322
      computeCurrentSpeedInInchesPerSecond();
323
      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
324
      mPreRender.finishRotation(angle);
325
      mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
326

  
327
      if( angle!=0 )
328
        {
329
        if( ScreenList.getCurrentScreen()== ScreenList.SOLV )
330
          {
331
          RubikActivity act = (RubikActivity)getContext();
332
          RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
333
          solving.addMove(act, mCurrentAxis, mCurrentRow, angle);
334
          }
335
        if( ScreenList.getCurrentScreen()== ScreenList.PLAY )
336
          {
337
          RubikActivity act = (RubikActivity)getContext();
338
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
339
          play.addMove(act, mCurrentAxis, mCurrentRow, angle);
340
          }
341
        }
342

  
343
      mContinuingRotation = false;
344
      mBeginningRotation  = false;
345
      mDragging           = true;
346
      }
347

  
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

  
350
    private void continueRotation(float x, float y)
351
      {
352
      float dx = x-mStartRotX;
353
      float dy = y-mStartRotY;
354
      float alpha = dx*mAxisX + dy*mAxisY;
355
      float x2 = dx - alpha*mAxisX;
356
      float y2 = dy - alpha*mAxisY;
357

  
358
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
359

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

  
363
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
364
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
365
      mPreRender.getObject().continueRotation(mCurrentAngle);
366

  
367
      addSpeedProbe(x2,y2);
368
      }
369

  
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

  
372
    private void beginRotation(float x, float y)
373
      {
374
      mStartRotX = x;
375
      mStartRotY = y;
376

  
377
      TwistyObject object = mPreRender.getObject();
378
      int numLayers = object.getNumLayers();
379

  
380
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
381
      Static4D rotatedTouchPoint2= QuatHelper.rotateVectorByInvertedQuat(touchPoint2, mQuat);
382
      Static2D res = mMovement.newRotation(rotatedTouchPoint2,object.getObjectRatio());
383

  
384
      mCurrentAxis = (int)res.get0();
385
      mCurrentRow  = (int)res.get1();
386

  
387
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
388
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
389

  
390
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
391

  
392
      if( ScreenList.getCurrentScreen()== ScreenList.READ )
393
        {
394
        RubikScreenSolving solving = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
395
        solving.resetElapsed();
396

  
397
        final RubikActivity act = (RubikActivity)getContext();
398

  
399
        act.runOnUiThread(new Runnable()
400
          {
401
          @Override
402
          public void run()
403
            {
404
            ScreenList.switchScreen( act, ScreenList.SOLV);
405
            }
406
          });
407
        }
408

  
409
      addSpeedProbe(x,y);
410

  
411
      mBeginningRotation = false;
412
      mContinuingRotation= true;
413
      }
414

  
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416

  
417
    private float getAngle(float x1, float y1, float x2, float y2)
418
      {
419
      return (float) Math.atan2(y1-y2, x1-x2);
420
      }
421

  
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

  
424
    void initialize()
425
      {
426
      mPointer1 = INVALID_POINTER_ID;
427
      mPointer2 = INVALID_POINTER_ID;
428
      }
429

  
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

  
432
    private void prepareDown(MotionEvent event)
433
      {
434
      mPointer1 = event.getPointerId(0);
435
      mX1 = event.getX();
436
      mY1 = event.getY();
437
      mPointer2 = INVALID_POINTER_ID;
438
      }
439

  
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441

  
442
    private void prepareMove(MotionEvent event)
443
      {
444
      int index1 = event.findPointerIndex(mPointer1);
445

  
446
      if( index1>=0 )
447
        {
448
        mX1 = event.getX(index1);
449
        mY1 = event.getY(index1);
450
        }
451

  
452
      int index2 = event.findPointerIndex(mPointer2);
453

  
454
      if( index2>=0 )
455
        {
456
        mX2 = event.getX(index2);
457
        mY2 = event.getY(index2);
458
        }
459
      }
460

  
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

  
463
    private void prepareUp(MotionEvent event)
464
      {
465
      mPointer1 = INVALID_POINTER_ID;
466
      mPointer2 = INVALID_POINTER_ID;
467
      }
468

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

  
471
    private void prepareDown2(MotionEvent event)
472
      {
473
      int index = event.getActionIndex();
474

  
475
      if( mPointer1==INVALID_POINTER_ID )
476
        {
477
        mPointer1 = event.getPointerId(index);
478
        mX1 = event.getX(index);
479
        mY1 = event.getY(index);
480
        }
481
      else if( mPointer2==INVALID_POINTER_ID )
482
        {
483
        mPointer2 = event.getPointerId(index);
484
        mX2 = event.getX(index);
485
        mY2 = event.getY(index);
486
        }
487
      }
488

  
489
///////////////////////////////////////////////////////////////////////////////////////////////////
490

  
491
    private void prepareUp2(MotionEvent event)
492
      {
493
      int index = event.getActionIndex();
494

  
495
           if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
496
      else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
78
      return mObjectController.getPreRender();
497 79
      }
498 80

  
499 81
///////////////////////////////////////////////////////////////////////////////////////////////////
......
506 88

  
507 89
      if(!isInEditMode())
508 90
        {
509
        mIsAutomatic = false;
510

  
511
        mLastCubitColor = -1;
512
        mCurrRotSpeed   = 0.0f;
513

  
514
        mLastX = new float[NUM_SPEED_PROBES];
515
        mLastY = new float[NUM_SPEED_PROBES];
516
        mLastT = new long[NUM_SPEED_PROBES];
517
        mFirstIndex =0;
518
        mLastIndex  =0;
519

  
520
        mRenderer  = new RubikRenderer(this);
521
        mPreRender = new ObjectPreRender(this,new RubikObjectStateActioner());
522

  
523 91
        RubikActivity act = (RubikActivity)context;
524
        DisplayMetrics dm = new DisplayMetrics();
525
        act.getWindowManager().getDefaultDisplay().getMetrics(dm);
526

  
527
        mDensity = dm.densityDpi;
92
        mRenderer = new RubikRenderer(this);
93
        mObjectController = new ObjectControl(act,this,new RubikObjectStateActioner());
528 94

  
529 95
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
530 96

  
......
556 122

  
557 123
///////////////////////////////////////////////////////////////////////////////////////////////////
558 124

  
559
    public void setQuat()
125
    public void setMovement(Movement movement)
560 126
      {
561
      mQuat.set(mTemp);
127
      mObjectController.setMovement(movement);
562 128
      }
563 129

  
564 130
///////////////////////////////////////////////////////////////////////////////////////////////////
565 131

  
566
    public Static4D getQuat()
132
    public void setQuat()
567 133
      {
568
      return mQuat;
134
      mObjectController.setQuat();
569 135
      }
570 136

  
571 137
///////////////////////////////////////////////////////////////////////////////////////////////////
572 138

  
573
    public void setMovement(Movement movement)
139
    public Static4D getQuat()
574 140
      {
575
      mMovement = movement;
141
      return mObjectController.getQuat();
576 142
      }
577 143

  
578 144
///////////////////////////////////////////////////////////////////////////////////////////////////
......
591 157

  
592 158
///////////////////////////////////////////////////////////////////////////////////////////////////
593 159

  
594
    public void prepareDown()
160
    public void initialize()
595 161
      {
596
      mIsAutomatic = true;
597
      mPointer1 = 0;
598
      mPointer2 = INVALID_POINTER_ID;
599
      }
600

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

  
603
    public void prepareDown2()
604
      {
605
      mPointer2 = 0;
606
      }
607

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

  
610
    public void prepareMove(float x1, float y1, float x2, float y2)
611
      {
612
      mX1 = x1;
613
      mY1 = y1;
614
      mX2 = x2;
615
      mY2 = y2;
616
      }
617

  
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

  
620
    public void prepareUp()
621
      {
622
      mIsAutomatic = false;
623
      mPointer1 = INVALID_POINTER_ID;
624
      mPointer2 = INVALID_POINTER_ID;
625
      }
626

  
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628

  
629
    public void actionMove(float x1, float y1, float x2, float y2)
630
      {
631
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
632
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
633

  
634
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
635
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
636

  
637
      if( mBeginningRotation )
638
        {
639
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
640
          {
641
          beginRotation(x,y);
642
          }
643
        }
644
      else if( mContinuingRotation )
645
        {
646
        continueRotation(x,y);
647
        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff