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 int mSortMode = -1;
|
30
|
private ObjectGridCreator mCreator;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
void createGrid(final MainActivity act, int windowWidth, int sortMode)
|
35
|
{
|
36
|
if( mCreator==null ) mCreator = new ObjectGridCreator(windowWidth);
|
37
|
|
38
|
mSortMode = sortMode;
|
39
|
|
40
|
int numObjects = RubikObjectList.getNumObjects();
|
41
|
ScrollView scrollView = act.findViewById(R.id.objectScroll);
|
42
|
scrollView.removeAllViews();
|
43
|
|
44
|
mCreator.createObjectGrid(act,scrollView,sortMode);
|
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 = mCreator.getChildAt(child);
|
53
|
ImageButton button = mCreator.getButton(obj,v);
|
54
|
final int ordinal = mCreator.getObjectIndex(child);
|
55
|
|
56
|
button.setOnClickListener( new View.OnClickListener()
|
57
|
{
|
58
|
@Override
|
59
|
public void onClick(View v)
|
60
|
{
|
61
|
act.setCurrentObject(ordinal);
|
62
|
int w = displaymetrics.widthPixels;
|
63
|
int h = displaymetrics.heightPixels;
|
64
|
MainObjectPopup popup = new MainObjectPopup(act,ordinal,w,h);
|
65
|
popup.show(v);
|
66
|
}
|
67
|
});
|
68
|
}
|
69
|
}
|
70
|
|
71
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
|
73
|
void updateGrid(final MainActivity act, int scrW)
|
74
|
{
|
75
|
act.runOnUiThread(new Runnable()
|
76
|
{
|
77
|
@Override
|
78
|
public void run()
|
79
|
{
|
80
|
if( mSortMode<0 ) mSortMode = MainSettingsPopup.SORT_DEFAULT;
|
81
|
createGrid(act,scrW,mSortMode);
|
82
|
}
|
83
|
});
|
84
|
}
|
85
|
}
|
86
|
|