Project

General

Profile

« Previous | Next » 

Revision fa679111

Added by Leszek Koltunski over 4 years ago

Make the ObjectPopup a 2D grid - corrections.

View differences:

src/main/java/org/distorted/objects/RubikObjectList.java
42 42
                       {5 , 24, R.raw.cube5, R.drawable.ui_small_cube5, R.drawable.ui_medium_cube5, R.drawable.ui_big_cube5, R.drawable.ui_huge_cube5}
43 43
                     },
44 44
         RubikCube.class,
45
         new RubikMovementCube()
45
         new RubikMovementCube(),
46
         0
46 47
       ),
47 48

  
48 49
  PYRA (
......
52 53
                       {5 , 20, R.raw.pyra5, R.drawable.ui_small_pyra5, R.drawable.ui_medium_pyra5, R.drawable.ui_big_pyra5, R.drawable.ui_huge_pyra5}
53 54
                     },
54 55
         RubikPyraminx.class,
55
         new RubikMovementPyraminx()
56
         new RubikMovementPyraminx(),
57
         1
56 58
       ),
57 59

  
58 60
  DINO (
......
60 62
                       {3 , 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
61 63
                     },
62 64
         RubikDino.class,
63
         new RubikMovementDino()
65
         new RubikMovementDino(),
66
         2
64 67
       ),
65 68
  ;
66 69

  
......
72 75
  private final int[] mObjectSizes, mMaxLevels, mSmallIconIDs, mMediumIconIDs, mBigIconIDs, mHugeIconIDs, mResourceIDs;
73 76
  private final Class<? extends RubikObject> mObjectClass;
74 77
  private final RubikMovement mObjectMovementClass;
78
  private final int mColumn, mNumSizes;
79

  
75 80
  private static final RubikObjectList[] objects;
76 81
  private static int mNumAll;
77 82
  private static int[] mIndices;
83
  private static int mColCount, mRowCount;
78 84

  
79 85
  static
