Project

General

Profile

« Previous | Next » 

Revision 344f290c

Added by Leszek Koltunski about 4 years ago

Start creating the Tutorial Activity.

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
112 112
   @Override
113 113
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
114 114
      {
115
      android.util.Log.e("main", "width="+width+" height="+height);
116

  
115 117
      mScreen.resize(width,height);
116 118
      mView.setScreenSize(width,height);
117 119
      mView.getPreRender().setScreenSize(width);
......
128 130
      BaseEffect.Type.enableEffects();
129 131

  
130 132
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
131

  
132
android.util.Log.e("ren", "onSurfaceCreated");
133 133
      }
134 134

  
135 135
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/states/RubikStateAbstract.java
19 19

  
20 20
package org.distorted.states;
21 21

  
22
import android.annotation.SuppressLint;
23 22
import android.content.SharedPreferences;
24
import android.util.TypedValue;
25
import android.widget.LinearLayout;
26 23

  
27 24
import org.distorted.main.RubikActivity;
28 25
import org.distorted.objects.ObjectList;
......
32 29

  
33 30
public abstract class RubikStateAbstract
34 31
  {
35
  @SuppressLint("ViewConstructor")
36
  static class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton
37
    {
38
    public TransparentImageButton(RubikActivity act, int icon, float scrWidth, int butWidth)
39
      {
40
      super(act);
41

  
42
      final int padding = (int)(scrWidth*RubikActivity.PADDING);
43
      final int margin  = (int)(scrWidth*RubikActivity.MARGIN);
44

  
45
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
46

  
47
      params.topMargin    = margin;
48
      params.bottomMargin = margin;
49
      params.leftMargin   = margin;
50
      params.rightMargin  = margin;
51

  
52
      setLayoutParams(params);
53
      setPadding(padding,0,padding,0);
54
      setImageResource(icon);
55

  
56
      TypedValue outValue = new TypedValue();
57
      act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
58
      setBackgroundResource(outValue.resourceId);
59
      }
60
    }
61

  
62
  @SuppressLint("ViewConstructor")
63
  static class TransparentButton extends androidx.appcompat.widget.AppCompatButton
64
    {
65
    public TransparentButton(RubikActivity act, int resId, float size, float scrWidth)
66
      {
67
      super(act);
68

  
69
      final int padding = (int)(scrWidth*RubikActivity.PADDING);
70
      final int margin  = (int)(scrWidth*RubikActivity.MARGIN);
71

  
72
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
73
      params.topMargin    = margin;
74
      params.bottomMargin = margin;
75
      params.leftMargin   = margin;
76
      params.rightMargin  = margin;
77

  
78
      setLayoutParams(params);
79
      setPadding(padding,0,padding,0);
80
      setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
81
      setText(resId);
82

  
83
      TypedValue outValue = new TypedValue();
84
      act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
85
      setBackgroundResource(outValue.resourceId);
86
      }
87
    }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91 32
  int getPatternOrdinal()
92 33
    {
93 34
    RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
src/main/java/org/distorted/states/TransparentButton.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.states;
21

  
22
import android.annotation.SuppressLint;
23
import android.content.Context;
24
import android.util.TypedValue;
25
import android.widget.LinearLayout;
26

  
27
import org.distorted.main.RubikActivity;
28

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

  
31
@SuppressLint("ViewConstructor")
32
public class TransparentButton extends androidx.appcompat.widget.AppCompatButton
33
{
34
   public TransparentButton(Context context, int resId, float size, float scrWidth)
35
      {
36
      super(context);
37

  
38
      final int padding = (int)(scrWidth*RubikActivity.PADDING);
39
      final int margin  = (int)(scrWidth*RubikActivity.MARGIN);
40

  
41
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
42
      params.topMargin    = margin;
43
      params.bottomMargin = margin;
44
      params.leftMargin   = margin;
45
      params.rightMargin  = margin;
46

  
47
      setLayoutParams(params);
48
      setPadding(padding,0,padding,0);
49
      setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
50
      setText(resId);
51

  
52
      TypedValue outValue = new TypedValue();
53
      context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
54
      setBackgroundResource(outValue.resourceId);
55
      }
56
}
src/main/java/org/distorted/states/TransparentImageButton.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.states;
21

  
22
import android.annotation.SuppressLint;
23
import android.content.Context;
24
import android.util.TypedValue;
25
import android.widget.LinearLayout;
26

  
27
import org.distorted.main.RubikActivity;
28

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

  
31
@SuppressLint("ViewConstructor")
32
public class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton
33
{
34
  public TransparentImageButton(Context context, int icon, float scrWidth, int butWidth)
35
      {
36
      super(context);
37

  
38
      final int padding = (int)(scrWidth*RubikActivity.PADDING);
39
      final int margin  = (int)(scrWidth*RubikActivity.MARGIN);
40

  
41
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
42

  
43
      params.topMargin    = margin;
44
      params.bottomMargin = margin;
45
      params.leftMargin   = margin;
46
      params.rightMargin  = margin;
47

  
48
      setLayoutParams(params);
49
      setPadding(padding,0,padding,0);
50
      setImageResource(icon);
51

  
52
      TypedValue outValue = new TypedValue();
53
      context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
54
      setBackgroundResource(outValue.resourceId);
55
      }
56
}
src/main/java/org/distorted/tutorial/TutorialActivity.java
61 61
    private static int mScreenWidth, mScreenHeight;
62 62
    private int mCurrentApiVersion;
63 63
    private WebView mWebView;
64
    private TutorialState mState;
64 65

  
65 66
///////////////////////////////////////////////////////////////////////////////////////////////////
66 67

  
......
117 118
      {
118 119
      super.onAttachedToWindow();
119 120

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

  
124
      TutorialSurfaceView viewL = findViewById(R.id.tutorialSurfaceView);
125
      ViewGroup.LayoutParams paramsL = viewL.getLayoutParams();
126
      paramsL.width = (int)(width*(1.0f-RATIO));
127
      viewL.setLayoutParams(paramsL);
128

  
129
      LinearLayout viewR = findViewById(R.id.rightBar);
130
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
131
      paramsR.width = (int)(width*RATIO);
132
      viewR.setLayoutParams(paramsR);
133

  
134
      if( mState==null ) mState = new TutorialState();
135

  
136
      mState.createRightPane(this,width);
126 137
      }
127 138

  
128 139
///////////////////////////////////////////////////////////////////////////////////////////////////
......
217 228
      errDiag.show(getSupportFragmentManager(), null);
218 229
      }
219 230

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

  
233
    TutorialState getState()
234
      {
235
      return mState;
236
      }
237

  
220 238
///////////////////////////////////////////////////////////////////////////////////////////////////
221 239
// PUBLIC API
222 240
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/tutorial/TutorialRenderer.java
64 64
   @Override
65 65
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
66 66
      {
67
      android.util.Log.e("tut", "width="+width+" height="+height);
68

  
67 69
      mScreen.resize(width,height);
68 70
      mView.setScreenSize(width,height);
69 71
      mView.getPreRender().setScreenSize(width);
......
80 82
      BaseEffect.Type.enableEffects();
81 83

  
82 84
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
83

  
84
android.util.Log.e("tut", "onSurfaceCreated");
85 85
      }
86 86

  
87 87
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/tutorial/TutorialState.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.view.View;
23
import android.widget.ImageButton;
24
import android.widget.LinearLayout;
25

  
26
import org.distorted.main.R;
27
import org.distorted.main.RubikActivity;
28
import org.distorted.main.RubikPreRender;
29
import org.distorted.objects.TwistyObject;
30
import org.distorted.states.TransparentImageButton;
31

  
32
import java.util.ArrayList;
33

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

  
36
public class TutorialState implements RubikPreRender.ActionFinishedListener
37
{
38
  private static final int DURATION_MILLIS = 750;
39

  
40
  private ImageButton mPrevButton, mLockButton, mSolveButton, mScrambleButton, mBackButton;
41

  
42
  private boolean mCanPrevMove;
43

  
44
  private static class Move
45
    {
46
    private 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
  ArrayList<Move> mMoves;
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  private void backMove(TutorialPreRender pre)
61
    {
62
    if( mCanPrevMove )
63
      {
64
      int numMoves = mMoves.size();
65

  
66
      if( numMoves>0 )
67
        {
68
        Move move = mMoves.remove(numMoves-1);
69
        TwistyObject object = pre.getObject();
70

  
71
        int axis  = move.mAxis;
72
        int row   = (1<<move.mRow);
73
        int angle = move.mAngle;
74
        int numRot= Math.abs(angle*object.getBasicAngle()/360);
75

  
76
        if( angle!=0 )
77
          {
78
          mCanPrevMove = false;
79
          pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS);
80
          }
81
        else
82
          {
83
          android.util.Log.e("solution", "error: trying to back move of angle 0");
84
          }
85
        }
86
      }
87
    }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
  private void toggleLock(TutorialActivity act)
92
    {
93
    act.toggleLock();
94
    mLockButton.setImageResource(getLockIcon(act));
95
    }
96

  
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

  
99
  private int getLockIcon(TutorialActivity act)
100
    {
101
    if( act.retLocked() )
102
      {
103
      return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
104
      }
105
    else
106
      {
107
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
108
      }
109
    }
110

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

  
113
  private void setupSolveButton(final TutorialActivity act, final float width)
114
    {
115
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
116
    mSolveButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
117

  
118
    mSolveButton.setOnClickListener( new View.OnClickListener()
119
      {
120
      @Override
121
      public void onClick(View v)
122
        {
123
        act.getPreRender().solveObject();
124
        mMoves.clear();
125
        }
126
      });
127
    }
128

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

  
131
  private void setupLockButton(final TutorialActivity act, final float width)
132
    {
133
    final int icon = getLockIcon(act);
134
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
135

  
136
    mLockButton.setOnClickListener( new View.OnClickListener()
137
      {
138
      @Override
139
      public void onClick(View v)
140
        {
141
        toggleLock(act);
142
        }
143
      });
144
    }
145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

  
148
  private void setupPrevButton(final TutorialActivity act, final float width)
149
    {
150
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back);
151
    mPrevButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
152

  
153
    mPrevButton.setOnClickListener( new View.OnClickListener()
154
      {
155
      @Override
156
      public void onClick(View v)
157
        {
158
        TutorialPreRender pre = act.getPreRender();
159
        backMove(pre);
160
        }
161
      });
162
    }
163

  
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

  
166
  private void setupScrambleButton(final TutorialActivity act, final float width)
167
    {
168
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
169
    mScrambleButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
170

  
171
    mScrambleButton.setOnClickListener( new View.OnClickListener()
172
      {
173
      @Override
174
      public void onClick(View v)
175
        {
176
        TutorialPreRender pre = act.getPreRender();
177
        // TODO
178
        }
179
      });
180
    }
181

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

  
184
  private void setupBackButton(final TutorialActivity act, final float width)
185
    {
186
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);
187
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
188

  
189
    mBackButton.setOnClickListener( new View.OnClickListener()
190
      {
191
      @Override
192
      public void onClick(View v)
193
        {
194
        act.finish();
195
        }
196
      });
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  void createRightPane(final TutorialActivity act, float width)
202
    {
203
    mCanPrevMove = true;
204

  
205
    if( mMoves==null ) mMoves = new ArrayList<>();
206
    else               mMoves.clear();
207

  
208
    LinearLayout layout = act.findViewById(R.id.rightBar);
209
    layout.removeAllViews();
210

  
211
    setupPrevButton(act,width);
212
    setupLockButton(act,width);
213
    setupSolveButton(act,width);
214
    setupScrambleButton(act,width);
215
    setupBackButton(act,width);
216

  
217
    layout.addView(mSolveButton);
218
    layout.addView(mPrevButton);
219
    layout.addView(mScrambleButton);
220
    layout.addView(mLockButton);
221
    layout.addView(mBackButton);
222
    }
223

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

  
226
  public void addMove(int axis, int row, int angle)
227
    {
228
    mMoves.add(new Move(axis,row,angle));
229
    }
230

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

  
233
  public void onActionFinished(final long effectID)
234
    {
235
    mCanPrevMove = true;
236
    }
237
}
src/main/java/org/distorted/tutorial/TutorialSurfaceView.java
32 32

  
33 33
import org.distorted.library.type.Static2D;
34 34
import org.distorted.library.type.Static4D;
35
import org.distorted.main.RubikActivity;
35 36
import org.distorted.objects.Movement;
36 37
import org.distorted.objects.TwistyObject;
37 38
import org.distorted.states.RubikStateSolving;
......
371 372
      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAngle, mCurrRotSpeed);
