Project

General

Profile

« Previous | Next » 

Revision 1cbcc6bf

Added by Leszek Koltunski over 5 years ago

Progress with Credits and Settings.

View differences:

src/main/java/org/distorted/magic/RubikActivity.java
41 41
    private static final int SMALLEST_SIZE = 2;
42 42
    private static final int[] button_ids  = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
43 43

  
44
    private static final int DEFAULT_APPEAR_POS     = 10;
45
    private static final int DEFAULT_DISAPPEAR_POS  = 10;
46
    private static final int DEFAULT_APPEAR_TYPE    = 1;
47
    private static final int DEFAULT_DISAPPEAR_TYPE = 1;
44
    public static final int DEFAULT_APPEAR_POS     = 10;
45
    public static final int DEFAULT_DISAPPEAR_POS  = 10;
46
    public static final int DEFAULT_APPEAR_TYPE    = 1;
47
    public static final int DEFAULT_DISAPPEAR_TYPE = 1;
48 48

  
49 49
    private static int mSize = DEFAULT_SIZE;
50 50

  
......
58 58
      {
59 59
      super.onCreate(savedState);
60 60
      setTheme(R.style.CustomActivityThemeNoActionBar);
61
      setContentView(R.layout.layout);
61
      setContentView(R.layout.main);
62 62
      markButton(mSize);
63 63

  
64 64
      restorePreferences();
......
103 103
      return mSize;
104 104
      }
105 105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
    public void Scramble(View v)
109
      {
110
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
111
      view.getRenderer().scrambleCube();
112
      }
113

  
114 106
///////////////////////////////////////////////////////////////////////////////////////////////////
115 107

  
116 108
    public void Settings(View v)
......
127 119
      settings.show(getSupportFragmentManager(), null);
128 120
      }
129 121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
    public void Credits(View v)
125
      {
126
      RubikCredits credits = new RubikCredits();
127
      credits.show(getSupportFragmentManager(), null);
128
      }
129

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

  
132
    public void Scramble(View v)
133
      {
134
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
135
      view.getRenderer().scrambleCube();
136
      }
137

  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

  
140
    public void Solve(View v)
141
      {
142

  
143
      }
144

  
130 145
///////////////////////////////////////////////////////////////////////////////////////////////////
131 146

  
132 147
    public void onComplete(int aP, int dP, int aT, int dT)
......
216 231
     RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
217 232
     RubikRenderer renderer = view.getRenderer();
218 233

  
219
     renderer.setAppearDuration(mAppearPos*100 +1);
220
     renderer.setDisappearDuration(mDisappearPos*100 +1);
234
     renderer.setAppearDuration(translateDuration(mAppearPos)+1);
235
     renderer.setDisappearDuration(translateDuration(mDisappearPos) +1);
221 236
     renderer.setAppearType(AppearEffect.getType(mAppearType));
222 237
     renderer.setDisappearType(DisappearEffect.getType(mDisappearType));
223 238
     }
239

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

  
242
   public static int translateDuration(int pos)
243
     {
244
     return (pos/2)*100;
245
     }
224 246
}
src/main/java/org/distorted/magic/RubikCredits.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.magic;
21

  
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.support.annotation.NonNull;
26
import android.support.v4.app.FragmentActivity;
27
import android.support.v7.app.AlertDialog;
28
import android.support.v7.app.AppCompatDialogFragment;
29
import android.view.LayoutInflater;
30
import android.view.View;
31

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

  
34
public class RubikCredits extends AppCompatDialogFragment
35
  {
36
  @NonNull
37
  @Override
38
  public Dialog onCreateDialog(Bundle savedInstanceState)
39
    {
40
    FragmentActivity act = getActivity();
41
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
42

  
43
    builder.setTitle(R.string.app_name);
44
    builder.setIcon(R.drawable.logo);
45
    builder.setCancelable(false);
46
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
47
      {
48
      @Override
49
      public void onClick(DialogInterface dialog, int which)
50
        {
51

  
52
        }
53
      });
54

  
55
    LayoutInflater inflater = act.getLayoutInflater();
56
    final View view = inflater.inflate(R.layout.credits, null);
57
    builder.setView(view);
58

  
59
    return builder.create();
60
    }
