Project

General

Profile

« Previous | Next » 

Revision f548942f

Added by Leszek Koltunski over 5 years ago

Progress with scrambling and solving cube.

View differences:

src/main/java/org/distorted/component/HorizontalNumberPicker.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.component;
21

  
22
import android.content.Context;
23
import android.support.annotation.Nullable;
24
import android.util.AttributeSet;
25
import android.view.View;
26
import android.widget.Button;
27
import android.widget.LinearLayout;
28
import android.widget.TextView;
29

  
30
import org.distorted.magic.R;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class HorizontalNumberPicker extends LinearLayout
35
{
36
  private TextView mNumber;
37
  private int mMin, mMax;
38

  
39
  public HorizontalNumberPicker(Context context, @Nullable AttributeSet attrs)
40
    {
41
    super(context, attrs);
42

  
43
    mMin = 0;
44
    mMax = 5;
45

  
46
    inflate(context, R.layout.numberpicker, this);
47

  
48
    mNumber = findViewById(R.id.textNumber);
49

  
50
    final Button btn_less = findViewById(R.id.buttonLess);
51
    btn_less.setOnClickListener(new AddHandler(-1));
52

  
53
    final Button btn_more = findViewById(R.id.buttonMore);
54
    btn_more.setOnClickListener(new AddHandler( 1));
55
    }
56

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

  
59
  private class AddHandler implements OnClickListener
60
    {
61
    final int diff;
62

  
63
    AddHandler(int diff)
64
      {
65
      this.diff = diff;
66
      }
67

  
68
    @Override
69
    public void onClick(View v)
70
      {
71
      int newValue = getValue() + diff;
72

  
73
      if (newValue < mMin)
74
        {
75
        newValue = mMin;
76
        }
77
      else if (newValue > mMax)
78
        {
79
        newValue = mMax;
80
        }
81
      setValue(newValue);
82
      }
83
    }
84

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

  
87
  public int getValue()
88
    {
89
    if(mNumber != null)
90
      {
91
      try
92
        {
93
        final String value = mNumber.getText().toString();
94
        return Integer.parseInt(value);
95
        }
96
      catch(NumberFormatException ex)
97
        {
98
        android.util.Log.e("HorizontalNumberPicker", ex.toString());
99
        }
100
      }
101
    return 0;
102
    }
103

  
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

  
106
  public void setValue(final int value)
107
    {
108
    if (mNumber != null)
109
      {
110
      mNumber.setText(String.valueOf(value));
111
      }
112
    }
113

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

  
116
  public int getMin()
117
    {
118
    return mMin;
119
    }
120

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

  
123
  public void setMin(int min)
124
    {
125
    mMin = min;
126
    }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
  public int getMax()
131
    {
132
    return mMax;
133
    }
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

  
137
  public void setMax(int max)
138
    {
139
    mMax = max;
140
    }
141
}
src/main/java/org/distorted/effect/AppearEffect.java
33 33
  {
34 34
  public enum Type
35 35
    {
36
    EMPTY         (AppearEffectEmpty.class       ),
36
    NONE          (AppearEffectNone.class        ),
37 37
    TRANSPARENCY  (AppearEffectTransparency.class),
38 38
    MOVE          (AppearEffectMove.class        ),
39 39
    ROUND         (AppearEffectRound.class       ),
src/main/java/org/distorted/effect/AppearEffectEmpty.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class AppearEffectEmpty extends AppearEffect
30
  {
31
  public int createEffects(int duration)
32
    {
33
    mCubeEffectPosition = new int[] {-1};
34
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
35

  
36
    Dynamic3D oldCube0 = new Dynamic3D(1,0.5f);
37
    oldCube0.add(new Static3D(0,0,0));
38
    mCubeEffects[0] = new MatrixEffectMove(oldCube0);
39

  
40
    return 1;
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
// enable all effects used in this Appear (here: none).  Called by reflection from the parent class.
45

  
46
  @SuppressWarnings("unused")
47
  static void enable()
48
    {
49

  
50
    }
51
  }
src/main/java/org/distorted/effect/AppearEffectNone.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class AppearEffectNone extends AppearEffect
30
  {
31
  public int createEffects(int duration)
32
    {
33
    mCubeEffectPosition = new int[] {-1};
34
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
35

  
36
    Dynamic3D oldCube0 = new Dynamic3D(1,0.5f);
37
    oldCube0.add(new Static3D(0,0,0));
38
    mCubeEffects[0] = new MatrixEffectMove(oldCube0);
39

  
40
    return 1;
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
// enable all effects used in this Appear (here: none).  Called by reflection from the parent class.
45

  
46
  @SuppressWarnings("unused")
47
  static void enable()
48
    {
49

  
50
    }
51
  }
src/main/java/org/distorted/effect/DisappearEffect.java
33 33
  {
34 34
  public enum Type
35 35
    {
36
    EMPTY         (DisappearEffectEmpty.class       ),
36
    NONE          (DisappearEffectNone.class       ),
37 37
    TRANSPARENCY  (DisappearEffectTransparency.class),
38 38
    MOVE          (DisappearEffectMove.class        ),
39 39
    ROUND         (DisappearEffectRound.class       ),
src/main/java/org/distorted/effect/DisappearEffectEmpty.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class DisappearEffectEmpty extends DisappearEffect
30
  {
31
  public int createEffects(int duration)
32
    {
33
    mCubeEffectPosition = new int[] {-1};
34
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
35

  
36
    Dynamic3D oldCube0 = new Dynamic3D(1,0.5f);
37
    oldCube0.add(new Static3D(0,0,0));
38
    mCubeEffects[0] = new MatrixEffectMove(oldCube0);
39

  
40
    return 1;
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
// enable all effects used in this Appear (here: none).  Called by reflection from the parent class.
45

  
46
  @SuppressWarnings("unused")
47
  static void enable()
48
    {
49

  
50
    }
51
  }
src/main/java/org/distorted/effect/DisappearEffectNone.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class DisappearEffectNone extends DisappearEffect
30
  {
31
  public int createEffects(int duration)
32
    {
33
    mCubeEffectPosition = new int[] {-1};
34
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
35

  
36
    Dynamic3D oldCube0 = new Dynamic3D(1,0.5f);
37
    oldCube0.add(new Static3D(0,0,0));
38
    mCubeEffects[0] = new MatrixEffectMove(oldCube0);
39

  
40
    return 1;
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
// enable all effects used in this Appear (here: none).  Called by reflection from the parent class.
45

  
46
  @SuppressWarnings("unused")
47
  static void enable()
48
    {
49

  
50
    }
51
  }
src/main/java/org/distorted/magic/RubikActivity.java
29 29
import android.support.v7.app.AppCompatActivity;
30 30
import android.view.View;
31 31

  
32
import org.distorted.component.HorizontalNumberPicker;
32 33
import org.distorted.effect.AppearEffect;
33 34
import org.distorted.effect.DisappearEffect;
34 35
import org.distorted.library.main.DistortedLibrary;
......
46 47
    public static final int DEFAULT_APPEAR_TYPE    = 1;
47 48
    public static final int DEFAULT_DISAPPEAR_TYPE = 1;
48 49

  
50
    public static final int MIN_SCRAMBLE =  1;
51
    public static final int MAX_SCRAMBLE = 10;
52

  
49 53
    private static int mSize = DEFAULT_SIZE;
50 54

  
51 55
    private int mAppearPos, mDisappearPos;
52 56
    private int mAppearType, mDisappearType;
53 57

  
58
    private HorizontalNumberPicker mPicker;
59

  
54 60
///////////////////////////////////////////////////////////////////////////////////////////////////
55 61

  
56 62
    @Override
......
61 67
      setContentView(R.layout.main);
62 68
      markButton(mSize);
63 69

  
70
      mPicker = findViewById(R.id.rubikNumberPicker);
71
      mPicker.setMin(MIN_SCRAMBLE);
72
      mPicker.setMax(MAX_SCRAMBLE);
73

  
64 74
      restorePreferences();
65 75
      applyPreferences();
66 76
      }
......
131 141

  
132 142
    public void Scramble(View v)
133 143
      {
144
      int scramble = mPicker.getValue();
145

  
134 146
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
135
      view.getRenderer().scrambleCube();
147
      view.getRenderer().scrambleCube(scramble);
136 148
      }
137 149

  
138 150
///////////////////////////////////////////////////////////////////////////////////////////////////
139 151

  
140 152
    public void Solve(View v)
141 153
      {
142

  
154
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
155
      view.getRenderer().solveCube();
143 156
      }
144 157

  
145 158
///////////////////////////////////////////////////////////////////////////////////////////////////
......
208 221
     editor.putInt("disappearPos" , mDisappearPos );
209 222
     editor.putInt("appearType"   , mAppearType   );
210 223
     editor.putInt("disappearType", mDisappearType);
224
     editor.putInt("scramble"     , mPicker.getValue() );
211 225

  
212 226
     editor.apply();
213 227
     }
......
222 236
     mDisappearPos  = preferences.getInt("disappearPos" , DEFAULT_DISAPPEAR_POS );
223 237
     mAppearType    = preferences.getInt("appearType"   , DEFAULT_APPEAR_TYPE   );
224 238
     mDisappearType = preferences.getInt("disappearType", DEFAULT_DISAPPEAR_TYPE);
239
     int scramble   = preferences.getInt("scramble"     , MIN_SCRAMBLE          );
240

  
241
     mPicker.setValue(scramble);
225 242
     }
226 243

  
227 244
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikRenderer.java
326 326

  
327 327
///////////////////////////////////////////////////////////////////////////////////////////////////
328 328

  
329
   void scrambleCube()
329
   void scrambleCube(int num)
330 330
     {
331
     android.util.Log.e("renderer","scrambling "+num+" times");
332
     }
333

  
334
///////////////////////////////////////////////////////////////////////////////////////////////////
331 335

  
336
   void solveCube()
337
     {
338
     android.util.Log.e("renderer","solving cube");
332 339
     }
333 340

  
334 341
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/layout/main.xml
5 5
    android:orientation="vertical" >
6 6

  
7 7
    <LinearLayout
8
        android:id="@+id/linearLayout"
9 8
        android:layout_width="fill_parent"
10 9
        android:layout_height="wrap_content"
11 10
        android:gravity="center|fill_horizontal" >
......
23 22
        <ImageButton
24 23
            android:id="@+id/rubikSize2"
25 24
            android:layout_width="64dp"
26
            android:layout_height="wrap_content"
25
            android:layout_height="64dp"
27 26
            android:onClick="setSize"
28 27
            android:paddingLeft="5dp"
29 28
            android:paddingRight="5dp"
......
32 31
        <ImageButton
33 32
            android:id="@+id/rubikSize3"
34 33
            android:layout_width="64dp"
35
            android:layout_height="wrap_content"
34
            android:layout_height="64dp"
36 35
            android:onClick="setSize"
37 36
            android:paddingLeft="5dp"
38 37
            android:paddingRight="5dp"
......
41 40
        <ImageButton
42 41
            android:id="@+id/rubikSize4"
43 42
            android:layout_width="64dp"
44
            android:layout_height="wrap_content"
43
            android:layout_height="64dp"
45 44
            android:onClick="setSize"
46 45
            android:paddingLeft="5dp"
47 46
            android:paddingRight="5dp"
......
59 58

  
60 59
    </LinearLayout>
61 60

  
61
    <LinearLayout
62
        android:layout_width="fill_parent"
63
        android:layout_height="64dp"
64
        android:gravity="center|fill_horizontal" >
65

  
66
        <Button
67
            android:id="@+id/rubikScramble"
68
            android:layout_width="wrap_content"
69
            android:layout_height="fill_parent"
70
            android:layout_weight="0.5"
71
            android:onClick="Scramble"
72
            android:paddingLeft="5dp"
73
            android:paddingRight="5dp"
74
            android:text="@string/scramble" />
75

  
76
        <org.distorted.component.HorizontalNumberPicker
77
            android:id="@+id/rubikNumberPicker"
78
            android:layout_width="192dp"
79
            android:layout_height="fill_parent"/>
80

  
81
        <Button
82
            android:id="@+id/rubikSolve"
83
            android:layout_width="wrap_content"
84
            android:layout_height="fill_parent"
85
            android:layout_weight="0.5"
86
            android:onClick="Solve"
87
            android:paddingLeft="5dp"
88
            android:paddingRight="5dp"
89
            android:text="@string/solve" />
90

  
91
    </LinearLayout>
92

  
62 93
    <org.distorted.magic.RubikSurfaceView
63 94
        android:id="@+id/rubikSurfaceView"
64 95
        android:layout_width="fill_parent"
src/main/res/layout/numberpicker.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:orientation="horizontal">
6

  
7
    <Button
8
        android:id="@+id/buttonLess"
9
        android:layout_width="0sp"
10
        android:layout_height="match_parent"
11
        android:layout_weight="1"
12
        android:text="-" />
13

  
14
    <TextView
15
        android:id="@+id/textNumber"
16
        android:layout_width="0sp"
17
        android:layout_height="match_parent"
18
        android:layout_weight="1"
19
        android:inputType="number"
20
        android:text="0"
21
        android:textAlignment="center"
22
        android:textSize="48sp" />
23

  
24
    <Button
25
        android:id="@+id/buttonMore"
26
        android:layout_width="0sp"
27
        android:layout_height="match_parent"
28
        android:layout_weight="1"
29
        android:text="+" />
30
</LinearLayout>

Also available in: Unified diff