Revision 4c0cd600
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/dialog/RubikDialogEffects.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 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.dialog; |
|
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.v4.content.ContextCompat; |
|
28 |
import android.support.v7.app.AlertDialog; |
|
29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
30 |
import android.util.DisplayMetrics; |
|
31 |
import android.view.Gravity; |
|
32 |
import android.view.LayoutInflater; |
|
33 |
import android.view.View; |
|
34 |
import android.view.Window; |
|
35 |
import android.view.WindowManager; |
|
36 |
import android.widget.AdapterView; |
|
37 |
import android.widget.ArrayAdapter; |
|
38 |
import android.widget.LinearLayout; |
|
39 |
import android.widget.SeekBar; |
|
40 |
import android.widget.Spinner; |
|
41 |
import android.widget.TextView; |
|
42 |
|
|
43 |
import org.distorted.effect.BaseEffect; |
|
44 |
import org.distorted.magic.R; |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
public class RubikDialogEffects extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
|
49 |
{ |
|
50 |
private TextView[] mDurationText; |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
private void addSettingsSection(FragmentActivity act, LinearLayout layout, int index) |
|
55 |
{ |
|
56 |
BaseEffect.Type beType = BaseEffect.Type.getType(index); |
|
57 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
58 |
float scale = metrics.density; |
|
59 |
|
|
60 |
int textH=32; |
|
61 |
int layoH=36; |
|
62 |
int margH=10; |
|
63 |
|
|
64 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
int margin = (int)(scale*margH + 0.5f); |
|
67 |
int color = ContextCompat.getColor(act, R.color.grey); |
|
68 |
LinearLayout outerLayout = new LinearLayout(act); |
|
69 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
70 |
outerLayoutParams.topMargin = margin; |
|
71 |
outerLayoutParams.bottomMargin = 0; |
|
72 |
outerLayoutParams.leftMargin = margin; |
|
73 |
outerLayoutParams.rightMargin = margin; |
|
74 |
|
|
75 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
76 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
77 |
outerLayout.setBackgroundColor(color); |
|
78 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
79 |
layout.addView(outerLayout); |
|
80 |
|
|
81 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
int layoutHeight = (int)(scale*textH + 0.5f); |
|
84 |
int padding = (int)(scale*10 + 0.5f); |
|
85 |
|
|
86 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
87 |
|
|
88 |
TextView textView = new TextView(act); |
|
89 |
textView.setText(beType.getText()); |
|
90 |
textView.setLayoutParams(textParams); |
|
91 |
textView.setGravity(Gravity.CENTER); |
|
92 |
textView.setPadding(padding,0,padding,0); |
|
93 |
textView.setTextAppearance(android.R.style.TextAppearance_Small); |
|
94 |
outerLayout.addView(textView); |
|
95 |
|
|
96 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
int innerLayout1Height = (int)(scale*layoH + 0.5f); |
|
99 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
100 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
101 |
|
|
102 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
103 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
104 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
105 |
outerLayout.addView(innerLayout1); |
|
106 |
|
|
107 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
108 |
|
|
109 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
110 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
111 |
|
|
112 |
TextView text1View = new TextView(act); |
|
113 |
text1View.setText(R.string.duration); |
|
114 |
text1View.setLayoutParams(text1LayoutParams); |
|
115 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
116 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
117 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
118 |
innerLayout1.addView(text1View); |
|
119 |
////////////////////////////////////////////////////////////////// |
|
120 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
121 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
122 |
|
|
123 |
mDurationText[index] = new TextView(act); |
|
124 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
125 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
126 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
127 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
128 |
innerLayout1.addView(mDurationText[index]); |
|
129 |
////////////////////////////////////////////////////////////////// |
|
130 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
131 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
132 |
|
|
133 |
SeekBar seekBar = new SeekBar(act); |
|
134 |
seekBar.setLayoutParams(seekLayoutParams); |
|
135 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
136 |
seekBar.setId(index); |
|
137 |
innerLayout1.addView(seekBar); |
|
138 |
|
|
139 |
seekBar.setOnSeekBarChangeListener(this); |
|
140 |
seekBar.setProgress(beType.getCurrentPos()); |
|
141 |
|
|
142 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
int innerLayout2Height = (int)(scale*layoH + 0.5f); |
|
145 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
146 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
147 |
|
|
148 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
149 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
150 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
151 |
outerLayout.addView(innerLayout2); |
|
152 |
|
|
153 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
154 |
|
|
155 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
156 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
157 |
|
|
158 |
TextView text3View = new TextView(act); |
|
159 |
text3View.setText(R.string.type); |
|
160 |
text3View.setLayoutParams(text3LayoutParams); |
|
161 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
162 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
163 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
164 |
innerLayout2.addView(text3View); |
|
165 |
////////////////////////////////////////////////////////////////// |
|
166 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
167 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
168 |
|
|
169 |
Spinner spinner = new Spinner(act); |
|
170 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
171 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
172 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
173 |
spinner.setId(index+BaseEffect.Type.LENGTH); |
|
174 |
innerLayout2.addView(spinner); |
|
175 |
|
|
176 |
spinner.setOnItemSelectedListener(this); |
|
177 |
String[] appear = BaseEffect.Type.getType(index).getNames(); |
|
178 |
|
|
179 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
180 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
181 |
spinner.setAdapter(adapterType); |
|
182 |
spinner.setSelection(beType.getCurrentType()); |
|
183 |
} |
|
184 |
|
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
// PUBLIC API |
|
187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
188 |
|
|
189 |
public RubikDialogEffects() |
|
190 |
{ |
|
191 |
mDurationText = new TextView[BaseEffect.Type.LENGTH]; |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
@Override |
|
197 |
public void onStart() |
|
198 |
{ |
|
199 |
super.onStart(); |
|
200 |
|
|
201 |
Window window = getDialog().getWindow(); |
|
202 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
203 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
204 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
205 |
} |
|
206 |
|
|
207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
|
|
209 |
@NonNull |
|
210 |
@Override |
|
211 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
212 |
{ |
|
213 |
FragmentActivity act = getActivity(); |
|
214 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
215 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
216 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
217 |
tv.setText(R.string.effects); |
|
218 |
builder.setCustomTitle(tv); |
|
219 |
|
|
220 |
builder.setCancelable(true); |
|
221 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
222 |
{ |
|
223 |
@Override |
|
224 |
public void onClick(DialogInterface dialog, int which) |
|
225 |
{ |
|
226 |
|
|
227 |
} |
|
228 |
}); |
|
229 |
|
|
230 |
final View view = inflater.inflate(R.layout.dialog_settings, null); |
|
231 |
builder.setView(view); |
|
232 |
|
|
233 |
LinearLayout linearLayout = view.findViewById(R.id.settingsLayout); |
|
234 |
|
|
235 |
if( linearLayout!=null ) |
|
236 |
{ |
|
237 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
238 |
{ |
|
239 |
addSettingsSection(act,linearLayout,i); |
|
240 |
} |
|
241 |
} |
|
242 |
else |
|
243 |
{ |
|
244 |
android.util.Log.e("dialog_settings", "linearLayout NULL!"); |
|
245 |
} |
|
246 |
|
|
247 |
return builder.create(); |
|
248 |
} |
|
249 |
|
|
250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 |
|
|
252 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
253 |
{ |
|
254 |
int parentID = parent.getId(); |
|
255 |
int len = BaseEffect.Type.LENGTH; |
|
256 |
|
|
257 |
if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection) |
|
258 |
{ |
|
259 |
BaseEffect.Type.getType(parentID-len).setCurrentType(pos); |
|
260 |
} |
|
261 |
} |
|
262 |
|
|
263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
264 |
|
|
265 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
266 |
{ |
|
267 |
int barID = bar.getId(); |
|
268 |
|
|
269 |
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) |
|
270 |
{ |
|
271 |
BaseEffect.Type.getType(barID).setCurrentPos(progress); |
|
272 |
int ms = BaseEffect.Type.translatePos(progress); |
|
273 |
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); |
|
274 |
} |
|
275 |
} |
|
276 |
|
|
277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 |
|
|
279 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
280 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
281 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
282 |
} |
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
---|---|---|
82 | 82 |
|
83 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
84 | 84 |
|
85 |
public void serverError(final String error)
|
|
85 |
public void error(final String error)
|
|
86 | 86 |
{ |
87 | 87 |
char errorNumber = error.charAt(0); |
88 | 88 |
|
89 | 89 |
switch(errorNumber) |
90 | 90 |
{ |
91 |
case '1': message("Client error"); |
|
92 |
break; |
|
91 | 93 |
case '2': RubikScores scores = RubikScores.getInstance(); |
92 | 94 |
Bundle bundle = new Bundle(); |
93 | 95 |
bundle.putString("name", scores.getName() ); |
... | ... | |
101 | 103 |
break; |
102 | 104 |
case '3': message("Server error"); |
103 | 105 |
break; |
106 |
default : message("Unexpected error"); |
|
104 | 107 |
} |
105 | 108 |
} |
106 | 109 |
|
src/main/java/org/distorted/dialog/RubikDialogSettings.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 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.dialog; |
|
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.v4.content.ContextCompat; |
|
28 |
import android.support.v7.app.AlertDialog; |
|
29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
30 |
import android.util.DisplayMetrics; |
|
31 |
import android.view.Gravity; |
|
32 |
import android.view.LayoutInflater; |
|
33 |
import android.view.View; |
|
34 |
import android.view.Window; |
|
35 |
import android.view.WindowManager; |
|
36 |
import android.widget.AdapterView; |
|
37 |
import android.widget.ArrayAdapter; |
|
38 |
import android.widget.LinearLayout; |
|
39 |
import android.widget.SeekBar; |
|
40 |
import android.widget.Spinner; |
|
41 |
import android.widget.TextView; |
|
42 |
|
|
43 |
import org.distorted.effect.BaseEffect; |
|
44 |
import org.distorted.magic.R; |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
public class RubikDialogSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
|
49 |
{ |
|
50 |
private TextView[] mDurationText; |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
private void addSettingsSection(FragmentActivity act, LinearLayout layout, int index) |
|
55 |
{ |
|
56 |
BaseEffect.Type beType = BaseEffect.Type.getType(index); |
|
57 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
58 |
float scale = metrics.density; |
|
59 |
|
|
60 |
int textH=32; |
|
61 |
int layoH=36; |
|
62 |
int margH=10; |
|
63 |
|
|
64 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
int margin = (int)(scale*margH + 0.5f); |
|
67 |
int color = ContextCompat.getColor(act, R.color.grey); |
|
68 |
LinearLayout outerLayout = new LinearLayout(act); |
|
69 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
70 |
outerLayoutParams.topMargin = margin; |
|
71 |
outerLayoutParams.bottomMargin = 0; |
|
72 |
outerLayoutParams.leftMargin = margin; |
|
73 |
outerLayoutParams.rightMargin = margin; |
|
74 |
|
|
75 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
76 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
77 |
outerLayout.setBackgroundColor(color); |
|
78 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
79 |
layout.addView(outerLayout); |
|
80 |
|
|
81 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
int layoutHeight = (int)(scale*textH + 0.5f); |
|
84 |
int padding = (int)(scale*10 + 0.5f); |
|
85 |
|
|
86 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
87 |
|
|
88 |
TextView textView = new TextView(act); |
|
89 |
textView.setText(beType.getText()); |
|
90 |
textView.setLayoutParams(textParams); |
|
91 |
textView.setGravity(Gravity.CENTER); |
|
92 |
textView.setPadding(padding,0,padding,0); |
|
93 |
textView.setTextAppearance(android.R.style.TextAppearance_Small); |
|
94 |
outerLayout.addView(textView); |
|
95 |
|
|
96 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
int innerLayout1Height = (int)(scale*layoH + 0.5f); |
|
99 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
100 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
101 |
|
|
102 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
103 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
104 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
105 |
outerLayout.addView(innerLayout1); |
|
106 |
|
|
107 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
108 |
|
|
109 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
110 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
111 |
|
|
112 |
TextView text1View = new TextView(act); |
|
113 |
text1View.setText(R.string.duration); |
|
114 |
text1View.setLayoutParams(text1LayoutParams); |
|
115 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
116 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
117 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
118 |
innerLayout1.addView(text1View); |
|
119 |
////////////////////////////////////////////////////////////////// |
|
120 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
121 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
122 |
|
|
123 |
mDurationText[index] = new TextView(act); |
|
124 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
125 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
126 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
127 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
128 |
innerLayout1.addView(mDurationText[index]); |
|
129 |
////////////////////////////////////////////////////////////////// |
|
130 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
131 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
132 |
|
|
133 |
SeekBar seekBar = new SeekBar(act); |
|
134 |
seekBar.setLayoutParams(seekLayoutParams); |
|
135 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
136 |
seekBar.setId(index); |
|
137 |
innerLayout1.addView(seekBar); |
|
138 |
|
|
139 |
seekBar.setOnSeekBarChangeListener(this); |
|
140 |
seekBar.setProgress(beType.getCurrentPos()); |
|
141 |
|
|
142 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
int innerLayout2Height = (int)(scale*layoH + 0.5f); |
|
145 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
146 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
147 |
|
|
148 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
149 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
150 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
151 |
outerLayout.addView(innerLayout2); |
|
152 |
|
|
153 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
154 |
|
|
155 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
156 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
157 |
|
|
158 |
TextView text3View = new TextView(act); |
|
159 |
text3View.setText(R.string.type); |
|
160 |
text3View.setLayoutParams(text3LayoutParams); |
|
161 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
162 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
163 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
164 |
innerLayout2.addView(text3View); |
|
165 |
////////////////////////////////////////////////////////////////// |
|
166 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
167 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
168 |
|
|
169 |
Spinner spinner = new Spinner(act); |
|
170 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
171 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
172 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
173 |
spinner.setId(index+BaseEffect.Type.LENGTH); |
|
174 |
innerLayout2.addView(spinner); |
|
175 |
|
|
176 |
spinner.setOnItemSelectedListener(this); |
|
177 |
String[] appear = BaseEffect.Type.getType(index).getNames(); |
|
178 |
|
|
179 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
180 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
181 |
spinner.setAdapter(adapterType); |
|
182 |
spinner.setSelection(beType.getCurrentType()); |
|
183 |
} |
|
184 |
|
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
// PUBLIC API |
|
187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
188 |
|
|
189 |
public RubikDialogSettings() |
|
190 |
{ |
|
191 |
mDurationText = new TextView[BaseEffect.Type.LENGTH]; |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
@Override |
|
197 |
public void onStart() |
|
198 |
{ |
|
199 |
super.onStart(); |
|
200 |
|
|
201 |
Window window = getDialog().getWindow(); |
|
202 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
203 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
204 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
205 |
} |
|
206 |
|
|
207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
|
|
209 |
@NonNull |
|
210 |
@Override |
|
211 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
212 |
{ |
|
213 |
FragmentActivity act = getActivity(); |
|
214 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
215 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
216 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
217 |
tv.setText(R.string.settings); |
|
218 |
builder.setCustomTitle(tv); |
|
219 |
|
|
220 |
builder.setCancelable(true); |
|
221 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
222 |
{ |
|
223 |
@Override |
|
224 |
public void onClick(DialogInterface dialog, int which) |
|
225 |
{ |
|
226 |
|
|
227 |
} |
|
228 |
}); |
|
229 |
|
|
230 |
final View view = inflater.inflate(R.layout.dialog_settings, null); |
|
231 |
builder.setView(view); |
|
232 |
|
|
233 |
LinearLayout linearLayout = view.findViewById(R.id.settingsLayout); |
|
234 |
|
|
235 |
if( linearLayout!=null ) |
|
236 |
{ |
|
237 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
238 |
{ |
|
239 |
addSettingsSection(act,linearLayout,i); |
|
240 |
} |
|
241 |
} |
|
242 |
else |
|
243 |
{ |
|
244 |
android.util.Log.e("dialog_settings", "linearLayout NULL!"); |
|
245 |
} |
|
246 |
|
|
247 |
return builder.create(); |
|
248 |
} |
|
249 |
|
|
250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 |
|
|
252 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
253 |
{ |
|
254 |
int parentID = parent.getId(); |
|
255 |
int len = BaseEffect.Type.LENGTH; |
|
256 |
|
|
257 |
if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection) |
|
258 |
{ |
|
259 |
BaseEffect.Type.getType(parentID-len).setCurrentType(pos); |
|
260 |
} |
|
261 |
} |
|
262 |
|
|
263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
264 |
|
|
265 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
266 |
{ |
|
267 |
int barID = bar.getId(); |
|
268 |
|
|
269 |
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) |
|
270 |
{ |
|
271 |
BaseEffect.Type.getType(barID).setCurrentPos(progress); |
|
272 |
int ms = BaseEffect.Type.translatePos(progress); |
|
273 |
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); |
|
274 |
} |
|
275 |
} |
|
276 |
|
|
277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 |
|
|
279 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
280 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
281 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
282 |
} |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.distorted.dialog.RubikDialogAbout; |
29 | 29 |
import org.distorted.dialog.RubikDialogScores; |
30 |
import org.distorted.dialog.RubikDialogSettings;
|
|
30 |
import org.distorted.dialog.RubikDialogEffects;
|
|
31 | 31 |
import org.distorted.effect.BaseEffect; |
32 | 32 |
import org.distorted.library.main.DistortedLibrary; |
33 | 33 |
|
... | ... | |
91 | 91 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
92 | 92 |
int object = play.getObject(); |
93 | 93 |
int size = play.getSize(); |
94 |
RubikObjectList obj = RubikObjectList.getObject(object); |
|
95 |
int objectSize = obj.getSizes()[size]; |
|
96 | 94 |
|
97 |
view.getRenderer().createObject( obj, objectSize ); |
|
95 |
if( object>=0 && object<RubikObjectList.NUM_OBJECTS ) |
|
96 |
{ |
|
97 |
RubikObjectList obj = RubikObjectList.getObject(object); |
|
98 |
int[] sizes = obj.getSizes(); |
|
99 |
|
|
100 |
if( size>=0 && size<sizes.length ) |
|
101 |
{ |
|
102 |
view.getRenderer().createObject( obj, sizes[size] ); |
|
103 |
} |
|
104 |
} |
|
98 | 105 |
} |
99 | 106 |
|
100 | 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
111 | 118 |
@Override |
112 | 119 |
public void onClick(View v) |
113 | 120 |
{ |
114 |
int id = v.getId(); |
|
115 |
|
|
116 |
if( id>=0 && id< RubikObjectList.getTotal() ) |
|
121 |
switch(v.getId()) |
|
117 | 122 |
{ |
118 |
int object = RubikObjectList.unpackObject(id); |
|
119 |
int size= RubikObjectList.unpackSize(id); |
|
123 |
case RubikStateAbstract.BUTTON_ID_OBJECT: RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
|
124 |
play.bringUpPopup(this,v); |
|
125 |
break; |
|
126 |
case RubikStateAbstract.BUTTON_ID_BACK: RubikState.goBack(this); |
|
127 |
break; |
|
128 |
} |
|
129 |
} |
|
120 | 130 |
|
121 |
RubikObjectList obj = RubikObjectList.getObject(object); |
|
122 |
int objectSize = obj.getSizes()[size]; |
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 | 132 |
|
124 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
125 |
boolean success = view.getRenderer().createObject(obj,objectSize); |
|
133 |
public void changeObject(int object, int size) |
|
134 |
{ |
|
135 |
RubikObjectList obj = RubikObjectList.getObject(object); |
|
136 |
int objectSize = obj.getSizes()[size]; |
|
126 | 137 |
|
127 |
if( success ) |
|
128 |
{ |
|
129 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
|
130 |
play.markButton(this,object,size); |
|
131 |
} |
|
132 |
} |
|
138 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
139 |
view.getRenderer().createObject(obj,objectSize); |
|
140 |
} |
|
133 | 141 |
|
134 |
if( id == RubikStateAbstract.BUTTON_ID_BACK ) |
|
135 |
{ |
|
136 |
RubikState.goBack(this); |
|
137 |
} |
|
142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
public boolean isVertical() |
|
145 |
{ |
|
146 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
147 |
return view.isVertical(); |
|
138 | 148 |
} |
139 | 149 |
|
140 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
196 | 206 |
|
197 | 207 |
public void Settings(View v) |
198 | 208 |
{ |
199 |
RubikDialogSettings settings = new RubikDialogSettings();
|
|
209 |
RubikDialogEffects settings = new RubikDialogEffects();
|
|
200 | 210 |
settings.show(getSupportFragmentManager(), null); |
201 | 211 |
} |
202 | 212 |
|
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
82 | 82 |
mScreenMin = Math.min(width, height); |
83 | 83 |
} |
84 | 84 |
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
boolean isVertical() |
|
88 |
{ |
|
89 |
return mScreenHeight>mScreenWidth; |
|
90 |
} |
|
91 |
|
|
85 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 | 93 |
|
87 | 94 |
RubikRenderer getRenderer() |
src/main/java/org/distorted/object/RubikObjectList.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
public enum RubikObjectList |
31 | 31 |
{ |
32 |
CUBE ( new int[][] { {2,R.drawable.cube2} , {3,R.drawable.cube3} , {4,R.drawable.cube4} }, |
|
33 |
new RubikCubeMovement() ), |
|
34 |
PYRAMINX ( new int[][] { {3,R.drawable.pyra3} , {4,R.drawable.pyra4} }, |
|
35 |
new RubikPyraminxMovement() ), |
|
32 |
CUBE ( |
|
33 |
new int[][] { |
|
34 |
{2 , R.drawable.cube2} , |
|
35 |
{3 , R.drawable.cube3} , |
|
36 |
{4 , R.drawable.cube4} , |
|
37 |
{5 , R.drawable.cube5} |
|
38 |
}, |
|
39 |
new RubikCubeMovement() |
|
40 |
), |
|
41 |
|
|
42 |
PYRA ( |
|
43 |
new int[][] { |
|
44 |
{3 , R.drawable.pyra3} , |
|
45 |
{4 , R.drawable.pyra4} , |
|
46 |
{5 , R.drawable.pyra5} |
|
47 |
}, |
|
48 |
new RubikPyraminxMovement() |
|
49 |
), |
|
36 | 50 |
; |
37 | 51 |
|
38 | 52 |
public static final int NUM_OBJECTS = values().length; |
src/main/java/org/distorted/scores/RubikScores.java | ||
---|---|---|
228 | 228 |
submStr = subStr.substring(comma+1); |
229 | 229 |
|
230 | 230 |
object = RubikObjectList.getOrdinal(nameStr); |
231 |
size = RubikObjectList.getSize(object,Integer.parseInt(sizeStr)); |
|
232 |
time = Long.parseLong(timeStr); |
|
233 |
subm = Integer.parseInt(submStr); |
|
234 | 231 |
|
235 |
if( object>=0 && object< NUM_OBJECTS && size>=0 && size<MAX_SIZE && subm>=0 && subm<=1 )
|
|
232 |
if( object>=0 && object< NUM_OBJECTS ) |
|
236 | 233 |
{ |
237 |
mRecords [object][size][scramble] = time; |
|
238 |
mSubmitted[object][size][scramble] = subm; |
|
239 |
/* |
|
240 |
if( time<NO_RECORD ) |
|
234 |
size = RubikObjectList.getSize(object,Integer.parseInt(sizeStr)); |
|
235 |
time = Long.parseLong(timeStr); |
|
236 |
subm = Integer.parseInt(submStr); |
|
237 |
|
|
238 |
if( size>=0 && size<MAX_SIZE && subm>=0 && subm<=1 ) |
|
239 |
{ |
|
240 |
mRecords [object][size][scramble] = time; |
|
241 |
mSubmitted[object][size][scramble] = subm; |
|
242 |
} |
|
243 |
else |
|
241 | 244 |
{ |
242 |
android.util.Log.e("solv", "Set record for: object="+object+" size="+size+" scramble="+scramble+" time: "+time+" submitted: "+subm);
|
|
245 |
android.util.Log.e("solv", "error: size="+size+" subm="+subm);
|
|
243 | 246 |
} |
244 |
*/ |
|
245 | 247 |
} |
246 | 248 |
else |
247 | 249 |
{ |
248 |
android.util.Log.e("solv", "error: object="+object+" size="+size);
|
|
250 |
android.util.Log.e("solv", "error: object="+object); |
|
249 | 251 |
} |
250 | 252 |
} |
251 | 253 |
} |
... | ... | |
270 | 272 |
{ |
271 | 273 |
if( mRecords[object][size][scramble-1]> timeTaken ) |
272 | 274 |
{ |
273 |
mRecords[object][size][scramble-1] = timeTaken; |
|
275 |
mRecords [object][size][scramble-1] = timeTaken; |
|
276 |
mSubmitted[object][size][scramble-1] = 0; |
|
274 | 277 |
return true; |
275 | 278 |
} |
276 | 279 |
} |
... | ... | |
421 | 424 |
|
422 | 425 |
for(int size=0; size<length; size++) |
423 | 426 |
for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++) |
427 |
{ |
|
424 | 428 |
if( mSubmitted[object][size][scramble]==0 && mRecords[object][size][scramble]<NO_RECORD ) |
425 | 429 |
{ |
426 | 430 |
return true; |
427 | 431 |
} |
432 |
} |
|
428 | 433 |
} |
429 | 434 |
|
430 | 435 |
return false; |
src/main/java/org/distorted/scores/RubikScoresDownloader.java | ||
---|---|---|
39 | 39 |
{ |
40 | 40 |
void receive(String[][][] country, String[][][] name, float[][][] time); |
41 | 41 |
void message(String mess); |
42 |
void serverError(String error);
|
|
42 |
void error(String error);
|
|
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
public static final int MAX_PLACES = 10; |
... | ... | |
131 | 131 |
int begin=-1 ,end, len = mScores.length(); |
132 | 132 |
String row; |
133 | 133 |
|
134 |
if( len==0 ) |
|
135 |
{ |
|
136 |
mReceiver.error("1"); |
|
137 |
return false; |
|
138 |
} |
|
139 |
else if( len==1 ) |
|
140 |
{ |
|
141 |
mReceiver.error(mScores); |
|
142 |
return false; |
|
143 |
} |
|
144 |
|
|
134 | 145 |
for(int i=0; i<mTotal; i++) |
135 | 146 |
for(int j=0; j<MAX_SCRAMBLE; j++) |
136 | 147 |
{ |
... | ... | |
145 | 156 |
try |
146 | 157 |
{ |
147 | 158 |
row = mScores.substring(begin+1,end); |
148 |
|
|
149 |
if( row.length()==1 ) |
|
150 |
{ |
|
151 |
mReceiver.serverError(row); |
|
152 |
return false; |
|
153 |
} |
|
154 |
else |
|
155 |
{ |
|
156 |
fillRow(row); |
|
157 |
} |
|
159 |
fillRow(row); |
|
158 | 160 |
} |
159 | 161 |
catch(Exception ex) |
160 | 162 |
{ |
... | ... | |
242 | 244 |
|
243 | 245 |
private boolean network(String url) |
244 | 246 |
{ |
245 |
android.util.Log.e("down", "url: "+url); |
|
247 |
//android.util.Log.e("down", "url: "+url);
|
|
246 | 248 |
|
247 | 249 |
try |
248 | 250 |
{ |
src/main/java/org/distorted/uistate/RubikStateAbstract.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
public abstract class RubikStateAbstract |
28 | 28 |
{ |
29 |
public static final int BUTTON_ID_BACK= 1023; |
|
29 |
public static final int BUTTON_ID_BACK = 1023; |
|
30 |
public static final int BUTTON_ID_OBJECT= 1022; |
|
30 | 31 |
|
31 | 32 |
abstract void enterState(RubikActivity act); |
32 | 33 |
abstract void leaveState(RubikActivity act); |
src/main/java/org/distorted/uistate/RubikStateMain.java | ||
---|---|---|
75 | 75 |
layoutTop.addView(text); |
76 | 76 |
|
77 | 77 |
// BOT //////////////////////////// |
78 |
LinearLayout layoutBot = act.findViewById(R.id.mainBar); |
|
79 |
layoutBot.removeAllViews(); |
|
78 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
79 |
layoutLeft.removeAllViews(); |
|
80 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
81 |
layoutRight.removeAllViews(); |
|
80 | 82 |
|
81 | 83 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
82 | 84 |
float scale = metrics.density; |
83 |
int size = (int)(60*scale +0.5f); |
|
84 |
int padding = (int)(5*scale + 0.5f); |
|
85 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,size,0.5f); |
|
86 |
|
|
87 |
Button buttonL = new Button(act); |
|
88 |
buttonL.setLayoutParams(params); |
|
89 |
buttonL.setId(BUTTON_ID_BACK); |
|
90 |
buttonL.setPadding(padding,0,padding,0); |
|
91 |
buttonL.setText(R.string.back); |
|
92 |
buttonL.setOnClickListener(act); |
|
93 |
layoutBot.addView(buttonL); |
|
85 |
int size = (int)(60*scale + 0.5f); |
|
86 |
int padding = (int)( 5*scale + 0.5f); |
|
87 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
94 | 88 |
|
95 | 89 |
Button buttonR = new Button(act); |
96 | 90 |
buttonR.setLayoutParams(params); |
... | ... | |
98 | 92 |
buttonR.setPadding(padding,0,padding,0); |
99 | 93 |
buttonR.setText(R.string.exit); |
100 | 94 |
buttonR.setOnClickListener(act); |
101 |
layoutBot.addView(buttonR); |
|
102 |
|
|
103 |
buttonL.setVisibility(INVISIBLE); |
|
95 |
layoutRight.addView(buttonR); |
|
104 | 96 |
} |
105 | 97 |
|
106 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/uistate/RubikStatePlay.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.uistate; |
21 | 21 |
|
22 |
import android.content.Context; |
|
22 | 23 |
import android.content.SharedPreferences; |
23 |
import android.graphics.PorterDuff; |
|
24 |
import android.graphics.drawable.Drawable; |
|
25 |
import android.support.v4.content.ContextCompat; |
|
24 |
import android.graphics.drawable.BitmapDrawable; |
|
26 | 25 |
import android.util.DisplayMetrics; |
26 |
import android.view.Gravity; |
|
27 | 27 |
import android.view.LayoutInflater; |
28 | 28 |
import android.view.View; |
29 |
import android.view.ViewGroup; |
|
30 | 29 |
import android.widget.Button; |
31 | 30 |
import android.widget.ImageButton; |
32 | 31 |
import android.widget.LinearLayout; |
32 |
import android.widget.PopupWindow; |
|
33 | 33 |
|
34 | 34 |
import org.distorted.component.HorizontalNumberPicker; |
35 | 35 |
import org.distorted.magic.R; |
... | ... | |
46 | 46 |
private static final int DEF_OBJECT = RubikObjectList.CUBE.ordinal(); |
47 | 47 |
private static final int DEF_SIZE = 1; // i.e. the second from the list of CUBE's sizes |
48 | 48 |
|
49 |
private ImageButton mObjButton; |
|
50 |
private Button mBackButton; |
|
51 |
private PopupWindow mPopup; |
|
49 | 52 |
private HorizontalNumberPicker mPicker; |
50 | 53 |
private int mPickerValue; |
51 | 54 |
private int mObject = DEF_OBJECT; |
52 | 55 |
private int mSize = DEF_SIZE; |
56 |
private int mLayoutWidth, mLayoutHeight; |
|
57 |
private LinearLayout mLayout; |
|
53 | 58 |
|
54 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 60 |
|
... | ... | |
60 | 65 |
|
61 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 67 |
|
63 |
void enterState(RubikActivity act) |
|
68 |
void enterState(final RubikActivity act)
|
|
64 | 69 |
{ |
65 | 70 |
LayoutInflater inflater = act.getLayoutInflater(); |
66 | 71 |
|
67 | 72 |
// TOP //////////////////////////// |
73 |
final View viewTop = inflater.inflate(R.layout.play_title, null); |
|
74 |
|
|
68 | 75 |
LinearLayout layoutTop = act.findViewById(R.id.mainTitle); |
69 | 76 |
layoutTop.removeAllViews(); |
70 |
|
|
71 |
final View viewTop = inflater.inflate(R.layout.play_title, null); |
|
72 | 77 |
layoutTop.addView(viewTop); |
73 | 78 |
|
74 | 79 |
// BOT //////////////////////////// |
75 |
LinearLayout layoutBot = act.findViewById(R.id.mainBar); |
|
76 |
layoutBot.removeAllViews(); |
|
77 |
|
|
78 | 80 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
79 |
float scale = metrics.density; |
|
80 |
int size = (int)(60*scale + 0.5f); |
|
81 |
int padding = (int)( 3*scale + 0.5f); |
|
82 |
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(size,size); |
|
81 |
final float scale = metrics.density; |
|
82 |
int padding = (int)(3*scale + 0.5f); |
|
83 | 83 |
|
84 |
for(int i=0; i< RubikObjectList.NUM_OBJECTS; i++)
|
|
84 |
if( mObjButton==null )
|
|
85 | 85 |
{ |
86 |
int[] iconIDs = RubikObjectList.getObject(i).getIconIDs(); |
|
87 |
int len = iconIDs.length; |
|
86 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
87 |
mObjButton = new ImageButton(act); |
|
88 |
mObjButton.setLayoutParams(objectParams); |
|
89 |
mObjButton.setId(BUTTON_ID_OBJECT); |
|
90 |
mObjButton.setPadding(padding,0,padding,0); |
|
91 |
mObjButton.setImageResource(R.drawable.cube_menu); |
|
92 |
mObjButton.setOnClickListener(act); |
|
93 |
} |
|
94 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
95 |
layoutLeft.removeAllViews(); |
|
96 |
layoutLeft.addView(mObjButton); |
|
88 | 97 |
|
89 |
for(int s=0; s<len; s++) |
|
90 |
{ |
|
91 |
ImageButton button = new ImageButton(act); |
|
92 |
button.setLayoutParams(params); |
|
93 |
button.setId(RubikObjectList.pack(i,s)); |
|
94 |
button.setPadding(padding,0,padding,0); |
|
95 |
button.setImageResource(iconIDs[s]); |
|
96 |
button.setOnClickListener(act); |
|
97 |
layoutBot.addView(button); |
|
98 |
} |
|
98 |
if( mBackButton==null ) |
|
99 |
{ |
|
100 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
101 |
mBackButton = new Button(act); |
|
102 |
mBackButton.setLayoutParams(backParams); |
|
103 |
mBackButton.setId(BUTTON_ID_BACK); |
|
104 |
mBackButton.setPadding(padding,0,padding,0); |
|
105 |
mBackButton.setText(R.string.back); |
|
106 |
mBackButton.setOnClickListener(act); |
|
99 | 107 |
} |
108 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
109 |
layoutRight.removeAllViews(); |
|
110 |
layoutRight.addView(mBackButton); |
|
100 | 111 |
|
101 |
ViewGroup.LayoutParams params2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,size); |
|
112 |
mPicker = act.findViewById(R.id.rubikNumberPicker); |
|
113 |
mPicker.setMin(MIN_SCRAMBLE); |
|
114 |
mPicker.setMax(MAX_SCRAMBLE); |
|
115 |
mPicker.setValue(mPickerValue); |
|
102 | 116 |
|
103 |
Button button = new Button(act); |
|
104 |
button.setLayoutParams(params2); |
|
105 |
button.setId(BUTTON_ID_BACK); |
|
106 |
button.setPadding(padding,0,padding,0); |
|
107 |
button.setText(R.string.back); |
|
108 |
button.setOnClickListener(act); |
|
109 |
layoutBot.addView(button); |
|
117 |
if( mPopup==null ) |
|
118 |
{ |
|
119 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
120 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
|
121 |
mLayout = layout.findViewById(R.id.popup); |
|
110 | 122 |
|
111 |
markButton(act,mObject,mSize); |
|
123 |
mPopup = new PopupWindow(act); |
|
124 |
mPopup.setContentView(layout); |
|
125 |
mPopup.setFocusable(true); |
|
126 |
int margin = (int)(5*scale + 0.5f); |
|
112 | 127 |
|
113 |
mPicker = act.findViewById(R.id.rubikNumberPicker); |
|
128 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2); |
|
129 |
int cubeWidth = bd.getIntrinsicWidth(); |
|
130 |
int cubeHeight = bd.getIntrinsicHeight(); |
|
114 | 131 |
|
115 |
if( mPicker!=null ) |
|
116 |
{ |
|
117 |
mPicker.setMin(MIN_SCRAMBLE); |
|
118 |
mPicker.setMax(MAX_SCRAMBLE); |
|
119 |
mPicker.setValue(mPickerValue); |
|
132 |
mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f); |
|
133 |
mLayoutHeight= (int)(cubeHeight+ 2*margin + 0.5f); |
|
134 |
|
|
135 |
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++) |
|
136 |
{ |
|
137 |
RubikObjectList list = RubikObjectList.getObject(object); |
|
138 |
int[] sizes = list.getSizes(); |
|
139 |
int[] icons = list.getIconIDs(); |
|
140 |
int len = sizes.length; |
|
141 |
final int obj = object; |
|
142 |
|
|
143 |
for(int i=0; i<len; i++) |
|
144 |
{ |
|
145 |
final int size = i; |
|
146 |
|
|
147 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
148 |
p.setMargins(margin, margin, margin, margin); |
|
149 |
|
|
150 |
ImageButton button = new ImageButton(act); |
|
151 |
button.setLayoutParams(p); |
|
152 |
|
|
153 |
button.setBackgroundResource(icons[i]); |
|
154 |
button.setOnClickListener( new View.OnClickListener() |
|
155 |
{ |
|
156 |
@Override |
|
157 |
public void onClick(View v) |
|
158 |
{ |
|
159 |
mObject = obj; |
|
160 |
mSize = size; |
|
161 |
act.changeObject(obj,size); |
|
162 |
mPopup.dismiss(); |
|
163 |
} |
|
164 |
}); |
|
165 |
|
|
166 |
mLayout.addView(button); |
|
167 |
} |
|
168 |
} |
|
120 | 169 |
} |
121 | 170 |
} |
122 | 171 |
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
|
|
174 |
public void bringUpPopup(RubikActivity act, View view) |
|
175 |
{ |
|
176 |
int total = RubikObjectList.getTotal(); |
|
177 |
boolean vertical = act.isVertical(); |
|
178 |
mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL); |
|
179 |
|
|
180 |
int height = view.getHeight(); |
|
181 |
int width = view.getWidth(); |
|
182 |
int laywid = mLayoutWidth * (vertical? 1:total); |
|
183 |
int layhei = mLayoutHeight* (vertical? total:1); |
|
184 |
|
|
185 |
mPopup.showAsDropDown(view, (width-laywid)/2, -height-layhei, Gravity.LEFT); |
|
186 |
} |
|
187 |
|
|
123 | 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 189 |
|
125 | 190 |
public void savePreferences(SharedPreferences.Editor editor) |
... | ... | |
131 | 196 |
|
132 | 197 |
editor.putInt("statePlay_object", mObject); |
133 | 198 |
editor.putInt("statePlay_size" , mSize); |
199 |
|
|
200 |
mObjButton = null; |
|
201 |
mBackButton= null; |
|
202 |
|
|
203 |
if( mPopup!=null ) |
|
204 |
{ |
|
205 |
mPopup.dismiss(); |
|
206 |
mPopup = null; |
|
207 |
} |
|
134 | 208 |
} |
135 | 209 |
|
136 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
162 | 236 |
{ |
163 | 237 |
return mSize; |
164 | 238 |
} |
165 |
|
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
public void markButton(RubikActivity act, int object, int size) |
|
169 |
{ |
|
170 |
mObject = object; |
|
171 |
mSize = size; |
|
172 |
|
|
173 |
int lookingFor = RubikObjectList.pack(object,size); |
|
174 |
int len = RubikObjectList.getTotal(); |
|
175 |
|
|
176 |
for(int button=0; button<len; button++) |
|
177 |
{ |
|
178 |
Drawable d = act.findViewById(button).getBackground(); |
|
179 |
|
|
180 |
if( button==lookingFor ) |
|
181 |
{ |
|
182 |
d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY); |
|
183 |
} |
|
184 |
else |
|
185 |
{ |
|
186 |
d.clearColorFilter(); |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 | 239 |
} |
src/main/java/org/distorted/uistate/RubikStateSolving.java | ||
---|---|---|
72 | 72 |
layoutTop.addView(mTime); |
73 | 73 |
|
74 | 74 |
// BOT //////////////////////////// |
75 |
LinearLayout layoutBot = act.findViewById(R.id.mainBar); |
|
76 |
layoutBot.removeAllViews(); |
|
75 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
|
76 |
layoutLeft.removeAllViews(); |
|
77 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
|
78 |
layoutRight.removeAllViews(); |
|
77 | 79 |
|
78 | 80 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
79 | 81 |
float scale = metrics.density; |
80 |
int size = (int)(60*scale +0.5f); |
|
81 | 82 |
int padding = (int)(5*scale + 0.5f); |
82 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,size,0.5f); |
|
83 |
|
|
84 |
Button buttonL = new Button(act); |
|
85 |
buttonL.setLayoutParams(params); |
|
86 |
buttonL.setId(BUTTON_ID_BACK); |
|
87 |
buttonL.setPadding(padding,0,padding,0); |
|
88 |
buttonL.setText(R.string.back); |
|
89 |
buttonL.setOnClickListener(act); |
|
90 |
layoutBot.addView(buttonL); |
|
83 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
91 | 84 |
|
92 | 85 |
mBack = new Button(act); |
93 | 86 |
mBack.setLayoutParams(params); |
... | ... | |
95 | 88 |
mBack.setPadding(padding,0,padding,0); |
96 | 89 |
mBack.setText(R.string.back); |
97 | 90 |
mBack.setOnClickListener(act); |
98 |
layoutBot.addView(mBack); |
|
99 |
|
|
100 |
buttonL.setVisibility(android.view.View.INVISIBLE); |
|
91 |
layoutRight.addView(mBack); |
|
101 | 92 |
} |
102 | 93 |
|
103 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/res/layout/dialog_main.xml | ||
---|---|---|
29 | 29 |
android:onClick="Settings" |
30 | 30 |
android:layout_marginLeft="10dp" |
31 | 31 |
android:layout_marginRight="10dp" |
32 |
android:text="@string/settings" />
|
|
32 |
android:text="@string/effects" />
|
|
33 | 33 |
|
34 | 34 |
<Button |
35 | 35 |
android:id="@+id/rubikScores" |
src/main/res/layout/main.xml | ||
---|---|---|
19 | 19 |
android:layout_weight="1" /> |
20 | 20 |
|
21 | 21 |
<LinearLayout |
22 |
android:id="@+id/mainBar" |
|
23 |
android:layout_width="fill_parent" |
|
22 |
android:layout_width="match_parent" |
|
24 | 23 |
android:layout_height="60dp" |
25 |
android:gravity="right" |
|
26 | 24 |
android:orientation="horizontal"> |
25 |
|
|
26 |
<LinearLayout |
|
27 |
android:id="@+id/mainBarLeft" |
|
28 |
android:layout_width="match_parent" |
|
29 |
android:layout_height="match_parent" |
|
30 |
android:layout_weight="1" |
|
31 |
android:orientation="horizontal"> |
|
32 |
</LinearLayout> |
|
33 |
|
|
34 |
<LinearLayout |
|
35 |
android:id="@+id/mainBarRight" |
|
36 |
android:layout_width="match_parent" |
|
37 |
android:layout_height="match_parent" |
|
38 |
android:layout_weight="1" |
|
39 |
android:orientation="horizontal"> |
|
40 |
</LinearLayout> |
|
41 |
|
|
27 | 42 |
</LinearLayout> |
28 | 43 |
|
29 | 44 |
</LinearLayout> |
src/main/res/layout/popup_objects.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="wrap_content" |
|
4 |
android:id="@+id/popup" |
|
5 |
android:layout_height="wrap_content" |
|
6 |
android:orientation="vertical" > |
|
7 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
6 | 6 |
<string name="solve">Solve</string> |
7 | 7 |
<string name="exit">Exit</string> |
8 | 8 |
<string name="play">Play</string> |
9 |
<string name="settings">Settings</string>
|
|
9 |
<string name="effects">Effects</string>
|
|
10 | 10 |
<string name="scores">High Scores</string> |
11 | 11 |
<string name="about">About</string> |
12 | 12 |
<string name="solved">Solved</string> |
Also available in: Unified diff
Change the series of Object buttons in the Play state into a PopupWindow.