61
  }
src/main/java/org/distorted/magic/RubikSettings.java
34 34
import android.widget.ArrayAdapter;
35 35
import android.widget.SeekBar;
36 36
import android.widget.Spinner;
37
import android.widget.TextView;
37 38

  
38 39
import org.distorted.effect.AppearEffect;
39 40
import org.distorted.effect.DisappearEffect;
......
52 53
  private int mAppearPos, mDisappearPos;
53 54
  private int mAppearType, mDisappearType;
54 55

  
56
  private TextView mAppearDuration, mDisappearDuration;
57

  
55 58
///////////////////////////////////////////////////////////////////////////////////////////////////
56 59

  
57 60
  @Override
......
87 90
      }
88 91
    catch(NullPointerException ex)
89 92
      {
90
      mAppearPos     = 10;
91
      mDisappearPos  = 10;
92
      mAppearType    =  1;
93
      mDisappearType =  1;
93
      mAppearPos     = RubikActivity.DEFAULT_APPEAR_POS;
94
      mDisappearPos  = RubikActivity.DEFAULT_DISAPPEAR_POS;
95
      mAppearType    = RubikActivity.DEFAULT_APPEAR_TYPE;
96
      mDisappearType = RubikActivity.DEFAULT_DISAPPEAR_TYPE;
94 97
      }
95 98
    }
96 99

  
......
117 120
    final View view = inflater.inflate(R.layout.settings, null);
118 121
    builder.setView(view);
119 122

  
123
    mAppearDuration    = view.findViewById(R.id.appearDurationText);
124
    mDisappearDuration = view.findViewById(R.id.disappearDurationText);
125

  
120 126
    Spinner appearTypeSpinner  = view.findViewById(R.id.appearType);
121 127

  
122 128
    if( appearTypeSpinner!=null )
......
224 230
      {
225 231
      switch (bar.getId())
226 232
        {
227
        case R.id.appearDuration   : mAppearPos   = progress; break;
228
        case R.id.disappearDuration: mDisappearPos= progress; break;
233
        case R.id.appearDuration   : mAppearPos   = progress;
234
                                     mAppearDuration.setText(RubikActivity.translateDuration(mAppearPos)+" ms");
235
                                     break;
236
        case R.id.disappearDuration: mDisappearPos= progress;
237
                                     mDisappearDuration.setText(RubikActivity.translateDuration(mDisappearPos)+" ms");
238
                                     break;
229 239
        }
230 240
      }
231 241

  
src/main/res/layout/credits.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:gravity="center_horizontal"
6
    android:orientation="vertical">
7

  
8

  
9
    <LinearLayout
10
        android:layout_width="fill_parent"
11
        android:layout_height="fill_parent"
12
        android:gravity="center|fill_horizontal"
13
        android:orientation="vertical">
14

  
15
        <TextView
16
            android:id="@+id/textView1"
17
            android:layout_width="match_parent"
18
            android:layout_height="fill_parent"
19
            android:layout_weight="0.33"
20
            android:layout_marginBottom="10dp"
21
            android:layout_marginTop="50dp"
22
            android:layout_marginLeft="20dp"
23
            android:layout_marginRight="20dp"
24
            android:text="@string/credits1"/>
25

  
26
        <TextView
27
            android:id="@+id/textView2"
28
            android:layout_width="match_parent"
29
            android:layout_height="fill_parent"
30
            android:layout_weight="0.33"
31
            android:layout_marginBottom="10dp"
32
            android:layout_marginTop="10dp"
33
            android:layout_marginLeft="20dp"
34
            android:layout_marginRight="20dp"
35
            android:text="@string/credits2"/>
