1 |
1c04d054
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2023 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.main;
|
11 |
|
|
|
12 |
b42c8399
|
leszek
|
import android.util.DisplayMetrics;
|
13 |
1c04d054
|
leszek
|
import android.view.View;
|
14 |
|
|
import android.widget.GridLayout;
|
15 |
|
|
import android.widget.ImageButton;
|
16 |
|
|
|
17 |
|
|
import org.distorted.helpers.PopupCreator;
|
18 |
|
|
import org.distorted.objects.RubikObject;
|
19 |
|
|
import org.distorted.objects.RubikObjectList;
|
20 |
|
|
|
21 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
22 |
|
|
|
23 |
|
|
public class MainScrollGrid
|
24 |
|
|
{
|
25 |
b42c8399
|
leszek
|
public static final int NUM_COLUMNS = 5;
|
26 |
|
|
public static final float POPUP_PADDING= 0.035f;
|
27 |
|
|
public static final float POPUP_MARGIN = 0.024f;
|
28 |
1c04d054
|
leszek
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
b45b986a
|
leszek
|
void createGrid(final MainActivity act, int windowWidth)
|
32 |
1c04d054
|
leszek
|
{
|
33 |
|
|
int numObjects = RubikObjectList.getNumObjects();
|
34 |
|
|
int rowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
|
35 |
|
|
int colCount = NUM_COLUMNS;
|
36 |
b42c8399
|
leszek
|
int objectSize = windowWidth / NUM_COLUMNS;
|
37 |
|
|
int margin = (int)(windowWidth*POPUP_MARGIN);
|
38 |
|
|
int padding = (int)(windowWidth*POPUP_PADDING);
|
39 |
1c04d054
|
leszek
|
int cubeSize = objectSize - 2*margin;
|
40 |
|
|
|
41 |
|
|
GridLayout objectGrid = act.findViewById(R.id.objectGrid);
|
42 |
b42c8399
|
leszek
|
objectGrid.removeAllViews();
|
43 |
|
|
|
44 |
1c04d054
|
leszek
|
PopupCreator.createObjectGrid(objectGrid,act,rowCount,colCount,numObjects,margin,cubeSize,padding);
|
45 |
|
|
|
46 |
b42c8399
|
leszek
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
47 |
|
|
act.getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
48 |
|
|
|
49 |
1c04d054
|
leszek
|
for(int child=0; child<numObjects; child++)
|
50 |
|
|
{
|
51 |
|
|
final RubikObject obj = RubikObjectList.getObject(child);
|
52 |
|
|
View v = objectGrid.getChildAt(child);
|
53 |
|
|
ImageButton button = PopupCreator.getButton(obj,v);
|
54 |
|
|
final int ordinal = child;
|
55 |
|
|
|
56 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
57 |
|
|
{
|
58 |
|
|
@Override
|
59 |
|
|
public void onClick(View v)
|
60 |
|
|
{
|
61 |
b42c8399
|
leszek
|
int w = displaymetrics.widthPixels;
|
62 |
|
|
int h = displaymetrics.heightPixels;
|
63 |
|
|
MainObjectPopup popup = new MainObjectPopup(act,ordinal,w,h);
|
64 |
|
|
popup.show(v);
|
65 |
1c04d054
|
leszek
|
}
|
66 |
|
|
});
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
b45b986a
|
leszek
|
void updateGrid(final MainActivity act, int scrW)
|
73 |
1c04d054
|
leszek
|
{
|
74 |
|
|
act.runOnUiThread(new Runnable()
|
75 |
|
|
{
|
76 |
|
|
@Override
|
77 |
|
|
public void run()
|
78 |
|
|
{
|
79 |
b42c8399
|
leszek
|
createGrid(act,scrW);
|
80 |
1c04d054
|
leszek
|
}
|
81 |
|
|
});
|
82 |
|
|
}
|
83 |
|
|
}
|