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