36

  
37
        <TextView
38
            android:id="@+id/textView3"
39
            android:layout_width="match_parent"
40
            android:layout_height="fill_parent"
41
            android:layout_weight="0.33"
42
            android:layout_marginBottom="20dp"
43
            android:layout_marginTop="10dp"
44
            android:layout_marginLeft="20dp"
45
            android:layout_marginRight="20dp"
46
            android:text="@string/credits3"/>
47

  
48
    </LinearLayout>
49

  
50
</LinearLayout>
src/main/res/layout/layout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:orientation="vertical" >
6

  
7
    <LinearLayout
8
        android:id="@+id/linearLayout"
9
        android:layout_width="fill_parent"
10
        android:layout_height="wrap_content"
11
        android:gravity="center|fill_horizontal" >
12

  
13
         <Button
14
            android:id="@+id/rubikSettings"
15
            android:layout_width="wrap_content"
16
            android:layout_height="64dp"
17
            android:layout_weight="0.5"
18
            android:onClick="Settings"
19
            android:paddingLeft="5dp"
20
            android:paddingRight="5dp"
21
            android:text="@string/settings" />
22

  
23
        <ImageButton
24
            android:id="@+id/rubikSize2"
25
            android:layout_width="64dp"
26
            android:layout_height="wrap_content"
27
            android:onClick="setSize"
28
            android:paddingLeft="5dp"
29
            android:paddingRight="5dp"
30
            android:src="@drawable/button2"/>
31

  
32
        <ImageButton
33
            android:id="@+id/rubikSize3"
34
            android:layout_width="64dp"
35
            android:layout_height="wrap_content"
36
            android:onClick="setSize"
37
            android:paddingLeft="5dp"
38
            android:paddingRight="5dp"
39
            android:src="@drawable/button3"/>
40

  
41
        <ImageButton
42
            android:id="@+id/rubikSize4"
43
            android:layout_width="64dp"
44
            android:layout_height="wrap_content"
45
            android:onClick="setSize"
46
            android:paddingLeft="5dp"
47
            android:paddingRight="5dp"
48
            android:src="@drawable/button4"/>
49

  
50
        <Button
51
            android:id="@+id/rubikScramble"
52
            android:layout_width="wrap_content"
53
            android:layout_height="64dp"
54
            android:layout_weight="0.5"
55
            android:onClick="Scramble"
56
            android:paddingLeft="5dp"
57
            android:paddingRight="5dp"
58
            android:text="@string/scramble" />
59

  
60
    </LinearLayout>
61

  
62
    <org.distorted.magic.RubikSurfaceView
63
        android:id="@+id/rubikSurfaceView"
64
        android:layout_width="fill_parent"
65
        android:layout_height="0dp"
66
        android:layout_weight="1" />
67

  
68
</LinearLayout>
src/main/res/layout/main.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:orientation="vertical" >
6

  
7
    <LinearLayout
8
        android:id="@+id/linearLayout"
9
        android:layout_width="fill_parent"
10
        android:layout_height="wrap_content"
11
        android:gravity="center|fill_horizontal" >
12

  
13
         <Button
14
            android:id="@+id/rubikSettings"
15
            android:layout_width="wrap_content"
16
            android:layout_height="64dp"
17
            android:layout_weight="0.5"
18
            android:onClick="Settings"
19
            android:paddingLeft="5dp"
20
            android:paddingRight="5dp"
21
            android:text="@string/settings" />
22

  
23
        <ImageButton
24
            android:id="@+id/rubikSize2"
25
            android:layout_width="64dp"
26
            android:layout_height="wrap_content"
27
            android:onClick="setSize"
28
            android:paddingLeft="5dp"
29
            android:paddingRight="5dp"
30
            android:src="@drawable/button2"/>
31

  
32
        <ImageButton
33
            android:id="@+id/rubikSize3"
34
            android:layout_width="64dp"
35
            android:layout_height="wrap_content"
