1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// 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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.bandaged;
|
11
|
|
12
|
import android.content.SharedPreferences;
|
13
|
import android.os.Build;
|
14
|
import android.os.Bundle;
|
15
|
import android.preference.PreferenceManager;
|
16
|
import android.util.DisplayMetrics;
|
17
|
import android.view.DisplayCutout;
|
18
|
import android.view.View;
|
19
|
import android.view.ViewGroup;
|
20
|
import android.view.WindowManager;
|
21
|
import android.widget.LinearLayout;
|
22
|
|
23
|
import androidx.appcompat.app.AppCompatActivity;
|
24
|
|
25
|
import org.distorted.dialogs.RubikDialogError;
|
26
|
import org.distorted.external.RubikFiles;
|
27
|
import org.distorted.library.main.DistortedLibrary;
|
28
|
import org.distorted.main.R;
|
29
|
import org.distorted.objectlib.main.ObjectControl;
|
30
|
import org.distorted.objectlib.main.TwistyObject;
|
31
|
|
32
|
import java.io.InputStream;
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
|
36
|
public class BandagedPlayActivity extends AppCompatActivity
|
37
|
{
|
38
|
private static final int ACTIVITY_NUMBER = 4;
|
39
|
private static final float RATIO_BAR = 0.10f;
|
40
|
private static final float RATIO_INSET= 0.09f;
|
41
|
|
42
|
public static final float DIALOG_BUTTON_SIZE = 0.06f;
|
43
|
public static final float MENU_BIG_TEXT_SIZE = 0.05f;
|
44
|
|
45
|
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
46
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
47
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
48
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
49
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
50
|
|
51
|
private static int mScreenWidth, mScreenHeight;
|
52
|
private int mCurrentApiVersion;
|
53
|
private BandagedPlayScreen mScreen;
|
54
|
private String mObjectName;
|
55
|
private int mHeightLowerBar, mHeightUpperBar;
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
@Override
|
60
|
protected void onCreate(Bundle savedState)
|
61
|
{
|
62
|
super.onCreate(savedState);
|
63
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
64
|
setTheme(R.style.MaterialThemeNoActionBar);
|
65
|
setContentView(R.layout.bandaged_play);
|
66
|
|
67
|
Bundle b = getIntent().getExtras();
|
68
|
mObjectName = b!=null ? b.getString("name") : "";
|
69
|
|
70
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
71
|
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
72
|
mScreenWidth =displaymetrics.widthPixels;
|
73
|
mScreenHeight=displaymetrics.heightPixels;
|
74
|
|
75
|
hideNavigationBar();
|
76
|
cutoutHack();
|
77
|
computeBarHeights();
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
// this does not include possible insets
|
82
|
|
83
|
private void computeBarHeights()
|
84
|
{
|
85
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
86
|
mHeightLowerBar = barHeight;
|
87
|
mHeightUpperBar = barHeight;
|
88
|
|
89
|
LinearLayout layoutTop = findViewById(R.id.upperBar);
|
90
|
LinearLayout layoutBot = findViewById(R.id.lowerBar);
|
91
|
|
92
|
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
|
93
|
paramsTop.height = mHeightUpperBar;
|
94
|
layoutTop.setLayoutParams(paramsTop);
|
95
|
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
|
96
|
paramsBot.height = mHeightLowerBar;
|
97
|
layoutBot.setLayoutParams(paramsBot);
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
private void hideNavigationBar()
|
103
|
{
|
104
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
105
|
|
106
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
107
|
{
|
108
|
final View decorView = getWindow().getDecorView();
|
109
|
|
110
|
decorView.setSystemUiVisibility(FLAGS);
|
111
|
|
112
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
113
|
{
|
114
|
@Override
|
115
|
public void onSystemUiVisibilityChange(int visibility)
|
116
|
{
|
117
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
118
|
{
|
119
|
decorView.setSystemUiVisibility(FLAGS);
|
120
|
}
|
121
|
}
|
122
|
});
|
123
|
}
|
124
|
}
|
125
|
|
126
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127
|
|
128
|
@Override
|
129
|
public void onAttachedToWindow()
|
130
|
{
|
131
|
super.onAttachedToWindow();
|
132
|
|
133
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
134
|
{
|
135
|
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
|
136
|
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
|
137
|
|
138
|
LinearLayout layoutHid = findViewById(R.id.hiddenBar);
|
139
|
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
|
140
|
paramsHid.height = (int)(insetHeight*RATIO_INSET);
|
141
|
layoutHid.setLayoutParams(paramsHid);
|
142
|
mHeightUpperBar += paramsHid.height;
|
143
|
}
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
// do not avoid cutouts
|
148
|
|
149
|
private void cutoutHack()
|
150
|
{
|
151
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
152
|
{
|
153
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
154
|
}
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
@Override
|
160
|
public void onWindowFocusChanged(boolean hasFocus)
|
161
|
{
|
162
|
super.onWindowFocusChanged(hasFocus);
|
163
|
|
164
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
165
|
{
|
166
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
167
|
}
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
@Override
|
173
|
protected void onPause()
|
174
|
{
|
175
|
super.onPause();
|
176
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
177
|
view.onPause();
|
178
|
savePreferences();
|
179
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
180
|
}
|
181
|
|
182
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
183
|
|
184
|
@Override
|
185
|
protected void onResume()
|
186
|
{
|
187
|
super.onResume();
|
188
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
189
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
190
|
view.onResume();
|
191
|
|
192
|
if( mScreen==null ) mScreen = new BandagedPlayScreen();
|
193
|
mScreen.onAttachedToWindow(this, mObjectName);
|
194
|
restorePreferences();
|
195
|
|
196
|
if( mObjectName.length()>0 )
|
197
|
{
|
198
|
changeIfDifferent(mObjectName,view.getObjectControl());
|
199
|
}
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
@Override
|
205
|
protected void onDestroy()
|
206
|
{
|
207
|
super.onDestroy();
|
208
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
209
|
}
|
210
|
|
211
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212
|
|
213
|
private void savePreferences()
|
214
|
{
|
215
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
216
|
SharedPreferences.Editor editor = preferences.edit();
|
217
|
mScreen.savePreferences(this,editor);
|
218
|
|
219
|
editor.apply();
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
|
224
|
private void restorePreferences()
|
225
|
{
|
226
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
227
|
mScreen.restorePreferences(this,preferences);
|
228
|
}
|
229
|
|
230
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
231
|
|
232
|
void OpenGLError()
|
233
|
{
|
234
|
RubikDialogError errDiag = new RubikDialogError();
|
235
|
errDiag.show(getSupportFragmentManager(), null);
|
236
|
}
|
237
|
|
238
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239
|
|
240
|
private void changeIfDifferent(String name,ObjectControl control)
|
241
|
{
|
242
|
RubikFiles files = RubikFiles.getInstance();
|
243
|
|
244
|
int meshState = TwistyObject.MESH_NICE;
|
245
|
int iconMode = TwistyObject.MODE_NORM;
|
246
|
InputStream jsonStream = files.openFile(this,name+"_object.json");
|
247
|
InputStream meshStream = null;
|
248
|
int ordinal = 0; // if jsonStream!=null, this doesn't matter
|
249
|
|
250
|
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
|
251
|
}
|
252
|
|
253
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254
|
// PUBLIC API
|
255
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256
|
|
257
|
public void changeObject(String name)
|
258
|
{
|
259
|
mObjectName = name;
|
260
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
261
|
ObjectControl control = view.getObjectControl();
|
262
|
changeIfDifferent(name,control);
|
263
|
}
|
264
|
|
265
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
266
|
|
267
|
public int getHeightBar()
|
268
|
{
|
269
|
return mHeightLowerBar;
|
270
|
}
|
271
|
|
272
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
273
|
|
274
|
public int getScreenWidthInPixels()
|
275
|
{
|
276
|
return mScreenWidth;
|
277
|
}
|
278
|
|
279
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
280
|
|
281
|
public int getScreenHeightInPixels()
|
282
|
{
|
283
|
return mScreenHeight;
|
284
|
}
|
285
|
|
286
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287
|
|
288
|
public ObjectControl getControl()
|
289
|
{
|
290
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
291
|
return view.getObjectControl();
|
292
|
}
|
293
|
|
294
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
295
|
|
296
|
public BandagedPlayScreen getScreen()
|
297
|
{
|
298
|
return mScreen;
|
299
|
}
|
300
|
|
301
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
302
|
|
303
|
public static int getDrawableSize()
|
304
|
{
|
305
|
if( mScreenHeight<1000 )
|
306
|
{
|
307
|
return 0;
|
308
|
}
|
309
|
if( mScreenHeight<1600 )
|
310
|
{
|
311
|
return 1;
|
312
|
}
|
313
|
if( mScreenHeight<1900 )
|
314
|
{
|
315
|
return 2;
|
316
|
}
|
317
|
|
318
|
return 3;
|
319
|
}
|
320
|
|
321
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
322
|
|
323
|
public static int getDrawable(int small, int medium, int big, int huge)
|
324
|
{
|
325
|
int size = getDrawableSize();
|
326
|
|
327
|
switch(size)
|
328
|
{
|
329
|
case 0 : return small;
|
330
|
case 1 : return medium;
|
331
|
case 2 : return big;
|
332
|
default: return huge;
|
333
|
}
|
334
|
}
|
335
|
|
336
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
337
|
|
338
|
public boolean isVertical()
|
339
|
{
|
340
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
341
|
return view.isVertical();
|
342
|
}
|
343
|
}
|