Revision 432a5f2c
Added by Leszek Koltunski about 3 years ago
| src/main/java/org/distorted/config/ConfigScreen.java | ||
|---|---|---|
| 14 | 14 |
import android.view.Gravity; |
| 15 | 15 |
import android.view.View; |
| 16 | 16 |
import android.widget.GridLayout; |
| 17 |
import android.widget.ImageButton; |
|
| 18 | 17 |
import android.widget.LinearLayout; |
| 19 | 18 |
import android.widget.PopupWindow; |
| 20 | 19 |
import android.widget.ScrollView; |
| 21 | 20 |
import android.widget.TextView; |
| 22 | 21 |
|
| 22 |
import org.distorted.helpers.PopupCreator; |
|
| 23 | 23 |
import org.distorted.objectlib.main.ObjectControl; |
| 24 | 24 |
|
| 25 | 25 |
import org.distorted.helpers.TransparentImageButton; |
| 26 | 26 |
import org.distorted.main.R; |
| 27 | 27 |
import org.distorted.main.RubikActivity; |
| 28 |
import org.distorted.objects.RubikObject; |
|
| 29 | 28 |
import org.distorted.objects.RubikObjectList; |
| 30 | 29 |
|
| 31 | 30 |
import static android.view.View.inflate; |
| ... | ... | |
| 51 | 50 |
|
| 52 | 51 |
private void setupObjectWindow(final ConfigActivity act, final float width, final float height) |
| 53 | 52 |
{
|
| 54 |
int cubeWidth = (int)(width/9); |
|
| 55 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
| 56 |
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f); |
|
| 57 |
mMaxRowCount = (int)((height-mBarHeight)/mObjectSize); |
|
| 53 |
int numObjects= RubikObjectList.getNumObjects(); |
|
| 54 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
|
| 55 |
mColCount = NUM_COLUMNS; |
|
| 56 |
|
|
| 57 |
int cubeSize = (int)(width/9); |
|
| 58 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
| 59 |
mObjectSize = (int)(cubeSize + 2*margin + 0.5f); |
|
| 60 |
mMaxRowCount = (int)((height-mBarHeight)/mObjectSize); |
|
| 58 | 61 |
|
| 59 | 62 |
ScrollView view = (ScrollView)inflate( act, R.layout.popup_object_simple, null); |
| 60 | 63 |
GridLayout objectGrid = view.findViewById(R.id.objectGrid); |
| 61 | 64 |
|
| 62 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount]; |
|
| 63 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount]; |
|
| 64 |
|
|
| 65 |
objectGrid.setColumnCount(mColCount); |
|
| 66 |
objectGrid.setRowCount(mRowCount); |
|
| 67 |
|
|
| 68 |
mObjectPopup = new PopupWindow(act); |
|
| 69 |
mObjectPopup.setFocusable(true); |
|
| 70 |
mObjectPopup.setContentView(view); |
|
| 71 |
|
|
| 72 |
int[] nextInRow = new int[mRowCount]; |
|
| 73 |
|
|
| 74 |
for(int row=0; row<mRowCount; row++) |
|
| 75 |
{
|
|
| 76 |
rowSpecs[row] = GridLayout.spec(row); |
|
| 77 |
nextInRow[row]= 0; |
|
| 78 |
} |
|
| 79 |
for(int col=0; col<mColCount; col++) |
|
| 80 |
{
|
|
| 81 |
colSpecs[col] = GridLayout.spec(col); |
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 65 |
PopupCreator.createObjectGrid(objectGrid,act,mRowCount,mColCount,numObjects,margin,cubeSize); |
|
| 85 | 66 |
|
| 86 |
for(int object=0; object<numObjects; object++)
|
|
| 67 |
for(int child=0; child<numObjects; child++)
|
|
| 87 | 68 |
{
|
| 88 |
final int ordinal = object; |
|
| 89 |
RubikObject rObject = RubikObjectList.getObject(ordinal); |
|
| 90 |
int row = object/NUM_COLUMNS; |
|
| 91 |
ImageButton button = new ImageButton(act); |
|
| 92 |
if( rObject!=null ) rObject.setIconTo(act,button); |
|
| 69 |
View button = objectGrid.getChildAt(child); |
|
| 70 |
final int ordinal = child; |
|
| 93 | 71 |
|
| 94 | 72 |
button.setOnClickListener( new View.OnClickListener() |
| 95 | 73 |
{
|
| ... | ... | |
| 107 | 85 |
mObjectPopup.dismiss(); |
| 108 | 86 |
} |
| 109 | 87 |
}); |
| 110 |
|
|
| 111 |
GridLayout.Spec rowS = rowSpecs[row]; |
|
| 112 |
GridLayout.Spec colS = colSpecs[nextInRow[row]]; |
|
| 113 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowS,colS); |
|
| 114 |
params.bottomMargin = margin; |
|
| 115 |
params.topMargin = margin; |
|
| 116 |
params.leftMargin = margin; |
|
| 117 |
params.rightMargin = margin; |
|
| 118 |
|
|
| 119 |
params.width = cubeWidth; |
|
| 120 |
params.height= cubeWidth; |
|
| 121 |
|
|
| 122 |
nextInRow[row]++; |
|
| 123 |
|
|
| 124 |
objectGrid.addView(button, params); |
|
| 125 | 88 |
} |
| 89 |
|
|
| 90 |
mObjectPopup = new PopupWindow(act); |
|
| 91 |
mObjectPopup.setFocusable(true); |
|
| 92 |
mObjectPopup.setContentView(view); |
|
| 126 | 93 |
} |
| 127 | 94 |
|
| 128 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 312 | 279 |
int width = act.getScreenWidthInPixels(); |
| 313 | 280 |
mBarHeight = act.getHeightBar(); |
| 314 | 281 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
| 315 |
|
|
| 316 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
|
| 317 |
mColCount = NUM_COLUMNS; |
|
| 318 |
|
|
| 319 | 282 |
mObjectOrdinal = objectOrdinal; |
| 320 | 283 |
|
| 321 | 284 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
| src/main/java/org/distorted/helpers/PopupCreator.java | ||
|---|---|---|
| 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 |
} |
|
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 35 | 35 |
import org.distorted.external.RubikScores; |
| 36 | 36 |
import org.distorted.external.RubikUpdates; |
| 37 | 37 |
|
| 38 |
import org.distorted.helpers.PopupCreator; |
|
| 38 | 39 |
import org.distorted.main.R; |
| 39 | 40 |
import org.distorted.main.RubikActivity; |
| 40 | 41 |
import org.distorted.dialogs.RubikDialogAbout; |
| ... | ... | |
| 182 | 183 |
|
| 183 | 184 |
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null); |
| 184 | 185 |
GridLayout objectGrid = view.findViewById(R.id.objectGrid); |
| 185 |
|
|
| 186 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount]; |
|
| 187 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount]; |
|
| 188 |
|
|
| 189 |
objectGrid.setColumnCount(mColCount); |
|
| 190 |
objectGrid.setRowCount(mRowCount); |
|
| 191 |
|
|
| 192 | 186 |
RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout); |
| 193 | 187 |
setupBottomLayout(act,bottomLayout); |
| 194 | 188 |
|
| 195 |
mObjectPopup = new PopupWindow(act); |
|
| 196 |
mObjectPopup.setFocusable(true); |
|
| 197 |
mObjectPopup.setContentView(view); |
|
| 198 |
|
|
| 199 |
int[] nextInRow = new int[mRowCount]; |
|
| 200 |
|
|
| 201 |
for(int row=0; row<mRowCount; row++) |
|
| 202 |
{
|
|
| 203 |
rowSpecs[row] = GridLayout.spec(row); |
|
| 204 |
nextInRow[row]= 0; |
|
| 205 |
} |
|
| 206 |
for(int col=0; col<mColCount; col++) |
|
| 207 |
{
|
|
| 208 |
colSpecs[col] = GridLayout.spec(col); |
|
| 209 |
} |
|
| 189 |
PopupCreator.createObjectGrid(objectGrid,act,mRowCount,mColCount,numObjects,margin,cubeSize); |
|
| 210 | 190 |
|
| 211 |
for(int object=0; object<numObjects; object++)
|
|
| 191 |
for(int child=0; child<numObjects; child++)
|
|
| 212 | 192 |
{
|
| 213 |
final int ordinal = object; |
|
| 214 |
final RubikObject rObject = RubikObjectList.getObject(object); |
|
| 215 |
int row = object/NUM_COLUMNS; |
|
| 216 |
ImageButton button = new ImageButton(act); |
|
| 217 |
if( rObject!=null ) rObject.setIconTo(act,button); |
|
| 193 |
View button = objectGrid.getChildAt(child); |
|
| 194 |
final int ordinal = child; |
|
| 218 | 195 |
|
| 219 | 196 |
button.setOnClickListener( new View.OnClickListener() |
| 220 | 197 |
{
|
| ... | ... | |
| 232 | 209 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
| 233 | 210 |
} |
| 234 | 211 |
}); |
| 235 |
|
|
| 236 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]); |
|
| 237 |
params.bottomMargin = margin; |
|
| 238 |
params.topMargin = margin; |
|
| 239 |
params.leftMargin = margin; |
|
| 240 |
params.rightMargin = margin; |
|
| 241 |
|
|
| 242 |
params.width = cubeSize; |
|
| 243 |
params.height= cubeSize; |
|
| 244 |
|
|
| 245 |
nextInRow[row]++; |
|
| 246 |
|
|
| 247 |
objectGrid.addView(button, params); |
|
| 248 | 212 |
} |
| 213 |
|
|
| 214 |
mObjectPopup = new PopupWindow(act); |
|
| 215 |
mObjectPopup.setFocusable(true); |
|
| 216 |
mObjectPopup.setContentView(view); |
|
| 249 | 217 |
} |
| 250 | 218 |
|
| 251 | 219 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
IAP, part 2: unify the way we create object popups in ScreenPlay and ConfigActivity.