36
            android:onClick="setSize"
37
            android:paddingLeft="5dp"
38
            android:paddingRight="5dp"
39
            android:src="@drawable/button3"/>
40

  
41
        <ImageButton
42
            android:id="@+id/rubikSize4"
43
            android:layout_width="64dp"
44
            android:layout_height="wrap_content"
45
            android:onClick="setSize"
46
            android:paddingLeft="5dp"
47
            android:paddingRight="5dp"
48
            android:src="@drawable/button4"/>
49

  
50
        <Button
51
            android:id="@+id/rubikCredits"
52
            android:layout_width="wrap_content"
53
            android:layout_height="64dp"
54
            android:layout_weight="0.5"
55
            android:onClick="Credits"
56
            android:paddingLeft="5dp"
57
            android:paddingRight="5dp"
58
            android:text="@string/credits" />
59

  
60
    </LinearLayout>
61

  
62
    <org.distorted.magic.RubikSurfaceView
63
        android:id="@+id/rubikSurfaceView"
64
        android:layout_width="fill_parent"
65
        android:layout_height="0dp"
66
        android:layout_weight="1" />
67

  
68
</LinearLayout>
src/main/res/layout/settings.xml
7 7

  
8 8
    <TextView
9 9
        android:layout_width="fill_parent"
10
        android:layout_height="48dp"
10
        android:layout_height="64dp"
11 11
        android:paddingStart="15dp"
12 12
        android:paddingEnd="15dp"
13
        android:gravity="start|bottom"
13
        android:gravity="start|center"
14 14
        android:text="@string/disappear"
15 15
        android:textAppearance="?android:attr/textAppearanceMedium" />
16 16

  
17 17
    <LinearLayout
18 18
        android:layout_width="fill_parent"
19
        android:layout_height="48dp"
19
        android:layout_height="40dp"
20 20
        android:gravity="center|fill_horizontal"
21 21
        android:orientation="horizontal">
22 22

  
23
        <TextView
24
            android:layout_weight="0.25"
25
            android:layout_width="0dp"
26
            android:layout_height="fill_parent"
27
            android:paddingStart="5dp"
28
            android:paddingEnd="5dp"
29
            android:gravity="start|center"
30
            android:text="@string/duration"
31
            android:textAppearance="?android:attr/textAppearanceSmall" />
32

  
33
        <TextView
34
            android:id="@+id/disappearDurationText"
35
            android:layout_weight="0.25"
36
            android:layout_width="0dp"
37
            android:layout_height="fill_parent"
38
            android:paddingStart="5dp"
39
            android:paddingEnd="5dp"
40
            android:gravity="end|center"
41
            android:textAppearance="?android:attr/textAppearanceSmall" />
42

  
23 43
        <SeekBar
24 44
            android:id="@+id/disappearDuration"
25
            android:layout_weight="0.6"
26
            android:layout_width="fill_parent"
45
            android:layout_weight="0.5"
46
            android:layout_width="0dp"
27 47
            android:layout_height="fill_parent"
28 48
            android:paddingLeft="10dp"
29 49
            android:paddingRight="10dp" />
30 50

  
51
    </LinearLayout>
52

  
53
    <LinearLayout
54
        android:layout_width="fill_parent"
55
        android:layout_height="40dp"
56
        android:gravity="center|fill_horizontal"
57
        android:orientation="horizontal">
58

  
59
        <TextView
60
            android:layout_weight="0.5"
61
            android:layout_width="0dp"
62
            android:layout_height="fill_parent"
63
            android:paddingStart="5dp"
64
            android:paddingEnd="5dp"
65
            android:gravity="start|center"
66
            android:text="@string/type"
67
            android:textAppearance="?android:attr/textAppearanceSmall" />
68

  
31 69
        <Spinner
32 70
            android:id="@+id/disappearType"
33
            android:layout_weight="0.4"
34
            android:layout_width="fill_parent"
71
            android:layout_weight="0.5"
