1 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fcd5b990
|
Leszek Koltunski
|
package org.distorted.screens;
|
21 |
211b48f2
|
Leszek Koltunski
|
|
22 |
4c0cd600
|
Leszek Koltunski
|
import android.content.Context;
|
23 |
211b48f2
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
24 |
b600ccd9
|
Leszek Koltunski
|
import android.content.res.Resources;
|
25 |
4c0cd600
|
Leszek Koltunski
|
import android.graphics.drawable.BitmapDrawable;
|
26 |
255492a0
|
Leszek Koltunski
|
import android.os.Build;
|
27 |
e03e0352
|
Leszek Koltunski
|
import android.os.Bundle;
|
28 |
e3c74c0f
|
Leszek Koltunski
|
import android.util.TypedValue;
|
29 |
255492a0
|
Leszek Koltunski
|
import android.view.Gravity;
|
30 |
211b48f2
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
31 |
|
|
import android.view.View;
|
32 |
|
|
import android.widget.Button;
|
33 |
e07c48a2
|
Leszek Koltunski
|
import android.widget.GridLayout;
|
34 |
211b48f2
|
Leszek Koltunski
|
import android.widget.ImageButton;
|
35 |
|
|
import android.widget.LinearLayout;
|
36 |
4c0cd600
|
Leszek Koltunski
|
import android.widget.PopupWindow;
|
37 |
d6e7c7fb
|
Leszek Koltunski
|
import android.widget.RelativeLayout;
|
38 |
10373dc7
|
Leszek Koltunski
|
import android.widget.TextView;
|
39 |
211b48f2
|
Leszek Koltunski
|
|
40 |
5f3801d3
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogUpdates;
|
41 |
63dd19c4
|
Leszek Koltunski
|
import org.distorted.network.RubikNetwork;
|
42 |
|
|
import org.distorted.network.RubikUpdates;
|
43 |
2afc6754
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
44 |
3f7a4363
|
Leszek Koltunski
|
|
45 |
|
|
import org.distorted.main.R;
|
46 |
|
|
import org.distorted.main.RubikActivity;
|
47 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogAbout;
|
48 |
a8576d91
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogPattern;
|
49 |
e03e0352
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogScores;
|
50 |
234a7582
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogTutorial;
|
51 |
55e6be1d
|
Leszek Koltunski
|
import org.distorted.helpers.TransparentButton;
|
52 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
53 |
6a083c6a
|
Leszek Koltunski
|
import org.distorted.network.RubikScores;
|
54 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
55 |
|
|
import org.distorted.objects.RubikObjectList;
|
56 |
211b48f2
|
Leszek Koltunski
|
|
57 |
b600ccd9
|
Leszek Koltunski
|
import static android.view.View.inflate;
|
58 |
88d28110
|
Leszek Koltunski
|
|
59 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
|
|
|
61 |
63dd19c4
|
Leszek Koltunski
|
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee
|
62 |
211b48f2
|
Leszek Koltunski
|
{
|
63 |
6e3fcb91
|
Leszek Koltunski
|
public static final int NUM_COLUMNS = 5;
|
64 |
00af5060
|
Leszek Koltunski
|
public static final int LEVELS_SHOWN = 10;
|
65 |
211b48f2
|
Leszek Koltunski
|
|
66 |
7cf2637d
|
Leszek Koltunski
|
private static final int[] BUTTON_LABELS = { R.string.scores,
|
67 |
|
|
R.string.patterns,
|
68 |
|
|
R.string.solver,
|
69 |
|
|
R.string.tutorials,
|
70 |
|
|
R.string.about };
|
71 |
|
|
|
72 |
e03e0352
|
Leszek Koltunski
|
private static final int NUM_BUTTONS = BUTTON_LABELS.length;
|
73 |
de62316a
|
Leszek Koltunski
|
private static final float LAST_BUTTON = 1.5f;
|
74 |
dc78f395
|
Leszek Koltunski
|
private static final int[] mLocation = new int[2];
|
75 |
e03e0352
|
Leszek Koltunski
|
|
76 |
0873a75a
|
Leszek Koltunski
|
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
|
77 |
033100af
|
Leszek Koltunski
|
private TransparentButton mPlayButton;
|
78 |
0254cfd7
|
Leszek Koltunski
|
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
|
79 |
400ff34d
|
Leszek Koltunski
|
private LinearLayout mPlayLayout;
|
80 |
10373dc7
|
Leszek Koltunski
|
private TextView mBubbleUpdates;
|
81 |
0254cfd7
|
Leszek Koltunski
|
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
|
82 |
85b09df4
|
Leszek Koltunski
|
private int mLevelValue;
|
83 |
e07c48a2
|
Leszek Koltunski
|
private float mButtonSize, mMenuItemSize, mMenuTextSize;
|
84 |
598de3ee
|
Leszek Koltunski
|
private int mColCount, mRowCount, mMaxRowCount;
|
85 |
255492a0
|
Leszek Koltunski
|
private int mUpperBarHeight;
|
86 |
dd874ae8
|
Leszek Koltunski
|
private boolean mShouldReactToEndOfScrambling;
|
87 |
6e3fcb91
|
Leszek Koltunski
|
private int mBottomHeight;
|
88 |
9c39179e
|
Leszek Koltunski
|
private float mScreenWidth;
|
89 |
255492a0
|
Leszek Koltunski
|
|
90 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
f5da732a
|
Leszek Koltunski
|
void leaveScreen(RubikActivity act)
|
93 |
211b48f2
|
Leszek Koltunski
|
{
|
94 |
85b09df4
|
Leszek Koltunski
|
|
95 |
211b48f2
|
Leszek Koltunski
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
f5da732a
|
Leszek Koltunski
|
void enterScreen(final RubikActivity act)
|
100 |
211b48f2
|
Leszek Koltunski
|
{
|
101 |
d433b50e
|
Leszek Koltunski
|
int numObjects = RubikObjectList.getNumObjects();
|
102 |
9c39179e
|
Leszek Koltunski
|
mScreenWidth = act.getScreenWidthInPixels();
|
103 |
255492a0
|
Leszek Koltunski
|
mUpperBarHeight = act.getHeightUpperBar();
|
104 |
a8576d91
|
Leszek Koltunski
|
|
105 |
9c39179e
|
Leszek Koltunski
|
mMenuTextSize = mScreenWidth*RubikActivity.MENU_MED_TEXT_SIZE;
|
106 |
|
|
mButtonSize = mScreenWidth*RubikActivity.BUTTON_TEXT_SIZE;
|
107 |
|
|
mMenuItemSize = mScreenWidth*RubikActivity.MENU_ITEM_SIZE;
|
108 |
e3c74c0f
|
Leszek Koltunski
|
|
109 |
d433b50e
|
Leszek Koltunski
|
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
|
110 |
287e91a6
|
Leszek Koltunski
|
mColCount = NUM_COLUMNS;
|
111 |
e07c48a2
|
Leszek Koltunski
|
|
112 |
211b48f2
|
Leszek Koltunski
|
// TOP ////////////////////////////
|
113 |
7289fd6c
|
Leszek Koltunski
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
114 |
211b48f2
|
Leszek Koltunski
|
layoutTop.removeAllViews();
|
115 |
85b09df4
|
Leszek Koltunski
|
|
116 |
9c39179e
|
Leszek Koltunski
|
setupObjectButton(act,mScreenWidth);
|
117 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mObjButton);
|
118 |
0254cfd7
|
Leszek Koltunski
|
|
119 |
9c39179e
|
Leszek Koltunski
|
setupMenuButton(act,mScreenWidth);
|
120 |
0254cfd7
|
Leszek Koltunski
|
layoutTop.addView(mMenuButton);
|
121 |
|
|
|
122 |
9c39179e
|
Leszek Koltunski
|
setupPlayButton(act,mScreenWidth);
|
123 |
85b09df4
|
Leszek Koltunski
|
layoutTop.addView(mPlayButton);
|
124 |
211b48f2
|
Leszek Koltunski
|
|
125 |
dd874ae8
|
Leszek Koltunski
|
setupSolveButton(act);
|
126 |
|
|
setupScrambleButton(act);
|
127 |
|
|
createBottomPane(act,mSolveButton,mScrambleButton);
|
128 |
769d7b9f
|
Leszek Koltunski
|
}
|
129 |
211b48f2
|
Leszek Koltunski
|
|
130 |
8ab435b9
|
Leszek Koltunski
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
4c0cd600
|
Leszek Koltunski
|
|
132 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupObjectButton(final RubikActivity act, final float width)
|
133 |
769d7b9f
|
Leszek Koltunski
|
{
|
134 |
e07c48a2
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
135 |
6e3fcb91
|
Leszek Koltunski
|
final int lMargin = (int)(width*RubikActivity.LARGE_MARGIN);
|
136 |
e07c48a2
|
Leszek Koltunski
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
|
137 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
138 |
|
|
mObjButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
139 |
769d7b9f
|
Leszek Koltunski
|
|
140 |
|
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
141 |
|
|
{
|
142 |
|
|
@Override
|
143 |
|
|
public void onClick(View view)
|
144 |
4c0cd600
|
Leszek Koltunski
|
{
|
145 |
2da68298
|
Leszek Koltunski
|
if( mObjectPopup==null )
|
146 |
|
|
{
|
147 |
|
|
float width = act.getScreenWidthInPixels();
|
148 |
|
|
float height= act.getScreenHeightInPixels();
|
149 |
|
|
setupObjectWindow(act,width,height);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
if( act.getControl().isUINotBlocked())
|
153 |
a42e25a6
|
Leszek Koltunski
|
{
|
154 |
598de3ee
|
Leszek Koltunski
|
int rowCount = Math.min(mMaxRowCount,mRowCount);
|
155 |
c5b4af4a
|
Leszek Koltunski
|
View popupView = mObjectPopup.getContentView();
|
156 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
157 |
1071fb69
|
Leszek Koltunski
|
displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount+mBottomHeight+2*lMargin+5*margin,margin,margin);
|
158 |
c5b4af4a
|
Leszek Koltunski
|
}
|
159 |
769d7b9f
|
Leszek Koltunski
|
}
|
160 |
|
|
});
|
161 |
|
|
}
|
162 |
4c0cd600
|
Leszek Koltunski
|
|
163 |
85b09df4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164 |
|
|
|
165 |
2da68298
|
Leszek Koltunski
|
private void setupPlayButton(final RubikActivity act, final float width)
|
166 |
85b09df4
|
Leszek Koltunski
|
{
|
167 |
2da68298
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
168 |
d90c55cc
|
Leszek Koltunski
|
|
169 |
033100af
|
Leszek Koltunski
|
mPlayButton = new TransparentButton(act, R.string.play, mButtonSize);
|
170 |
85b09df4
|
Leszek Koltunski
|
|
171 |
|
|
mPlayButton.setOnClickListener( new View.OnClickListener()
|
172 |
|
|
{
|
173 |
|
|
@Override
|
174 |
0254cfd7
|
Leszek Koltunski
|
public void onClick(View view)
|
175 |
85b09df4
|
Leszek Koltunski
|
{
|
176 |
2da68298
|
Leszek Koltunski
|
if( mPlayPopup==null )
|
177 |
|
|
{
|
178 |
|
|
float width = act.getScreenWidthInPixels();
|
179 |
|
|
setupPlayWindow(act,width);
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
if( act.getControl().isUINotBlocked())
|
183 |
6e194411
|
Leszek Koltunski
|
{
|
184 |
d38a302b
|
Leszek Koltunski
|
adjustSolvedIcons();
|
185 |
2da68298
|
Leszek Koltunski
|
float height= act.getScreenHeightInPixels();
|
186 |
|
|
final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) );
|
187 |
c5b4af4a
|
Leszek Koltunski
|
View popupView = mPlayPopup.getContentView();
|
188 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
189 |
400ff34d
|
Leszek Koltunski
|
final int object = RubikObjectList.getCurrObject();
|
190 |
|
|
final int dbLevel = RubikObjectList.getDBLevel(object);
|
191 |
0a7aa15b
|
Leszek Koltunski
|
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
|
192 |
d90c55cc
|
Leszek Koltunski
|
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
|
193 |
255492a0
|
Leszek Koltunski
|
final int realHeight = Math.min(popupHeight,maxHeight);
|
194 |
|
|
displayPopup(act,view,mPlayPopup,mPlayLayoutWidth,realHeight,margin,margin);
|
195 |
6fad862b
|
Leszek Koltunski
|
}
|
196 |
85b09df4
|
Leszek Koltunski
|
}
|
197 |
|
|
});
|
198 |
|
|
}
|
199 |
|
|
|
200 |
e31abc1e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201 |
|
|
|
202 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuButton(final RubikActivity act, final float width)
|
203 |
e31abc1e
|
Leszek Koltunski
|
{
|
204 |
2da68298
|
Leszek Koltunski
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
205 |
0254cfd7
|
Leszek Koltunski
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);
|
206 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
207 |
|
|
mMenuButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
208 |
e31abc1e
|
Leszek Koltunski
|
|
209 |
e03e0352
|
Leszek Koltunski
|
mMenuButton.setOnClickListener( new View.OnClickListener()
|
210 |
e31abc1e
|
Leszek Koltunski
|
{
|
211 |
|
|
@Override
|
212 |
|
|
public void onClick(View view)
|
213 |
|
|
{
|
214 |
2da68298
|
Leszek Koltunski
|
if( mMenuPopup==null )
|
215 |
|
|
{
|
216 |
|
|
float width = act.getScreenWidthInPixels();
|
217 |
|
|
setupMenuWindow(act,width);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
if( act.getControl().isUINotBlocked())
|
221 |
e03e0352
|
Leszek Koltunski
|
{
|
222 |
c5b4af4a
|
Leszek Koltunski
|
View popupView = mMenuPopup.getContentView();
|
223 |
|
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
224 |
255492a0
|
Leszek Koltunski
|
displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-width/12),margin);
|
225 |
6fad862b
|
Leszek Koltunski
|
}
|
226 |
e31abc1e
|
Leszek Koltunski
|
}
|
227 |
|
|
});
|
228 |
|
|
}
|
229 |
|
|
|
230 |
4c0cd600
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
231 |
|
|
|
232 |
598de3ee
|
Leszek Koltunski
|
private void setupObjectWindow(final RubikActivity act, final float width, final float height)
|
233 |
4c0cd600
|
Leszek Koltunski
|
{
|
234 |
6e3fcb91
|
Leszek Koltunski
|
int cubeWidth = (int)(width/9);
|
235 |
598de3ee
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
236 |
|
|
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
|
237 |
0b162619
|
Leszek Koltunski
|
mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize);
|
238 |
598de3ee
|
Leszek Koltunski
|
|
239 |
8d1da3f1
|
Leszek Koltunski
|
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null);
|
240 |
b600ccd9
|
Leszek Koltunski
|
GridLayout objectGrid = view.findViewById(R.id.objectGrid);
|
241 |
e07c48a2
|
Leszek Koltunski
|
|
242 |
|
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
243 |
|
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
244 |
|
|
|
245 |
92843d3b
|
Leszek Koltunski
|
objectGrid.setColumnCount(mColCount);
|
246 |
|
|
objectGrid.setRowCount(mRowCount);
|
247 |
e07c48a2
|
Leszek Koltunski
|
|
248 |
d6e7c7fb
|
Leszek Koltunski
|
RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout);
|
249 |
|
|
setupBottomLayout(act,bottomLayout);
|
250 |
0b162619
|
Leszek Koltunski
|
|
251 |
b600ccd9
|
Leszek Koltunski
|
mObjectPopup = new PopupWindow(act);
|
252 |
|
|
mObjectPopup.setFocusable(true);
|
253 |
|
|
mObjectPopup.setContentView(view);
|
254 |
|
|
|
255 |
0501a4b8
|
Leszek Koltunski
|
int[] nextInRow = new int[mRowCount];
|
256 |
fa679111
|
Leszek Koltunski
|
|
257 |
e07c48a2
|
Leszek Koltunski
|
for(int row=0; row<mRowCount; row++)
|
258 |
|
|
{
|
259 |
|
|
rowSpecs[row] = GridLayout.spec(row);
|
260 |
0501a4b8
|
Leszek Koltunski
|
nextInRow[row]= 0;
|
261 |
e07c48a2
|
Leszek Koltunski
|
}
|
262 |
|
|
for(int col=0; col<mColCount; col++)
|
263 |
|
|
{
|
264 |
|
|
colSpecs[col] = GridLayout.spec(col);
|
265 |
|
|
}
|
266 |
769d7b9f
|
Leszek Koltunski
|
|
267 |
d433b50e
|
Leszek Koltunski
|
int numObjects = RubikObjectList.getNumObjects();
|
268 |
|
|
|
269 |
|
|
for(int object=0; object<numObjects; object++)
|
270 |
769d7b9f
|
Leszek Koltunski
|
{
|
271 |
d433b50e
|
Leszek Koltunski
|
final RubikObject robject = RubikObjectList.getObject(object);
|
272 |
6e3fcb91
|
Leszek Koltunski
|
int icons = robject==null ? 0 : robject.getIconID();
|
273 |
287e91a6
|
Leszek Koltunski
|
int row = object/NUM_COLUMNS;
|
274 |
400ff34d
|
Leszek Koltunski
|
final int ordinal = robject==null ? 0 : robject.getOrdinal();
|
275 |
769d7b9f
|
Leszek Koltunski
|
|
276 |
7ac0ee88
|
Leszek Koltunski
|
ImageButton button = new ImageButton(act);
|
277 |
|
|
button.setBackgroundResource(icons);
|
278 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
279 |
769d7b9f
|
Leszek Koltunski
|
{
|
280 |
7ac0ee88
|
Leszek Koltunski
|
@Override
|
281 |
|
|
public void onClick(View v)
|
282 |
769d7b9f
|
Leszek Koltunski
|
{
|
283 |
2afc6754
|
Leszek Koltunski
|
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
|
284 |
769d7b9f
|
Leszek Koltunski
|
{
|
285 |
400ff34d
|
Leszek Koltunski
|
RubikObjectList.setCurrObject(act,ordinal);
|
286 |
|
|
act.changeObject(ordinal,true);
|
287 |
4c9947bd
|
Leszek Koltunski
|
if( mPlayLayout!=null ) adjustLevels(act);
|
288 |
dd1a65c1
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
289 |
769d7b9f
|
Leszek Koltunski
|
}
|
290 |
|
|
|
291 |
7ac0ee88
|
Leszek Koltunski
|
mObjectPopup.dismiss();
|
292 |
|
|
}
|
293 |
|
|
});
|
294 |
e07c48a2
|
Leszek Koltunski
|
|
295 |
7ac0ee88
|
Leszek Koltunski
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
|
296 |
|
|
params.bottomMargin = margin;
|
297 |
|
|
params.topMargin = margin;
|
298 |
|
|
params.leftMargin = margin;
|
299 |
|
|
params.rightMargin = margin;
|
300 |
fa679111
|
Leszek Koltunski
|
|
301 |
6e3fcb91
|
Leszek Koltunski
|
params.width = cubeWidth;
|
302 |
|
|
params.height= cubeWidth;
|
303 |
|
|
|
304 |
7ac0ee88
|
Leszek Koltunski
|
nextInRow[row]++;
|
305 |
|
|
|
306 |
|
|
objectGrid.addView(button, params);
|
307 |
769d7b9f
|
Leszek Koltunski
|
}
|
308 |
4c0cd600
|
Leszek Koltunski
|
}
|
309 |
|
|
|
310 |
8d1da3f1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
311 |
|
|
|
312 |
d6e7c7fb
|
Leszek Koltunski
|
private void setupBottomLayout(final RubikActivity act, final RelativeLayout layout)
|
313 |
8d1da3f1
|
Leszek Koltunski
|
{
|
314 |
|
|
int iconT = RubikActivity.getDrawable(R.drawable.ui_small_tutorial,R.drawable.ui_medium_tutorial, R.drawable.ui_big_tutorial, R.drawable.ui_huge_tutorial);
|
315 |
d6e7c7fb
|
Leszek Koltunski
|
int iconD = RubikActivity.getDrawable(R.drawable.ui_small_download,R.drawable.ui_medium_download, R.drawable.ui_big_download, R.drawable.ui_huge_download);
|
316 |
|
|
int iconI = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
|
317 |
8d1da3f1
|
Leszek Koltunski
|
|
318 |
|
|
ImageButton buttonTut = layout.findViewById(R.id.buttonTut);
|
319 |
d6e7c7fb
|
Leszek Koltunski
|
ImageButton buttonDow = layout.findViewById(R.id.buttonDow);
|
320 |
|
|
ImageButton buttonInf = layout.findViewById(R.id.buttonInf);
|
321 |
8d1da3f1
|
Leszek Koltunski
|
|
322 |
|
|
buttonTut.setImageResource(iconT);
|
323 |
d6e7c7fb
|
Leszek Koltunski
|
buttonDow.setImageResource(iconD);
|
324 |
|
|
buttonInf.setImageResource(iconI);
|
325 |
8d1da3f1
|
Leszek Koltunski
|
|
326 |
6e3fcb91
|
Leszek Koltunski
|
Resources res = act.getResources();
|
327 |
d6e7c7fb
|
Leszek Koltunski
|
BitmapDrawable bd = (BitmapDrawable)res.getDrawable(iconI);
|
328 |
6e3fcb91
|
Leszek Koltunski
|
mBottomHeight = bd.getIntrinsicHeight();
|
329 |
|
|
|
330 |
8d1da3f1
|
Leszek Koltunski
|
TypedValue outValue = new TypedValue();
|
331 |
|
|
act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
|
332 |
|
|
buttonTut.setBackgroundResource(outValue.resourceId);
|
333 |
d6e7c7fb
|
Leszek Koltunski
|
buttonDow.setBackgroundResource(outValue.resourceId);
|
334 |
|
|
buttonInf.setBackgroundResource(outValue.resourceId);
|
335 |
8d1da3f1
|
Leszek Koltunski
|
|
336 |
|
|
buttonTut.setOnClickListener( new View.OnClickListener()
|
337 |
|
|
{
|
338 |
|
|
@Override
|
339 |
|
|
public void onClick(View v)
|
340 |
|
|
{
|
341 |
|
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
342 |
|
|
RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
343 |
|
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
344 |
|
|
}
|
345 |
|
|
});
|
346 |
|
|
|
347 |
d6e7c7fb
|
Leszek Koltunski
|
buttonDow.setOnClickListener( new View.OnClickListener()
|
348 |
|
|
{
|
349 |
|
|
@Override
|
350 |
|
|
public void onClick(View v)
|
351 |
|
|
{
|
352 |
5f3801d3
|
Leszek Koltunski
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
353 |
|
|
RubikDialogUpdates uDiag = new RubikDialogUpdates();
|
354 |
|
|
uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() );
|
355 |
d6e7c7fb
|
Leszek Koltunski
|
}
|
356 |
|
|
});
|
357 |
|
|
|
358 |
|
|
buttonInf.setOnClickListener( new View.OnClickListener()
|
359 |
8d1da3f1
|
Leszek Koltunski
|
{
|
360 |
|
|
@Override
|
361 |
|
|
public void onClick(View v)
|
362 |
|
|
{
|
363 |
f12e4de9
|
Leszek Koltunski
|
if( mObjectPopup!=null ) mObjectPopup.dismiss();
|
364 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
365 |
|
|
act.switchConfig(currObject);
|
366 |
8d1da3f1
|
Leszek Koltunski
|
}
|
367 |
|
|
});
|
368 |
d6e7c7fb
|
Leszek Koltunski
|
|
369 |
10373dc7
|
Leszek Koltunski
|
mBubbleUpdates = layout.findViewById(R.id.bubbleUpdates);
|
370 |
|
|
mBubbleUpdates.setVisibility(View.INVISIBLE);
|
371 |
|
|
|
372 |
d6e7c7fb
|
Leszek Koltunski
|
RubikNetwork network = RubikNetwork.getInstance();
|
373 |
|
|
network.signUpForUpdates(this);
|
374 |
8d1da3f1
|
Leszek Koltunski
|
}
|
375 |
|
|
|
376 |
e03e0352
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
377 |
|
|
|
378 |
ad0c8e0e
|
Leszek Koltunski
|
private void setupMenuWindow(final RubikActivity act, final float width)
|
379 |
e03e0352
|
Leszek Koltunski
|
{
|
380 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
381 |
e07c48a2
|
Leszek Koltunski
|
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
382 |
|
|
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
|
383 |
e03e0352
|
Leszek Koltunski
|
|
384 |
|
|
mMenuPopup = new PopupWindow(act);
|
385 |
|
|
mMenuPopup.setContentView(layout);
|
386 |
|
|
mMenuPopup.setFocusable(true);
|
387 |
ad0c8e0e
|
Leszek Koltunski
|
int margin = (int)(width*RubikActivity.MARGIN);
|
388 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
389 |
e03e0352
|
Leszek Koltunski
|
|
390 |
0254cfd7
|
Leszek Koltunski
|
mMenuLayoutWidth = (int)(width/2);
|
391 |
|
|
mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
|
392 |
|
|
|
393 |
43162dfb
|
Leszek Koltunski
|
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
394 |
e03e0352
|
Leszek Koltunski
|
|
395 |
|
|
for(int i=0; i<NUM_BUTTONS; i++)
|
396 |
|
|
{
|
397 |
|
|
final int but = i;
|
398 |
|
|
Button button = new Button(act);
|
399 |
43162dfb
|
Leszek Koltunski
|
button.setLayoutParams(p);
|
400 |
e03e0352
|
Leszek Koltunski
|
button.setText(BUTTON_LABELS[i]);
|
401 |
88fb92ba
|
Leszek Koltunski
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
402 |
e03e0352
|
Leszek Koltunski
|
|
403 |
|
|
button.setOnClickListener( new View.OnClickListener()
|
404 |
|
|
{
|
405 |
|
|
@Override
|
406 |
|
|
public void onClick(View v)
|
407 |
|
|
{
|
408 |
|
|
mMenuPopup.dismiss();
|
409 |
0254cfd7
|
Leszek Koltunski
|
MenuAction(act,but);
|
410 |
e03e0352
|
Leszek Koltunski
|
}
|
411 |
|
|
});
|
412 |
|
|
|
413 |
e07c48a2
|
Leszek Koltunski
|
menuLayout.addView(button);
|
414 |
e03e0352
|
Leszek Koltunski
|
}
|
415 |
0254cfd7
|
Leszek Koltunski
|
}
|
416 |
e03e0352
|
Leszek Koltunski
|
|
417 |
0254cfd7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
418 |
|
|
|
419 |
|
|
private void setupPlayWindow(final RubikActivity act, final float width)
|
420 |
|
|
{
|
421 |
|
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
422 |
|
|
final View layout = layoutInflater.inflate(R.layout.popup_play, null);
|
423 |
|
|
mPlayLayout = layout.findViewById(R.id.playGrid);
|
424 |
|
|
|
425 |
|
|
mPlayLayoutWidth = (int)(width*0.4f);
|
426 |
|
|
|
427 |
|
|
mPlayPopup = new PopupWindow(act);
|
428 |
|
|
mPlayPopup.setContentView(layout);
|
429 |
|
|
mPlayPopup.setFocusable(true);
|
430 |
|
|
|
431 |
|
|
adjustLevels(act);
|
432 |
e03e0352
|
Leszek Koltunski
|
}
|
433 |
|
|
|
434 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
435 |
|
|
|
436 |
0254cfd7
|
Leszek Koltunski
|
private void MenuAction(RubikActivity act, int button)
|
437 |
e03e0352
|
Leszek Koltunski
|
{
|
438 |
|
|
switch(button)
|
439 |
|
|
{
|
440 |
8ab435b9
|
Leszek Koltunski
|
case 0: Bundle sBundle = new Bundle();
|
441 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
442 |
|
|
sBundle.putInt("tab", currObject );
|
443 |
a8576d91
|
Leszek Koltunski
|
sBundle.putBoolean("submitting", false);
|
444 |
e03e0352
|
Leszek Koltunski
|
RubikDialogScores scores = new RubikDialogScores();
|
445 |
a8576d91
|
Leszek Koltunski
|
scores.setArguments(sBundle);
|
446 |
e03e0352
|
Leszek Koltunski
|
scores.show(act.getSupportFragmentManager(), null);
|
447 |
|
|
break;
|
448 |
234a7582
|
Leszek Koltunski
|
case 1: RubikDialogPattern pDiag = new RubikDialogPattern();
|
449 |
|
|
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
|
450 |
e03e0352
|
Leszek Koltunski
|
break;
|
451 |
b2a92941
|
Leszek Koltunski
|
case 2: ScreenList.switchScreen(act, ScreenList.SVER);
|
452 |
e03e0352
|
Leszek Koltunski
|
break;
|
453 |
b2a92941
|
Leszek Koltunski
|
case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
454 |
234a7582
|
Leszek Koltunski
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
455 |
2971588c
|
Leszek Koltunski
|
break;
|
456 |
b2a92941
|
Leszek Koltunski
|
case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
|
457 |
a8576d91
|
Leszek Koltunski
|
aDiag.show(act.getSupportFragmentManager(), null);
|
458 |
e03e0352
|
Leszek Koltunski
|
break;
|
459 |
|
|
}
|
460 |
|
|
}
|
461 |
|
|
|
462 |
46405bb4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
463 |
|
|
|
464 |
dd874ae8
|
Leszek Koltunski
|
void setupSolveButton(final RubikActivity act)
|
465 |
46405bb4
|
Leszek Koltunski
|
{
|
466 |
dd874ae8
|
Leszek Koltunski
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve_new,R.drawable.ui_medium_cube_solve_new, R.drawable.ui_big_cube_solve_new, R.drawable.ui_huge_cube_solve_new);
|
467 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
468 |
|
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_END,params);
|
469 |
46405bb4
|
Leszek Koltunski
|
|
470 |
a8576d91
|
Leszek Koltunski
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
471 |
46405bb4
|
Leszek Koltunski
|
{
|
472 |
a8576d91
|
Leszek Koltunski
|
@Override
|
473 |
|
|
public void onClick(View v)
|
474 |
|
|
{
|
475 |
2afc6754
|
Leszek Koltunski
|
act.getControl().solveObject();
|
476 |
dd1a65c1
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
477 |
a8576d91
|
Leszek Koltunski
|
}
|
478 |
|
|
});
|
479 |
46405bb4
|
Leszek Koltunski
|
}
|
480 |
|
|
|
481 |
dd874ae8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
482 |
|
|
|
483 |
|
|
private void setupScrambleButton(final RubikActivity act)
|
484 |
|
|
{
|
485 |
|
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble_new,R.drawable.ui_medium_cube_scramble_new, R.drawable.ui_big_cube_scramble_new, R.drawable.ui_huge_cube_scramble_new);
|
486 |
b600ccd9
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
487 |
|
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_START, params);
|
488 |
dd874ae8
|
Leszek Koltunski
|
|
489 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
490 |
|
|
{
|
491 |
|
|
@Override
|
492 |
|
|
public void onClick(View v)
|
493 |
|
|
{
|
494 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
495 |
|
|
RubikObject object = RubikObjectList.getObject(currObject);
|
496 |
d433b50e
|
Leszek Koltunski
|
int numScrambles = object==null ? 0 : object.getNumScramble();
|
497 |
dd874ae8
|
Leszek Koltunski
|
mShouldReactToEndOfScrambling = false;
|
498 |
|
|
act.getControl().scrambleObject(numScrambles);
|
499 |
|
|
}
|
500 |
|
|
});
|
501 |
|
|
}
|
502 |
|
|
|
503 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
504 |
3398a606
|
Leszek Koltunski
|
// This is necessary! Otherwise the ObjectPopup will not be re-created next time and we will still
|
505 |
|
|
// hold a reference to the old instance of the RubikActivity class (because setupObjectWindow is not
|
506 |
|
|
// going to be called)
|
507 |
|
|
// An reference to the old instance of RubikActivity will cause all sorts of strange issues.
|
508 |
211b48f2
|
Leszek Koltunski
|
|
509 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
510 |
|
|
{
|
511 |
d38a302b
|
Leszek Koltunski
|
editor.putInt("play_LevelValue", mLevelValue );
|
512 |
|
|
|
513 |
3398a606
|
Leszek Koltunski
|
if( mObjectPopup!=null )
|
514 |
|
|
{
|
515 |
|
|
mObjectPopup.dismiss();
|
516 |
|
|
mObjectPopup = null;
|
517 |
|
|
}
|
518 |
87d86e5f
|
Leszek Koltunski
|
|
519 |
3398a606
|
Leszek Koltunski
|
if( mMenuPopup!=null )
|
520 |
|
|
{
|
521 |
|
|
mMenuPopup.dismiss();
|
522 |
|
|
mMenuPopup = null;
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
if( mPlayPopup!=null )
|
526 |
|
|
{
|
527 |
|
|
mPlayPopup.dismiss();
|
528 |
|
|
mPlayPopup = null;
|
529 |
|
|
}
|
530 |
211b48f2
|
Leszek Koltunski
|
}
|
531 |
|
|
|
532 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
533 |
|
|
|
534 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
535 |
|
|
{
|
536 |
d38a302b
|
Leszek Koltunski
|
mLevelValue = preferences.getInt("play_LevelValue", 0);
|
537 |
211b48f2
|
Leszek Koltunski
|
}
|
538 |
|
|
|
539 |
53f23b64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
540 |
|
|
|
541 |
400ff34d
|
Leszek Koltunski
|
public void setCurrObject(RubikActivity act)
|
542 |
53f23b64
|
Leszek Koltunski
|
{
|
543 |
400ff34d
|
Leszek Koltunski
|
if( mPlayLayout!=null ) adjustLevels(act);
|
544 |
7b7d65ce
|
Leszek Koltunski
|
}
|
545 |
|
|
|
546 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
547 |
255492a0
|
Leszek Koltunski
|
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes
|
548 |
|
|
|
549 |
|
|
private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
|
550 |
|
|
{
|
551 |
|
|
View topLayout = act.findViewById(R.id.relativeLayout);
|
552 |
7ac0ee88
|
Leszek Koltunski
|
boolean isFullScreen;
|
553 |
00aa398a
|
Leszek Koltunski
|
|
554 |
|
|
if( topLayout!=null )
|
555 |
|
|
{
|
556 |
|
|
topLayout.getLocationOnScreen(mLocation);
|
557 |
7ac0ee88
|
Leszek Koltunski
|
isFullScreen = (mLocation[1]==0);
|
558 |
00aa398a
|
Leszek Koltunski
|
}
|
559 |
|
|
else
|
560 |
|
|
{
|
561 |
7ac0ee88
|
Leszek Koltunski
|
isFullScreen = true;
|
562 |
00aa398a
|
Leszek Koltunski
|
}
|
563 |
255492a0
|
Leszek Koltunski
|
|
564 |
69a271f3
|
Leszek Koltunski
|
try
|
565 |
255492a0
|
Leszek Koltunski
|
{
|
566 |
69a271f3
|
Leszek Koltunski
|
// if on Android 11 or we are fullscreen
|
567 |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || isFullScreen )
|
568 |
|
|
{
|
569 |
|
|
window.showAsDropDown(view, xoff, yoff, Gravity.CENTER);
|
570 |
|
|
window.update(view, w, h);
|
571 |
|
|
}
|
572 |
|
|
else // Android 10 or below in pop-up mode or split-screen mode
|
573 |
|
|
{
|
574 |
|
|
view.getLocationOnScreen(mLocation);
|
575 |
|
|
int width = view.getWidth();
|
576 |
|
|
int height = view.getHeight();
|
577 |
|
|
int x = mLocation[0]+(width-w)/2;
|
578 |
|
|
int y = mLocation[1]+height+yoff;
|
579 |
|
|
|
580 |
|
|
window.showAsDropDown(view);
|
581 |
|
|
window.update(x,y,w,h);
|
582 |
|
|
}
|
583 |
255492a0
|
Leszek Koltunski
|
}
|
584 |
69a271f3
|
Leszek Koltunski
|
catch( IllegalArgumentException iae )
|
585 |
255492a0
|
Leszek Koltunski
|
{
|
586 |
69a271f3
|
Leszek Koltunski
|
// ignore, this means window is 'not attached to window manager' -
|
587 |
|
|
// which most probably is because we are already exiting the app.
|
588 |
255492a0
|
Leszek Koltunski
|
}
|
589 |
|
|
}
|
590 |
|
|
|
591 |
ae77f661
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
592 |
|
|
|
593 |
d38a302b
|
Leszek Koltunski
|
private void adjustSolvedIcons()
|
594 |
ae77f661
|
Leszek Koltunski
|
{
|
595 |
59cc16ae
|
Leszek Koltunski
|
if( mPlayLayout!=null )
|
596 |
ae77f661
|
Leszek Koltunski
|
{
|
597 |
59cc16ae
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
598 |
|
|
int dbLevel = RubikObjectList.getDBLevel(currObject);
|
599 |
|
|
int numLevel= Math.min(dbLevel, LEVELS_SHOWN);
|
600 |
|
|
RubikScores scores = RubikScores.getInstance();
|
601 |
|
|
|
602 |
|
|
for(int i=0; i<numLevel; i++)
|
603 |
|
|
{
|
604 |
|
|
int level = i<numLevel-1 ? i+1 : dbLevel;
|
605 |
|
|
Button button = (Button)mPlayLayout.getChildAt(i);
|
606 |
|
|
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
607 |
|
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
608 |
|
|
}
|
609 |
ae77f661
|
Leszek Koltunski
|
}
|
610 |
|
|
}
|
611 |
|
|
|
612 |
255492a0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
613 |
7b7d65ce
|
Leszek Koltunski
|
|
614 |
0254cfd7
|
Leszek Koltunski
|
private void adjustLevels(final RubikActivity act)
|
615 |
7b7d65ce
|
Leszek Koltunski
|
{
|
616 |
400ff34d
|
Leszek Koltunski
|
int currObject = RubikObjectList.getCurrObject();
|
617 |
|
|
int dbLevel = RubikObjectList.getDBLevel(currObject);
|
618 |
|
|
RubikObject object = RubikObjectList.getObject(currObject);
|
619 |
d433b50e
|
Leszek Koltunski
|
int numScrambles = object==null ? 0 : object.getNumScramble();
|
620 |
0a7aa15b
|
Leszek Koltunski
|
int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
|
621 |
00af5060
|
Leszek Koltunski
|
String[] levels = new String[numLevel];
|
622 |
7b7d65ce
|
Leszek Koltunski
|
|
623 |
00af5060
|
Leszek Koltunski
|
for(int i=0; i<numLevel-1; i++)
|
624 |
53f23b64
|
Leszek Koltunski
|
{
|
625 |
7b7d65ce
|
Leszek Koltunski
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
626 |
53f23b64
|
Leszek Koltunski
|
}
|
627 |
|
|
|
628 |
4fc7b1e6
|
Leszek Koltunski
|
if( numLevel>0 )
|
629 |
|
|
{
|
630 |
|
|
levels[numLevel-1] = act.getString(R.string.level_full);
|
631 |
|
|
}
|
632 |
00af5060
|
Leszek Koltunski
|
|
633 |
0a7aa15b
|
Leszek Koltunski
|
if( mLevelValue>dbLevel || mLevelValue<1 ||
|
634 |
|
|
(mLevelValue<dbLevel || mLevelValue>LEVELS_SHOWN ) )
|
635 |
00af5060
|
Leszek Koltunski
|
{
|
636 |
|
|
mLevelValue=1;
|
637 |
|
|
}
|
638 |
0254cfd7
|
Leszek Koltunski
|
|
639 |
de62316a
|
Leszek Koltunski
|
float width = act.getScreenWidthInPixels();
|
640 |
|
|
int margin = (int)(width*RubikActivity.MARGIN);
|
641 |
|
|
int padding = (int)(width*RubikActivity.PADDING);
|
642 |
|
|
int butWidth = mPlayLayoutWidth - 2*padding;
|
643 |
|
|
int butHeight= (int)mMenuItemSize;
|
644 |
|
|
int lastButH = (int)(mMenuItemSize*LAST_BUTTON) ;
|
645 |
0254cfd7
|
Leszek Koltunski
|
|
646 |
de62316a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( butWidth, butHeight );
|
647 |
0254cfd7
|
Leszek Koltunski
|
pM.setMargins(margin, 0, margin, margin);
|
648 |
de62316a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( butWidth, butHeight );
|
649 |
0254cfd7
|
Leszek Koltunski
|
pT.setMargins(margin, margin, margin, margin);
|
650 |
de62316a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( butWidth, lastButH );
|
651 |
0254cfd7
|
Leszek Koltunski
|
pB.setMargins(margin, margin, margin, 2*margin);
|
652 |
|
|
|
653 |
|
|
mPlayLayout.removeAllViews();
|
654 |
|
|
|
655 |
d7e539d0
|
Leszek Koltunski
|
RubikScores scores = RubikScores.getInstance();
|
656 |
|
|
|
657 |
00af5060
|
Leszek Koltunski
|
for(int i=0; i<numLevel; i++)
|
658 |
011fcfe0
|
Leszek Koltunski
|
{
|
659 |
0a7aa15b
|
Leszek Koltunski
|
final int level = i<numLevel-1 ? i+1 : dbLevel;
|
660 |
|
|
final int scrambles = i<numLevel-1 ? i+1 : numScrambles;
|
661 |
0254cfd7
|
Leszek Koltunski
|
Button button = new Button(act);
|
662 |
00af5060
|
Leszek Koltunski
|
button.setLayoutParams(i==0 ? pT : (i==numLevel-1 ? pB : pM));
|
663 |
0254cfd7
|
Leszek Koltunski
|
button.setText(levels[i]);
|
664 |
|
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
665 |
|
|
|
666 |
400ff34d
|
Leszek Koltunski
|
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
667 |
d7e539d0
|
Leszek Koltunski
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
668 |
|
|
|
669 |
0254cfd7
|
Leszek Koltunski
|
button.setOnClickListener( new View.OnClickListener()
|
670 |
011fcfe0
|
Leszek Koltunski
|
{
|
671 |
0254cfd7
|
Leszek Koltunski
|
@Override
|
672 |
|
|
public void onClick(View v)
|
673 |
|
|
{
|
674 |
2afc6754
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
675 |
6fad862b
|
Leszek Koltunski
|
|
676 |
2afc6754
|
Leszek Koltunski
|
if(control.isUINotBlocked())
|
677 |
6fad862b
|
Leszek Koltunski
|
{
|
678 |
598de3ee
|
Leszek Koltunski
|
if( mPlayPopup!=null ) mPlayPopup.dismiss();
|
679 |
0a7aa15b
|
Leszek Koltunski
|
mLevelValue = level;
|
680 |
dd874ae8
|
Leszek Koltunski
|
mShouldReactToEndOfScrambling = true;
|
681 |
2afc6754
|
Leszek Koltunski
|
control.scrambleObject(scrambles);
|
682 |
6fad862b
|
Leszek Koltunski
|
}
|
683 |
0254cfd7
|
Leszek Koltunski
|
}
|
684 |
|
|
});
|
685 |
011fcfe0
|
Leszek Koltunski
|
|
686 |
0254cfd7
|
Leszek Koltunski
|
mPlayLayout.addView(button);
|
687 |
|
|
}
|
688 |
53f23b64
|
Leszek Koltunski
|
}
|
689 |
|
|
|
690 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
691 |
|
|
|
692 |
dca3888a
|
Leszek Koltunski
|
public int getLevel()
|
693 |
211b48f2
|
Leszek Koltunski
|
{
|
694 |
85b09df4
|
Leszek Koltunski
|
return mLevelValue;
|
695 |
211b48f2
|
Leszek Koltunski
|
}
|
696 |
|
|
|
697 |
dd874ae8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
698 |
|
|
|
699 |
|
|
public boolean shouldReactToEndOfScrambling()
|
700 |
|
|
{
|
701 |
|
|
return mShouldReactToEndOfScrambling;
|
702 |
|
|
}
|
703 |
63dd19c4
|
Leszek Koltunski
|
|
704 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
705 |
|
|
|
706 |
|
|
public void receiveUpdate(RubikUpdates updates)
|
707 |
|
|
{
|
708 |
c99db493
|
Leszek Koltunski
|
updates.showDebug();
|
709 |
|
|
|
710 |
9c39179e
|
Leszek Koltunski
|
int numN = updates.getNewNumber();
|
711 |
|
|
int numU = updates.getUpdNumber();
|
712 |
|
|
int num = numN+numU;
|
713 |
10373dc7
|
Leszek Koltunski
|
|
714 |
|
|
if( num>0 )
|
715 |
|
|
{
|
716 |
|
|
String shownNum = String.valueOf(num);
|
717 |
|
|
mBubbleUpdates.setText(shownNum);
|
718 |
|
|
mBubbleUpdates.setVisibility(View.VISIBLE);
|
719 |
9c39179e
|
Leszek Koltunski
|
int height = (int)(0.05f*mScreenWidth);
|
720 |
|
|
mBubbleUpdates.setTextSize(TypedValue.COMPLEX_UNIT_PX,height);
|
721 |
10373dc7
|
Leszek Koltunski
|
}
|
722 |
903c7bbc
|
Leszek Koltunski
|
else
|
723 |
|
|
{
|
724 |
|
|
mBubbleUpdates.setVisibility(View.INVISIBLE);
|
725 |
|
|
}
|
726 |
63dd19c4
|
Leszek Koltunski
|
}
|
727 |
|
|
|
728 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
729 |
|
|
|
730 |
|
|
public void errorUpdate()
|
731 |
|
|
{
|
732 |
c99db493
|
Leszek Koltunski
|
android.util.Log.e("D", "Screen: Error receiving update");
|
733 |
63dd19c4
|
Leszek Koltunski
|
}
|
734 |
211b48f2
|
Leszek Koltunski
|
}
|