1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 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
|
package org.distorted.bandaged;
|
21
|
|
22
|
import android.os.Build;
|
23
|
import android.os.Bundle;
|
24
|
import android.util.DisplayMetrics;
|
25
|
import android.view.View;
|
26
|
import android.view.ViewGroup;
|
27
|
import android.view.WindowManager;
|
28
|
import android.widget.LinearLayout;
|
29
|
|
30
|
import androidx.appcompat.app.AppCompatActivity;
|
31
|
|
32
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
33
|
|
34
|
import org.distorted.config.ConfigSurfaceView;
|
35
|
import org.distorted.dialogs.RubikDialogError;
|
36
|
import org.distorted.library.main.DistortedLibrary;
|
37
|
import org.distorted.main.R;
|
38
|
import org.distorted.objectlib.main.ObjectControl;
|
39
|
import org.distorted.objects.RubikObject;
|
40
|
import org.distorted.objects.RubikObjectList;
|
41
|
|
42
|
import java.io.InputStream;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public class BandagedPlayActivity extends AppCompatActivity
|
47
|
{
|
48
|
private static final int ACTIVITY_NUMBER = 4;
|
49
|
private static final float RATIO_BAR = 0.10f;
|
50
|
|
51
|
public static final float DIALOG_BUTTON_SIZE = 0.06f;
|
52
|
public static final float MENU_BIG_TEXT_SIZE = 0.05f;
|
53
|
|
54
|
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
55
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
56
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
57
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
58
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
59
|
|
60
|
private FirebaseAnalytics mFirebaseAnalytics;
|
61
|
private static int mScreenWidth, mScreenHeight;
|
62
|
private int mCurrentApiVersion;
|
63
|
private BandagedPlayScreen mScreen;
|
64
|
private int mObjectOrdinal;
|
65
|
private int mHeightBar;
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
@Override
|
70
|
protected void onCreate(Bundle savedState)
|
71
|
{
|
72
|
super.onCreate(savedState);
|
73
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
74
|
setTheme(R.style.MaterialThemeNoActionBar);
|
75
|
setContentView(R.layout.bandaged_play);
|
76
|
|
77
|
Bundle b = getIntent().getExtras();
|
78
|
|
79
|
if(b != null) mObjectOrdinal = b.getInt("obj");
|
80
|
|
81
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
82
|
|
83
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
84
|
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
85
|
mScreenWidth =displaymetrics.widthPixels;
|
86
|
mScreenHeight=displaymetrics.heightPixels;
|
87
|
mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
|
88
|
// which is not yet hidden.
|
89
|
// TODO: figure this out exactly.
|
90
|
hideNavigationBar();
|
91
|
cutoutHack();
|
92
|
computeBarHeights();
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
// this does not include possible insets
|
97
|
|
98
|
private void computeBarHeights()
|
99
|
{
|
100
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
101
|
mHeightBar = barHeight;
|
102
|
|
103
|
LinearLayout layout = findViewById(R.id.lowerBar);
|
104
|
ViewGroup.LayoutParams params = layout.getLayoutParams();
|
105
|
params.height = barHeight;
|
106
|
layout.setLayoutParams(params);
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
private void hideNavigationBar()
|
112
|
{
|
113
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
114
|
|
115
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
116
|
{
|
117
|
final View decorView = getWindow().getDecorView();
|
118
|
|
119
|
decorView.setSystemUiVisibility(FLAGS);
|
120
|
|
121
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
122
|
{
|
123
|
@Override
|
124
|
public void onSystemUiVisibilityChange(int visibility)
|
125
|
{
|
126
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
127
|
{
|
128
|
decorView.setSystemUiVisibility(FLAGS);
|
129
|
}
|
130
|
}
|
131
|
});
|
132
|
}
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
// do not avoid cutouts
|
137
|
|
138
|
private void cutoutHack()
|
139
|
{
|
140
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
141
|
{
|
142
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
143
|
}
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
@Override
|
149
|
public void onWindowFocusChanged(boolean hasFocus)
|
150
|
{
|
151
|
super.onWindowFocusChanged(hasFocus);
|
152
|
|
153
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
154
|
{
|
155
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
156
|
}
|
157
|
}
|
158
|
|
159
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160
|
|
161
|
@Override
|
162
|
protected void onPause()
|
163
|
{
|
164
|
super.onPause();
|
165
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
166
|
view.onPause();
|
167
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
168
|
}
|
169
|
|
170
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171
|
|
172
|
@Override
|
173
|
protected void onResume()
|
174
|
{
|
175
|
super.onResume();
|
176
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
177
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
178
|
view.onResume();
|
179
|
|
180
|
if( mScreen==null ) mScreen = new BandagedPlayScreen();
|
181
|
mScreen.onAttachedToWindow(this,mObjectOrdinal);
|
182
|
|
183
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
184
|
{
|
185
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
186
|
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
|
187
|
}
|
188
|
}
|
189
|
|
190
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
191
|
|
192
|
@Override
|
193
|
protected void onDestroy()
|
194
|
{
|
195
|
super.onDestroy();
|
196
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
197
|
}
|
198
|
|
199
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200
|
|
201
|
void OpenGLError()
|
202
|
{
|
203
|
RubikDialogError errDiag = new RubikDialogError();
|
204
|
errDiag.show(getSupportFragmentManager(), null);
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
|
209
|
private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
|
210
|
{
|
211
|
if( object!=null )
|
212
|
{
|
213
|
int meshState = object.getMeshState();
|
214
|
InputStream jsonStream = object.getObjectStream(this);
|
215
|
InputStream meshStream = object.getMeshStream(this);
|
216
|
String name = object.getUpperName();
|
217
|
|
218
|
control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream);
|
219
|
}
|
220
|
}
|
221
|
|
222
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
// PUBLIC API
|
224
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225
|
|
226
|
public void changeObject(int ordinal)
|
227
|
{
|
228
|
mObjectOrdinal = ordinal;
|
229
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
230
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
231
|
ObjectControl control = view.getObjectControl();
|
232
|
changeIfDifferent(object,ordinal,control);
|
233
|
}
|
234
|
|
235
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
236
|
|
237
|
public FirebaseAnalytics getAnalytics()
|
238
|
{
|
239
|
return mFirebaseAnalytics;
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
public int getHeightBar()
|
245
|
{
|
246
|
return mHeightBar;
|
247
|
}
|
248
|
|
249
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
250
|
|
251
|
public int getScreenWidthInPixels()
|
252
|
{
|
253
|
return mScreenWidth;
|
254
|
}
|
255
|
|
256
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257
|
|
258
|
public int getScreenHeightInPixels()
|
259
|
{
|
260
|
return mScreenHeight;
|
261
|
}
|
262
|
|
263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264
|
|
265
|
public ObjectControl getControl()
|
266
|
{
|
267
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
268
|
return view.getObjectControl();
|
269
|
}
|
270
|
|
271
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
272
|
|
273
|
public static int getDrawableSize()
|
274
|
{
|
275
|
if( mScreenHeight<1000 )
|
276
|
{
|
277
|
return 0;
|
278
|
}
|
279
|
if( mScreenHeight<1600 )
|
280
|
{
|
281
|
return 1;
|
282
|
}
|
283
|
if( mScreenHeight<1900 )
|
284
|
{
|
285
|
return 2;
|
286
|
}
|
287
|
|
288
|
return 3;
|
289
|
}
|
290
|
|
291
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
292
|
|
293
|
public static int getDrawable(int small, int medium, int big, int huge)
|
294
|
{
|
295
|
int size = getDrawableSize();
|
296
|
|
297
|
switch(size)
|
298
|
{
|
299
|
case 0 : return small;
|
300
|
case 1 : return medium;
|
301
|
case 2 : return big;
|
302
|
default: return huge;
|
303
|
}
|
304
|
}
|
305
|
|
306
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
307
|
|
308
|
public boolean isVertical()
|
309
|
{
|
310
|
BandagedPlayView view = findViewById(R.id.bandagedPlayView);
|
311
|
return view.isVertical();
|
312
|
}
|
313
|
}
|