1 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
da56b12f
|
Leszek Koltunski
|
// Copyright 2022 Leszek Koltunski //
|
3 |
9530f6b0
|
Leszek Koltunski
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
44fec653
|
Leszek Koltunski
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.bandaged;
|
11 |
|
|
|
12 |
2ceeb6b5
|
Leszek Koltunski
|
import static android.view.View.LAYOUT_DIRECTION_RTL;
|
13 |
|
|
|
14 |
707f79ff
|
Leszek Koltunski
|
import java.io.InputStream;
|
15 |
|
|
|
16 |
88b94310
|
Leszek Koltunski
|
import android.content.Intent;
|
17 |
a41e3c94
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
18 |
2ceeb6b5
|
Leszek Koltunski
|
import android.content.res.Configuration;
|
19 |
7cb8d4b0
|
Leszek Koltunski
|
import android.graphics.Bitmap;
|
20 |
9530f6b0
|
Leszek Koltunski
|
import android.os.Build;
|
21 |
|
|
import android.os.Bundle;
|
22 |
|
|
import android.util.DisplayMetrics;
|
23 |
|
|
import android.view.View;
|
24 |
|
|
import android.view.ViewGroup;
|
25 |
|
|
import android.view.WindowManager;
|
26 |
|
|
import android.widget.LinearLayout;
|
27 |
|
|
|
28 |
|
|
import androidx.appcompat.app.AppCompatActivity;
|
29 |
ada8ab26
|
leszek
|
import androidx.preference.PreferenceManager;
|
30 |
9530f6b0
|
Leszek Koltunski
|
|
31 |
|
|
import org.distorted.dialogs.RubikDialogError;
|
32 |
81493402
|
Leszek Koltunski
|
import org.distorted.external.RubikFiles;
|
33 |
9530f6b0
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
34 |
1c04d054
|
leszek
|
import org.distorted.main.MainActivity;
|
35 |
9530f6b0
|
Leszek Koltunski
|
import org.distorted.main.R;
|
36 |
9234018b
|
Leszek Koltunski
|
import org.distorted.objectlib.main.InitAssets;
|
37 |
707f79ff
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyJson;
|
38 |
|
|
import org.distorted.objectlib.main.TwistyObject;
|
39 |
21a1bb5d
|
Leszek Koltunski
|
import org.distorted.os.OSInterface;
|
40 |
7ee8337b
|
leszek
|
import org.distorted.playui.PlayActivity;
|
41 |
9530f6b0
|
Leszek Koltunski
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
7ee8337b
|
leszek
|
public class BandagedActivity extends AppCompatActivity
|
45 |
9530f6b0
|
Leszek Koltunski
|
{
|
46 |
7bb30586
|
leszek
|
public static final float SPINNER_TEXT_SIZE = 0.03f;
|
47 |
|
|
public static final float PADDING = 0.010f;
|
48 |
|
|
public static final int FLAGS = MainActivity.FLAGS;
|
49 |
|
|
public static final float RATIO_SCROLL = 0.30f;
|
50 |
|
|
|
51 |
c9f72ca3
|
leszek
|
private static final int ACTIVITY_NUMBER = 2;
|
52 |
1c04d054
|
leszek
|
private static final float RATIO_BAR = MainActivity.RATIO_BAR;
|
53 |
ada8ab26
|
leszek
|
private static final float RATIO_BUT = 0.07f;
|
54 |
7ee8337b
|
leszek
|
private static final int NUM_SCRAMBLES = 300;
|
55 |
9530f6b0
|
Leszek Koltunski
|
|
56 |
|
|
private static int mScreenWidth, mScreenHeight;
|
57 |
|
|
private int mCurrentApiVersion;
|
58 |
7ee8337b
|
leszek
|
private BandagedScreen mScreen;
|
59 |
2ceeb6b5
|
Leszek Koltunski
|
private boolean mRTL;
|
60 |
5a4ee169
|
leszek
|
private int mObjectOrdinal;
|
61 |
9530f6b0
|
Leszek Koltunski
|
|
62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
|
|
@Override
|
65 |
|
|
protected void onCreate(Bundle savedState)
|
66 |
|
|
{
|
67 |
|
|
super.onCreate(savedState);
|
68 |
5597ccee
|
leszek
|
|
69 |
|
|
Bundle b = getIntent().getExtras();
|
70 |
|
|
mObjectOrdinal = (b != null) ? b.getInt("obj") : 0;
|
71 |
|
|
|
72 |
9530f6b0
|
Leszek Koltunski
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
73 |
|
|
setTheme(R.style.MaterialThemeNoActionBar);
|
74 |
|
|
setContentView(R.layout.bandaged);
|
75 |
|
|
|
76 |
|
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
77 |
7fe59aa5
|
Leszek Koltunski
|
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
78 |
9530f6b0
|
Leszek Koltunski
|
mScreenWidth =displaymetrics.widthPixels;
|
79 |
|
|
mScreenHeight=displaymetrics.heightPixels;
|
80 |
7fe59aa5
|
Leszek Koltunski
|
|
81 |
2ceeb6b5
|
Leszek Koltunski
|
final Configuration config = getResources().getConfiguration();
|
82 |
|
|
final int layoutDirection = config.getLayoutDirection();
|
83 |
|
|
mRTL = layoutDirection==LAYOUT_DIRECTION_RTL;
|
84 |
|
|
|
85 |
9530f6b0
|
Leszek Koltunski
|
hideNavigationBar();
|
86 |
|
|
cutoutHack();
|
87 |
|
|
computeHeights();
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
// this does not include possible insets
|
92 |
|
|
|
93 |
|
|
private void computeHeights()
|
94 |
|
|
{
|
95 |
|
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
96 |
b9d062cf
|
Leszek Koltunski
|
int butHeight = (int)(mScreenHeight*RATIO_BUT);
|
97 |
48314d6a
|
Leszek Koltunski
|
int viewHeight = (int)(mScreenHeight*RATIO_SCROLL);
|
98 |
bc7e49ec
|
Leszek Koltunski
|
int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
|
99 |
7ee8337b
|
leszek
|
int padding = (int)(mScreenHeight*PADDING);
|
100 |
9530f6b0
|
Leszek Koltunski
|
|
101 |
b9d062cf
|
Leszek Koltunski
|
LinearLayout botLayout = findViewById(R.id.lowerBar);
|
102 |
|
|
ViewGroup.LayoutParams paramsL = botLayout.getLayoutParams();
|
103 |
9530f6b0
|
Leszek Koltunski
|
paramsL.height = barHeight;
|
104 |
b9d062cf
|
Leszek Koltunski
|
botLayout.setLayoutParams(paramsL);
|
105 |
|
|
|
106 |
|
|
LinearLayout butLayout = findViewById(R.id.bandagedCreatorButtons);
|
107 |
|
|
ViewGroup.LayoutParams paramsB = butLayout.getLayoutParams();
|
108 |
|
|
paramsB.height = butHeight;
|
109 |
|
|
butLayout.setPadding(padding,0,padding,padding);
|
110 |
|
|
butLayout.setLayoutParams(paramsB);
|
111 |
9530f6b0
|
Leszek Koltunski
|
|
112 |
9f8d4c92
|
Leszek Koltunski
|
LinearLayout topLayout = findViewById(R.id.bandagedCreatorTopView);
|
113 |
|
|
ViewGroup.LayoutParams paramsT = topLayout.getLayoutParams();
|
114 |
|
|
paramsT.height = viewHeight;
|
115 |
b9d062cf
|
Leszek Koltunski
|
topLayout.setPadding(padding,padding,padding,padding);
|
116 |
9f8d4c92
|
Leszek Koltunski
|
topLayout.setLayoutParams(paramsT);
|
117 |
48314d6a
|
Leszek Koltunski
|
|
118 |
7ee8337b
|
leszek
|
BandagedView creator = findViewById(R.id.bandagedCreatorObjectView);
|
119 |
48314d6a
|
Leszek Koltunski
|
ViewGroup.LayoutParams paramsC = creator.getLayoutParams();
|
120 |
|
|
paramsC.height = objectHeight;
|
121 |
|
|
creator.setLayoutParams(paramsC);
|
122 |
9530f6b0
|
Leszek Koltunski
|
}
|
123 |
|
|
|
124 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125 |
|
|
|
126 |
|
|
private void hideNavigationBar()
|
127 |
|
|
{
|
128 |
|
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
129 |
|
|
|
130 |
|
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
131 |
|
|
{
|
132 |
|
|
final View decorView = getWindow().getDecorView();
|
133 |
|
|
|
134 |
|
|
decorView.setSystemUiVisibility(FLAGS);
|
135 |
|
|
|
136 |
|
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
137 |
|
|
{
|
138 |
|
|
@Override
|
139 |
|
|
public void onSystemUiVisibilityChange(int visibility)
|
140 |
|
|
{
|
141 |
|
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
142 |
|
|
{
|
143 |
|
|
decorView.setSystemUiVisibility(FLAGS);
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
});
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
// do not avoid cutouts
|
152 |
|
|
|
153 |
|
|
private void cutoutHack()
|
154 |
|
|
{
|
155 |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
156 |
|
|
{
|
157 |
|
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
158 |
|
|
}
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162 |
|
|
|
163 |
|
|
@Override
|
164 |
|
|
public void onWindowFocusChanged(boolean hasFocus)
|
165 |
|
|
{
|
166 |
|
|
super.onWindowFocusChanged(hasFocus);
|
167 |
|
|
|
168 |
|
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
169 |
|
|
{
|
170 |
|
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
171 |
|
|
}
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175 |
|
|
|
176 |
|
|
@Override
|
177 |
|
|
protected void onPause()
|
178 |
|
|
{
|
179 |
|
|
super.onPause();
|
180 |
7ee8337b
|
leszek
|
BandagedView view = findViewById(R.id.bandagedCreatorObjectView);
|
181 |
9530f6b0
|
Leszek Koltunski
|
view.onPause();
|
182 |
|
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
183 |
13a3dfa9
|
Leszek Koltunski
|
savePreferences();
|
184 |
9530f6b0
|
Leszek Koltunski
|
}
|
185 |
|
|
|
186 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187 |
|
|
|
188 |
|
|
@Override
|
189 |
|
|
protected void onResume()
|
190 |
|
|
{
|
191 |
|
|
super.onResume();
|
192 |
b3786da4
|
leszek
|
|
193 |
9530f6b0
|
Leszek Koltunski
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
194 |
7ee8337b
|
leszek
|
BandagedView view = findViewById(R.id.bandagedCreatorObjectView);
|
195 |
9530f6b0
|
Leszek Koltunski
|
view.onResume();
|
196 |
|
|
|
197 |
7da27d2b
|
leszek
|
if( mScreen==null )
|
198 |
|
|
{
|
199 |
|
|
int ordinal = getObjectOrdinal();
|
200 |
7ee8337b
|
leszek
|
mScreen = new BandagedScreen(ordinal);
|
201 |
7da27d2b
|
leszek
|
}
|
202 |
|
|
|
203 |
bebd7af5
|
Leszek Koltunski
|
mScreen.onAttachedToWindow(this);
|
204 |
7cb8d4b0
|
Leszek Koltunski
|
|
205 |
a41e3c94
|
Leszek Koltunski
|
restorePreferences();
|
206 |
7ee8337b
|
leszek
|
BandagedWorkerThread.create(this);
|
207 |
9530f6b0
|
Leszek Koltunski
|
}
|
208 |
|
|
|
209 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210 |
|
|
|
211 |
|
|
@Override
|
212 |
|
|
protected void onDestroy()
|
213 |
|
|
{
|
214 |
|
|
super.onDestroy();
|
215 |
|
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219 |
|
|
|
220 |
|
|
void OpenGLError()
|
221 |
|
|
{
|
222 |
|
|
RubikDialogError errDiag = new RubikDialogError();
|
223 |
|
|
errDiag.show(getSupportFragmentManager(), null);
|
224 |
|
|
}
|
225 |
|
|
|
226 |
13a3dfa9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
227 |
|
|
|
228 |
|
|
private void savePreferences()
|
229 |
|
|
{
|
230 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
231 |
|
|
SharedPreferences.Editor editor = preferences.edit();
|
232 |
b9d062cf
|
Leszek Koltunski
|
mScreen.savePreferences(editor);
|
233 |
13a3dfa9
|
Leszek Koltunski
|
editor.apply();
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
237 |
|
|
|
238 |
|
|
private void restorePreferences()
|
239 |
|
|
{
|
240 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
241 |
b9d062cf
|
Leszek Koltunski
|
mScreen.restorePreferences(this,preferences);
|
242 |
13a3dfa9
|
Leszek Koltunski
|
}
|
243 |
|
|
|
244 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
// PUBLIC API
|
246 |
b9d062cf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247 |
|
|
|
248 |
|
|
public void changeObject(int x, int y, int z)
|
249 |
|
|
{
|
250 |
7ee8337b
|
leszek
|
BandagedRenderer renderer = getRenderer();
|
251 |
b9d062cf
|
Leszek Koltunski
|
renderer.changeObject(x,y,z);
|
252 |
|
|
}
|
253 |
|
|
|
254 |
2ceeb6b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
255 |
|
|
|
256 |
|
|
public boolean isRTL()
|
257 |
|
|
{
|
258 |
|
|
return mRTL;
|
259 |
|
|
}
|
260 |
|
|
|
261 |
50ec342b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
262 |
|
|
|
263 |
7ee8337b
|
leszek
|
public BandagedRenderer getRenderer()
|
264 |
50ec342b
|
Leszek Koltunski
|
{
|
265 |
7ee8337b
|
leszek
|
BandagedView view = findViewById(R.id.bandagedCreatorObjectView);
|
266 |
50ec342b
|
Leszek Koltunski
|
return view.getRenderer();
|
267 |
|
|
}
|
268 |
|
|
|
269 |
bfb59352
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
270 |
|
|
|
271 |
|
|
public boolean objectDoesntExist(String name)
|
272 |
|
|
{
|
273 |
|
|
return mScreen.objectDoesntExist(name);
|
274 |
|
|
}
|
275 |
|
|
|
276 |
e48ad1af
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277 |
|
|
|
278 |
|
|
public void addObject(String name)
|
279 |
|
|
{
|
280 |
bfb59352
|
Leszek Koltunski
|
mScreen.addObject(this,name);
|
281 |
e48ad1af
|
Leszek Koltunski
|
}
|
282 |
|
|
|
283 |
d3d639b1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284 |
|
|
|
285 |
85770de9
|
Leszek Koltunski
|
public void deleteObject(String name)
|
286 |
d3d639b1
|
Leszek Koltunski
|
{
|
287 |
81493402
|
Leszek Koltunski
|
RubikFiles files = RubikFiles.getInstance();
|
288 |
707f79ff
|
Leszek Koltunski
|
InputStream jsonStream = files.openFile(this,name+"_object.json");
|
289 |
2876aeb6
|
Leszek Koltunski
|
InitAssets assets = new InitAssets(jsonStream,null,null);
|
290 |
707f79ff
|
Leszek Koltunski
|
|
291 |
9234018b
|
Leszek Koltunski
|
if( !assets.noJsonStream() )
|
292 |
213c15de
|
Leszek Koltunski
|
{
|
293 |
337f4660
|
leszek
|
TwistyObject object = new TwistyJson( TwistyObject.MODE_NORM, null, null, 1.0f, assets);
|
294 |
a8be1a23
|
Leszek Koltunski
|
|
295 |
|
|
if( !object.getError() )
|
296 |
|
|
{
|
297 |
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
298 |
|
|
SharedPreferences.Editor editor = preferences.edit();
|
299 |
88451205
|
Leszek Koltunski
|
OSInterface os = new OSInterface(this,null);
|
300 |
05e4c778
|
Leszek Koltunski
|
os.setEditor(editor);
|
301 |
21a1bb5d
|
Leszek Koltunski
|
object.removePreferences(os);
|
302 |
a8be1a23
|
Leszek Koltunski
|
editor.apply();
|
303 |
|
|
}
|
304 |
213c15de
|
Leszek Koltunski
|
}
|
305 |
707f79ff
|
Leszek Koltunski
|
|
306 |
|
|
mScreen.deleteObject(this,name);
|
307 |
|
|
files.deleteIcon(this,name);
|
308 |
|
|
files.deleteJsonObject(this,name);
|
309 |
d3d639b1
|
Leszek Koltunski
|
}
|
310 |
|
|
|
311 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
312 |
|
|
|
313 |
|
|
public void playObject(String name)
|
314 |
|
|
{
|
315 |
7ee8337b
|
leszek
|
Intent intent = new Intent(this, PlayActivity.class);
|
316 |
97201782
|
leszek
|
intent.putExtra("level", -1);
|
317 |
88b94310
|
Leszek Koltunski
|
intent.putExtra("name", name);
|
318 |
7ee8337b
|
leszek
|
intent.putExtra("scrambles", NUM_SCRAMBLES);
|
319 |
|
|
intent.putExtra("local", true);
|
320 |
|
|
intent.putExtra("ordinal", 0);
|
321 |
88b94310
|
Leszek Koltunski
|
startActivity(intent);
|
322 |
d3d639b1
|
Leszek Koltunski
|
}
|
323 |
|
|
|
324 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
325 |
|
|
|
326 |
7cb8d4b0
|
Leszek Koltunski
|
public void iconCreationDone(Bitmap bmp)
|
327 |
9530f6b0
|
Leszek Koltunski
|
{
|
328 |
20b60ad9
|
Leszek Koltunski
|
mScreen.iconCreationDone(this,bmp);
|
329 |
9530f6b0
|
Leszek Koltunski
|
}
|
330 |
|
|
|
331 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
332 |
|
|
|
333 |
|
|
public int getScreenWidthInPixels()
|
334 |
|
|
{
|
335 |
|
|
return mScreenWidth;
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
339 |
|
|
|
340 |
|
|
public int getScreenHeightInPixels()
|
341 |
|
|
{
|
342 |
|
|
return mScreenHeight;
|
343 |
|
|
}
|
344 |
|
|
|
345 |
7da27d2b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
346 |
|
|
|
347 |
|
|
public int getObjectOrdinal()
|
348 |
|
|
{
|
349 |
5a4ee169
|
leszek
|
return mObjectOrdinal;
|
350 |
7da27d2b
|
leszek
|
}
|
351 |
9530f6b0
|
Leszek Koltunski
|
}
|