1 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
14da3188
|
leszek
|
// Copyright 2024 Leszek Koltunski //
|
3 |
58fd2ec0
|
leszek
|
// //
|
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 |
2659f9dd
|
leszek
|
import android.app.Activity;
|
13 |
58fd2ec0
|
leszek
|
import android.util.TypedValue;
|
14 |
2659f9dd
|
leszek
|
import android.view.View;
|
15 |
|
|
import android.view.ViewGroup;
|
16 |
|
|
import android.widget.GridLayout;
|
17 |
|
|
import android.widget.ImageButton;
|
18 |
3979a11d
|
leszek
|
import android.widget.ImageView;
|
19 |
58fd2ec0
|
leszek
|
import android.widget.LinearLayout;
|
20 |
14da3188
|
leszek
|
import android.widget.SeekBar;
|
21 |
58fd2ec0
|
leszek
|
import android.widget.TextView;
|
22 |
|
|
|
23 |
3979a11d
|
leszek
|
import androidx.appcompat.widget.AppCompatImageButton;
|
24 |
|
|
|
25 |
2659f9dd
|
leszek
|
import org.distorted.main.MainActivity;
|
26 |
58fd2ec0
|
leszek
|
import org.distorted.main.R;
|
27 |
9211042f
|
leszek
|
import org.distorted.os.OSInterface;
|
28 |
58fd2ec0
|
leszek
|
|
29 |
40249d5b
|
leszek
|
import static org.distorted.objectlib.shape.ShapeColors.*;
|
30 |
|
|
|
31 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32 |
|
|
|
33 |
|
|
public class ConfigScreenPane
|
34 |
|
|
{
|
35 |
14da3188
|
leszek
|
public static final int DEFAULT_BORDERS = 2;
|
36 |
|
|
public static final int DEFAULT_CORNERS = 2;
|
37 |
|
|
|
38 |
406c2fa5
|
leszek
|
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 |
14da3188
|
leszek
|
|
41 |
94ff5962
|
leszek
|
private static final float PADDING_RATIO = 0.010f;
|
42 |
2659f9dd
|
leszek
|
private static final float MARGIN_RATIO = 0.017f;
|
43 |
58fd2ec0
|
leszek
|
private static final float TEXT_RATIO = 0.025f;
|
44 |
|
|
|
45 |
2659f9dd
|
leszek
|
private static final int[][] COLORS =
|
46 |
|
|
{
|
47 |
15b600fd
|
leszek
|
{ 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 |
2659f9dd
|
leszek
|
};
|
52 |
|
|
|
53 |
14da3188
|
leszek
|
private final SeekBar mSeekBarBorders, mSeekBarCorners;
|
54 |
|
|
private int mCurrentBorders, mCurrentCorners;
|
55 |
2659f9dd
|
leszek
|
private GridLayout mGrid;
|
56 |
3979a11d
|
leszek
|
private int mRow, mCol;
|
57 |
14da3188
|
leszek
|
|
58 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
4bd09fe2
|
leszek
|
void resetUI(ConfigActivity act)
|
61 |
58fd2ec0
|
leszek
|
{
|
62 |
2659f9dd
|
leszek
|
mSeekBarBorders.setProgress(DEFAULT_BORDERS);
|
63 |
|
|
mSeekBarCorners.setProgress(DEFAULT_CORNERS);
|
64 |
58fd2ec0
|
leszek
|
|
65 |
4bd09fe2
|
leszek
|
act.runOnUiThread(new Runnable()
|
66 |
|
|
{
|
67 |
|
|
@Override
|
68 |
|
|
public void run()
|
69 |
|
|
{
|
70 |
|
|
markButton(0,0);
|
71 |
|
|
}
|
72 |
|
|
});
|
73 |
58fd2ec0
|
leszek
|
}
|
74 |
|
|
|
75 |
14da3188
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
2659f9dd
|
leszek
|
private void createColorGrid(final ConfigActivity act, int width, int height)
|
78 |
14da3188
|
leszek
|
{
|
79 |
2659f9dd
|
leszek
|
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 |
3979a11d
|
leszek
|
|
117 |
|
|
markButton(mRow,mCol);
|
118 |
2659f9dd
|
leszek
|
}
|
119 |
|
|
|
120 |
988e3d33
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
2659f9dd
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
|
|
141 |
3979a11d
|
leszek
|
private View createView(final Activity act, final int row, final int col)
|
142 |
2659f9dd
|
leszek
|
{
|
143 |
3979a11d
|
leszek
|
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 |
2659f9dd
|
leszek
|
return button;
|
160 |
14da3188
|
leszek
|
}
|
161 |
|
|
|
162 |
3979a11d
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
|
|
private void markButton(int row, int col)
|
165 |
|
|
{
|
166 |
988e3d33
|
leszek
|
if( mGrid!=null )
|
167 |
|
|
{
|
168 |
|
|
int index = mRow*COLORS[0].length + mCol;
|
169 |
|
|
ImageButton button = (ImageButton)mGrid.getChildAt(index);
|
170 |
|
|
button.setImageResource(0);
|
171 |
3979a11d
|
leszek
|
|
172 |
988e3d33
|
leszek
|
mRow = row;
|
173 |
|
|
mCol = col;
|
174 |
3979a11d
|
leszek
|
|
175 |
988e3d33
|
leszek
|
index = mRow*COLORS[0].length + mCol;
|
176 |
|
|
button = (ImageButton)mGrid.getChildAt(index);
|
177 |
|
|
button.setImageResource(R.drawable.check);
|
178 |
|
|
}
|
179 |
3979a11d
|
leszek
|
}
|
180 |
|
|
|
181 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182 |
|
|
|
183 |
|
|
int getCurrentColor()
|
184 |
|
|
{
|
185 |
|
|
return COLORS[mRow][mCol];
|
186 |
|
|
}
|
187 |
|
|
|
188 |
4bd09fe2
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189 |
|
|
|
190 |
9211042f
|
leszek
|
private int extractIndex(float val, float[] table)
|
191 |
4bd09fe2
|
leszek
|
{
|
192 |
9211042f
|
leszek
|
int len = table.length;
|
193 |
4bd09fe2
|
leszek
|
|
194 |
9211042f
|
leszek
|
for(int i=0; i<len; i++)
|
195 |
|
|
if( table[i]==val ) return i;
|
196 |
4bd09fe2
|
leszek
|
|
197 |
9211042f
|
leszek
|
return len/2;
|
198 |
4bd09fe2
|
leszek
|
}
|
199 |
|
|
|
200 |
58fd2ec0
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201 |
|
|
|
202 |
988e3d33
|
leszek
|
ConfigScreenPane(final ConfigActivity act, String key, OSInterface os, boolean supportsAdjColors)
|
203 |
58fd2ec0
|
leszek
|
{
|
204 |
3979a11d
|
leszek
|
mRow = 0;
|
205 |
|
|
mCol = 0;
|
206 |
2659f9dd
|
leszek
|
int width = act.getScreenWidthInPixels();
|
207 |
58fd2ec0
|
leszek
|
int height = act.getScreenHeightInPixels();
|
208 |
|
|
float textSize = height*TEXT_RATIO;
|
209 |
|
|
int padding = (int)(height*PADDING_RATIO);
|
210 |
|
|
|
211 |
9211042f
|
leszek
|
float borders = os.getFloat(key+"_border",1.0f);
|
212 |
|
|
float corners = os.getFloat(key+"_corner",1.0f);
|
213 |
|
|
|
214 |
94ff5962
|
leszek
|
///// UPPER LAYOUT /////////////////////////////////
|
215 |
|
|
LinearLayout configLayoutU = act.findViewById(R.id.configLayoutUpper);
|
216 |
|
|
configLayoutU.setPadding(padding,padding,padding,padding);
|
217 |
58fd2ec0
|
leszek
|
|
218 |
94ff5962
|
leszek
|
LinearLayout.LayoutParams paramsLayoutU = (LinearLayout.LayoutParams)configLayoutU.getLayoutParams();
|
219 |
|
|
paramsLayoutU.bottomMargin = padding;
|
220 |
|
|
paramsLayoutU.topMargin = 0;
|
221 |
|
|
paramsLayoutU.leftMargin = padding;
|
222 |
|
|
paramsLayoutU.rightMargin = padding;
|
223 |
58fd2ec0
|
leszek
|
|
224 |
94ff5962
|
leszek
|
configLayoutU.setLayoutParams(paramsLayoutU);
|
225 |
58fd2ec0
|
leszek
|
|
226 |
94ff5962
|
leszek
|
TextView textBorder = configLayoutU.findViewById(R.id.configTextBorder);
|
227 |
14da3188
|
leszek
|
textBorder.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
228 |
94ff5962
|
leszek
|
TextView textCorner = configLayoutU.findViewById(R.id.configTextCorner);
|
229 |
14da3188
|
leszek
|
textCorner.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
230 |
|
|
|
231 |
94ff5962
|
leszek
|
mSeekBarBorders = configLayoutU.findViewById(R.id.configSeekBarBorder);
|
232 |
9211042f
|
leszek
|
mCurrentBorders = extractIndex(borders,BORDER_STEPS);
|
233 |
|
|
|
234 |
|
|
if( mCurrentBorders!=mSeekBarBorders.getProgress() )
|
235 |
|
|
{
|
236 |
|
|
mSeekBarBorders.setProgress(mCurrentBorders);
|
237 |
|
|
}
|
238 |
14da3188
|
leszek
|
|
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 |
94ff5962
|
leszek
|
mSeekBarCorners = configLayoutU.findViewById(R.id.configSeekBarCorner);
|
257 |
9211042f
|
leszek
|
mCurrentCorners = extractIndex(corners,CORNER_STEPS);
|
258 |
|
|
|
259 |
|
|
if( mCurrentCorners!=mSeekBarCorners.getProgress() )
|
260 |
|
|
{
|
261 |
|
|
mSeekBarCorners.setProgress(mCurrentCorners);
|
262 |
|
|
}
|
263 |
14da3188
|
leszek
|
|
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 |
94ff5962
|
leszek
|
|
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 |
2659f9dd
|
leszek
|
|
293 |
988e3d33
|
leszek
|
View view = createColorSection(act, width, height, supportsAdjColors);
|
294 |
427ba5bf
|
leszek
|
configLayoutL.removeAllViews();
|
295 |
988e3d33
|
leszek
|
configLayoutL.addView(view);
|
296 |
58fd2ec0
|
leszek
|
}
|
297 |
|
|
}
|