Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / MainScrollGrid.java @ 18b0ae9c

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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.main;
11

    
12
import android.util.DisplayMetrics;
13
import android.view.View;
14
import android.widget.GridLayout;
15
import android.widget.ImageButton;
16

    
17
import org.distorted.helpers.PopupCreator;
18
import org.distorted.objects.RubikObject;
19
import org.distorted.objects.RubikObjectList;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public class MainScrollGrid
24
  {
25
  public static final int   NUM_COLUMNS  = 5;
26
  public static final float POPUP_PADDING= 0.035f;
27
  public static final float POPUP_MARGIN = 0.024f;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
  void createGrid(final MainActivity act, int windowWidth)
32
    {
33
    int numObjects = RubikObjectList.getNumObjects();
34
    int rowCount   = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
35
    int colCount   = NUM_COLUMNS;
36
    int objectSize = windowWidth / NUM_COLUMNS;
37
    int margin     = (int)(windowWidth*POPUP_MARGIN);
38
    int padding    = (int)(windowWidth*POPUP_PADDING);
39
    int cubeSize   = objectSize - 2*margin;
40

    
41
    GridLayout objectGrid = act.findViewById(R.id.objectGrid);
42
    objectGrid.removeAllViews();
43

    
44
    PopupCreator.createObjectGrid(objectGrid,act,rowCount,colCount,numObjects,margin,cubeSize,padding);
45

    
46
    DisplayMetrics displaymetrics = new DisplayMetrics();
47
    act.getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
48

    
49
    for(int child=0; child<numObjects; child++)
50
      {
51
      final RubikObject obj = RubikObjectList.getObject(child);
52
      View v = objectGrid.getChildAt(child);
53
      ImageButton button = PopupCreator.getButton(obj,v);
54
      final int ordinal = child;
55

    
56
      button.setOnClickListener( new View.OnClickListener()
57
        {
58
        @Override
59
        public void onClick(View v)
60
          {
61
          int w = displaymetrics.widthPixels;
62
          int h = displaymetrics.heightPixels;
63
          MainObjectPopup popup = new MainObjectPopup(act,ordinal,w,h);
64
          popup.show(v);
65
          }
66
        });
67
      }
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  void updateGrid(final MainActivity act, int scrW)
73
    {
74
    act.runOnUiThread(new Runnable()
75
      {
76
      @Override
77
      public void run()
78
        {
79
        createGrid(act,scrW);
80
        }
81
      });
82
    }
83
  }
84

    
(3-3/3)