Revision 598de3ee
Added by Leszek Koltunski almost 3 years ago
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 |
} |
Also available in: Unified diff
add possible scrolling to the 'object' popup in case the grid of objects does not fit on the screen.