Revision 598de3ee
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffect.java | ||
---|---|---|
50 | 50 |
} |
51 | 51 |
} |
52 | 52 |
|
53 |
private static int NUM_EFFECTS = Type.values().length; |
|
53 |
private static final int NUM_EFFECTS = Type.values().length;
|
|
54 | 54 |
private static final int NUM_PHASES = 2; |
55 | 55 |
private static final int FAKE_EFFECT_ID = -1; |
56 | 56 |
private static final Type[] types; |
... | ... | |
68 | 68 |
|
69 | 69 |
private EffectController mController; |
70 | 70 |
private int mDuration; |
71 |
private int[] mEffectReturned; |
|
72 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
73 |
private int[] mEffectFinished; |
|
74 |
private boolean[] mPhaseActive; |
|
71 |
private final int[] mEffectReturned;
|
|
72 |
private final int[] mCubeEffectNumber, mNodeEffectNumber;
|
|
73 |
private final int[] mEffectFinished;
|
|
74 |
private final boolean[] mPhaseActive;
|
|
75 | 75 |
|
76 | 76 |
TwistyObject[] mObject; |
77 | 77 |
DistortedScreen mScreen; |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
86 | 86 |
public static final int FLAGS2= View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
87 | 87 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
88 | 88 |
|
89 |
private static final float RATIO_BAR = 0.10f; |
|
90 |
private static final float RATIO_INSET= 0.08f; |
|
91 |
|
|
89 | 92 |
private boolean mJustStarted; |
90 | 93 |
private FirebaseAnalytics mFirebaseAnalytics; |
91 | 94 |
private static int mScreenWidth, mScreenHeight; |
92 | 95 |
private boolean mPolicyAccepted, mIsChinese; |
93 | 96 |
private int mCurrentApiVersion; |
97 |
private int mHeightUpperBar, mHeightLowerBar; |
|
94 | 98 |
|
95 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
96 | 100 |
|
... | ... | |
116 | 120 |
|
117 | 121 |
hideNavigationBar(); |
118 | 122 |
cutoutHack(); |
123 |
computeBarHeights(); |
|
119 | 124 |
// askForPermissions(); |
120 | 125 |
} |
121 | 126 |
|
127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
128 |
// this does not include possible insets |
|
129 |
|
|
130 |
private void computeBarHeights() |
|
131 |
{ |
|
132 |
float height = getScreenHeightInPixels(); |
|
133 |
int barHeight = (int)(height*RATIO_BAR); |
|
134 |
mHeightLowerBar = barHeight; |
|
135 |
mHeightUpperBar = barHeight; |
|
136 |
} |
|
137 |
|
|
122 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
123 | 139 |
|
124 | 140 |
private void hideNavigationBar() |
... | ... | |
159 | 175 |
|
160 | 176 |
LinearLayout layoutHid = findViewById(R.id.hiddenBar); |
161 | 177 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
162 |
paramsHid.height = (int)(0.8f*insetHeight);
|
|
178 |
paramsHid.height = (int)(insetHeight*RATIO_INSET);
|
|
163 | 179 |
layoutHid.setLayoutParams(paramsHid); |
180 |
mHeightUpperBar += paramsHid.height; |
|
164 | 181 |
} |
165 | 182 |
|
166 |
final float RATIO = 0.10f; |
|
167 | 183 |
float height = getScreenHeightInPixels(); |
168 | 184 |
|
169 | 185 |
LinearLayout layoutTop = findViewById(R.id.upperBar); |
170 | 186 |
LinearLayout layoutBot = findViewById(R.id.lowerBar); |
171 | 187 |
|
172 | 188 |
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams(); |
173 |
paramsTop.height = (int)(height*RATIO); |
|
189 |
paramsTop.height = (int)(height*RATIO_BAR);
|
|
174 | 190 |
layoutTop.setLayoutParams(paramsTop); |
175 | 191 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
176 |
paramsBot.height = (int)(height*RATIO); |
|
192 |
paramsBot.height = (int)(height*RATIO_BAR);
|
|
177 | 193 |
layoutBot.setLayoutParams(paramsBot); |
178 | 194 |
} |
179 | 195 |
|
... | ... | |
380 | 396 |
return mFirebaseAnalytics; |
381 | 397 |
} |
382 | 398 |
|
399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
400 |
|
|
401 |
public int getHeightUpperBar() |
|
402 |
{ |
|
403 |
return mHeightUpperBar; |
|
404 |
} |
|
405 |
|
|
406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
407 |
|
|
408 |
public int getHeightLowerBar() |
|
409 |
{ |
|
410 |
return mHeightLowerBar; |
|
411 |
} |
|
412 |
|
|
383 | 413 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
384 | 414 |
|
385 | 415 |
public TwistyObject getObject() |
src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
---|---|---|
32 | 32 |
import android.widget.ImageButton; |
33 | 33 |
import android.widget.LinearLayout; |
34 | 34 |
import android.widget.PopupWindow; |
35 |
import android.widget.ScrollView; |
|
35 | 36 |
|
36 | 37 |
import org.distorted.control.RubikControl; |
37 | 38 |
import org.distorted.dialogs.RubikDialogAbout; |
... | ... | |
72 | 73 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
73 | 74 |
private int mLevelValue; |
74 | 75 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
75 |
private int mColCount, mRowCount; |
|
76 |
private int mColCount, mRowCount, mMaxRowCount;
|
|
76 | 77 |
private LinearLayout mPlayLayout; |
77 | 78 |
|
78 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
87 | 88 |
void enterScreen(final RubikActivity act) |
88 | 89 |
{ |
89 | 90 |
float width = act.getScreenWidthInPixels(); |
91 |
float height= act.getScreenHeightInPixels(); |
|
90 | 92 |
|
91 | 93 |
mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE; |
92 | 94 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE; |
... | ... | |
99 | 101 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
100 | 102 |
layoutTop.removeAllViews(); |
101 | 103 |
|
102 |
setupObjectWindow(act,width); |
|
104 |
setupObjectWindow(act,width,height);
|
|
103 | 105 |
setupObjectButton(act,width); |
104 | 106 |
layoutTop.addView(mObjButton); |
105 | 107 |
|
... | ... | |
128 | 130 |
@Override |
129 | 131 |
public void onClick(View view) |
130 | 132 |
{ |
131 |
if(act.getPreRender().isUINotBlocked()) |
|
133 |
if( mObjectPopup!=null && act.getPreRender().isUINotBlocked())
|
|
132 | 134 |
{ |
133 |
if( mObjectPopup==null ) |
|
134 |
{ |
|
135 |
// I completely don't understand it, but Firebase says occasionally mObjectPopup is null here. Recreate. |
|
136 |
float width = act.getScreenWidthInPixels(); |
|
137 |
setupObjectWindow(act,width); |
|
138 |
} |
|
139 |
|
|
140 |
mObjectPopup.setFocusable(false); |
|
141 |
mObjectPopup.update(); |
|
135 |
int rowCount = Math.min(mMaxRowCount,mRowCount); |
|
142 | 136 |
|
143 | 137 |
View popupView = mObjectPopup.getContentView(); |
144 | 138 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
145 | 139 |
|
146 | 140 |
mObjectPopup.showAsDropDown(view, margin, margin); |
147 |
mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount); |
|
148 |
|
|
141 |
mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*rowCount); |
|
149 | 142 |
mObjectPopup.setFocusable(true); |
150 | 143 |
mObjectPopup.update(); |
151 | 144 |
} |
... | ... | |
165 | 158 |
@Override |
166 | 159 |
public void onClick(View view) |
167 | 160 |
{ |
168 |
if(act.getPreRender().isUINotBlocked()) |
|
161 |
if( mPlayPopup!=null && act.getPreRender().isUINotBlocked())
|
|
169 | 162 |
{ |
170 |
if( mPlayPopup==null ) |
|
171 |
{ |
|
172 |
// I completely don't understand it, but Firebase says occasionally mPlayPopup is null here. Recreate. |
|
173 |
float width = act.getScreenWidthInPixels(); |
|
174 |
setupPlayWindow(act,width); |
|
175 |
} |
|
176 |
|
|
177 |
mPlayPopup.setFocusable(false); |
|
178 |
mPlayPopup.update(); |
|
179 |
|
|
180 | 163 |
View popupView = mPlayPopup.getContentView(); |
181 | 164 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
182 | 165 |
|
... | ... | |
206 | 189 |
@Override |
207 | 190 |
public void onClick(View view) |
208 | 191 |
{ |
209 |
if(act.getPreRender().isUINotBlocked()) |
|
192 |
if( mMenuPopup!=null && act.getPreRender().isUINotBlocked())
|
|
210 | 193 |
{ |
211 |
if( mMenuPopup==null ) |
|
212 |
{ |
|
213 |
// I completely don't understand it, but Firebase says occasionally mMenuPopup is null here. Recreate. |
|
214 |
float width = act.getScreenWidthInPixels(); |
|
215 |
setupMenuWindow(act,width); |
|
216 |
} |
|
217 |
|
|
218 |
mMenuPopup.setFocusable(false); |
|
219 |
mMenuPopup.update(); |
|
220 |
|
|
221 | 194 |
View popupView = mMenuPopup.getContentView(); |
222 | 195 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
223 | 196 |
|
224 | 197 |
mMenuPopup.showAsDropDown(view, (int)(-width/12), margin, Gravity.CENTER); |
225 | 198 |
mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight); |
226 | 199 |
mMenuPopup.setFocusable(true); |
227 |
mMenuPopup.update(); |
|
228 | 200 |
} |
229 | 201 |
} |
230 | 202 |
}); |
... | ... | |
232 | 204 |
|
233 | 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
234 | 206 |
|
235 |
private void setupObjectWindow(final RubikActivity act, final float width) |
|
207 |
private void setupObjectWindow(final RubikActivity act, final float width, final float height)
|
|
236 | 208 |
{ |
237 |
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
238 |
final View layout = layoutInflater.inflate(R.layout.popup_objects, null); |
|
239 |
GridLayout objectGrid = layout.findViewById(R.id.objectGrid); |
|
209 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2); |
|
210 |
|
|
211 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon); |
|
212 |
int cubeWidth = bd.getIntrinsicWidth(); |
|
213 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
214 |
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f); |
|
215 |
int upperBarHeight = act.getHeightUpperBar(); |
|
216 |
mMaxRowCount = (int)((height-upperBarHeight)/mObjectSize); |
|
217 |
GridLayout objectGrid = new GridLayout(act); |
|
218 |
mObjectPopup = new PopupWindow(act); |
|
219 |
mObjectPopup.setFocusable(true); |
|
220 |
|
|
221 |
if( mMaxRowCount<mRowCount ) |
|
222 |
{ |
|
223 |
ScrollView scrollView = new ScrollView(act); |
|
224 |
scrollView.addView(objectGrid); |
|
225 |
mObjectPopup.setContentView(scrollView); |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
mObjectPopup.setContentView(objectGrid); |
|
230 |
} |
|
240 | 231 |
|
241 | 232 |
int[] indices = ObjectList.getIndices(); |
242 | 233 |
|
... | ... | |
258 | 249 |
colSpecs[col] = GridLayout.spec(col); |
259 | 250 |
} |
260 | 251 |
|
261 |
mObjectPopup = new PopupWindow(act); |
|
262 |
mObjectPopup.setContentView(layout); |
|
263 |
mObjectPopup.setFocusable(true); |
|
264 |
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2); |
|
265 |
|
|
266 |
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon); |
|
267 |
int cubeWidth = bd.getIntrinsicWidth(); |
|
268 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
269 |
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f); |
|
270 |
|
|
271 | 252 |
for(int object=0; object< ObjectList.NUM_OBJECTS; object++) |
272 | 253 |
{ |
273 | 254 |
final ObjectList list = ObjectList.getObject(object); |
... | ... | |
574 | 555 |
|
575 | 556 |
if(pre.isUINotBlocked()) |
576 | 557 |
{ |
577 |
mPlayPopup.dismiss(); |
|
558 |
if( mPlayPopup!=null ) mPlayPopup.dismiss();
|
|
578 | 559 |
mLevelValue = level; |
579 | 560 |
pre.scrambleObject(scrambles); |
580 | 561 |
} |
src/main/res/layout/popup_objects.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:id="@+id/objectGrid" |
|
4 |
android:layout_width="wrap_content" |
|
5 |
android:layout_height="wrap_content"> |
|
6 |
</GridLayout> |
Also available in: Unified diff
add possible scrolling to the 'object' popup in case the grid of objects does not fit on the screen.