72
            android:layout_width="0dp"
35 73
            android:layout_height="fill_parent"
36 74
            android:textAlignment="center"
37 75
            android:paddingLeft="10dp"
......
44 82
        android:layout_height="48dp"
45 83
        android:paddingStart="15dp"
46 84
        android:paddingEnd="15dp"
47
        android:gravity="start|bottom"
85
        android:gravity="start|center"
48 86
        android:text="@string/appear"
49 87
        android:textAppearance="?android:attr/textAppearanceMedium" />
50 88

  
51 89
    <LinearLayout
52 90
        android:layout_width="fill_parent"
53
        android:layout_height="48dp"
91
        android:layout_height="40dp"
54 92
        android:gravity="center|fill_horizontal"
55 93
        android:orientation="horizontal">
56 94

  
95
        <TextView
96
            android:layout_weight="0.25"
97
            android:layout_width="0dp"
98
            android:layout_height="fill_parent"
99
            android:paddingStart="5dp"
100
            android:paddingEnd="5dp"
101
            android:gravity="start|center"
102
            android:text="@string/duration"
103
            android:textAppearance="?android:attr/textAppearanceSmall" />
104

  
105
        <TextView
106
            android:id="@+id/appearDurationText"
107
            android:layout_weight="0.25"
108
            android:layout_width="0dp"
109
            android:layout_height="fill_parent"
110
            android:paddingStart="5dp"
111
            android:paddingEnd="5dp"
112
            android:gravity="end|center"
113
            android:textAppearance="?android:attr/textAppearanceSmall" />
114

  
57 115
        <SeekBar
58 116
            android:id="@+id/appearDuration"
59
            android:layout_weight="0.6"
60
            android:layout_width="fill_parent"
117
            android:layout_weight="0.5"
118
            android:layout_width="0dp"
61 119
            android:layout_height="fill_parent"
62 120
            android:paddingLeft="10dp"
63 121
            android:paddingRight="10dp" />
64 122

  
123
    </LinearLayout>
124

  
125
    <LinearLayout
126
        android:layout_width="fill_parent"
127
        android:layout_height="40dp"
128
        android:gravity="center|fill_horizontal"
129
        android:orientation="horizontal">
130

  
131
        <TextView
132
            android:layout_weight="0.5"
133
            android:layout_width="0dp"
134
            android:layout_height="fill_parent"
135
            android:paddingStart="5dp"
136
            android:paddingEnd="5dp"
137
            android:gravity="start|center"
138
            android:text="@string/type"
139
            android:textAppearance="?android:attr/textAppearanceSmall" />
140

  
65 141
        <Spinner
66 142
            android:id="@+id/appearType"
67
            android:layout_weight="0.4"
68
            android:layout_width="fill_parent"
143
            android:layout_weight="0.5"
144
            android:layout_width="0dp"
69 145
            android:layout_height="fill_parent"
70 146
            android:textAlignment="center"
71 147
            android:paddingLeft="10dp"
src/main/res/values/strings.xml
1 1
<resources>
2 2
    <string name="app_name">Magic Cube</string>
3
    <string name="distorted">DISTORTED</string>
3 4
    <string name="scramble">Scramble</string>
5
    <string name="solve">Solve</string>
4 6
    <string name="settings">Settings</string>
7
    <string name="credits">Credits</string>
5 8
    <string name="save">SAVE</string>
9
    <string name="ok">OK</string>
6 10
    <string name="appear">Appear Effects</string>
7 11
    <string name="disappear">Disappear Effects</string>
12
    <string name="duration">Duration:</string>
13
    <string name="type">Type:</string>
14
    <string name="credits1">Open Source app developed using the Distorted graphics library. </string>
15
    <string name="credits2">Code, tutorials, how to write your own graphics effect: http://www.distorted.org/cube</string>
16
    <string name="credits3">Distorted.org 2019</string>
8 17
</resources>

Also available in: Unified diff