80 86
    {
......
85 91
    int maxLevel= Integer.MIN_VALUE;
86 92
    int maxSize = Integer.MIN_VALUE;
87 93

  
88
    mIndices = new int[] {0,1,2};
89

  
90 94
    for(RubikObjectList object: RubikObjectList.values())
91 95
      {
92 96
      objects[i] = object;
......
108 112
    }
109 113

  
110 114
///////////////////////////////////////////////////////////////////////////////////////////////////
111
// TODO
115

  
116
  private static void setUpColAndRow()
117
    {
118
    mIndices = new int[NUM_OBJECTS];
119
    mColCount= 0;
120

  
121
    for(int obj=0; obj<NUM_OBJECTS; obj++)
122
      {
123
      mIndices[obj] = objects[obj].mColumn;
124
      if( mIndices[obj]>=mColCount ) mColCount = mIndices[obj]+1;
125
      }
126

  
127
    mRowCount = 0;
128

  
129
    for(int col=0; col<mColCount; col++)
130
      {
131
      int numObjects = computeNumObjectsInColumn(col);
132
      if( numObjects>mRowCount ) mRowCount = numObjects;
133
      }
134
    }
135

  
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

  
138
  private static int computeNumObjectsInColumn(int column)
139
    {
140
    int num=0;
141

  
142
    for(int object=0; object<NUM_OBJECTS; object++)
143
      {
144
      if( objects[object].mColumn == column )
145
        {
146
        num += objects[object].mNumSizes;
147
        }
148
      }
149

  
150
    return num;
151
    }
152

  
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

  
112 155
  public static int getColumnCount()
113 156
    {
114
    return 3;
157
    if( mIndices==null ) setUpColAndRow();
158

  
159
    return mColCount;
115 160
    }
116 161

  
117 162
///////////////////////////////////////////////////////////////////////////////////////////////////
118
// TODO
163

  
119 164
  public static int getRowCount()
120 165
    {
121
    return 4;
166
    if( mIndices==null ) setUpColAndRow();
167

  
168
    return mRowCount;
122 169
    }
123 170

  
124 171
///////////////////////////////////////////////////////////////////////////////////////////////////
125
// TODO
172

  
126 173
  public static int[] getIndices()
127 174
    {
175
    if( mIndices==null ) setUpColAndRow();
176

  
128 177
    return mIndices;
129 178
    }
130 179

  
......
307 356

  
308 357
///////////////////////////////////////////////////////////////////////////////////////////////////
309 358

  
310
  RubikObjectList(int[][] info, Class<? extends RubikObject> object , RubikMovement movement)
359
  RubikObjectList(int[][] info, Class<? extends RubikObject> object , RubikMovement movement, int column)
311 360
    {
312
    int length = info.length;
361
    mNumSizes = info.length;
313 362

  
314
    mObjectSizes  = new int[length];
315
    mMaxLevels    = new int[length];
316
    mResourceIDs  = new int[length];
317
    mSmallIconIDs = new int[length];
318
    mMediumIconIDs= new int[length];
319
    mBigIconIDs   = new int[length];
320
    mHugeIconIDs  = new int[length];
363
    mObjectSizes  = new int[mNumSizes];
364
    mMaxLevels    = new int[mNumSizes];
365
    mResourceIDs  = new int[mNumSizes];
366
    mSmallIconIDs = new int[mNumSizes];
367
    mMediumIconIDs= new int[mNumSizes];
368
    mBigIconIDs   = new int[mNumSizes];
369
    mHugeIconIDs  = new int[mNumSizes];
321 370

  
322
    for(int i=0; i<length; i++)
371
    for(int i=0; i<mNumSizes; i++)
323 372
      {
324 373
      mObjectSizes[i]  = info[i][0];
325 374
      mMaxLevels[i]    = info[i][1];
......
332 381

  
333 382
    mObjectClass         = object;
334 383
    mObjectMovementClass = movement;
384
    mColumn              = column;
335 385
    }
336 386

  
337 387
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/states/RubikStatePlay.java
175 175
          {
176 176
          boolean vertical = act.isVertical();
177 177
          mObjectGrid.setOrientation(vertical ? GridLayout.VERTICAL:GridLayout.HORIZONTAL);
178
          mObjectPopup.showAsDropDown(view, 0, margin, Gravity.LEFT);
178
          mObjectPopup.showAsDropDown(view, margin, margin, Gravity.LEFT);
179 179

  
180
          if( android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1 )
181
            {
182
            int layhei = mObjectSize * (vertical? mRowCount:mColCount);
183
            int laywid = mObjectSize * (vertical? mColCount:mRowCount);
184
            mObjectPopup.update(view, laywid, layhei);
185
            }
180
          int layhei = mObjectSize * (vertical? mRowCount:mColCount);
181
          int laywid = mObjectSize * (vertical? mColCount:mRowCount);
182
          mObjectPopup.update(view, laywid, layhei);
186 183
          }
187 184
        }
188 185
      });
......
383 380
    mObjectGrid.setColumnCount(mColCount);
384 381
    mObjectGrid.setRowCount(mRowCount);
385 382

  
383
    int[] nextInColumn = new int[mColCount];
384

  
386 385
    for(int row=0; row<mRowCount; row++)
387 386
      {
388 387
      rowSpecs[row] = GridLayout.spec(row);
......
390 389
    for(int col=0; col<mColCount; col++)
391 390
      {
392 391
      colSpecs[col] = GridLayout.spec(col);
392
      nextInColumn[col] =0;
393 393
      }
394 394

  
395 395
    mObjectPopup = new PopupWindow(act);
......
409 409
      int[] icons = list.getIconIDs();
410 410
      int len = sizes.length;
411 411
      final int obj = object;
412
      int col = indices[object];
412 413

  
413 414
      for(int i=0; i<len; i++)
414 415
        {
......
434 435
            }
435 436
          });
436 437

  
437
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[index],colSpecs[indices[object]]);
438
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[nextInColumn[col]],colSpecs[col]);
438 439
        params.bottomMargin = margin;
439 440
        params.topMargin    = margin;
440 441
        params.leftMargin   = margin;
441 442
        params.rightMargin  = margin;
442 443

  
444
        nextInColumn[col]++;
445

  
443 446
        mObjectGrid.addView(button, params);
444 447
        }
445 448
      }

Also available in: Unified diff