Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 2659f9dd

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.LinearLayout;
19
import android.widget.SeekBar;
20
import android.widget.TextView;
21

    
22
import org.distorted.main.MainActivity;
23
import org.distorted.main.R;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class ConfigScreenPane
28
{
29
  public static final int DEFAULT_BORDERS = 2;
30
  public static final int DEFAULT_CORNERS = 2;
31

    
32
  public static final float[] BORDER_STEPS = { 0.50f, 0.75f, 1.00f, 1.50f, 2.00f };
33
  public static final float[] CORNER_STEPS = { 0.00f, 0.50f, 1.00f, 1.50f, 2.00f };
34

    
35
  private static final float PADDING_RATIO = 0.010f;
36
  private static final float MARGIN_RATIO  = 0.017f;
37
  private static final float TEXT_RATIO    = 0.025f;
38

    
39
  static final int ICO_01= 0xffe191b4;
40
  static final int ICO_02= 0xff604c94;
41
  static final int ICO_03= 0xff472258;
42
  static final int ICO_04= 0xff591218;
43
  static final int ICO_05= 0xffba365b;
44
  static final int ICO_06= 0xffe4e000;
45
  static final int ICO_07= 0xff4a90d5;
46
  static final int ICO_08= 0xff0e28a3;
47
  static final int ICO_09= 0xff00ff00;
48
  static final int ICO_10= 0xffd7660a;
49
  static final int ICO_11= 0xff092d2b;
50
  static final int ICO_12= 0xff034d3e;
51
  static final int ICO_13= 0xff1a7516;
52
  static final int ICO_14= 0xff58b6be;
53
  static final int ICO_15= 0xffd3c49b;
54
  static final int ICO_16= 0xff0a1662;
55
  static final int ICO_17= 0xffa21a1c;
56
  static final int ICO_18= 0xffe1b410;
57
  static final int ICO_19= 0xffff0000;
58
  static final int ICO_20= 0xff0157ba;
59
  static final int ICO_21= 0xff000000;
60
  static final int ICO_22= 0xff222222;
61
  static final int ICO_23= 0xff555555;
62
  static final int ICO_24= 0xffffffff;
63

    
64
  private static final int[][] COLORS =
65
    {
66
      { ICO_01, ICO_02, ICO_03, ICO_04, ICO_05, ICO_21 },
67
      { ICO_06, ICO_07, ICO_08, ICO_09, ICO_10, ICO_22 },
68
      { ICO_11, ICO_12, ICO_13, ICO_14, ICO_15, ICO_23 },
69
      { ICO_16, ICO_17, ICO_18, ICO_19, ICO_20, ICO_24 },
70
    };
71

    
72
  private final SeekBar mSeekBarBorders, mSeekBarCorners;
73
  private int mCurrentBorders, mCurrentCorners;
74
  private GridLayout mGrid;
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  void resetUI()
79
    {
80
    mSeekBarBorders.setProgress(DEFAULT_BORDERS);
81
    mSeekBarCorners.setProgress(DEFAULT_CORNERS);
82

    
83
    // reset color grid
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  private void createColorGrid(final ConfigActivity act, int width, int height)
89
    {
90
    mGrid = new GridLayout(act);
91
    ViewGroup.LayoutParams paramsG = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
92
    mGrid.setLayoutParams(paramsG);
93

    
94
    int rowCount = COLORS.length;
95
    int colCount = COLORS[0].length;
96

    
97
    int margin  = (int)(width*MARGIN_RATIO);
98
    int hsize   = (int)(0.83f*width/colCount - margin);
99
    int vsize   = (int)(0.78f*(height*(1-MainActivity.RATIO_BAR)*(2.0f)/(2.0f+0.75f+3.0f))/rowCount - margin );
100

    
101
    mGrid.setColumnCount(colCount);
102
    mGrid.setRowCount(rowCount);
103

    
104
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount];
105
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount];
106

    
107
    for(int row=0; row<rowCount; row++) rowSpecs[row] = GridLayout.spec(row);
108
    for(int col=0; col<colCount; col++) colSpecs[col] = GridLayout.spec(col);
109

    
110
    for(int row=0; row<rowCount; row++)
111
      for(int col=0; col<colCount; col++)
112
        {
113
        View v = createView(act,row,col);
114
        GridLayout.Spec rs = rowSpecs[row];
115
        GridLayout.Spec cs = colSpecs[col];
116

    
117
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rs,cs);
118
        params.bottomMargin = margin;
119
        params.topMargin    = margin;
120
        params.leftMargin   = margin;
121
        params.rightMargin  = margin;
122
        params.width = hsize;
123
        params.height= vsize;
124

    
125
        mGrid.addView(v,params);
126
        }
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  private View createView(Activity act, int row, int col)
132
    {
133
    ImageButton button = new ImageButton(act);
134
    button.setBackgroundColor( COLORS[row][col] );
135
    return button;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
141
    {
142
    int width = act.getScreenWidthInPixels();
143
    int height = act.getScreenHeightInPixels();
144
    float textSize = height*TEXT_RATIO;
145
    int padding = (int)(height*PADDING_RATIO);
146

    
147
    ///// UPPER LAYOUT /////////////////////////////////
148
    LinearLayout configLayoutU = act.findViewById(R.id.configLayoutUpper);
149
    configLayoutU.setPadding(padding,padding,padding,padding);
150

    
151
    LinearLayout.LayoutParams paramsLayoutU = (LinearLayout.LayoutParams)configLayoutU.getLayoutParams();
152
    paramsLayoutU.bottomMargin = padding;
153
    paramsLayoutU.topMargin    = 0;
154
    paramsLayoutU.leftMargin   = padding;
155
    paramsLayoutU.rightMargin  = padding;
156

    
157
    configLayoutU.setLayoutParams(paramsLayoutU);
158

    
159
    TextView textBorder   = configLayoutU.findViewById(R.id.configTextBorder);
160
    textBorder.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
161
    TextView textCorner   = configLayoutU.findViewById(R.id.configTextCorner);
162
    textCorner.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
163

    
164
    mSeekBarBorders = configLayoutU.findViewById(R.id.configSeekBarBorder);
165
    mCurrentBorders = mSeekBarBorders.getProgress();
166

    
167
    mSeekBarBorders.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
168
      {
169
      @Override
170
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
171
        {
172
        mCurrentBorders = progress;
173
        }
174

    
175
      @Override
176
      public void onStartTrackingTouch(SeekBar seekBar) {}
177

    
178
      @Override
179
      public void onStopTrackingTouch(SeekBar seekBar)
180
        {
181
        act.recreateStickers(mCurrentBorders,mCurrentCorners);
182
        }
183
      });
184

    
185
    mSeekBarCorners = configLayoutU.findViewById(R.id.configSeekBarCorner);
186
    mCurrentCorners = mSeekBarCorners.getProgress();
187

    
188
    mSeekBarCorners.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
189
      {
190
      @Override
191
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
192
        {
193
        mCurrentCorners = progress;
194
        }
195

    
196
      @Override
197
      public void onStartTrackingTouch(SeekBar seekBar) {}
198
      @Override
199
      public void onStopTrackingTouch(SeekBar seekBar)
200
        {
201
        act.recreateStickers(mCurrentBorders,mCurrentCorners);
202
        }
203
      });
204

    
205
    ///// LOWER LAYOUT /////////////////////////////////
206
    LinearLayout configLayoutL = act.findViewById(R.id.configLayoutLower);
207
    configLayoutL.setPadding(padding,padding,padding,padding);
208

    
209
    LinearLayout.LayoutParams paramsLayoutL = (LinearLayout.LayoutParams)configLayoutL.getLayoutParams();
210
    paramsLayoutL.bottomMargin = padding;
211
    paramsLayoutL.topMargin    = 0;
212
    paramsLayoutL.leftMargin   = padding;
213
    paramsLayoutL.rightMargin  = padding;
214

    
215
    configLayoutL.setLayoutParams(paramsLayoutL);
216

    
217
    createColorGrid(act, width, height);
218
    configLayoutL.addView(mGrid);
219
    }
220
}
(5-5/6)