Revision ad0c8e0e
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
43 | 43 |
|
44 | 44 |
public class RubikActivity extends AppCompatActivity |
45 | 45 |
{ |
46 |
public static final float PADDING = 0.01f; |
|
47 |
public static final float MARGIN = 0.004f; |
|
46 | 48 |
public static final float BUTTON_TEXT_SIZE = 0.05f; |
47 | 49 |
public static final float TITLE_TEXT_SIZE = 0.06f; |
48 | 50 |
public static final float BITMAP_TEXT_SIZE = 0.09f; |
src/main/java/org/distorted/states/RubikStateDone.java | ||
---|---|---|
49 | 49 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
50 | 50 |
|
51 | 51 |
LayoutInflater inflater = act.getLayoutInflater(); |
52 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
53 |
float scale = metrics.density; |
|
54 | 52 |
|
55 | 53 |
// TOP //////////////////////////// |
56 | 54 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
... | ... | |
67 | 65 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
68 | 66 |
layoutRight.removeAllViews(); |
69 | 67 |
|
70 |
int padding = (int)(5*scale + 0.5f); |
|
68 |
int padding = (int)(width*RubikActivity.PADDING); |
|
69 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
70 |
|
|
71 | 71 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
72 |
params.topMargin = margin; |
|
73 |
params.bottomMargin = margin; |
|
74 |
params.leftMargin = margin; |
|
75 |
params.rightMargin = margin; |
|
72 | 76 |
|
73 | 77 |
Button back = new Button(act); |
74 | 78 |
back.setLayoutParams(params); |
src/main/java/org/distorted/states/RubikStatePattern.java | ||
---|---|---|
113 | 113 |
|
114 | 114 |
// BOT //////////////////////////// |
115 | 115 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
116 |
final float scale = metrics.density; |
|
117 | 116 |
|
118 |
setupPrevButton(act,scale);
|
|
119 |
setupNextButton(act,scale);
|
|
120 |
setupTextView(act,scale);
|
|
117 |
setupPrevButton(act,width);
|
|
118 |
setupNextButton(act,width);
|
|
119 |
setupTextView(act,width);
|
|
121 | 120 |
|
122 | 121 |
setTrioState(false); |
123 | 122 |
|
... | ... | |
127 | 126 |
layoutLeft.addView(mMovesText); |
128 | 127 |
layoutLeft.addView(mNextButton); |
129 | 128 |
|
130 |
setupBackButton(act,scale);
|
|
129 |
setupBackButton(act,width);
|
|
131 | 130 |
|
132 | 131 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
133 | 132 |
layoutRight.removeAllViews(); |
... | ... | |
158 | 157 |
|
159 | 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
160 | 159 |
|
161 |
private void setupBackButton(final RubikActivity act, final float scale)
|
|
160 |
private void setupBackButton(final RubikActivity act, final float width)
|
|
162 | 161 |
{ |
163 |
int padding = (int)(3*scale + 0.5f); |
|
164 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
162 |
int padding = (int)(width*RubikActivity.PADDING); |
|
163 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
164 |
|
|
165 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
166 |
params.topMargin = margin; |
|
167 |
params.bottomMargin = margin; |
|
168 |
params.leftMargin = margin; |
|
169 |
params.rightMargin = margin; |
|
170 |
|
|
165 | 171 |
mBackButton = new Button(act); |
166 |
mBackButton.setLayoutParams(backParams);
|
|
172 |
mBackButton.setLayoutParams(params);
|
|
167 | 173 |
mBackButton.setPadding(padding,0,padding,0); |
168 | 174 |
mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
169 | 175 |
mBackButton.setText(R.string.back); |
... | ... | |
193 | 199 |
|
194 | 200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
195 | 201 |
|
196 |
private void setupPrevButton(final RubikActivity act, final float scale)
|
|
202 |
private void setupPrevButton(final RubikActivity act, final float width)
|
|
197 | 203 |
{ |
198 |
int padding = (int)(3*scale + 0.5f); |
|
204 |
int padding = (int)(width*RubikActivity.PADDING); |
|
205 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
206 |
|
|
199 | 207 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
208 |
params.topMargin = margin; |
|
209 |
params.bottomMargin = margin; |
|
210 |
params.leftMargin = margin; |
|
211 |
params.rightMargin = margin; |
|
212 |
|
|
200 | 213 |
mPrevButton = new ImageButton(act); |
201 | 214 |
mPrevButton.setLayoutParams(params); |
202 | 215 |
mPrevButton.setPadding(padding,0,padding,0); |
... | ... | |
218 | 231 |
|
219 | 232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
220 | 233 |
|
221 |
private void setupNextButton(final RubikActivity act, final float scale)
|
|
234 |
private void setupNextButton(final RubikActivity act, final float width)
|
|
222 | 235 |
{ |
223 |
int padding = (int)( 3*scale + 0.5f); |
|
236 |
int padding = (int)(width*RubikActivity.PADDING); |
|
237 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
238 |
|
|
224 | 239 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
240 |
params.topMargin = margin; |
|
241 |
params.bottomMargin = margin; |
|
242 |
params.leftMargin = margin; |
|
243 |
params.rightMargin = margin; |
|
244 |
|
|
225 | 245 |
mNextButton = new ImageButton(act); |
226 | 246 |
mNextButton.setLayoutParams(params); |
227 | 247 |
mNextButton.setPadding(padding,0,padding,0); |
... | ... | |
243 | 263 |
|
244 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
245 | 265 |
|
246 |
private void setupTextView(final RubikActivity act, final float scale)
|
|
266 |
private void setupTextView(final RubikActivity act, final float width)
|
|
247 | 267 |
{ |
248 |
int padding = (int)( 3*scale + 0.5f); |
|
268 |
int padding = (int)(width*RubikActivity.PADDING); |
|
269 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
270 |
|
|
249 | 271 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
272 |
params.topMargin = margin; |
|
273 |
params.bottomMargin = margin; |
|
274 |
params.leftMargin = margin; |
|
275 |
params.rightMargin = margin; |
|
250 | 276 |
|
251 | 277 |
mMovesText = new TextView(act); |
252 | 278 |
mMovesText.setTextSize(20); |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
103 | 103 |
void enterState(final RubikActivity act) |
104 | 104 |
{ |
105 | 105 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
106 |
final float scale = metrics.density; |
|
107 | 106 |
|
108 | 107 |
float width = act.getScreenWidthInPixels(); |
109 | 108 |
mMenuTextSize = width*RubikActivity.MENU_MEDIUM_TEXT_SIZE; |
... | ... | |
120 | 119 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
121 | 120 |
layoutTop.removeAllViews(); |
122 | 121 |
|
123 |
setupObjectButton(act,scale);
|
|
122 |
setupObjectButton(act,width);
|
|
124 | 123 |
layoutTop.addView(mObjButton); |
125 |
setupLevelSpinner(act,scale);
|
|
124 |
setupLevelSpinner(act,width);
|
|
126 | 125 |
layoutTop.addView(mLevelSpinner); |
127 |
setupPlayButton(act,scale);
|
|
126 |
setupPlayButton(act,width);
|
|
128 | 127 |
layoutTop.addView(mPlayButton); |
129 | 128 |
|
130 |
setupObjectWindow(act, scale);
|
|
129 |
setupObjectWindow(act,width);
|
|
131 | 130 |
|
132 | 131 |
// BOT //////////////////////////// |
133 | 132 |
|
134 | 133 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
135 | 134 |
layoutLeft.removeAllViews(); |
136 | 135 |
|
137 |
setupPrevButton(act,scale,width);
|
|
136 |
setupPrevButton(act,width); |
|
138 | 137 |
layoutLeft.addView(mPrevButton); |
139 |
setupSolveButton(act,scale,width);
|
|
138 |
setupSolveButton(act,width); |
|
140 | 139 |
layoutLeft.addView(mSolveButton); |
141 | 140 |
|
142 | 141 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
143 | 142 |
layoutRight.removeAllViews(); |
144 | 143 |
|
145 |
setupMenuButton(act,scale);
|
|
144 |
setupMenuButton(act,width);
|
|
146 | 145 |
layoutRight.addView(mMenuButton); |
147 | 146 |
|
148 |
setupMenuWindow(act, scale, width);
|
|
147 |
setupMenuWindow(act,width); |
|
149 | 148 |
} |
150 | 149 |
|
151 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
152 | 151 |
|
153 |
private void setupObjectButton(final RubikActivity act, final float scale)
|
|
152 |
private void setupObjectButton(final RubikActivity act, final float width)
|
|
154 | 153 |
{ |
155 |
int padding = (int)(3*scale + 0.5f); |
|
156 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f); |
|
154 |
int padding = (int)(width*RubikActivity.PADDING); |
|
155 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
156 |
|
|
157 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f); |
|
158 |
params.topMargin = margin; |
|
159 |
params.bottomMargin = margin; |
|
160 |
params.leftMargin = margin; |
|
161 |
params.rightMargin = margin; |
|
162 |
|
|
157 | 163 |
mObjButton = new ImageButton(act); |
158 |
mObjButton.setLayoutParams(objectParams);
|
|
164 |
mObjButton.setLayoutParams(params);
|
|
159 | 165 |
mObjButton.setPadding(padding,0,padding,0); |
160 | 166 |
mObjButton.setImageResource(R.drawable.cube_menu); |
161 | 167 |
|
... | ... | |
187 | 193 |
|
188 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
189 | 195 |
|
190 |
private void setupLevelSpinner(final RubikActivity act, final float scale)
|
|
196 |
private void setupLevelSpinner(final RubikActivity act, final float width)
|
|
191 | 197 |
{ |
192 |
int padding = (int)(scale* 10 + 0.5f);
|
|
193 |
int margin = (int)(scale* 3 + 0.5f);
|
|
194 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
|
195 |
spinnerLayoutParams.topMargin = margin;
|
|
196 |
spinnerLayoutParams.bottomMargin = margin;
|
|
197 |
spinnerLayoutParams.leftMargin = margin;
|
|
198 |
spinnerLayoutParams.rightMargin = margin;
|
|
198 |
int padding = (int)(width*RubikActivity.PADDING);
|
|
199 |
int margin = (int)(width*RubikActivity.MARGIN);
|
|
200 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
|
201 |
params.topMargin = margin;
|
|
202 |
params.bottomMargin = margin;
|
|
203 |
params.leftMargin = margin;
|
|
204 |
params.rightMargin = margin;
|
|
199 | 205 |
|
200 | 206 |
mLevelSpinner = new AppCompatSpinner(act); |
201 |
mLevelSpinner.setLayoutParams(spinnerLayoutParams);
|
|
207 |
mLevelSpinner.setLayoutParams(params);
|
|
202 | 208 |
mLevelSpinner.setPadding(padding,0,padding,0); |
203 | 209 |
mLevelSpinner.setBackgroundResource(R.drawable.spinner); |
204 | 210 |
mLevelSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
... | ... | |
234 | 240 |
|
235 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
236 | 242 |
|
237 |
private void setupPlayButton(final RubikActivity act, final float scale)
|
|
243 |
private void setupPlayButton(final RubikActivity act, final float width)
|
|
238 | 244 |
{ |
239 |
int padding = (int)(3*scale + 0.5f); |
|
240 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f); |
|
245 |
int padding = (int)(width*RubikActivity.PADDING); |
|
246 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
247 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f); |
|
248 |
params.topMargin = margin; |
|
249 |
params.bottomMargin = margin; |
|
250 |
params.leftMargin = margin; |
|
251 |
params.rightMargin = margin; |
|
252 |
|
|
241 | 253 |
mPlayButton = new Button(act); |
242 |
mPlayButton.setLayoutParams(backParams);
|
|
254 |
mPlayButton.setLayoutParams(params);
|
|
243 | 255 |
mPlayButton.setPadding(padding,0,padding,0); |
244 | 256 |
mPlayButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
245 | 257 |
mPlayButton.setText(R.string.play); |
... | ... | |
256 | 268 |
|
257 | 269 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
258 | 270 |
|
259 |
private void setupMenuButton(final RubikActivity act, final float scale)
|
|
271 |
private void setupMenuButton(final RubikActivity act, final float width)
|
|
260 | 272 |
{ |
261 |
int padding = (int)(3*scale + 0.5f); |
|
262 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); |
|
273 |
int padding = (int)(width*RubikActivity.PADDING); |
|
274 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
275 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); |
|
276 |
params.topMargin = margin; |
|
277 |
params.bottomMargin = margin; |
|
278 |
params.leftMargin = margin; |
|
279 |
params.rightMargin = margin; |
|
280 |
|
|
263 | 281 |
mMenuButton = new ImageButton(act); |
264 |
mMenuButton.setLayoutParams(objectParams);
|
|
282 |
mMenuButton.setLayoutParams(params);
|
|
265 | 283 |
mMenuButton.setPadding(padding,0,padding,0); |
266 | 284 |
mMenuButton.setImageResource(R.drawable.menu); |
267 | 285 |
|
... | ... | |
283 | 301 |
|
284 | 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
285 | 303 |
|
286 |
private void setupSolveButton(final RubikActivity act, final float scale, final float width)
|
|
304 |
private void setupSolveButton(final RubikActivity act, final float width) |
|
287 | 305 |
{ |
288 |
int padding = (int)(3*scale + 0.5f); |
|
306 |
int padding = (int)(width*RubikActivity.PADDING); |
|
307 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
289 | 308 |
int widthBut = (int)(width/6); |
290 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(widthBut, LinearLayout.LayoutParams.MATCH_PARENT); |
|
309 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(widthBut, LinearLayout.LayoutParams.MATCH_PARENT); |
|
310 |
params.topMargin = margin; |
|
311 |
params.bottomMargin = margin; |
|
312 |
params.leftMargin = margin; |
|
313 |
params.rightMargin = margin; |
|
314 |
|
|
291 | 315 |
mSolveButton = new ImageButton(act); |
292 |
mSolveButton.setLayoutParams(backParams);
|
|
316 |
mSolveButton.setLayoutParams(params);
|
|
293 | 317 |
mSolveButton.setPadding(padding,0,padding,0); |
294 | 318 |
mSolveButton.setImageResource(R.drawable.cube_solve); |
295 | 319 |
|
... | ... | |
306 | 330 |
|
307 | 331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
308 | 332 |
|
309 |
private void setupPrevButton(final RubikActivity act, final float scale, final float width)
|
|
333 |
private void setupPrevButton(final RubikActivity act, final float width) |
|
310 | 334 |
{ |
311 |
int padding = (int)(3*scale + 0.5f); |
|
335 |
int padding = (int)(width*RubikActivity.PADDING); |
|
336 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
312 | 337 |
int widthBut = (int)(width/6); |
313 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(widthBut, LinearLayout.LayoutParams.MATCH_PARENT); |
|
338 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(widthBut, LinearLayout.LayoutParams.MATCH_PARENT); |
|
339 |
params.topMargin = margin; |
|
340 |
params.bottomMargin = margin; |
|
341 |
params.leftMargin = margin; |
|
342 |
params.rightMargin = margin; |
|
343 |
|
|
314 | 344 |
mPrevButton = new ImageButton(act); |
315 |
mPrevButton.setLayoutParams(backParams);
|
|
345 |
mPrevButton.setLayoutParams(params);
|
|
316 | 346 |
mPrevButton.setPadding(padding,0,padding,0); |
317 | 347 |
mPrevButton.setImageResource(R.drawable.cube_back); |
318 | 348 |
|
... | ... | |
329 | 359 |
|
330 | 360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
331 | 361 |
|
332 |
private void setupObjectWindow(final RubikActivity act, final float scale)
|
|
362 |
private void setupObjectWindow(final RubikActivity act, final float width)
|
|
333 | 363 |
{ |
334 | 364 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
335 | 365 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
... | ... | |
338 | 368 |
mObjectPopup = new PopupWindow(act); |
339 | 369 |
mObjectPopup.setContentView(layout); |
340 | 370 |
mObjectPopup.setFocusable(true); |
341 |
int margin = (int)(5*scale + 0.5f);
|
|
371 |
int margin = (int)(width*RubikActivity.PADDING);
|
|
342 | 372 |
|
343 | 373 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2); |
344 | 374 |
int cubeWidth = bd.getIntrinsicWidth(); |
... | ... | |
388 | 418 |
|
389 | 419 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
390 | 420 |
|
391 |
private void setupMenuWindow(final RubikActivity act, final float scale, final float width)
|
|
421 |
private void setupMenuWindow(final RubikActivity act, final float width) |
|
392 | 422 |
{ |
393 | 423 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
394 | 424 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
... | ... | |
397 | 427 |
mMenuPopup = new PopupWindow(act); |
398 | 428 |
mMenuPopup.setContentView(layout); |
399 | 429 |
mMenuPopup.setFocusable(true); |
400 |
int margin = (int)(3*scale + 0.5f);
|
|
401 |
int padding= (int)(7*scale + 0.5f);
|
|
430 |
int margin = (int)(width*RubikActivity.MARGIN);
|
|
431 |
int padding = (int)(width*RubikActivity.PADDING);
|
|
402 | 432 |
|
403 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( (int)width/2 - 2*padding, (int)mMenuItemSize); |
|
404 |
p.setMargins(margin, margin/2, margin, margin/2); |
|
433 |
LinearLayout.LayoutParams p0 = new LinearLayout.LayoutParams( (int)width/2 - 2*padding, (int)mMenuItemSize); |
|
434 |
p0.setMargins(margin, 0, margin, margin); |
|
435 |
LinearLayout.LayoutParams p1 = new LinearLayout.LayoutParams( (int)width/2 - 2*padding, (int)mMenuItemSize); |
|
436 |
p1.setMargins(margin, margin, margin, margin); |
|
405 | 437 |
|
406 | 438 |
for(int i=0; i<NUM_BUTTONS; i++) |
407 | 439 |
{ |
408 | 440 |
final int but = i; |
409 | 441 |
Button button = new Button(act); |
410 |
button.setLayoutParams(p);
|
|
442 |
button.setLayoutParams(i==0 ? p1:p0);
|
|
411 | 443 |
button.setText(BUTTON_LABELS[i]); |
412 | 444 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
413 | 445 |
|
... | ... | |
424 | 456 |
mMenuLayout.addView(button); |
425 | 457 |
} |
426 | 458 |
|
427 |
mMenuLayoutHeight= (int)(NUM_BUTTONS*(mMenuItemSize+margin)); |
|
459 |
mMenuLayoutHeight= (int)(margin + NUM_BUTTONS*(mMenuItemSize+margin));
|
|
428 | 460 |
} |
429 | 461 |
|
430 | 462 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/states/RubikStateReady.java | ||
---|---|---|
20 | 20 |
package org.distorted.states; |
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 |
import android.util.DisplayMetrics; |
|
24 | 23 |
import android.util.TypedValue; |
25 | 24 |
import android.view.LayoutInflater; |
26 | 25 |
import android.view.View; |
... | ... | |
54 | 53 |
float titleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
55 | 54 |
|
56 | 55 |
LayoutInflater inflater = act.getLayoutInflater(); |
57 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
58 |
float scale = metrics.density; |
|
59 | 56 |
|
60 | 57 |
// TOP //////////////////////////// |
61 | 58 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
... | ... | |
69 | 66 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
70 | 67 |
layoutLeft.removeAllViews(); |
71 | 68 |
|
72 |
setupPrevMoveButtom(act,scale,width);
|
|
69 |
setupPrevMoveButtom(act,width); |
|
73 | 70 |
layoutLeft.addView(mPrevButton); |
74 | 71 |
|
75 | 72 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
76 | 73 |
layoutRight.removeAllViews(); |
77 | 74 |
|
78 |
int padding = (int)(5*scale + 0.5f); |
|
75 |
int padding = (int)(width*RubikActivity.PADDING); |
|
76 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
79 | 77 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
78 |
params.topMargin = margin; |
|
79 |
params.bottomMargin = margin; |
|
80 |
params.leftMargin = margin; |
|
81 |
params.rightMargin = margin; |
|
80 | 82 |
|
81 | 83 |
Button back = new Button(act); |
82 | 84 |
back.setLayoutParams(params); |
... | ... | |
98 | 100 |
|
99 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 102 |
|
101 |
private void setupPrevMoveButtom(final RubikActivity act, float scale, float width)
|
|
103 |
private void setupPrevMoveButtom(final RubikActivity act, float width) |
|
102 | 104 |
{ |
103 |
int padding = (int)( 3*scale + 0.5f);
|
|
105 |
int padding = (int)(width*RubikActivity.PADDING);
|
|
104 | 106 |
int widthBut= (int)(width/6); |
105 | 107 |
|
106 | 108 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(widthBut,LinearLayout.LayoutParams.MATCH_PARENT); |
src/main/java/org/distorted/states/RubikStateSolution.java | ||
---|---|---|
20 | 20 |
package org.distorted.states; |
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 |
import android.util.DisplayMetrics; |
|
24 | 23 |
import android.util.TypedValue; |
25 | 24 |
import android.view.Gravity; |
26 | 25 |
import android.view.LayoutInflater; |
... | ... | |
66 | 65 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
67 | 66 |
mTitleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
68 | 67 |
|
69 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
70 |
final float scale = metrics.density; |
|
71 | 68 |
LayoutInflater inflater = act.getLayoutInflater(); |
72 | 69 |
|
73 | 70 |
// TOP //////////////////////////// |
... | ... | |
80 | 77 |
layoutTop.addView(text); |
81 | 78 |
|
82 | 79 |
// BOT //////////////////////////// |
83 |
setupPrevButton(act,scale);
|
|
84 |
setupNextButton(act,scale);
|
|
85 |
setupTextView(act,scale);
|
|
80 |
setupPrevButton(act,width);
|
|
81 |
setupNextButton(act,width);
|
|
82 |
setupTextView(act,width);
|
|
86 | 83 |
|
87 | 84 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
88 | 85 |
layoutLeft.removeAllViews(); |
... | ... | |
90 | 87 |
layoutLeft.addView(mMovesText); |
91 | 88 |
layoutLeft.addView(mNextButton); |
92 | 89 |
|
93 |
setupBackButton(act,scale);
|
|
90 |
setupBackButton(act,width);
|
|
94 | 91 |
|
95 | 92 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
96 | 93 |
layoutRight.removeAllViews(); |
... | ... | |
99 | 96 |
|
100 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
101 | 98 |
|
102 |
private void setupPrevButton(final RubikActivity act, final float scale)
|
|
99 |
private void setupPrevButton(final RubikActivity act, final float width)
|
|
103 | 100 |
{ |
104 |
int padding = (int)(3*scale + 0.5f); |
|
101 |
int padding = (int)(width*RubikActivity.PADDING); |
|
102 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
105 | 103 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
104 |
params.topMargin = margin; |
|
105 |
params.bottomMargin = margin; |
|
106 |
params.leftMargin = margin; |
|
107 |
params.rightMargin = margin; |
|
108 |
|
|
106 | 109 |
mPrevButton = new ImageButton(act); |
107 | 110 |
mPrevButton.setLayoutParams(params); |
108 | 111 |
mPrevButton.setPadding(padding,0,padding,0); |
... | ... | |
122 | 125 |
|
123 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 127 |
|
125 |
private void setupNextButton(final RubikActivity act, final float scale)
|
|
128 |
private void setupNextButton(final RubikActivity act, final float width)
|
|
126 | 129 |
{ |
127 |
int padding = (int)( 3*scale + 0.5f); |
|
130 |
int padding = (int)(width*RubikActivity.PADDING); |
|
131 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
128 | 132 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
133 |
params.topMargin = margin; |
|
134 |
params.bottomMargin = margin; |
|
135 |
params.leftMargin = margin; |
|
136 |
params.rightMargin = margin; |
|
137 |
|
|
129 | 138 |
mNextButton = new ImageButton(act); |
130 | 139 |
mNextButton.setLayoutParams(params); |
131 | 140 |
mNextButton.setPadding(padding,0,padding,0); |
... | ... | |
145 | 154 |
|
146 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
147 | 156 |
|
148 |
private void setupTextView(final RubikActivity act, final float scale)
|
|
157 |
private void setupTextView(final RubikActivity act, final float width)
|
|
149 | 158 |
{ |
150 |
int padding = (int)( 3*scale + 0.5f); |
|
159 |
int padding = (int)(width*RubikActivity.PADDING); |
|
160 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
151 | 161 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
162 |
params.topMargin = margin; |
|
163 |
params.bottomMargin = margin; |
|
164 |
params.leftMargin = margin; |
|
165 |
params.rightMargin = margin; |
|
152 | 166 |
|
153 | 167 |
mMovesText = new TextView(act); |
154 | 168 |
mMovesText.setTextSize(20); |
... | ... | |
161 | 175 |
|
162 | 176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
163 | 177 |
|
164 |
private void setupBackButton(final RubikActivity act, final float scale)
|
|
178 |
private void setupBackButton(final RubikActivity act, final float width)
|
|
165 | 179 |
{ |
166 |
int padding = (int)(3*scale + 0.5f); |
|
167 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
180 |
int padding = (int)(width*RubikActivity.PADDING); |
|
181 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
182 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
183 |
params.topMargin = margin; |
|
184 |
params.bottomMargin = margin; |
|
185 |
params.leftMargin = margin; |
|
186 |
params.rightMargin = margin; |
|
187 |
|
|
168 | 188 |
mBackButton = new Button(act); |
169 |
mBackButton.setLayoutParams(backParams);
|
|
189 |
mBackButton.setLayoutParams(params);
|
|
170 | 190 |
mBackButton.setPadding(padding,0,padding,0); |
171 | 191 |
mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
172 | 192 |
mBackButton.setText(R.string.back); |
src/main/java/org/distorted/states/RubikStateSolver.java | ||
---|---|---|
27 | 27 |
import android.graphics.drawable.Drawable; |
28 | 28 |
import android.os.Bundle; |
29 | 29 |
import androidx.core.content.ContextCompat; |
30 |
import android.util.DisplayMetrics; |
|
31 | 30 |
import android.util.TypedValue; |
32 | 31 |
import android.view.View; |
33 | 32 |
import android.widget.Button; |
... | ... | |
93 | 92 |
mFaceColors = RubikObjectList.retFaceColors(mCurrentObject); |
94 | 93 |
mNumFaces = mFaceColors!=null ? mFaceColors.length : 0; |
95 | 94 |
|
96 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
97 |
final float scale = metrics.density; |
|
98 |
|
|
99 | 95 |
// TOP //////////////////////////// |
100 | 96 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
101 | 97 |
layoutTop.removeAllViews(); |
... | ... | |
103 | 99 |
if( mNumFaces>0 ) |
104 | 100 |
{ |
105 | 101 |
setupBitmaps(); |
106 |
setupColorButtons(act,scale);
|
|
102 |
setupColorButtons(act,width);
|
|
107 | 103 |
markButton(act); |
108 | 104 |
} |
109 | 105 |
|
110 | 106 |
for(ImageButton button: mColorButton) layoutTop.addView(button); |
111 | 107 |
|
112 | 108 |
// BOT //////////////////////////// |
113 |
setupSolveButton(act,scale);
|
|
109 |
setupSolveButton(act,width);
|
|
114 | 110 |
|
115 | 111 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
116 | 112 |
layoutLeft.removeAllViews(); |
117 | 113 |
layoutLeft.addView(mSolveButton); |
118 | 114 |
|
119 |
setupBackButton(act,scale);
|
|
115 |
setupBackButton(act,width);
|
|
120 | 116 |
|
121 | 117 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
122 | 118 |
layoutRight.removeAllViews(); |
... | ... | |
156 | 152 |
|
157 | 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
158 | 154 |
|
159 |
private void setupColorButtons(final RubikActivity act, final float scale)
|
|
155 |
private void setupColorButtons(final RubikActivity act, final float width)
|
|
160 | 156 |
{ |
161 | 157 |
mColorButton = new ImageButton[mNumFaces]; |
158 |
int padding = (int)(width*RubikActivity.PADDING); |
|
159 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
162 | 160 |
|
163 | 161 |
for(int i=0; i<mNumFaces; i++) |
164 | 162 |
{ |
165 | 163 |
final int ii = i; |
166 |
int padding = (int)(3*scale + 0.5f); |
|
167 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
|
164 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); |
|
165 |
params.topMargin = margin; |
|
166 |
params.bottomMargin = margin; |
|
167 |
params.leftMargin = margin; |
|
168 |
params.rightMargin = margin; |
|
169 |
|
|
168 | 170 |
mColorButton[i] = new ImageButton(act); |
169 |
mColorButton[i].setLayoutParams(objectParams);
|
|
171 |
mColorButton[i].setLayoutParams(params);
|
|
170 | 172 |
mColorButton[i].setPadding(padding,0,padding,0); |
171 | 173 |
mColorButton[i].setImageBitmap(mBitmap[i]); |
172 | 174 |
|
... | ... | |
184 | 186 |
|
185 | 187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
186 | 188 |
|
187 |
private void setupSolveButton(final RubikActivity act, final float scale)
|
|
189 |
private void setupSolveButton(final RubikActivity act, final float width)
|
|
188 | 190 |
{ |
189 |
int padding = (int)(3*scale + 0.5f); |
|
190 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
191 |
int padding = (int)(width*RubikActivity.PADDING); |
|
192 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
193 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
194 |
params.topMargin = margin; |
|
195 |
params.bottomMargin = margin; |
|
196 |
params.leftMargin = margin; |
|
197 |
params.rightMargin = margin; |
|
198 |
|
|
191 | 199 |
mSolveButton = new Button(act); |
192 |
mSolveButton.setLayoutParams(backParams);
|
|
200 |
mSolveButton.setLayoutParams(params);
|
|
193 | 201 |
mSolveButton.setPadding(padding,0,padding,0); |
194 | 202 |
mSolveButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
195 | 203 |
mSolveButton.setText(R.string.solve); |
... | ... | |
213 | 221 |
|
214 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 | 223 |
|
216 |
private void setupBackButton(final RubikActivity act, final float scale)
|
|
224 |
private void setupBackButton(final RubikActivity act, final float width)
|
|
217 | 225 |
{ |
218 |
int padding = (int)(3*scale + 0.5f); |
|
219 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
226 |
int padding = (int)(width*RubikActivity.PADDING); |
|
227 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
228 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
229 |
params.topMargin = margin; |
|
230 |
params.bottomMargin = margin; |
|
231 |
params.leftMargin = margin; |
|
232 |
params.rightMargin = margin; |
|
233 |
|
|
220 | 234 |
mBackButton = new Button(act); |
221 |
mBackButton.setLayoutParams(backParams);
|
|
235 |
mBackButton.setLayoutParams(params);
|
|
222 | 236 |
mBackButton.setPadding(padding,0,padding,0); |
223 | 237 |
mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize); |
224 | 238 |
mBackButton.setText(R.string.back); |
src/main/java/org/distorted/states/RubikStateSolving.java | ||
---|---|---|
20 | 20 |
package org.distorted.states; |
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 |
import android.util.DisplayMetrics; |
|
24 | 23 |
import android.util.TypedValue; |
25 | 24 |
import android.view.LayoutInflater; |
26 | 25 |
import android.view.View; |
... | ... | |
98 | 97 |
else mMoves.clear(); |
99 | 98 |
|
100 | 99 |
LayoutInflater inflater = act.getLayoutInflater(); |
101 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
102 |
float scale = metrics.density; |
|
103 | 100 |
|
104 | 101 |
// TOP //////////////////////////// |
105 | 102 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
... | ... | |
114 | 111 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft); |
115 | 112 |
layoutLeft.removeAllViews(); |
116 | 113 |
|
117 |
setupPrevMoveButtom(act,scale,width);
|
|
114 |
setupPrevMoveButtom(act,width); |
|
118 | 115 |
layoutLeft.addView(mPrevButton); |
119 | 116 |
|
120 | 117 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight); |
121 | 118 |
layoutRight.removeAllViews(); |
122 | 119 |
|
123 |
int padding = (int)(5*scale + 0.5f); |
|
120 |
int padding = (int)(width*RubikActivity.PADDING); |
|
121 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
124 | 122 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
123 |
params.topMargin = margin; |
|
124 |
params.bottomMargin = margin; |
|
125 |
params.leftMargin = margin; |
|
126 |
params.rightMargin = margin; |
|
125 | 127 |
|
126 | 128 |
Button back = new Button(act); |
127 | 129 |
back.setLayoutParams(params); |
... | ... | |
143 | 145 |
|
144 | 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
145 | 147 |
|
146 |
private void setupPrevMoveButtom(final RubikActivity act, float scale, float width)
|
|
148 |
private void setupPrevMoveButtom(final RubikActivity act, float width) |
|
147 | 149 |
{ |
148 |
int padding = (int)( 3*scale + 0.5f); |
|
150 |
int padding = (int)(width*RubikActivity.PADDING); |
|
151 |
int margin = (int)(width*RubikActivity.MARGIN); |
|
149 | 152 |
int widthBut= (int)(width/6); |
150 | 153 |
|
151 | 154 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(widthBut,LinearLayout.LayoutParams.MATCH_PARENT); |
155 |
params.topMargin = margin; |
|
156 |
params.bottomMargin = margin; |
|
157 |
params.leftMargin = margin; |
|
158 |
params.rightMargin = margin; |
|
159 |
|
|
152 | 160 |
mPrevButton = new ImageButton(act); |
153 | 161 |
mPrevButton.setLayoutParams(params); |
154 | 162 |
mPrevButton.setPadding(padding,0,padding,0); |
Also available in: Unified diff
Make the margins and paddings proportional to screen size.