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