| 1 |
1c04d054
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
b42c8399
|
leszek
|
import android.util.DisplayMetrics;
|
| 13 |
1c04d054
|
leszek
|
import android.view.View;
|
| 14 |
|
|
import android.widget.ImageButton;
|
| 15 |
def32b2c
|
leszek
|
import android.widget.ScrollView;
|
| 16 |
1c04d054
|
leszek
|
|
| 17 |
def32b2c
|
leszek
|
import org.distorted.helpers.ObjectGridCreator;
|
| 18 |
1c04d054
|
leszek
|
import org.distorted.objects.RubikObject;
|
| 19 |
|
|
import org.distorted.objects.RubikObjectList;
|
| 20 |
|
|
|
| 21 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 22 |
|
|
|
| 23 |
|
|
public class MainScrollGrid
|
| 24 |
|
|
{
|
| 25 |
b42c8399
|
leszek
|
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 |
1c04d054
|
leszek
|
|
| 29 |
ae1ec951
|
leszek
|
private int mSortMode = -1;
|
| 30 |
ae0e03d2
|
leszek
|
private ObjectGridCreator mCreator;
|
| 31 |
def32b2c
|
leszek
|
|
| 32 |
1c04d054
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 33 |
|
|
|
| 34 |
8c4e4bf4
|
leszek
|
void createGrid(final MainActivity act, int windowWidth, int sortMode, int darkC, int passedC)
|
| 35 |
1c04d054
|
leszek
|
{
|
| 36 |
3eaf5f2a
|
leszek
|
if( mCreator==null ) mCreator = new ObjectGridCreator(windowWidth);
|
| 37 |
def32b2c
|
leszek
|
|
| 38 |
|
|
mSortMode = sortMode;
|
| 39 |
|
|
|
| 40 |
1c04d054
|
leszek
|
int numObjects = RubikObjectList.getNumObjects();
|
| 41 |
def32b2c
|
leszek
|
ScrollView scrollView = act.findViewById(R.id.objectScroll);
|
| 42 |
|
|
scrollView.removeAllViews();
|
| 43 |
b42c8399
|
leszek
|
|
| 44 |
8c4e4bf4
|
leszek
|
mCreator.createObjectGrid(act,scrollView,sortMode,darkC);
|
| 45 |
1c04d054
|
leszek
|
|
| 46 |
b42c8399
|
leszek
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
| 47 |
|
|
act.getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
| 48 |
|
|
|
| 49 |
1c04d054
|
leszek
|
for(int child=0; child<numObjects; child++)
|
| 50 |
|
|
{
|
| 51 |
|
|
final RubikObject obj = RubikObjectList.getObject(child);
|
| 52 |
def32b2c
|
leszek
|
View v = mCreator.getChildAt(child);
|
| 53 |
3eaf5f2a
|
leszek
|
ImageButton button = mCreator.getButton(obj,v);
|
| 54 |
|
|
final int ordinal = mCreator.getObjectIndex(child);
|
| 55 |
1c04d054
|
leszek
|
|
| 56 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
| 57 |
|
|
{
|
| 58 |
|
|
@Override
|
| 59 |
|
|
public void onClick(View v)
|
| 60 |
|
|
{
|
| 61 |
c02235d5
|
leszek
|
act.setCurrentObject(ordinal);
|
| 62 |
b42c8399
|
leszek
|
int w = displaymetrics.widthPixels;
|
| 63 |
|
|
int h = displaymetrics.heightPixels;
|
| 64 |
8c4e4bf4
|
leszek
|
MainObjectPopup popup = new MainObjectPopup(act,ordinal,w,h,darkC,passedC);
|
| 65 |
b42c8399
|
leszek
|
popup.show(v);
|
| 66 |
1c04d054
|
leszek
|
}
|
| 67 |
|
|
});
|
| 68 |
|
|
}
|
| 69 |
|
|
}
|
| 70 |
|
|
|
| 71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 72 |
|
|
|
| 73 |
8c4e4bf4
|
leszek
|
void updateGrid(final MainActivity act, int scrW, int darkC, int passedC)
|
| 74 |
1c04d054
|
leszek
|
{
|
| 75 |
|
|
act.runOnUiThread(new Runnable()
|
| 76 |
|
|
{
|
| 77 |
|
|
@Override
|
| 78 |
|
|
public void run()
|
| 79 |
|
|
{
|
| 80 |
417d51b6
|
leszek
|
if( mSortMode<0 ) mSortMode = MainSettingsPopup.SORT_DEFAULT;
|
| 81 |
8c4e4bf4
|
leszek
|
createGrid(act,scrW,mSortMode,darkC,passedC);
|
| 82 |
1c04d054
|
leszek
|
}
|
| 83 |
|
|
});
|
| 84 |
|
|
}
|
| 85 |
|
|
}
|