1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2024 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.config;
|
11
|
|
12
|
import android.app.Activity;
|
13
|
import android.util.TypedValue;
|
14
|
import android.view.View;
|
15
|
import android.view.ViewGroup;
|
16
|
import android.widget.GridLayout;
|
17
|
import android.widget.ImageButton;
|
18
|
import android.widget.ImageView;
|
19
|
import android.widget.LinearLayout;
|
20
|
import android.widget.SeekBar;
|
21
|
import android.widget.TextView;
|
22
|
|
23
|
import androidx.appcompat.widget.AppCompatImageButton;
|
24
|
|
25
|
import org.distorted.main.MainActivity;
|
26
|
import org.distorted.main.R;
|
27
|
|
28
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29
|
|
30
|
public class ConfigScreenPane
|
31
|
{
|
32
|
public static final int DEFAULT_BORDERS = 2;
|
33
|
public static final int DEFAULT_CORNERS = 2;
|
34
|
|
35
|
public static final float[] BORDER_STEPS = { 0.50f, 0.75f, 1.00f, 1.50f, 2.00f };
|
36
|
public static final float[] CORNER_STEPS = { 0.00f, 0.50f, 1.00f, 1.50f, 2.00f };
|
37
|
|
38
|
private static final float PADDING_RATIO = 0.010f;
|
39
|
private static final float MARGIN_RATIO = 0.017f;
|
40
|
private static final float TEXT_RATIO = 0.025f;
|
41
|
|
42
|
static final int ICO_01= 0xffe191b4;
|
43
|
static final int ICO_02= 0xff604c94;
|
44
|
static final int ICO_03= 0xff472258;
|
45
|
static final int ICO_04= 0xff591218;
|
46
|
static final int ICO_05= 0xffba365b;
|
47
|
static final int ICO_06= 0xffe4e000;
|
48
|
static final int ICO_07= 0xff4a90d5;
|
49
|
static final int ICO_08= 0xff0e28a3;
|
50
|
static final int ICO_09= 0xff00ff00;
|
51
|
static final int ICO_10= 0xffd7660a;
|
52
|
static final int ICO_11= 0xff092d2b;
|
53
|
static final int ICO_12= 0xff034d3e;
|
54
|
static final int ICO_13= 0xff1a7516;
|
55
|
static final int ICO_14= 0xff58b6be;
|
56
|
static final int ICO_15= 0xffd3c49b;
|
57
|
static final int ICO_16= 0xff0a1662;
|
58
|
static final int ICO_17= 0xffa21a1c;
|
59
|
static final int ICO_18= 0xffe1b410;
|
60
|
static final int ICO_19= 0xffff0000;
|
61
|
static final int ICO_20= 0xff0157ba;
|
62
|
static final int ICO_21= 0xff000000;
|
63
|
static final int ICO_22= 0xff222222;
|
64
|
static final int ICO_23= 0xff555555;
|
65
|
static final int ICO_24= 0xffffffff;
|
66
|
|
67
|
private static final int[][] COLORS =
|
68
|
{
|
69
|
{ ICO_01, ICO_02, ICO_03, ICO_04, ICO_05, ICO_21 },
|
70
|
{ ICO_06, ICO_07, ICO_08, ICO_09, ICO_10, ICO_22 },
|
71
|
{ ICO_11, ICO_12, ICO_13, ICO_14, ICO_15, ICO_23 },
|
72
|
{ ICO_16, ICO_17, ICO_18, ICO_19, ICO_20, ICO_24 },
|
73
|
};
|
74
|
|
75
|
private final SeekBar mSeekBarBorders, mSeekBarCorners;
|
76
|
private int mCurrentBorders, mCurrentCorners;
|
77
|
private GridLayout mGrid;
|
78
|
private int mRow, mCol;
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
void resetUI()
|
83
|
{
|
84
|
mSeekBarBorders.setProgress(DEFAULT_BORDERS);
|
85
|
mSeekBarCorners.setProgress(DEFAULT_CORNERS);
|
86
|
|
87
|
markButton(0,0);
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
private void createColorGrid(final ConfigActivity act, int width, int height)
|
93
|
{
|
94
|
mGrid = new GridLayout(act);
|
95
|
ViewGroup.LayoutParams paramsG = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
|
96
|
mGrid.setLayoutParams(paramsG);
|
97
|
|
98
|
int rowCount = COLORS.length;
|
99
|
int colCount = COLORS[0].length;
|
100
|
|
101
|
int margin = (int)(width*MARGIN_RATIO);
|
102
|
int hsize = (int)(0.83f*width/colCount - margin);
|
103
|
int vsize = (int)(0.78f*(height*(1-MainActivity.RATIO_BAR)*(2.0f)/(2.0f+0.75f+3.0f))/rowCount - margin );
|
104
|
|
105
|
mGrid.setColumnCount(colCount);
|
106
|
mGrid.setRowCount(rowCount);
|
107
|
|
108
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount];
|
109
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount];
|
110
|
|
111
|
for(int row=0; row<rowCount; row++) rowSpecs[row] = GridLayout.spec(row);
|
112
|
for(int col=0; col<colCount; col++) colSpecs[col] = GridLayout.spec(col);
|
113
|
|
114
|
for(int row=0; row<rowCount; row++)
|
115
|
for(int col=0; col<colCount; col++)
|
116
|
{
|
117
|
View v = createView(act,row,col);
|
118
|
GridLayout.Spec rs = rowSpecs[row];
|
119
|
GridLayout.Spec cs = colSpecs[col];
|
120
|
|
121
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rs,cs);
|
122
|
params.bottomMargin = margin;
|
123
|
params.topMargin = margin;
|
124
|
params.leftMargin = margin;
|
125
|
params.rightMargin = margin;
|
126
|
params.width = hsize;
|
127
|
params.height= vsize;
|
128
|
|
129
|
mGrid.addView(v,params);
|
130
|
}
|
131
|
|
132
|
markButton(mRow,mCol);
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
private View createView(final Activity act, final int row, final int col)
|
138
|
{
|
139
|
AppCompatImageButton button = new AppCompatImageButton(act);
|
140
|
|
141
|
int p = 10;
|
142
|
button.setPadding(p,p,p,p);
|
143
|
button.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
144
|
button.setBackgroundColor(COLORS[row][col]);
|
145
|
|
146
|
button.setOnClickListener( new View.OnClickListener()
|
147
|
{
|
148
|
@Override
|
149
|
public void onClick(View v)
|
150
|
{
|
151
|
markButton(row,col);
|
152
|
}
|
153
|
});
|
154
|
|
155
|
return button;
|
156
|
}
|
157
|
|
158
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
159
|
|
160
|
private void markButton(int row, int col)
|
161
|
{
|
162
|
int index = mRow*COLORS[0].length + mCol;
|
163
|
ImageButton button = (ImageButton)mGrid.getChildAt(index);
|
164
|
button.setImageResource(0);
|
165
|
|
166
|
mRow = row;
|
167
|
mCol = col;
|
168
|
|
169
|
index = mRow*COLORS[0].length + mCol;
|
170
|
button = (ImageButton)mGrid.getChildAt(index);
|
171
|
button.setImageResource(R.drawable.check);
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
int getCurrentColor()
|
177
|
{
|
178
|
return COLORS[mRow][mCol];
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
|
184
|
{
|
185
|
mRow = 0;
|
186
|
mCol = 0;
|
187
|
int width = act.getScreenWidthInPixels();
|
188
|
int height = act.getScreenHeightInPixels();
|
189
|
float textSize = height*TEXT_RATIO;
|
190
|
int padding = (int)(height*PADDING_RATIO);
|
191
|
|
192
|
///// UPPER LAYOUT /////////////////////////////////
|
193
|
LinearLayout configLayoutU = act.findViewById(R.id.configLayoutUpper);
|
194
|
configLayoutU.setPadding(padding,padding,padding,padding);
|
195
|
|
196
|
LinearLayout.LayoutParams paramsLayoutU = (LinearLayout.LayoutParams)configLayoutU.getLayoutParams();
|
197
|
paramsLayoutU.bottomMargin = padding;
|
198
|
paramsLayoutU.topMargin = 0;
|
199
|
paramsLayoutU.leftMargin = padding;
|
200
|
paramsLayoutU.rightMargin = padding;
|
201
|
|
202
|
configLayoutU.setLayoutParams(paramsLayoutU);
|
203
|
|
204
|
TextView textBorder = configLayoutU.findViewById(R.id.configTextBorder);
|
205
|
textBorder.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
206
|
TextView textCorner = configLayoutU.findViewById(R.id.configTextCorner);
|
207
|
textCorner.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
208
|
|
209
|
mSeekBarBorders = configLayoutU.findViewById(R.id.configSeekBarBorder);
|
210
|
mCurrentBorders = mSeekBarBorders.getProgress();
|
211
|
|
212
|
mSeekBarBorders.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
|
213
|
{
|
214
|
@Override
|
215
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
216
|
{
|
217
|
mCurrentBorders = progress;
|
218
|
}
|
219
|
|
220
|
@Override
|
221
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
222
|
|
223
|
@Override
|
224
|
public void onStopTrackingTouch(SeekBar seekBar)
|
225
|
{
|
226
|
act.recreateStickers(mCurrentBorders,mCurrentCorners);
|
227
|
}
|
228
|
});
|
229
|
|
230
|
mSeekBarCorners = configLayoutU.findViewById(R.id.configSeekBarCorner);
|
231
|
mCurrentCorners = mSeekBarCorners.getProgress();
|
232
|
|
233
|
mSeekBarCorners.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
|
234
|
{
|
235
|
@Override
|
236
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
237
|
{
|
238
|
mCurrentCorners = progress;
|
239
|
}
|
240
|
|
241
|
@Override
|
242
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
243
|
@Override
|
244
|
public void onStopTrackingTouch(SeekBar seekBar)
|
245
|
{
|
246
|
act.recreateStickers(mCurrentBorders,mCurrentCorners);
|
247
|
}
|
248
|
});
|
249
|
|
250
|
///// LOWER LAYOUT /////////////////////////////////
|
251
|
LinearLayout configLayoutL = act.findViewById(R.id.configLayoutLower);
|
252
|
configLayoutL.setPadding(padding,padding,padding,padding);
|
253
|
|
254
|
LinearLayout.LayoutParams paramsLayoutL = (LinearLayout.LayoutParams)configLayoutL.getLayoutParams();
|
255
|
paramsLayoutL.bottomMargin = padding;
|
256
|
paramsLayoutL.topMargin = 0;
|
257
|
paramsLayoutL.leftMargin = padding;
|
258
|
paramsLayoutL.rightMargin = padding;
|
259
|
|
260
|
configLayoutL.setLayoutParams(paramsLayoutL);
|
261
|
|
262
|
createColorGrid(act, width, height);
|
263
|
configLayoutL.addView(mGrid);
|
264
|
}
|
265
|
}
|