Project

General

Profile

« Previous | Next » 

Revision 2659f9dd

Added by Leszek Koltunski 9 months ago

progress with configurable stickers

View differences:

src/main/java/org/distorted/config/ConfigScreenPane.java
9 9

  
10 10
package org.distorted.config;
11 11

  
12
import android.app.Activity;
12 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;
13 18
import android.widget.LinearLayout;
14 19
import android.widget.SeekBar;
15 20
import android.widget.TextView;
16 21

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

  
19 25
///////////////////////////////////////////////////////////////////////////////////////////////////
......
27 33
  public static final float[] CORNER_STEPS = { 0.00f, 0.50f, 1.00f, 1.50f, 2.00f };
28 34

  
29 35
  private static final float PADDING_RATIO = 0.010f;
36
  private static final float MARGIN_RATIO  = 0.017f;
30 37
  private static final float TEXT_RATIO    = 0.025f;
31 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

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

  
35 76
///////////////////////////////////////////////////////////////////////////////////////////////////
36 77

  
37
  void updatePane(ConfigActivity act, int objectOrdinal)
78
  void resetUI()
38 79
    {
80
    mSeekBarBorders.setProgress(DEFAULT_BORDERS);
81
    mSeekBarCorners.setProgress(DEFAULT_CORNERS);
39 82

  
83
    // reset color grid
40 84
    }
41 85

  
42 86
///////////////////////////////////////////////////////////////////////////////////////////////////
43 87

  
44
  void resetUI()
88
  private void createColorGrid(final ConfigActivity act, int width, int height)
45 89
    {
46
    mSeekBarBorders.setProgress(DEFAULT_BORDERS);
47
    mSeekBarCorners.setProgress(DEFAULT_CORNERS);
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;
48 136
    }
49 137

  
50 138
///////////////////////////////////////////////////////////////////////////////////////////////////
51 139

  
52 140
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
53 141
    {
142
    int width = act.getScreenWidthInPixels();
54 143
    int height = act.getScreenHeightInPixels();
55 144
    float textSize = height*TEXT_RATIO;
56 145
    int padding = (int)(height*PADDING_RATIO);
......
124 213
    paramsLayoutL.rightMargin  = padding;
125 214

  
126 215
    configLayoutL.setLayoutParams(paramsLayoutL);
216

  
217
    createColorGrid(act, width, height);
218
    configLayoutL.addView(mGrid);
127 219
    }
128 220
}
src/main/res/layout/config.xml
86 86
        android:layout_marginLeft="5dp"
87 87
        android:layout_marginRight="5dp"
88 88
        android:layout_marginBottom="5dp"
89
        android:gravity="center"
89 90
        android:paddingLeft="5dp"
90 91
        android:paddingRight="5dp"
91 92
        android:background="@color/grey"

Also available in: Unified diff