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