33 |
33 |
import android.widget.AdapterView;
|
34 |
34 |
import android.widget.ArrayAdapter;
|
35 |
35 |
import android.widget.Button;
|
|
36 |
import android.widget.GridLayout;
|
36 |
37 |
import android.widget.ImageButton;
|
37 |
38 |
import android.widget.LinearLayout;
|
38 |
39 |
import android.widget.PopupWindow;
|
... | ... | |
69 |
70 |
private PopupWindow mObjectPopup, mMenuPopup;
|
70 |
71 |
private int mObject = DEF_OBJECT;
|
71 |
72 |
private int mSize = DEF_SIZE;
|
72 |
|
private int mObjectLayoutWidth, mMenuLayoutWidth, mMenuLayoutHeight;
|
73 |
|
private LinearLayout mObjectLayout, mMenuLayout;
|
|
73 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight;
|
|
74 |
private GridLayout mObjectGrid;
|
74 |
75 |
private AppCompatSpinner mLevelSpinner;
|
75 |
76 |
private ArrayAdapter<String> mSpinnerAdapter;
|
76 |
77 |
private int mLevelValue;
|
77 |
78 |
private int mBarHeight;
|
78 |
|
private float mButtonSize, mTitleSize, mMenuItemSize, mMenuTextSize;
|
|
79 |
private float mButtonSize, mMenuItemSize, mMenuTextSize;
|
|
80 |
private int mColCount, mRowCount;
|
79 |
81 |
|
80 |
82 |
private ArrayList<Move> mMoves;
|
81 |
83 |
private boolean mCanPrevMove;
|
... | ... | |
106 |
108 |
float width = act.getScreenWidthInPixels();
|
107 |
109 |
mMenuTextSize = width*RubikActivity.MENU_MEDIUM_TEXT_SIZE;
|
108 |
110 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
109 |
|
mTitleSize = width*RubikActivity.TITLE_TEXT_SIZE;
|
110 |
111 |
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
|
111 |
112 |
|
112 |
113 |
mCanPrevMove = true;
|
... | ... | |
114 |
115 |
if( mMoves==null ) mMoves = new ArrayList<>();
|
115 |
116 |
else mMoves.clear();
|
116 |
117 |
|
|
118 |
mRowCount = RubikObjectList.getRowCount();
|
|
119 |
mColCount = RubikObjectList.getColumnCount();
|
|
120 |
|
117 |
121 |
// TOP ////////////////////////////
|
118 |
122 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
119 |
123 |
layoutTop.removeAllViews();
|
... | ... | |
147 |
151 |
|
148 |
152 |
private void setupObjectButton(final RubikActivity act, final float width)
|
149 |
153 |
{
|
150 |
|
int padding = (int)(width*RubikActivity.PADDING);
|
151 |
|
int margin = (int)(width*RubikActivity.MARGIN);
|
152 |
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
|
|
154 |
final int padding = (int)(width*RubikActivity.PADDING);
|
|
155 |
final int margin = (int)(width*RubikActivity.MARGIN);
|
|
156 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
|
153 |
157 |
|
154 |
158 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.2f);
|
155 |
159 |
params.topMargin = margin;
|
... | ... | |
169 |
173 |
{
|
170 |
174 |
if( act.getPreRender().canPlay() )
|
171 |
175 |
{
|
172 |
|
int total = RubikObjectList.getTotal();
|
173 |
176 |
boolean vertical = act.isVertical();
|
174 |
|
mObjectLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
|
175 |
|
|
176 |
|
int width = view.getWidth();
|
177 |
|
int layhei = mObjectLayoutWidth * (vertical? total:1);
|
178 |
|
int laywid = mObjectLayoutWidth * (vertical? 1:total);
|
179 |
|
|
180 |
|
mObjectPopup.showAsDropDown(view, (width-laywid)/2, 0, Gravity.LEFT);
|
|
177 |
mObjectGrid.setOrientation(vertical ? GridLayout.VERTICAL:GridLayout.HORIZONTAL);
|
|
178 |
mObjectPopup.showAsDropDown(view, 0, margin, Gravity.LEFT);
|
181 |
179 |
|
182 |
180 |
if( android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 )
|
183 |
181 |
{
|
|
182 |
int layhei = mObjectSize * (vertical? mRowCount:mColCount);
|
|
183 |
int laywid = mObjectSize * (vertical? mColCount:mRowCount);
|
184 |
184 |
mObjectPopup.update(view, laywid, layhei);
|
185 |
185 |
}
|
186 |
186 |
}
|
... | ... | |
373 |
373 |
{
|
374 |
374 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
375 |
375 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
376 |
|
mObjectLayout = layout.findViewById(R.id.popup);
|
|
376 |
mObjectGrid = layout.findViewById(R.id.objectGrid);
|
|
377 |
|
|
378 |
int[] indices = RubikObjectList.getIndices();
|
|
379 |
|
|
380 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
|
381 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
|
382 |
|
|
383 |
mObjectGrid.setColumnCount(mColCount);
|
|
384 |
mObjectGrid.setRowCount(mRowCount);
|
|
385 |
|
|
386 |
for(int row=0; row<mRowCount; row++)
|
|
387 |
{
|
|
388 |
rowSpecs[row] = GridLayout.spec(row);
|
|
389 |
}
|
|
390 |
for(int col=0; col<mColCount; col++)
|
|
391 |
{
|
|
392 |
colSpecs[col] = GridLayout.spec(col);
|
|
393 |
}
|
377 |
394 |
|
378 |
395 |
mObjectPopup = new PopupWindow(act);
|
379 |
396 |
mObjectPopup.setContentView(layout);
|
380 |
397 |
mObjectPopup.setFocusable(true);
|
381 |
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
382 |
398 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);
|
383 |
399 |
|
384 |
400 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
|
385 |
|
int cubeWidth = bd.getIntrinsicWidth();
|
386 |
|
mObjectLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
|
387 |
|
|
388 |
|
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
|
389 |
|
p.setMargins(margin, margin, margin, margin);
|
|
401 |
int cubeWidth = bd.getIntrinsicWidth();
|
|
402 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
|
403 |
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
|
390 |
404 |
|
391 |
405 |
for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
392 |
406 |
{
|
... | ... | |
398 |
412 |
|
399 |
413 |
for(int i=0; i<len; i++)
|
400 |
414 |
{
|
401 |
|
final int size = i;
|
|
415 |
final int index = i;
|
402 |
416 |
|
403 |
417 |
ImageButton button = new ImageButton(act);
|
404 |
|
button.setLayoutParams(p);
|
405 |
|
|
406 |
418 |
button.setBackgroundResource(icons[i]);
|
407 |
419 |
button.setOnClickListener( new View.OnClickListener()
|
408 |
420 |
{
|
... | ... | |
412 |
424 |
if( act.getPreRender().canPlay() && RubikState.getCurrentState()==RubikState.PLAY )
|
413 |
425 |
{
|
414 |
426 |
mObject = obj;
|
415 |
|
mSize = sizes[size];
|
416 |
|
act.changeObject(list,sizes[size], true);
|
|
427 |
mSize = sizes[index];
|
|
428 |
act.changeObject(list,sizes[index], true);
|
417 |
429 |
adjustSpinner(act);
|
418 |
430 |
mMoves.clear();
|
419 |
431 |
}
|
... | ... | |
422 |
434 |
}
|
423 |
435 |
});
|
424 |
436 |
|
425 |
|
mObjectLayout.addView(button);
|
|
437 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[index],colSpecs[indices[object]]);
|
|
438 |
params.bottomMargin = margin;
|
|
439 |
params.topMargin = margin;
|
|
440 |
params.leftMargin = margin;
|
|
441 |
params.rightMargin = margin;
|
|
442 |
|
|
443 |
mObjectGrid.addView(button, params);
|
426 |
444 |
}
|
427 |
445 |
}
|
428 |
446 |
}
|
... | ... | |
432 |
450 |
private void setupMenuWindow(final RubikActivity act, final float width)
|
433 |
451 |
{
|
434 |
452 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
435 |
|
final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
|
436 |
|
mMenuLayout = layout.findViewById(R.id.popup);
|
|
453 |
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
|
454 |
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
|
437 |
455 |
|
438 |
456 |
mMenuPopup = new PopupWindow(act);
|
439 |
457 |
mMenuPopup.setContentView(layout);
|
... | ... | |
464 |
482 |
}
|
465 |
483 |
});
|
466 |
484 |
|
467 |
|
mMenuLayout.addView(button);
|
|
485 |
menuLayout.addView(button);
|
468 |
486 |
}
|
469 |
487 |
|
470 |
488 |
mMenuLayoutWidth = (int)(width/2);
|
Make the ObjectPopup a 2D grid.