Revision 85038b84
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
---|---|---|
25 | 25 |
import android.content.Context; |
26 | 26 |
import android.content.SharedPreferences; |
27 | 27 |
import android.content.res.Resources; |
28 |
import android.graphics.Color; |
|
28 | 29 |
import android.graphics.drawable.BitmapDrawable; |
29 | 30 |
import android.os.Build; |
30 | 31 |
import android.os.Bundle; |
... | ... | |
32 | 33 |
import android.view.Gravity; |
33 | 34 |
import android.view.LayoutInflater; |
34 | 35 |
import android.view.View; |
36 |
import android.view.ViewGroup; |
|
35 | 37 |
import android.widget.Button; |
36 | 38 |
import android.widget.GridLayout; |
37 | 39 |
import android.widget.ImageButton; |
38 | 40 |
import android.widget.LinearLayout; |
39 | 41 |
import android.widget.PopupWindow; |
40 | 42 |
import android.widget.RelativeLayout; |
43 |
import android.widget.ScrollView; |
|
41 | 44 |
import android.widget.TextView; |
42 | 45 |
|
46 |
import org.distorted.config.ConfigActivity; |
|
43 | 47 |
import org.distorted.dialogs.RubikDialogUpdates; |
44 | 48 |
import org.distorted.external.RubikNetwork; |
45 | 49 |
import org.distorted.external.RubikUpdates; |
50 |
import org.distorted.main.RubikRenderer; |
|
46 | 51 |
import org.distorted.objectlib.main.ObjectControl; |
47 | 52 |
|
48 | 53 |
import org.distorted.main.R; |
... | ... | |
61 | 66 |
|
62 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 68 |
|
64 |
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee
|
|
69 |
public class RubikScreenPlay extends RubikScreenAbstract implements RubikNetwork.Updatee
|
|
65 | 70 |
{ |
66 | 71 |
public static final int NUM_COLUMNS = 5; |
67 | 72 |
public static final int LEVELS_SHOWN = 10; |
68 | 73 |
|
69 |
private static final int[] BUTTON_LABELS = { R.string.scores, |
|
70 |
R.string.patterns, |
|
71 |
R.string.solver, |
|
72 |
R.string.tutorials, |
|
73 |
R.string.bandaged, |
|
74 |
R.string.about }; |
|
75 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
|
76 |
|
|
77 | 74 |
private static final float LAST_BUTTON = 1.5f; |
78 | 75 |
private static final int[] mLocation = new int[2]; |
79 | 76 |
|
80 |
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton; |
|
81 |
private TransparentButton mPlayButton; |
|
82 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
|
77 |
private ImageButton mAboutButton, mUpdatesButton, mExitButton; |
|
78 |
// private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
|
83 | 79 |
private LinearLayout mPlayLayout; |
84 | 80 |
private TextView mBubbleUpdates; |
81 |
private int mCurrentBubbleNumber; |
|
85 | 82 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
86 | 83 |
private int mLevelValue; |
87 | 84 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
88 | 85 |
private int mColCount, mRowCount, mMaxRowCount; |
89 |
private int mUpperBarHeight; |
|
86 |
private int mUpperBarHeight, mLowerBarHeight;
|
|
90 | 87 |
private boolean mShouldReactToEndOfScrambling; |
91 | 88 |
private int mBottomHeight; |
92 |
private float mScreenWidth; |
|
89 |
private float mScreenWidth, mScreenHeight;
|
|
93 | 90 |
private WeakReference<RubikActivity> mWeakAct; |
94 | 91 |
|
95 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
96 | 93 |
|
97 | 94 |
void leaveScreen(RubikActivity act) |
98 | 95 |
{ |
99 |
|
|
96 |
act.switchRenderingOn(); |
|
97 |
LinearLayout hiddenView = act.findViewById(R.id.hiddenView); |
|
98 |
hiddenView.removeAllViews(); |
|
100 | 99 |
} |
101 | 100 |
|
102 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
103 | 102 |
|
104 | 103 |
void enterScreen(final RubikActivity act) |
105 | 104 |
{ |
105 |
act.switchRenderingOff(); |
|
106 | 106 |
mWeakAct = new WeakReference<>(act); |
107 | 107 |
int numObjects = RubikObjectList.getNumObjects(); |
108 | 108 |
mScreenWidth = act.getScreenWidthInPixels(); |
109 |
mScreenHeight= act.getScreenHeightInPixels(); |
|
109 | 110 |
mUpperBarHeight = act.getHeightUpperBar(); |
111 |
mLowerBarHeight = act.getHeightLowerBar(); |
|
110 | 112 |
|
111 | 113 |
mMenuTextSize = mScreenWidth*RubikActivity.MENU_MED_TEXT_SIZE; |
112 | 114 |
mButtonSize = mScreenWidth*RubikActivity.BUTTON_TEXT_SIZE; |
... | ... | |
115 | 117 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
116 | 118 |
mColCount = NUM_COLUMNS; |
117 | 119 |
|
120 |
float titleSize = mScreenWidth*RubikActivity.TITLE_TEXT_SIZE; |
|
121 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
122 |
|
|
118 | 123 |
// TOP //////////////////////////// |
119 | 124 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar); |
120 | 125 |
layoutTop.removeAllViews(); |
126 |
TextView label = (TextView)inflater.inflate(R.layout.upper_text, null); |
|
127 |
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
128 |
// label.setText(R.string.app_name); |
|
129 |
layoutTop.addView(label); |
|
130 |
|
|
131 |
// BOTTOM ///////////////////////// |
|
132 |
LinearLayout layoutBot = act.findViewById(R.id.lowerBar); |
|
133 |
layoutBot.removeAllViews(); |
|
134 |
RelativeLayout relLayout = (RelativeLayout)inflater.inflate(R.layout.play_bottom_bar, null); |
|
135 |
//relLayout.setBackgroundColor(Color.parseColor("#000000")); |
|
136 |
layoutBot.addView(relLayout); |
|
137 |
|
|
138 |
TypedValue outValue = new TypedValue(); |
|
139 |
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
140 |
|
|
141 |
setupAboutButton(act,relLayout,outValue); |
|
142 |
setupUpdatesButtonAndBubble(act,relLayout,outValue); |
|
143 |
setupExitButton(act,relLayout,outValue); |
|
144 |
|
|
145 |
// POPUP ////////////////////////// |
|
146 |
LinearLayout hiddenView = act.findViewById(R.id.hiddenView); |
|
147 |
hiddenView.removeAllViews(); |
|
121 | 148 |
|
122 |
setupObjectButton(act,mScreenWidth); |
|
123 |
layoutTop.addView(mObjButton); |
|
149 |
ViewGroup.LayoutParams paramsMid = hiddenView.getLayoutParams(); |
|
150 |
paramsMid.height = (int)(mScreenHeight-mUpperBarHeight-mLowerBarHeight); |
|
151 |
hiddenView.setLayoutParams(paramsMid); |
|
124 | 152 |
|
125 |
setupMenuButton(act,mScreenWidth); |
|
126 |
layoutTop.addView(mMenuButton); |
|
153 |
label.setText("s:"+mScreenHeight+" u:"+mUpperBarHeight+" l:"+mLowerBarHeight); |
|
127 | 154 |
|
128 |
setupPlayButton(act,mScreenWidth);
|
|
129 |
layoutTop.addView(mPlayButton);
|
|
155 |
ScrollView scroll = (ScrollView)inflater.inflate(R.layout.popup_object_simple, null);
|
|
156 |
hiddenView.addView(scroll);
|
|
130 | 157 |
|
131 |
setupSolveButton(act); |
|
132 |
setupScrambleButton(act); |
|
133 |
createBottomPane(act,mSolveButton,mScrambleButton); |
|
158 |
setupScrollingObjects(act,scroll,mScreenWidth,mScreenHeight); |
|
134 | 159 |
} |
135 | 160 |
|
136 | 161 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
137 | 162 |
|
163 |
private void setupAboutButton(final RubikActivity act, RelativeLayout relLayout, TypedValue value) |
|
164 |
{ |
|
165 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info); |
|
166 |
mAboutButton = relLayout.findViewById(R.id.buttonAbout); |
|
167 |
mAboutButton.setImageResource(icon); |
|
168 |
mAboutButton.setBackgroundResource(value.resourceId); |
|
169 |
|
|
170 |
mAboutButton.setOnClickListener( new View.OnClickListener() |
|
171 |
{ |
|
172 |
@Override |
|
173 |
public void onClick(View v) |
|
174 |
{ |
|
175 |
RubikDialogAbout aDiag = new RubikDialogAbout(); |
|
176 |
aDiag.show(act.getSupportFragmentManager(), null); |
|
177 |
} |
|
178 |
}); |
|
179 |
} |
|
180 |
|
|
181 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
182 |
|
|
183 |
private void setupUpdatesButtonAndBubble(final RubikActivity act, RelativeLayout relLayout, TypedValue value) |
|
184 |
{ |
|
185 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download); |
|
186 |
mUpdatesButton = relLayout.findViewById(R.id.buttonDown); |
|
187 |
mUpdatesButton.setImageResource(icon); |
|
188 |
mUpdatesButton.setBackgroundResource(value.resourceId); |
|
189 |
|
|
190 |
mUpdatesButton.setOnClickListener( new View.OnClickListener() |
|
191 |
{ |
|
192 |
@Override |
|
193 |
public void onClick(View v) |
|
194 |
{ |
|
195 |
RubikDialogUpdates uDiag = new RubikDialogUpdates(); |
|
196 |
uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() ); |
|
197 |
} |
|
198 |
}); |
|
199 |
|
|
200 |
mBubbleUpdates = relLayout.findViewById(R.id.bubbleUpdates); |
|
201 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
|
202 |
|
|
203 |
RubikNetwork network = RubikNetwork.getInstance(); |
|
204 |
network.signUpForUpdates(this); |
|
205 |
} |
|
206 |
|
|
207 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
|
|
209 |
private void setupExitButton(final RubikActivity act, RelativeLayout relLayout, TypedValue value) |
|
210 |
{ |
|
211 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_exit,R.drawable.ui_medium_exit, R.drawable.ui_big_exit, R.drawable.ui_huge_exit); |
|
212 |
mExitButton = relLayout.findViewById(R.id.buttonExit); |
|
213 |
mExitButton.setImageResource(icon); |
|
214 |
mExitButton.setBackgroundResource(value.resourceId); |
|
215 |
|
|
216 |
mExitButton.setOnClickListener( new View.OnClickListener() |
|
217 |
{ |
|
218 |
@Override |
|
219 |
public void onClick(View v) |
|
220 |
{ |
|
221 |
act.finish(); |
|
222 |
} |
|
223 |
}); |
|
224 |
} |
|
225 |
|
|
226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
227 |
|
|
228 |
private void setupScrollingObjects(final RubikActivity act, final ScrollView view, final float width, final float height) |
|
229 |
{ |
|
230 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
231 |
int cubeWidth = (int)(width/NUM_COLUMNS) - 2*margin; |
|
232 |
|
|
233 |
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f); |
|
234 |
mMaxRowCount = (int)((height-mUpperBarHeight-mLowerBarHeight)/mObjectSize); |
|
235 |
|
|
236 |
GridLayout objectGrid = view.findViewById(R.id.objectGrid); |
|
237 |
|
|
238 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount]; |
|
239 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount]; |
|
240 |
|
|
241 |
objectGrid.setColumnCount(mColCount); |
|
242 |
objectGrid.setRowCount(mRowCount); |
|
243 |
|
|
244 |
int[] nextInRow = new int[mRowCount]; |
|
245 |
|
|
246 |
for(int row=0; row<mRowCount; row++) |
|
247 |
{ |
|
248 |
rowSpecs[row] = GridLayout.spec(row); |
|
249 |
nextInRow[row]= 0; |
|
250 |
} |
|
251 |
for(int col=0; col<mColCount; col++) |
|
252 |
{ |
|
253 |
colSpecs[col] = GridLayout.spec(col); |
|
254 |
} |
|
255 |
|
|
256 |
int numObjects = RubikObjectList.getNumObjects(); |
|
257 |
|
|
258 |
for(int object=0; object<numObjects; object++) |
|
259 |
{ |
|
260 |
final int ordinal = object; |
|
261 |
RubikObject rObject = RubikObjectList.getObject(ordinal); |
|
262 |
int row = object/NUM_COLUMNS; |
|
263 |
ImageButton button = new ImageButton(act); |
|
264 |
if( rObject!=null ) rObject.setIconTo(act,button); |
|
265 |
|
|
266 |
button.setOnClickListener( new View.OnClickListener() |
|
267 |
{ |
|
268 |
@Override |
|
269 |
public void onClick(View v) |
|
270 |
{ |
|
271 |
// TODO |
|
272 |
android.util.Log.e("D", "object "+ordinal+" clicked"); |
|
273 |
} |
|
274 |
}); |
|
275 |
|
|
276 |
GridLayout.Spec rowS = rowSpecs[row]; |
|
277 |
GridLayout.Spec colS = colSpecs[nextInRow[row]]; |
|
278 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowS,colS); |
|
279 |
params.bottomMargin = margin; |
|
280 |
params.topMargin = margin; |
|
281 |
params.leftMargin = margin; |
|
282 |
params.rightMargin = margin; |
|
283 |
|
|
284 |
params.width = cubeWidth; |
|
285 |
params.height= cubeWidth; |
|
286 |
|
|
287 |
nextInRow[row]++; |
|
288 |
|
|
289 |
objectGrid.addView(button, params); |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
293 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 |
/* |
|
138 | 295 |
private void setupObjectButton(final RubikActivity act, final float width) |
139 | 296 |
{ |
140 | 297 |
final int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
... | ... | |
251 | 408 |
objectGrid.setColumnCount(mColCount); |
252 | 409 |
objectGrid.setRowCount(mRowCount); |
253 | 410 |
|
254 |
RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout); |
|
255 |
setupBottomLayout(act,bottomLayout); |
|
256 |
|
|
257 | 411 |
mObjectPopup = new PopupWindow(act); |
258 | 412 |
mObjectPopup.setFocusable(true); |
259 | 413 |
mObjectPopup.setContentView(view); |
... | ... | |
285 | 439 |
@Override |
286 | 440 |
public void onClick(View v) |
287 | 441 |
{ |
288 |
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
|
289 |
{ |
|
290 |
RubikObjectList.setCurrObject(act,ordinal); |
|
291 |
act.changeObject(ordinal,true); |
|
292 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
293 |
mMovesController.clearMoves(act); |
|
294 |
} |
|
295 |
|
|
296 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
|
442 |
// TODO |
|
297 | 443 |
} |
298 | 444 |
}); |
299 | 445 |
|
... | ... | |
506 | 652 |
} |
507 | 653 |
}); |
508 | 654 |
} |
509 |
|
|
655 |
*/ |
|
510 | 656 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
511 |
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still |
|
512 |
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not |
|
513 |
// going to be called) |
|
514 |
// An reference to the old instance of RubikActivity will cause all sorts of strange issues. |
|
515 | 657 |
|
516 | 658 |
public void savePreferences(SharedPreferences.Editor editor) |
517 | 659 |
{ |
518 | 660 |
editor.putInt("play_LevelValue", mLevelValue ); |
519 |
|
|
520 |
if( mObjectPopup!=null ) |
|
521 |
{ |
|
522 |
mObjectPopup.dismiss(); |
|
523 |
mObjectPopup = null; |
|
524 |
} |
|
525 |
|
|
526 |
if( mMenuPopup!=null ) |
|
527 |
{ |
|
528 |
mMenuPopup.dismiss(); |
|
529 |
mMenuPopup = null; |
|
530 |
} |
|
531 |
|
|
532 |
if( mPlayPopup!=null ) |
|
533 |
{ |
|
534 |
mPlayPopup.dismiss(); |
|
535 |
mPlayPopup = null; |
|
536 |
} |
|
537 | 661 |
} |
538 | 662 |
|
539 | 663 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
682 | 806 |
|
683 | 807 |
if(control.isUINotBlocked()) |
684 | 808 |
{ |
685 |
if( mPlayPopup!=null ) mPlayPopup.dismiss(); |
|
809 |
// if( mPlayPopup!=null ) mPlayPopup.dismiss();
|
|
686 | 810 |
mLevelValue = level; |
687 | 811 |
mShouldReactToEndOfScrambling = true; |
688 | 812 |
control.scrambleObject(scrambles); |
... | ... | |
705 | 829 |
|
706 | 830 |
public void recreatePopup() |
707 | 831 |
{ |
708 |
mObjectPopup = null; |
|
709 |
|
|
710 | 832 |
int numObjects = RubikObjectList.getNumObjects(); |
711 | 833 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
712 | 834 |
mColCount = NUM_COLUMNS; |
835 |
|
|
836 |
RubikActivity act = mWeakAct.get(); |
|
837 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
838 |
|
|
839 |
act.runOnUiThread(new Runnable() |
|
840 |
{ |
|
841 |
@Override |
|
842 |
public void run() |
|
843 |
{ |
|
844 |
LinearLayout hiddenView = act.findViewById(R.id.hiddenView); |
|
845 |
hiddenView.removeAllViews(); |
|
846 |
ScrollView scroll = (ScrollView)inflater.inflate(R.layout.popup_object_simple, null); |
|
847 |
hiddenView.addView(scroll); |
|
848 |
setupScrollingObjects(act,scroll,mScreenWidth,mScreenHeight); |
|
849 |
|
|
850 |
mCurrentBubbleNumber--; |
|
851 |
updateNumberOfNewObjects(); |
|
852 |
} |
|
853 |
}); |
|
713 | 854 |
} |
714 | 855 |
|
715 | 856 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
719 | 860 |
return mShouldReactToEndOfScrambling; |
720 | 861 |
} |
721 | 862 |
|
863 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
864 |
|
|
865 |
private void updateNumberOfNewObjects() |
|
866 |
{ |
|
867 |
if( mCurrentBubbleNumber>0 ) |
|
868 |
{ |
|
869 |
String shownNum = String.valueOf(mCurrentBubbleNumber); |
|
870 |
mBubbleUpdates.setText(shownNum); |
|
871 |
mBubbleUpdates.setVisibility(View.VISIBLE); |
|
872 |
int height = (int)(0.05f*mScreenWidth); |
|
873 |
mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height); |
|
874 |
} |
|
875 |
else |
|
876 |
{ |
|
877 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
|
878 |
} |
|
879 |
} |
|
880 |
|
|
722 | 881 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
723 | 882 |
|
724 | 883 |
public void receiveUpdate(RubikUpdates updates) |
... | ... | |
727 | 886 |
|
728 | 887 |
if( act!=null ) |
729 | 888 |
{ |
889 |
mCurrentBubbleNumber = updates.getCompletedNumber(); |
|
890 |
|
|
730 | 891 |
act.runOnUiThread(new Runnable() |
731 | 892 |
{ |
732 | 893 |
@Override |
733 | 894 |
public void run() |
734 | 895 |
{ |
735 |
int num = updates.getCompletedNumber(); |
|
736 |
|
|
737 |
if( num>0 ) |
|
738 |
{ |
|
739 |
String shownNum = String.valueOf(num); |
|
740 |
mBubbleUpdates.setText(shownNum); |
|
741 |
mBubbleUpdates.setVisibility(View.VISIBLE); |
|
742 |
int height = (int)(0.05f*mScreenWidth); |
|
743 |
mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height); |
|
744 |
} |
|
745 |
else |
|
746 |
{ |
|
747 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
|
748 |
} |
|
896 |
updateNumberOfNewObjects(); |
|
749 | 897 |
} |
750 | 898 |
}); |
751 | 899 |
} |
Also available in: Unified diff
New UI