Revision f6fcf06a
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/effect/AppearEffect.java | ||
---|---|---|
48 | 48 |
} |
49 | 49 |
} |
50 | 50 |
|
51 |
public static final int NUM_EFFECTS = Type.values().length; |
|
51 | 52 |
private final int FAKE_EFFECT_ID = -1; |
52 | 53 |
|
53 | 54 |
private int mCubeEffectNumber, mCubeEffectFinished, mCubeEffectReturned; |
src/main/java/org/distorted/effect/DisappearEffect.java | ||
---|---|---|
48 | 48 |
} |
49 | 49 |
} |
50 | 50 |
|
51 |
public static final int NUM_EFFECTS = Type.values().length; |
|
51 | 52 |
private final int FAKE_EFFECT_ID = -2; |
52 | 53 |
|
53 | 54 |
private int mCubeEffectNumber, mCubeEffectFinished, mCubeEffectReturned; |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.magic; |
21 | 21 |
|
22 |
import android.app.Activity; |
|
23 | 22 |
import android.graphics.PorterDuff; |
24 | 23 |
import android.graphics.drawable.Drawable; |
25 | 24 |
import android.opengl.GLSurfaceView; |
26 | 25 |
import android.os.Bundle; |
27 | 26 |
import android.support.v4.content.ContextCompat; |
27 |
import android.support.v7.app.AppCompatActivity; |
|
28 | 28 |
import android.view.View; |
29 | 29 |
|
30 | 30 |
import org.distorted.library.main.DistortedLibrary; |
31 | 31 |
|
32 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
33 | 33 |
|
34 |
public class RubikActivity extends Activity
|
|
34 |
public class RubikActivity extends AppCompatActivity implements RubikSettings.OnCompleteListener
|
|
35 | 35 |
{ |
36 | 36 |
static final int DEFAULT_SIZE = 3; |
37 | 37 |
private static final int SMALLEST_SIZE = 2; |
... | ... | |
39 | 39 |
|
40 | 40 |
private static int mSize = DEFAULT_SIZE; |
41 | 41 |
|
42 |
private int mAppearPos, mDisappearPos; |
|
43 |
private int mAppearType, mDisappearType; |
|
44 |
|
|
42 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 46 |
|
44 | 47 |
@Override |
45 | 48 |
protected void onCreate(Bundle savedState) |
46 | 49 |
{ |
47 | 50 |
super.onCreate(savedState); |
51 |
setTheme(R.style.CustomActivityThemeNoActionBar); |
|
48 | 52 |
setContentView(R.layout.layout); |
49 | 53 |
markButton(mSize); |
54 |
|
|
55 |
mAppearPos = 10; |
|
56 |
mDisappearPos = 10; |
|
57 |
mAppearType = 1; |
|
58 |
mDisappearType = 1; |
|
50 | 59 |
} |
51 | 60 |
|
52 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
98 | 107 |
|
99 | 108 |
public void Settings(View v) |
100 | 109 |
{ |
101 |
android.util.Log.e("rubik", "settings..."); |
|
110 |
Bundle args = new Bundle(); |
|
111 |
|
|
112 |
args.putInt("appearPos" , mAppearPos ); |
|
113 |
args.putInt("disappearPos" , mDisappearPos ); |
|
114 |
args.putInt("appearType" , mAppearType ); |
|
115 |
args.putInt("disappearType", mDisappearType); |
|
116 |
|
|
117 |
RubikSettings settings = new RubikSettings(); |
|
118 |
settings.setArguments(args); |
|
119 |
settings.show(getSupportFragmentManager(), null); |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
public void onComplete(int aP, int dP, int aT, int dT) |
|
125 |
{ |
|
126 |
mAppearPos = aP; |
|
127 |
mDisappearPos = dP; |
|
128 |
mAppearType = aT; |
|
129 |
mDisappearType= dT; |
|
102 | 130 |
} |
103 | 131 |
|
104 | 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikSettings.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.Context; |
|
24 |
import android.content.DialogInterface; |
|
25 |
import android.os.Bundle; |
|
26 |
import android.support.annotation.NonNull; |
|
27 |
import android.support.annotation.Nullable; |
|
28 |
import android.support.v4.app.FragmentActivity; |
|
29 |
import android.support.v7.app.AlertDialog; |
|
30 |
import android.support.v7.app.AppCompatDialogFragment; |
|
31 |
import android.view.LayoutInflater; |
|
32 |
import android.view.View; |
|
33 |
import android.widget.AdapterView; |
|
34 |
import android.widget.ArrayAdapter; |
|
35 |
import android.widget.SeekBar; |
|
36 |
import android.widget.Spinner; |
|
37 |
|
|
38 |
import org.distorted.effect.AppearEffect; |
|
39 |
import org.distorted.effect.DisappearEffect; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public class RubikSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
|
44 |
{ |
|
45 |
public interface OnCompleteListener |
|
46 |
{ |
|
47 |
void onComplete(int aP, int dP, int aT, int dT); |
|
48 |
} |
|
49 |
|
|
50 |
private OnCompleteListener mListener; |
|
51 |
|
|
52 |
private int mAppearPos, mDisappearPos; |
|
53 |
private int mAppearType, mDisappearType; |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
@Override |
|
58 |
public void onAttach(Context context) |
|
59 |
{ |
|
60 |
super.onAttach(context); |
|
61 |
|
|
62 |
try |
|
63 |
{ |
|
64 |
mListener = (OnCompleteListener)context; |
|
65 |
} |
|
66 |
catch (final ClassCastException e) |
|
67 |
{ |
|
68 |
throw new ClassCastException(context.toString() + " must implement OnCompleteListener"); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
@Override |
|
75 |
public void onCreate(@Nullable Bundle savedInstanceState) |
|
76 |
{ |
|
77 |
super.onCreate(savedInstanceState); |
|
78 |
|
|
79 |
Bundle args = getArguments(); |
|
80 |
|
|
81 |
mAppearPos = args.getInt("appearPos"); |
|
82 |
mDisappearPos = args.getInt("disappearPos"); |
|
83 |
mAppearType = args.getInt("appearType"); |
|
84 |
mDisappearType = args.getInt("disappearType"); |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
@NonNull |
|
90 |
@Override |
|
91 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
92 |
{ |
|
93 |
FragmentActivity act = getActivity(); |
|
94 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
95 |
|
|
96 |
builder.setCancelable(false); |
|
97 |
builder.setPositiveButton( R.string.save, new DialogInterface.OnClickListener() |
|
98 |
{ |
|
99 |
@Override |
|
100 |
public void onClick(DialogInterface dialog, int which) |
|
101 |
{ |
|
102 |
saveOptions(); |
|
103 |
} |
|
104 |
}); |
|
105 |
|
|
106 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
107 |
final View view = inflater.inflate(R.layout.settings, null); |
|
108 |
builder.setView(view); |
|
109 |
|
|
110 |
Spinner appearTypeSpinner = view.findViewById(R.id.appearType); |
|
111 |
|
|
112 |
if( appearTypeSpinner!=null ) |
|
113 |
{ |
|
114 |
appearTypeSpinner.setOnItemSelectedListener(this); |
|
115 |
String[] appear = getAppearEffectNames(); |
|
116 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
117 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
118 |
appearTypeSpinner.setAdapter(adapterType); |
|
119 |
|
|
120 |
if(mAppearType>=0 && mAppearType<appear.length) |
|
121 |
{ |
|
122 |
appearTypeSpinner.setSelection(mAppearType); |
|
123 |
} |
|
124 |
} |
|
125 |
else |
|
126 |
{ |
|
127 |
android.util.Log.e("dialog", "APPEAR TYPE SPINNER NULL!!"); |
|
128 |
} |
|
129 |
|
|
130 |
SeekBar appearBar = view.findViewById(R.id.appearDuration); |
|
131 |
appearBar.setOnSeekBarChangeListener(this); |
|
132 |
appearBar.setProgress(mAppearPos); |
|
133 |
|
|
134 |
Spinner disappearTypeSpinner = view.findViewById(R.id.disappearType); |
|
135 |
|
|
136 |
if( disappearTypeSpinner!=null ) |
|
137 |
{ |
|
138 |
disappearTypeSpinner.setOnItemSelectedListener(this); |
|
139 |
String[] disappear = getDisappearEffectNames(); |
|
140 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, disappear); |
|
141 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
142 |
disappearTypeSpinner.setAdapter(adapterType); |
|
143 |
|
|
144 |
if(mDisappearType>=0 && mDisappearType<disappear.length) |
|
145 |
{ |
|
146 |
disappearTypeSpinner.setSelection(mDisappearType); |
|
147 |
} |
|
148 |
} |
|
149 |
else |
|
150 |
{ |
|
151 |
android.util.Log.e("dialog", "DISAPPEAR TYPE SPINNER NULL!!"); |
|
152 |
} |
|
153 |
|
|
154 |
SeekBar disappearBar = view.findViewById(R.id.disappearDuration); |
|
155 |
disappearBar.setOnSeekBarChangeListener(this); |
|
156 |
disappearBar.setProgress(mDisappearPos); |
|
157 |
|
|
158 |
return builder.create(); |
|
159 |
} |
|
160 |
|
|
161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
162 |
|
|
163 |
private String[] getAppearEffectNames() |
|
164 |
{ |
|
165 |
int length = AppearEffect.NUM_EFFECTS; |
|
166 |
AppearEffect.Type[] types = AppearEffect.Type.values(); |
|
167 |
String[] names = new String[length]; |
|
168 |
|
|
169 |
for( int i=0; i<length; i++) |
|
170 |
{ |
|
171 |
names[i] = types[i].name(); |
|
172 |
} |
|
173 |
|
|
174 |
return names; |
|
175 |
} |
|
176 |
|
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
|
179 |
private String[] getDisappearEffectNames() |
|
180 |
{ |
|
181 |
int length = DisappearEffect.NUM_EFFECTS; |
|
182 |
DisappearEffect.Type[] types = DisappearEffect.Type.values(); |
|
183 |
String[] names = new String[length]; |
|
184 |
|
|
185 |
for( int i=0; i<length; i++) |
|
186 |
{ |
|
187 |
names[i] = types[i].name(); |
|
188 |
} |
|
189 |
|
|
190 |
return names; |
|
191 |
} |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
private void saveOptions() |
|
196 |
{ |
|
197 |
mListener.onComplete(mAppearPos, mDisappearPos, mAppearType, mDisappearType); |
|
198 |
} |
|
199 |
|
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
203 |
{ |
|
204 |
switch(parent.getId()) |
|
205 |
{ |
|
206 |
case R.id.appearType : mAppearType = pos; break; |
|
207 |
case R.id.disappearType: mDisappearType= pos; break; |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
212 |
|
|
213 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
214 |
{ |
|
215 |
switch (bar.getId()) |
|
216 |
{ |
|
217 |
case R.id.appearDuration : mAppearPos = progress; break; |
|
218 |
case R.id.disappearDuration: mDisappearPos= progress; break; |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
|
|
224 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
225 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
226 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
227 |
} |
src/main/res/layout/settings.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 |
<TextView |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="48dp" |
|
11 |
android:paddingStart="15dp" |
|
12 |
android:paddingEnd="15dp" |
|
13 |
android:gravity="start|bottom" |
|
14 |
android:text="@string/appear" |
|
15 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
16 |
|
|
17 |
<LinearLayout |
|
18 |
android:layout_width="fill_parent" |
|
19 |
android:layout_height="48dp" |
|
20 |
android:gravity="center|fill_horizontal" |
|
21 |
android:orientation="horizontal"> |
|
22 |
|
|
23 |
<SeekBar |
|
24 |
android:id="@+id/appearDuration" |
|
25 |
android:layout_weight="0.6" |
|
26 |
android:layout_width="fill_parent" |
|
27 |
android:layout_height="fill_parent" |
|
28 |
android:paddingLeft="10dp" |
|
29 |
android:paddingRight="10dp" /> |
|
30 |
|
|
31 |
<Spinner |
|
32 |
android:id="@+id/appearType" |
|
33 |
android:layout_weight="0.4" |
|
34 |
android:layout_width="fill_parent" |
|
35 |
android:layout_height="fill_parent" |
|
36 |
android:textAlignment="center" |
|
37 |
android:paddingLeft="10dp" |
|
38 |
android:paddingRight="10dp" /> |
|
39 |
|
|
40 |
</LinearLayout> |
|
41 |
|
|
42 |
<TextView |
|
43 |
android:layout_width="fill_parent" |
|
44 |
android:layout_height="48dp" |
|
45 |
android:paddingStart="15dp" |
|
46 |
android:paddingEnd="15dp" |
|
47 |
android:gravity="start|bottom" |
|
48 |
android:text="@string/disappear" |
|
49 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
50 |
|
|
51 |
<LinearLayout |
|
52 |
android:layout_width="fill_parent" |
|
53 |
android:layout_height="48dp" |
|
54 |
android:gravity="center|fill_horizontal" |
|
55 |
android:orientation="horizontal"> |
|
56 |
|
|
57 |
<SeekBar |
|
58 |
android:id="@+id/disappearDuration" |
|
59 |
android:layout_weight="0.6" |
|
60 |
android:layout_width="fill_parent" |
|
61 |
android:layout_height="fill_parent" |
|
62 |
android:paddingLeft="10dp" |
|
63 |
android:paddingRight="10dp" /> |
|
64 |
|
|
65 |
<Spinner |
|
66 |
android:id="@+id/disappearType" |
|
67 |
android:layout_weight="0.4" |
|
68 |
android:layout_width="fill_parent" |
|
69 |
android:layout_height="fill_parent" |
|
70 |
android:textAlignment="center" |
|
71 |
android:paddingLeft="10dp" |
|
72 |
android:paddingRight="10dp" /> |
|
73 |
|
|
74 |
</LinearLayout> |
|
75 |
|
|
76 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
2 | 2 |
<string name="app_name">Magic Cube</string> |
3 | 3 |
<string name="scramble">Scramble</string> |
4 | 4 |
<string name="settings">Settings</string> |
5 |
<string name="save">SAVE</string> |
|
6 |
<string name="appear">Appear Effects</string> |
|
7 |
<string name="disappear">Disappear Effects</string> |
|
5 | 8 |
</resources> |
src/main/res/values/styles.xml | ||
---|---|---|
8 | 8 |
<item name="colorAccent">@color/colorAccent</item> |
9 | 9 |
</style> |
10 | 10 |
|
11 |
<style name="CustomActivityThemeNoActionBar" parent="@style/Theme.AppCompat.NoActionBar"> |
|
12 |
<item name="android:windowNoTitle">true</item> |
|
13 |
<item name="android:windowActionBar">false</item> |
|
14 |
<item name="android:windowFullscreen">true</item> |
|
15 |
<item name="android:windowContentOverlay">@null</item> |
|
16 |
</style> |
|
17 |
|
|
11 | 18 |
</resources> |
Also available in: Unified diff
New RubikSettings dialog.