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