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