1 |
432a5f2c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2022 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.helpers;
|
11 |
|
|
|
12 |
|
|
import android.app.Activity;
|
13 |
ab66b70e
|
Leszek Koltunski
|
import android.content.Context;
|
14 |
|
|
import android.view.LayoutInflater;
|
15 |
|
|
import android.view.View;
|
16 |
432a5f2c
|
Leszek Koltunski
|
import android.widget.GridLayout;
|
17 |
|
|
import android.widget.ImageButton;
|
18 |
a88b947f
|
Leszek Koltunski
|
import android.widget.ImageView;
|
19 |
432a5f2c
|
Leszek Koltunski
|
|
20 |
ab66b70e
|
Leszek Koltunski
|
import org.distorted.main.R;
|
21 |
432a5f2c
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
22 |
|
|
import org.distorted.objects.RubikObjectList;
|
23 |
|
|
|
24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25 |
|
|
|
26 |
|
|
public class PopupCreator
|
27 |
|
|
{
|
28 |
a88b947f
|
Leszek Koltunski
|
public static void createObjectGrid(GridLayout grid, Activity act, int rowCount, int colCount, int numObjects, int margin, int size, int pad)
|
29 |
432a5f2c
|
Leszek Koltunski
|
{
|
30 |
|
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount];
|
31 |
|
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount];
|
32 |
|
|
|
33 |
|
|
grid.setColumnCount(colCount);
|
34 |
|
|
grid.setRowCount(rowCount);
|
35 |
|
|
|
36 |
|
|
int[] nextInRow = new int[rowCount];
|
37 |
|
|
|
38 |
|
|
for(int row=0; row<rowCount; row++)
|
39 |
|
|
{
|
40 |
|
|
rowSpecs[row] = GridLayout.spec(row);
|
41 |
|
|
nextInRow[row]= 0;
|
42 |
|
|
}
|
43 |
|
|
for(int col=0; col<colCount; col++)
|
44 |
|
|
{
|
45 |
|
|
colSpecs[col] = GridLayout.spec(col);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
ab66b70e
|
Leszek Koltunski
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
49 |
|
|
|
50 |
432a5f2c
|
Leszek Koltunski
|
for(int object=0; object<numObjects; object++)
|
51 |
|
|
{
|
52 |
a88b947f
|
Leszek Koltunski
|
View v = createView(act,layoutInflater,object,pad);
|
53 |
432a5f2c
|
Leszek Koltunski
|
int row = object/colCount;
|
54 |
|
|
|
55 |
|
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
|
56 |
|
|
params.bottomMargin = margin;
|
57 |
|
|
params.topMargin = margin;
|
58 |
|
|
params.leftMargin = margin;
|
59 |
|
|
params.rightMargin = margin;
|
60 |
|
|
|
61 |
|
|
params.width = size;
|
62 |
|
|
params.height= size;
|
63 |
|
|
|
64 |
|
|
nextInRow[row]++;
|
65 |
|
|
|
66 |
ab66b70e
|
Leszek Koltunski
|
grid.addView(v,params);
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
302c76a0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
public static ImageButton getButton(RubikObject object, View view)
|
73 |
|
|
{
|
74 |
|
|
return object!=null && object.isFree() ? (ImageButton)view : view.findViewById(R.id.non_free_button);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
ab66b70e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
a88b947f
|
Leszek Koltunski
|
private static View createView(Activity act, LayoutInflater inflater, int ordinal, int pad)
|
80 |
ab66b70e
|
Leszek Koltunski
|
{
|
81 |
|
|
final RubikObject obj = RubikObjectList.getObject(ordinal);
|
82 |
|
|
|
83 |
|
|
if( obj!=null )
|
84 |
|
|
{
|
85 |
|
|
if( obj.isFree() )
|
86 |
|
|
{
|
87 |
|
|
ImageButton button = new ImageButton(act);
|
88 |
|
|
obj.setIconTo(act,button);
|
89 |
|
|
return button;
|
90 |
|
|
}
|
91 |
|
|
else
|
92 |
|
|
{
|
93 |
|
|
final View layout = inflater.inflate(R.layout.non_free_object, null);
|
94 |
|
|
ImageButton button= layout.findViewById(R.id.non_free_button);
|
95 |
|
|
obj.setIconTo(act,button);
|
96 |
a88b947f
|
Leszek Koltunski
|
ImageView view= layout.findViewById(R.id.non_free_lock);
|
97 |
|
|
view.setPadding(0,pad,0,0);
|
98 |
ab66b70e
|
Leszek Koltunski
|
return layout;
|
99 |
|
|
}
|
100 |
432a5f2c
|
Leszek Koltunski
|
}
|
101 |
ab66b70e
|
Leszek Koltunski
|
|
102 |
|
|
return null;
|
103 |
432a5f2c
|
Leszek Koltunski
|
}
|
104 |
|
|
}
|