Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / MainScrollGrid.java @ ae1ec951

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.ImageButton;
15
import android.widget.ScrollView;
16

    
17
import org.distorted.helpers.ObjectGridCreator;
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
  private ObjectGridCreator mCreator;
30
  private int mSortMode = -1;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
  void createGrid(final MainActivity act, int windowWidth, int sortMode)
35
    {
36
    if( mCreator==null ) mCreator = new ObjectGridCreator();
37

    
38
    mSortMode = sortMode;
39

    
40
    int numObjects = RubikObjectList.getNumObjects();
41
    int rowCount   = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
42
    int colCount   = NUM_COLUMNS;
43
    int objectSize = windowWidth / NUM_COLUMNS;
44
    int margin     = (int)(windowWidth*POPUP_MARGIN);
45
    int padding    = (int)(windowWidth*POPUP_PADDING);
46
    int cubeSize   = objectSize - 2*margin;
47

    
48
    ScrollView scrollView = act.findViewById(R.id.objectScroll);
49
    scrollView.removeAllViews();
50

    
51
    mCreator.createObjectGrid(scrollView,act,rowCount,colCount,numObjects,margin,cubeSize,padding,sortMode);
52

    
53
    DisplayMetrics displaymetrics = new DisplayMetrics();
54
    act.getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
55

    
56
    for(int child=0; child<numObjects; child++)
57
      {
58
      final RubikObject obj = RubikObjectList.getObject(child);
59
      View v = mCreator.getChildAt(child);
60
      ImageButton button = ObjectGridCreator.getButton(obj,v);
61
      final int ordinal = child;
62

    
63
      button.setOnClickListener( new View.OnClickListener()
64
        {
65
        @Override
66
        public void onClick(View v)
67
          {
68
          act.setCurrentObject(ordinal);
69
          int w = displaymetrics.widthPixels;
70
          int h = displaymetrics.heightPixels;
71
          MainObjectPopup popup = new MainObjectPopup(act,ordinal,w,h);
72
          popup.show(v);
73
          }
74
        });
75
      }
76
    }
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  void updateGrid(final MainActivity act, int scrW)
81
    {
82
    act.runOnUiThread(new Runnable()
83
      {
84
      @Override
85
      public void run()
86
        {
87
        if( mSortMode<0 ) mSortMode = MainSettingsPopup.SORT_DEFAULT;
88
        createGrid(act,scrW,mSortMode);
89
        }
90
      });
91
    }
92
  }
93

    
(3-3/4)