372 373
      mPreRender.finishRotation(angle);
373 374

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

  
386 382
      mContinuingRotation = false;
387 383
      mBeginningRotation  = false;
src/main/res/layout/tutorial.xml
17 17
        android:id="@+id/lowerPart"
18 18
        android:layout_width="match_parent"
19 19
        android:layout_height="0dp"
20
        android:gravity="center"
21 20
        android:layout_weight="1"
22 21
        android:orientation="horizontal"
23 22
        android:background="@android:color/transparent">
24 23

  
25 24
        <org.distorted.tutorial.TutorialSurfaceView
26 25
           android:id="@+id/tutorialSurfaceView"
27
           android:layout_width="fill_parent"
28
           android:layout_height="fill_parent"/>
26
           android:layout_width="0dp"
27
           android:layout_height="match_parent"/>
29 28

  
30 29
        <LinearLayout
31 30
           android:id="@+id/rightBar"
32
           android:layout_width="200dp"
31
           android:layout_width="0dp"
33 32
           android:layout_height="match_parent"
33

  
34 34
           android:orientation="vertical"
35 35
           android:background="@android:color/transparent">
36

  
37

  
36 38
        </LinearLayout>
37 39
    </LinearLayout>
38 40
</LinearLayout>

Also available in: Unified diff