Project

General

Profile

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

magiccube / src / main / java / org / distorted / helpers / PopupCreator.java @ 432a5f2c

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.helpers;
11

    
12
import android.app.Activity;
13
import android.widget.GridLayout;
14
import android.widget.ImageButton;
15

    
16
import org.distorted.objects.RubikObject;
17
import org.distorted.objects.RubikObjectList;
18

    
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
public class PopupCreator
22
  {
23
  public static void createObjectGrid(GridLayout grid, Activity act, int rowCount, int colCount, int numObjects, int margin, int size)
24
    {
25
    GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount];
26
    GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount];
27

    
28
    grid.setColumnCount(colCount);
29
    grid.setRowCount(rowCount);
30

    
31
    int[] nextInRow = new int[rowCount];
32

    
33
    for(int row=0; row<rowCount; row++)
34
      {
35
      rowSpecs[row] = GridLayout.spec(row);
36
      nextInRow[row]= 0;
37
      }
38
    for(int col=0; col<colCount; col++)
39
      {
40
      colSpecs[col] = GridLayout.spec(col);
41
      }
42

    
43
    for(int object=0; object<numObjects; object++)
44
      {
45
      final RubikObject rObject = RubikObjectList.getObject(object);
46
      int row = object/colCount;
47
      ImageButton button = new ImageButton(act);
48
      if( rObject!=null ) rObject.setIconTo(act,button);
49

    
50
      GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
51
      params.bottomMargin = margin;
52
      params.topMargin    = margin;
53
      params.leftMargin   = margin;
54
      params.rightMargin  = margin;
55

    
56
      params.width = size;
57
      params.height= size;
58

    
59
      nextInRow[row]++;
60

    
61
      grid.addView(button, params);
62
      }
63
    }
64
  }
(3-3/5)