Project

General

Profile

Download (9.62 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 4bd09fe2

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(ConfigActivity act)
83
    {
84
    mSeekBarBorders.setProgress(DEFAULT_BORDERS);
85
    mSeekBarCorners.setProgress(DEFAULT_CORNERS);
86

    
87
    act.runOnUiThread(new Runnable()
88
      {
89
      @Override
90
      public void run()
91
        {
92
        markButton(0,0);
93
        }
94
      });
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  private void createColorGrid(final ConfigActivity act, int width, int height)
100
    {
101
    mGrid = new GridLayout(act);
102
    ViewGroup.LayoutParams paramsG = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
103
    mGrid.setLayoutParams(paramsG);
104

    
105
    int rowCount = COLORS.length;
106
    int colCount = COLORS[0].length;
107

    
108
    int margin  = (int)(width*MARGIN_RATIO);
109
    int hsize   = (int)(0.83f*width/colCount - margin);
110
    int vsize   = (int)(0.78f*(height*(1-MainActivity.RATIO_BAR)*(2.0f)/(2.0f+0.75f+3.0f))/rowCount - margin );
111

    
112
    mGrid.setColumnCount(colCount);
113
    mGrid.setRowCount(rowCount);
114

    
115
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount];
116
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount];
117

    
118
    for(int row=0; row<rowCount; row++) rowSpecs[row] = GridLayout.spec(row);
119
    for(int col=0; col<colCount; col++) colSpecs[col] = GridLayout.spec(col);
120

    
121
    for(int row=0; row<rowCount; row++)
122
      for(int col=0; col<colCount; col++)
123
        {
124
        View v = createView(act,row,col);
125
        GridLayout.Spec rs = rowSpecs[row];
126
        GridLayout.Spec cs = colSpecs[col];
127

    
128
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rs,cs);
129
        params.bottomMargin = margin;
130
        params.topMargin    = margin;
131
        params.leftMargin   = margin;
132
        params.rightMargin  = margin;
133
        params.width = hsize;
134
        params.height= vsize;
135

    
136
        mGrid.addView(v,params);
137
        }
138

    
139
    markButton(mRow,mCol);
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  private View createView(final Activity act, final int row, final int col)
145
    {
146
    AppCompatImageButton button = new AppCompatImageButton(act);
147

    
148
    int p = 10;
149
    button.setPadding(p,p,p,p);
150
    button.setScaleType(ImageView.ScaleType.FIT_CENTER);
151
    button.setBackgroundColor(COLORS[row][col]);
152

    
153
    button.setOnClickListener( new View.OnClickListener()
154
      {
155
      @Override
156
      public void onClick(View v)
157
        {
158
        markButton(row,col);
159
        }
160
      });
161

    
162
    return button;
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  private void markButton(int row, int col)
168
    {
169
    int index = mRow*COLORS[0].length + mCol;
170
    ImageButton button = (ImageButton)mGrid.getChildAt(index);
171
    button.setImageResource(0);
172

    
173
    mRow = row;
174
    mCol = col;
175

    
176
    index = mRow*COLORS[0].length + mCol;
177
    button = (ImageButton)mGrid.getChildAt(index);
178
    button.setImageResource(R.drawable.check);
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  int getCurrentColor()
184
    {
185
    return COLORS[mRow][mCol];
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  int getCurrentBorders()
191
    {
192
    return mCurrentBorders;
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  int getCurrentCorners()
198
    {
199
    return mCurrentCorners;
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
205
    {
206
    mRow = 0;
207
    mCol = 0;
208
    int width = act.getScreenWidthInPixels();
209
    int height = act.getScreenHeightInPixels();
210
    float textSize = height*TEXT_RATIO;
211
    int padding = (int)(height*PADDING_RATIO);
212

    
213
    ///// UPPER LAYOUT /////////////////////////////////
214
    LinearLayout configLayoutU = act.findViewById(R.id.configLayoutUpper);
215
    configLayoutU.setPadding(padding,padding,padding,padding);
216

    
217
    LinearLayout.LayoutParams paramsLayoutU = (LinearLayout.LayoutParams)configLayoutU.getLayoutParams();
218
    paramsLayoutU.bottomMargin = padding;
219
    paramsLayoutU.topMargin    = 0;
220
    paramsLayoutU.leftMargin   = padding;
221
    paramsLayoutU.rightMargin  = padding;
222

    
223
    configLayoutU.setLayoutParams(paramsLayoutU);
224

    
225
    TextView textBorder   = configLayoutU.findViewById(R.id.configTextBorder);
226
    textBorder.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
227
    TextView textCorner   = configLayoutU.findViewById(R.id.configTextCorner);
228
    textCorner.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
229

    
230
    mSeekBarBorders = configLayoutU.findViewById(R.id.configSeekBarBorder);
231
    mCurrentBorders = mSeekBarBorders.getProgress();
232

    
233
    mSeekBarBorders.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
234
      {
235
      @Override
236
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
237
        {
238
        mCurrentBorders = progress;
239
        }
240

    
241
      @Override
242
      public void onStartTrackingTouch(SeekBar seekBar) {}
243

    
244
      @Override
245
      public void onStopTrackingTouch(SeekBar seekBar)
246
        {
247
        act.recreateStickers(mCurrentBorders,mCurrentCorners);
248
        }
249
      });
250

    
251
    mSeekBarCorners = configLayoutU.findViewById(R.id.configSeekBarCorner);
252
    mCurrentCorners = mSeekBarCorners.getProgress();
253

    
254
    mSeekBarCorners.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
255
      {
256
      @Override
257
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
258
        {
259
        mCurrentCorners = progress;
260
        }
261

    
262
      @Override
263
      public void onStartTrackingTouch(SeekBar seekBar) {}
264
      @Override
265
      public void onStopTrackingTouch(SeekBar seekBar)
266
        {
267
        act.recreateStickers(mCurrentBorders,mCurrentCorners);
268
        }
269
      });
270

    
271
    ///// LOWER LAYOUT /////////////////////////////////
272
    LinearLayout configLayoutL = act.findViewById(R.id.configLayoutLower);
273
    configLayoutL.setPadding(padding,padding,padding,padding);
274

    
275
    LinearLayout.LayoutParams paramsLayoutL = (LinearLayout.LayoutParams)configLayoutL.getLayoutParams();
276
    paramsLayoutL.bottomMargin = padding;
277
    paramsLayoutL.topMargin    = 0;
278
    paramsLayoutL.leftMargin   = padding;
279
    paramsLayoutL.rightMargin  = padding;
280

    
281
    configLayoutL.setLayoutParams(paramsLayoutL);
282

    
283
    createColorGrid(act, width, height);
284
    configLayoutL.addView(mGrid);
285
    }
286
}
(5-5/6)