Revision 917d15f5
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/bandaged/BandagedPlayScreen.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import android.app.Activity; |
25 | 25 |
import android.content.SharedPreferences; |
26 |
import android.os.Bundle; |
|
26 | 27 |
import android.view.View; |
27 | 28 |
import android.widget.LinearLayout; |
28 | 29 |
|
... | ... | |
42 | 43 |
public static final int ANIMATION_ON = 0; |
43 | 44 |
public static final int ANIMATION_OFF = 1; |
44 | 45 |
|
45 |
private static final int NUM_SCRAMBLES = 30; |
|
46 |
|
|
47 | 46 |
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton; |
48 | 47 |
private final LockController mLockController; |
49 | 48 |
private final MovesController mMovesController; |
... | ... | |
60 | 59 |
{ |
61 | 60 |
mLockController = new LockController(); |
62 | 61 |
mMovesController= new MovesController(); |
63 |
|
|
64 |
mAnimationMode = ANIMATION_OFF; |
|
65 |
mScrambleDepth = NUM_SCRAMBLES; |
|
66 | 62 |
} |
67 | 63 |
|
68 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
98 | 94 |
@Override |
99 | 95 |
public void onClick(View v) |
100 | 96 |
{ |
97 |
Bundle bundle = new Bundle(); |
|
98 |
bundle.putInt("scraPos", mScrambleDepth ); |
|
99 |
bundle.putInt("animPos", mAnimationMode ); |
|
100 |
|
|
101 | 101 |
RubikDialogBandagedSettings setDiag = new RubikDialogBandagedSettings(); |
102 |
setDiag.setArguments(bundle); |
|
102 | 103 |
setDiag.show(act.getSupportFragmentManager(), null); |
103 | 104 |
} |
104 | 105 |
}); |
... | ... | |
142 | 143 |
TwistyObject object = control.getObject(); |
143 | 144 |
ObjectScrambler.setSignature(object.getSignature()); |
144 | 145 |
|
146 |
int depth = RubikDialogBandagedSettings.DEPTHS[mScrambleDepth]; |
|
147 |
|
|
145 | 148 |
if( mAnimationMode==ANIMATION_OFF ) |
146 | 149 |
{ |
147 |
if( mMoves==null || mMoves.length<mScrambleDepth ) mMoves = new int[mScrambleDepth][3];
|
|
150 |
if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
|
|
148 | 151 |
if( mRnd==null ) mRnd = new Random(); |
149 | 152 |
|
150 |
for(int move=0; move<mScrambleDepth; move++)
|
|
153 |
for(int move=0; move<depth; move++)
|
|
151 | 154 |
{ |
152 |
object.randomizeNewScramble(mMoves, mRnd, move, mScrambleDepth);
|
|
155 |
object.randomizeNewScramble(mMoves, mRnd, move, depth);
|
|
153 | 156 |
} |
154 |
for(int move=0; move<mScrambleDepth; move++)
|
|
157 |
for(int move=0; move<depth; move++)
|
|
155 | 158 |
{ |
156 | 159 |
int row = mMoves[move][1]; |
157 | 160 |
mMoves[move][1] = (1<<row); |
... | ... | |
162 | 165 |
|
163 | 166 |
if( mAnimationMode==ANIMATION_ON ) |
164 | 167 |
{ |
165 |
control.scrambleObject(mScrambleDepth);
|
|
168 |
control.scrambleObject(depth);
|
|
166 | 169 |
} |
167 | 170 |
} |
168 | 171 |
}); |
... | ... | |
255 | 258 |
mMovesController.savePreferences(mKey,editor); |
256 | 259 |
ObjectControl control = act.getControl(); |
257 | 260 |
control.savePreferences(editor); |
261 |
|
|
262 |
editor.putInt("playScreen_scramble" , mScrambleDepth); |
|
263 |
editor.putInt("playScreen_animation", mAnimationMode); |
|
258 | 264 |
} |
259 | 265 |
|
260 | 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
264 | 270 |
mMovesController.restorePreferences(act,mKey,preferences); |
265 | 271 |
ObjectControl control = act.getControl(); |
266 | 272 |
control.restorePreferences(preferences); |
273 |
|
|
274 |
mScrambleDepth = preferences.getInt("playScreen_scramble",1); |
|
275 |
mAnimationMode = preferences.getInt("playScreen_animation",ANIMATION_OFF); |
|
267 | 276 |
} |
268 | 277 |
|
269 | 278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/dialogs/RubikDialogBandagedSettings.java | ||
---|---|---|
27 | 27 |
import android.view.LayoutInflater; |
28 | 28 |
import android.view.View; |
29 | 29 |
import android.view.Window; |
30 |
import android.widget.AdapterView; |
|
31 |
import android.widget.ArrayAdapter; |
|
30 | 32 |
import android.widget.Button; |
33 |
import android.widget.Spinner; |
|
31 | 34 |
import android.widget.TextView; |
32 | 35 |
|
33 | 36 |
import androidx.annotation.NonNull; |
... | ... | |
35 | 38 |
import androidx.appcompat.app.AppCompatDialogFragment; |
36 | 39 |
import androidx.fragment.app.FragmentActivity; |
37 | 40 |
|
41 |
import org.distorted.bandaged.BandagedPlayActivity; |
|
42 |
import org.distorted.bandaged.BandagedPlayScreen; |
|
38 | 43 |
import org.distorted.main.R; |
39 | 44 |
import org.distorted.main.RubikActivity; |
40 | 45 |
|
41 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 47 |
|
43 |
public class RubikDialogBandagedSettings extends AppCompatDialogFragment |
|
48 |
public class RubikDialogBandagedSettings extends AppCompatDialogFragment implements AdapterView.OnItemSelectedListener
|
|
44 | 49 |
{ |
50 |
public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000}; |
|
51 |
private int mAnimPos, mScraPos; |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
private String[] createScrambleModes() |
|
56 |
{ |
|
57 |
int len = DEPTHS.length; |
|
58 |
String[] ret = new String[len]; |
|
59 |
|
|
60 |
for(int i=0; i<len; i++) |
|
61 |
{ |
|
62 |
ret[i] = String.valueOf(DEPTHS[i]); |
|
63 |
} |
|
64 |
|
|
65 |
return ret; |
|
66 |
} |
|
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
private void configureView(FragmentActivity act, View view, float textSize, int scraPos, int animPos) |
|
71 |
{ |
|
72 |
TextView text1 = view.findViewById(R.id.bandaged_text_scramble); |
|
73 |
text1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
74 |
TextView text2 = view.findViewById(R.id.bandaged_text_animation); |
|
75 |
text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
76 |
|
|
77 |
mScraPos = scraPos; |
|
78 |
mAnimPos = animPos; |
|
79 |
|
|
80 |
Spinner scramble = view.findViewById(R.id.bandaged_spinner_scramble); |
|
81 |
scramble.setOnItemSelectedListener(this); |
|
82 |
String[] scrambleModes = createScrambleModes(); |
|
83 |
|
|
84 |
ArrayAdapter<String> scrambleAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, scrambleModes ); |
|
85 |
scrambleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
86 |
scramble.setAdapter(scrambleAdapter); |
|
87 |
scramble.setSelection(mScraPos); |
|
88 |
|
|
89 |
Spinner animation = view.findViewById(R.id.bandaged_spinner_animation); |
|
90 |
animation.setOnItemSelectedListener(this); |
|
91 |
String[] animationModes = { "ON" , "OFF" }; |
|
92 |
|
|
93 |
ArrayAdapter<String> animationAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, animationModes ); |
|
94 |
animationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
95 |
animation.setAdapter(animationAdapter); |
|
96 |
animation.setSelection(mAnimPos); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
@Override |
|
102 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
103 |
{ |
|
104 |
int spinnerID = parent.getId(); |
|
105 |
|
|
106 |
if( spinnerID == R.id.bandaged_spinner_scramble ) |
|
107 |
{ |
|
108 |
mScraPos = pos; |
|
109 |
} |
|
110 |
else if( spinnerID == R.id.bandaged_spinner_animation ) |
|
111 |
{ |
|
112 |
mAnimPos = pos; |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
@Override |
|
119 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
120 |
|
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
45 | 123 |
@NonNull |
46 | 124 |
@Override |
47 | 125 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
... | ... | |
54 | 132 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
55 | 133 |
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE; |
56 | 134 |
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
57 |
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
|
|
135 |
final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
|
58 | 136 |
|
59 | 137 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
60 | 138 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
61 | 139 |
tv.setText(R.string.settings); |
62 | 140 |
builder.setCustomTitle(tv); |
63 | 141 |
|
142 |
Bundle args = getArguments(); |
|
143 |
int scraPos, animPos; |
|
144 |
|
|
145 |
try |
|
146 |
{ |
|
147 |
scraPos = args.getInt("scraPos"); |
|
148 |
animPos = args.getInt("animPos"); |
|
149 |
} |
|
150 |
catch(Exception e) |
|
151 |
{ |
|
152 |
scraPos = 0; |
|
153 |
animPos = 0; |
|
154 |
} |
|
155 |
|
|
156 |
final BandagedPlayActivity bact = (BandagedPlayActivity)getContext(); |
|
157 |
|
|
64 | 158 |
builder.setCancelable(true); |
65 | 159 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
66 | 160 |
{ |
67 | 161 |
@Override |
68 | 162 |
public void onClick(DialogInterface dialog, int which) |
69 | 163 |
{ |
164 |
BandagedPlayScreen screen = bact!=null ? bact.getScreen() : null; |
|
70 | 165 |
|
166 |
if( screen!=null ) |
|
167 |
{ |
|
168 |
screen.setScrambleDepth(mScraPos); |
|
169 |
screen.setAnimationMode(mAnimPos); |
|
170 |
} |
|
71 | 171 |
} |
72 | 172 |
}); |
73 | 173 |
|
74 | 174 |
final View view = inflater.inflate(R.layout.dialog_settings, null); |
75 |
|
|
76 |
|
|
175 |
configureView(act,view,textSize,scraPos,animPos); |
|
77 | 176 |
builder.setView(view); |
78 | 177 |
|
79 | 178 |
Dialog dialog = builder.create(); |
src/main/res/layout/dialog_settings.xml | ||
---|---|---|
11 | 11 |
android:gravity="center|fill_horizontal" |
12 | 12 |
android:layout_marginLeft="10dp" |
13 | 13 |
android:layout_marginRight="10dp" |
14 |
android:layout_marginTop="0dp" |
|
15 | 14 |
android:background="@color/grey" |
16 | 15 |
android:orientation="vertical"> |
17 | 16 |
|
18 |
<TextView |
|
19 |
android:id="@+id/solved_time" |
|
20 |
android:layout_width="match_parent" |
|
21 |
android:layout_height="match_parent" |
|
22 |
android:gravity="center" |
|
23 |
android:textSize="24sp" |
|
24 |
android:layout_marginTop="10dp" |
|
17 |
<LinearLayout |
|
18 |
android:layout_width="fill_parent" |
|
19 |
android:layout_height="wrap_content" |
|
20 |
android:gravity="center|fill_horizontal" |
|
25 | 21 |
android:layout_marginLeft="10dp" |
26 | 22 |
android:layout_marginRight="10dp" |
27 |
android:layout_marginBottom="10dp"/> |
|
23 |
android:layout_marginTop="10dp" |
|
24 |
android:layout_marginBottom="5dp" |
|
25 |
android:orientation="horizontal"> |
|
26 |
|
|
27 |
<TextView |
|
28 |
android:id="@+id/bandaged_text_scramble" |
|
29 |
android:layout_width="0dp" |
|
30 |
android:layout_height="wrap_content" |
|
31 |
android:layout_weight="0.5" |
|
32 |
android:gravity="start" |
|
33 |
android:textSize="24sp" |
|
34 |
android:text="@string/scramble" |
|
35 |
android:layout_marginLeft="10dp" |
|
36 |
android:layout_marginRight="10dp"/> |
|
37 |
|
|
38 |
<Spinner |
|
39 |
android:id="@+id/bandaged_spinner_scramble" |
|
40 |
android:gravity="end" |
|
41 |
android:layout_width="0dp" |
|
42 |
android:layout_height="wrap_content" |
|
43 |
android:layout_weight="0.5"/> |
|
44 |
|
|
45 |
</LinearLayout> |
|
46 |
|
|
47 |
<LinearLayout |
|
48 |
android:layout_width="fill_parent" |
|
49 |
android:layout_height="wrap_content" |
|
50 |
android:gravity="center|fill_horizontal" |
|
51 |
android:layout_marginLeft="10dp" |
|
52 |
android:layout_marginRight="10dp" |
|
53 |
android:layout_marginTop="5dp" |
|
54 |
android:layout_marginBottom="10dp" |
|
55 |
android:orientation="horizontal"> |
|
56 |
|
|
57 |
<TextView |
|
58 |
android:id="@+id/bandaged_text_animation" |
|
59 |
android:layout_width="0dp" |
|
60 |
android:layout_height="wrap_content" |
|
61 |
android:layout_weight="0.5" |
|
62 |
android:gravity="start" |
|
63 |
android:textSize="24sp" |
|
64 |
android:text="@string/animation" |
|
65 |
android:layout_marginTop="10dp" |
|
66 |
android:layout_marginLeft="10dp" |
|
67 |
android:layout_marginRight="10dp" |
|
68 |
android:layout_marginBottom="10dp"/> |
|
69 |
|
|
70 |
<Spinner |
|
71 |
android:id="@+id/bandaged_spinner_animation" |
|
72 |
android:gravity="end" |
|
73 |
android:layout_width="0dp" |
|
74 |
android:layout_height="wrap_content" |
|
75 |
android:layout_weight="0.5"/> |
|
76 |
|
|
77 |
</LinearLayout> |
|
28 | 78 |
|
29 | 79 |
</LinearLayout> |
30 | 80 |
</LinearLayout> |
src/main/res/values-de/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">Löschen</string> |
43 | 43 |
<string name="delete_object_really">Möchten Sie diesen Cube löschen?</string> |
44 | 44 |
<string name="settings">Einstellungen</string> |
45 |
<string name="animation">Animation</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">Highscores</string> |
47 | 48 |
<string name="patterns">Hübsche Muster</string> |
src/main/res/values-es/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">Borrar</string> |
43 | 43 |
<string name="delete_object_really">¿Quieres borrar este Cubo?</string> |
44 | 44 |
<string name="settings">Ajustes</string> |
45 |
<string name="animation">Animación</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">Leaderboard</string> |
47 | 48 |
<string name="patterns">Patrones</string> |
src/main/res/values-fr/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">Supprimer</string> |
43 | 43 |
<string name="delete_object_really">Voulez-vous supprimer ce Cube?</string> |
44 | 44 |
<string name="settings">Réglages</string> |
45 |
<string name="animation">Animation</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">Meilleurs scores</string> |
47 | 48 |
<string name="patterns">Jolis motifs</string> |
src/main/res/values-ja/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">消す</string> |
43 | 43 |
<string name="delete_object_really">このキューブを削除しますか?</string> |
44 | 44 |
<string name="settings">設定</string> |
45 |
<string name="animation">効果</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">ハイスコア</string> |
47 | 48 |
<string name="patterns">プリティパターン</string> |
src/main/res/values-ko/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">삭제</string> |
43 | 43 |
<string name="delete_object_really">이 큐브를 삭제하시겠습니까?</string> |
44 | 44 |
<string name="settings">설정</string> |
45 |
<string name="animation">효과</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">고득점</string> |
47 | 48 |
<string name="patterns">예쁜 패턴</string> |
src/main/res/values-pl/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">Usuń</string> |
43 | 43 |
<string name="delete_object_really">Chcesz usunąć tą kostkę?</string> |
44 | 44 |
<string name="settings">Ustawienia</string> |
45 |
<string name="animation">Animacja</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">Lista najlepszych</string> |
47 | 48 |
<string name="patterns">Piękne Wzory</string> |
src/main/res/values-ru/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">Удалить</string> |
43 | 43 |
<string name="delete_object_really">Вы хотите удалить этот куб?</string> |
44 | 44 |
<string name="settings">Настройки</string> |
45 |
<string name="animation">Эффект</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">Высокие баллы</string> |
47 | 48 |
<string name="patterns">Красивые узоры</string> |
src/main/res/values-zh-rCN/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">删除</string> |
43 | 43 |
<string name="delete_object_really">你想删除这个立方体吗?</string> |
44 | 44 |
<string name="settings">设置</string> |
45 |
<string name="animation">动画</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">高分</string> |
47 | 48 |
<string name="patterns">模式</string> |
src/main/res/values-zh-rTW/strings.xml | ||
---|---|---|
42 | 42 |
<string name="delete_object">刪除</string> |
43 | 43 |
<string name="delete_object_really">是否要刪除此多維數據集?</string> |
44 | 44 |
<string name="settings">設置</string> |
45 |
<string name="animation">動畫</string> |
|
45 | 46 |
|
46 | 47 |
<string name="scores">高分</string> |
47 | 48 |
<string name="patterns">模式</string> |
src/main/res/values/strings.xml | ||
---|---|---|
43 | 43 |
<string name="delete_object">Delete</string> |
44 | 44 |
<string name="delete_object_really">Do you want to delete this Cube?</string> |
45 | 45 |
<string name="settings">Settings</string> |
46 |
<string name="animation">Animation</string> |
|
46 | 47 |
|
47 | 48 |
<string name="scores">High Scores</string> |
48 | 49 |
<string name="patterns">Pretty Patterns</string> |
Also available in: Unified diff
BandagedPlay: configurable mode and scramble depth