Revision 88fb92ba
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
46 | 46 |
public static final float BUTTON_TEXT_SIZE = 0.05f; |
47 | 47 |
public static final float TITLE_TEXT_SIZE = 0.06f; |
48 | 48 |
public static final float BITMAP_TEXT_SIZE = 0.09f; |
49 |
public static final float MENU_ITEM_SIZE = 0.12f; |
|
49 | 50 |
|
50 | 51 |
public static final float MENU_BIG_TEXT_SIZE = 0.05f; |
51 | 52 |
public static final float MENU_MEDIUM_TEXT_SIZE= 0.04f; |
... | ... | |
53 | 54 |
|
54 | 55 |
private boolean mJustStarted; |
55 | 56 |
private FirebaseAnalytics mFirebaseAnalytics; |
56 |
private float mScreenWidth;
|
|
57 |
private int mScreenWidth, mScreenHeight;
|
|
57 | 58 |
|
58 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 | 60 |
|
... | ... | |
69 | 70 |
|
70 | 71 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
71 | 72 |
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
72 |
mScreenWidth=displaymetrics.widthPixels; |
|
73 |
mScreenWidth =displaymetrics.widthPixels; |
|
74 |
mScreenHeight=displaymetrics.heightPixels; |
|
73 | 75 |
} |
74 | 76 |
|
75 | 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
221 | 223 |
|
222 | 224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
223 | 225 |
|
224 |
public float getScreenWidthInPixels()
|
|
226 |
public int getScreenWidthInPixels()
|
|
225 | 227 |
{ |
226 | 228 |
return mScreenWidth; |
227 | 229 |
} |
228 | 230 |
|
231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
232 |
|
|
233 |
public int getScreenHeightInPixels() |
|
234 |
{ |
|
235 |
return mScreenHeight; |
|
236 |
} |
|
237 |
|
|
229 | 238 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
230 | 239 |
|
231 | 240 |
public RubikPreRender getPreRender() |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
74 | 74 |
private AppCompatSpinner mLevelSpinner; |
75 | 75 |
private ArrayAdapter<String> mSpinnerAdapter; |
76 | 76 |
private int mLevelValue; |
77 |
private float mButtonSize, mTitleSize; |
|
77 |
private float mButtonSize, mTitleSize, mMenuItemSize, mMenuTextSize;
|
|
78 | 78 |
|
79 | 79 |
private ArrayList<Move> mMoves; |
80 | 80 |
private boolean mCanPrevMove; |
... | ... | |
106 | 106 |
final float scale = metrics.density; |
107 | 107 |
|
108 | 108 |
float width = act.getScreenWidthInPixels(); |
109 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
|
110 |
mTitleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
|
109 |
mMenuTextSize = width*RubikActivity.MENU_MEDIUM_TEXT_SIZE; |
|
110 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
|
111 |
mTitleSize = width*RubikActivity.TITLE_TEXT_SIZE; |
|
112 |
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE; |
|
111 | 113 |
|
112 | 114 |
mCanPrevMove = true; |
113 | 115 |
|
... | ... | |
143 | 145 |
setupMenuButton(act,scale); |
144 | 146 |
layoutRight.addView(mMenuButton); |
145 | 147 |
|
146 |
setupMenuWindow(act, scale); |
|
148 |
setupMenuWindow(act, scale, width);
|
|
147 | 149 |
} |
148 | 150 |
|
149 | 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
263 | 265 |
mMenuButton.setPadding(padding,0,padding,0); |
264 | 266 |
mMenuButton.setImageResource(R.drawable.menu); |
265 | 267 |
|
268 |
final int barHeight = act.getScreenHeightInPixels()/10; |
|
269 |
|
|
266 | 270 |
mMenuButton.setOnClickListener( new View.OnClickListener() |
267 | 271 |
{ |
268 | 272 |
@Override |
... | ... | |
270 | 274 |
{ |
271 | 275 |
if( act.getPreRender().canPlay() ) |
272 | 276 |
{ |
273 |
int total = RubikObjectList.getTotal(); |
|
274 |
boolean vertical = act.isVertical(); |
|
275 |
mMenuLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL); |
|
276 |
|
|
277 |
mMenuPopup.showAsDropDown(view, 0, -3*mMenuLayoutHeight, Gravity.LEFT); |
|
277 |
mMenuPopup.showAsDropDown(view, 0, -mMenuLayoutHeight-barHeight, Gravity.LEFT); |
|
278 | 278 |
mMenuPopup.update(); |
279 | 279 |
} |
280 | 280 |
} |
... | ... | |
387 | 387 |
|
388 | 388 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
389 | 389 |
|
390 |
private void setupMenuWindow(final RubikActivity act, final float scale) |
|
390 |
private void setupMenuWindow(final RubikActivity act, final float scale, final float width)
|
|
391 | 391 |
{ |
392 | 392 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
393 | 393 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
... | ... | |
396 | 396 |
mMenuPopup = new PopupWindow(act); |
397 | 397 |
mMenuPopup.setContentView(layout); |
398 | 398 |
mMenuPopup.setFocusable(true); |
399 |
int margin = (int)(5*scale + 0.5f); |
|
399 |
int margin = (int)(3*scale + 0.5f); |
|
400 |
int padding= (int)(7*scale + 0.5f); |
|
400 | 401 |
|
401 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
402 |
p.setMargins(margin, margin, margin, margin);
|
|
402 |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( (int)width/2 - 2*padding, (int)mMenuItemSize);
|
|
403 |
p.setMargins(margin, margin/2, margin, margin/2);
|
|
403 | 404 |
|
404 | 405 |
for(int i=0; i<NUM_BUTTONS; i++) |
405 | 406 |
{ |
... | ... | |
407 | 408 |
Button button = new Button(act); |
408 | 409 |
button.setLayoutParams(p); |
409 | 410 |
button.setText(BUTTON_LABELS[i]); |
411 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
|
410 | 412 |
|
411 | 413 |
button.setOnClickListener( new View.OnClickListener() |
412 | 414 |
{ |
... | ... | |
421 | 423 |
mMenuLayout.addView(button); |
422 | 424 |
} |
423 | 425 |
|
424 |
mMenuLayoutHeight= (int)(margin + NUM_BUTTONS*(mButtonSize+margin));
|
|
426 |
mMenuLayoutHeight= (int)(NUM_BUTTONS*(mMenuItemSize+margin));
|
|
425 | 427 |
} |
426 | 428 |
|
427 | 429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
452 | 454 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
453 | 455 |
} |
454 | 456 |
} |
455 |
else |
|
456 |
{ |
|
457 |
android.util.Log.e("solv", "error: no moves to back!"); |
|
458 |
} |
|
459 | 457 |
} |
460 | 458 |
} |
461 | 459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/states/RubikStateSolving.java | ||
---|---|---|
193 | 193 |
android.util.Log.e("solution", "error: trying to back move of angle 0"); |
194 | 194 |
} |
195 | 195 |
} |
196 |
else |
|
197 |
{ |
|
198 |
android.util.Log.e("solv", "error: no moves to back!"); |
|
199 |
} |
|
200 | 196 |
} |
201 | 197 |
} |
202 | 198 |
|
src/main/res/layout/main.xml | ||
---|---|---|
20 | 20 |
android:layout_weight="1" /> |
21 | 21 |
|
22 | 22 |
<LinearLayout |
23 |
android:id="@+id/lowerBar" |
|
23 | 24 |
android:layout_width="match_parent" |
24 | 25 |
android:layout_height="0dp" |
25 | 26 |
android:layout_weight="0.1" |
Also available in: Unified diff
Improvements to the Menu.