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
|
import org.distorted.os.OSInterface;
|
28
|
|
29
|
import static org.distorted.objectlib.shape.ShapeColors.*;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class ConfigScreenPane
|
34
|
{
|
35
|
public static final int DEFAULT_BORDERS = 2;
|
36
|
public static final int DEFAULT_CORNERS = 2;
|
37
|
|
38
|
public static final float[] BORDER_STEPS = { 0.50f, 0.75f, 1.00f, 1.50f, 2.00f };
|
39
|
public static final float[] CORNER_STEPS = { 0.00f, 0.50f, 1.00f, 1.50f, 2.00f };
|
40
|
|
41
|
private static final float PADDING_RATIO = 0.010f;
|
42
|
private static final float MARGIN_RATIO = 0.017f;
|
43
|
private static final float TEXT_RATIO = 0.025f;
|
44
|
|
45
|
private static final int[][] COLORS =
|
46
|
{
|
47
|
{ COLOR_WHITE , COLOR_YELLOW, COLOR_BLUE , COLOR_LGREEN , COLOR_RED , COLOR_ORANGE },
|
48
|
{ COLOR_LPINK , COLOR_VIOLET, COLOR_PURPLE, COLOR_BURGUN , COLOR_DPINK, COLOR_DYELLO },
|
49
|
{ COLOR_DGREEN, COLOR_SELEDY, COLOR_GREEN , COLOR_BLUEISH, COLOR_SANDY, COLOR_DBLUE },
|
50
|
{ COLOR_BROWN , COLOR_LBLUE , COLOR_BLACK , COLOR_DGREY , COLOR_LGREY, COLOR_GREY },
|
51
|
};
|
52
|
|
53
|
private final SeekBar mSeekBarBorders, mSeekBarCorners;
|
54
|
private int mCurrentBorders, mCurrentCorners;
|
55
|
private GridLayout mGrid;
|
56
|
private int mRow, mCol;
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
void resetUI(ConfigActivity act)
|
61
|
{
|
62
|
mSeekBarBorders.setProgress(DEFAULT_BORDERS);
|
63
|
mSeekBarCorners.setProgress(DEFAULT_CORNERS);
|
64
|
|
65
|
act.runOnUiThread(new Runnable()
|
66
|
{
|
67
|
@Override
|
68
|
public void run()
|
69
|
{
|
70
|
markButton(0,0);
|
71
|
}
|
72
|
});
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
private void createColorGrid(final ConfigActivity act, int width, int height)
|
78
|
{
|
79
|
mGrid = new GridLayout(act);
|
80
|
ViewGroup.LayoutParams paramsG = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
|
81
|
mGrid.setLayoutParams(paramsG);
|
82
|
|
83
|
int rowCount = COLORS.length;
|
84
|
int colCount = COLORS[0].length;
|
85
|
|
86
|
int margin = (int)(width*MARGIN_RATIO);
|
87
|
int hsize = (int)(0.83f*width/colCount - margin);
|
88
|
int vsize = (int)(0.78f*(height*(1-MainActivity.RATIO_BAR)*(2.0f)/(2.0f+0.75f+3.0f))/rowCount - margin );
|
89
|
|
90
|
mGrid.setColumnCount(colCount);
|
91
|
mGrid.setRowCount(rowCount);
|
92
|
|
93
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount];
|
94
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount];
|
95
|
|
96
|
for(int row=0; row<rowCount; row++) rowSpecs[row] = GridLayout.spec(row);
|
97
|
for(int col=0; col<colCount; col++) colSpecs[col] = GridLayout.spec(col);
|
98
|
|
99
|
for(int row=0; row<rowCount; row++)
|
100
|
for(int col=0; col<colCount; col++)
|
101
|
{
|
102
|
View v = createView(act,row,col);
|
103
|
GridLayout.Spec rs = rowSpecs[row];
|
104
|
GridLayout.Spec cs = colSpecs[col];
|
105
|
|
106
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rs,cs);
|
107
|
params.bottomMargin = margin;
|
108
|
params.topMargin = margin;
|
109
|
params.leftMargin = margin;
|
110
|
params.rightMargin = margin;
|
111
|
params.width = hsize;
|
112
|
params.height= vsize;
|
113
|
|
114
|
mGrid.addView(v,params);
|
115
|
}
|
116
|
|
117
|
markButton(mRow,mCol);
|
118
|
}
|
119
|
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121
|
|
122
|
private View createColorSection(final ConfigActivity act, int width, int height, boolean supports)
|
123
|
{
|
124
|
if( supports )
|
125
|
{
|
126
|
createColorGrid(act,width,height);
|
127
|
return mGrid;
|
128
|
}
|
129
|
else
|
130
|
{
|
131
|
float textSize = height*TEXT_RATIO;
|
132
|
TextView text = new TextView(act);
|
133
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
134
|
text.setText(R.string.config_no_support);
|
135
|
return text;
|
136
|
}
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
|
141
|
private View createView(final Activity act, final int row, final int col)
|
142
|
{
|
143
|
AppCompatImageButton button = new AppCompatImageButton(act);
|
144
|
|
145
|
int p = 10;
|
146
|
button.setPadding(p,p,p,p);
|
147
|
button.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
148
|
button.setBackgroundColor(COLORS[row][col]);
|
149
|
|
150
|
button.setOnClickListener( new View.OnClickListener()
|
151
|
{
|
152
|
@Override
|
153
|
public void onClick(View v)
|
154
|
{
|
155
|
markButton(row,col);
|
156
|
}
|
157
|
});
|
158
|
|
159
|
return button;
|
160
|
}
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
|
164
|
private void markButton(int row, int col)
|
165
|
{
|
166
|
if( mGrid!=null )
|
167
|
{
|
168
|
int index = mRow*COLORS[0].length + mCol;
|
169
|
ImageButton button = (ImageButton)mGrid.getChildAt(index);
|
170
|
button.setImageResource(0);
|
171
|
|
172
|
mRow = row;
|
173
|
mCol = col;
|
174
|
|
175
|
index = mRow*COLORS[0].length + mCol;
|
176
|
button = (ImageButton)mGrid.getChildAt(index);
|
177
|
button.setImageResource(R.drawable.check);
|
178
|
}
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
int getCurrentColor()
|
184
|
{
|
185
|
return COLORS[mRow][mCol];
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
private int extractIndex(float val, float[] table)
|
191
|
{
|
192
|
int len = table.length;
|
193
|
|
194
|
for(int i=0; i<len; i++)
|
195
|
if( table[i]==val ) return i;
|
196
|
|
197
|
return len/2;
|
198
|
}
|
199
|
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
ConfigScreenPane(final ConfigActivity act, String key, OSInterface os, boolean supportsAdjColors)
|
203
|
{
|
204
|
mRow = 0;
|
205
|
mCol = 0;
|
206
|
int width = act.getScreenWidthInPixels();
|
207
|
int height = act.getScreenHeightInPixels();
|
208
|
float textSize = height*TEXT_RATIO;
|
209
|
int padding = (int)(height*PADDING_RATIO);
|
210
|
|
211
|
float borders = os.getFloat(key+"_border",1.0f);
|
212
|
float corners = os.getFloat(key+"_corner",1.0f);
|
213
|
|
214
|
///// UPPER LAYOUT /////////////////////////////////
|
215
|
LinearLayout configLayoutU = act.findViewById(R.id.configLayoutUpper);
|
216
|
configLayoutU.setPadding(padding,padding,padding,padding);
|
217
|
|
218
|
LinearLayout.LayoutParams paramsLayoutU = (LinearLayout.LayoutParams)configLayoutU.getLayoutParams();
|
219
|
paramsLayoutU.bottomMargin = padding;
|
220
|
paramsLayoutU.topMargin = 0;
|
221
|
paramsLayoutU.leftMargin = padding;
|
222
|
paramsLayoutU.rightMargin = padding;
|
223
|
|
224
|
configLayoutU.setLayoutParams(paramsLayoutU);
|
225
|
|
226
|
TextView textBorder = configLayoutU.findViewById(R.id.configTextBorder);
|
227
|
textBorder.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
228
|
TextView textCorner = configLayoutU.findViewById(R.id.configTextCorner);
|
229
|
textCorner.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
230
|
|
231
|
mSeekBarBorders = configLayoutU.findViewById(R.id.configSeekBarBorder);
|
232
|
mCurrentBorders = extractIndex(borders,BORDER_STEPS);
|
233
|
|
234
|
if( mCurrentBorders!=mSeekBarBorders.getProgress() )
|
235
|
{
|
236
|
mSeekBarBorders.setProgress(mCurrentBorders);
|
237
|
}
|
238
|
|
239
|
mSeekBarBorders.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
|
240
|
{
|
241
|
@Override
|
242
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
243
|
{
|
244
|
mCurrentBorders = progress;
|
245
|
}
|
246
|
|
247
|
@Override
|
248
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
249
|
@Override
|
250
|
public void onStopTrackingTouch(SeekBar seekBar)
|
251
|
{
|
252
|
act.recreateStickers(mCurrentBorders,mCurrentCorners);
|
253
|
}
|
254
|
});
|
255
|
|
256
|
mSeekBarCorners = configLayoutU.findViewById(R.id.configSeekBarCorner);
|
257
|
mCurrentCorners = extractIndex(corners,CORNER_STEPS);
|
258
|
|
259
|
if( mCurrentCorners!=mSeekBarCorners.getProgress() )
|
260
|
{
|
261
|
mSeekBarCorners.setProgress(mCurrentCorners);
|
262
|
}
|
263
|
|
264
|
mSeekBarCorners.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
|
265
|
{
|
266
|
@Override
|
267
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
268
|
{
|
269
|
mCurrentCorners = progress;
|
270
|
}
|
271
|
|
272
|
@Override
|
273
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
274
|
@Override
|
275
|
public void onStopTrackingTouch(SeekBar seekBar)
|
276
|
{
|
277
|
act.recreateStickers(mCurrentBorders,mCurrentCorners);
|
278
|
}
|
279
|
});
|
280
|
|
281
|
///// LOWER LAYOUT /////////////////////////////////
|
282
|
LinearLayout configLayoutL = act.findViewById(R.id.configLayoutLower);
|
283
|
configLayoutL.setPadding(padding,padding,padding,padding);
|
284
|
|
285
|
LinearLayout.LayoutParams paramsLayoutL = (LinearLayout.LayoutParams)configLayoutL.getLayoutParams();
|
286
|
paramsLayoutL.bottomMargin = padding;
|
287
|
paramsLayoutL.topMargin = 0;
|
288
|
paramsLayoutL.leftMargin = padding;
|
289
|
paramsLayoutL.rightMargin = padding;
|
290
|
|
291
|
configLayoutL.setLayoutParams(paramsLayoutL);
|
292
|
|
293
|
View view = createColorSection(act, width, height, supportsAdjColors);
|
294
|
configLayoutL.removeAllViews();
|
295
|
configLayoutL.addView(view);
|
296
|
}
|
297
|
}
|