1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.config;
|
11
|
|
12
|
import java.io.InputStream;
|
13
|
|
14
|
import android.os.Build;
|
15
|
import android.os.Bundle;
|
16
|
import android.util.DisplayMetrics;
|
17
|
import android.view.View;
|
18
|
import android.view.ViewGroup;
|
19
|
import android.view.WindowManager;
|
20
|
import android.widget.LinearLayout;
|
21
|
import androidx.appcompat.app.AppCompatActivity;
|
22
|
|
23
|
import org.distorted.library.main.DistortedLibrary;
|
24
|
import org.distorted.main.MainActivity;
|
25
|
import org.distorted.objectlib.main.InitAssets;
|
26
|
import org.distorted.objectlib.main.ObjectControl;
|
27
|
import org.distorted.main.R;
|
28
|
import org.distorted.dialogs.RubikDialogError;
|
29
|
import org.distorted.objectlib.main.TwistyObject;
|
30
|
import org.distorted.objects.RubikObject;
|
31
|
import org.distorted.objects.RubikObjectList;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class ConfigActivity extends AppCompatActivity
|
36
|
{
|
37
|
private static final int ACTIVITY_NUMBER = 1;
|
38
|
private static final float RATIO_BAR = MainActivity.RATIO_BAR;
|
39
|
public static final int FLAGS = MainActivity.FLAGS;
|
40
|
|
41
|
private static int mScreenWidth, mScreenHeight;
|
42
|
private int mCurrentApiVersion;
|
43
|
private ConfigScreen mScreen;
|
44
|
private int mObjectOrdinal;
|
45
|
private int mHeightBar;
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
@Override
|
50
|
protected void onCreate(Bundle savedState)
|
51
|
{
|
52
|
super.onCreate(savedState);
|
53
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
54
|
setTheme(R.style.MaterialThemeNoActionBar);
|
55
|
setContentView(R.layout.config);
|
56
|
|
57
|
Bundle b = getIntent().getExtras();
|
58
|
|
59
|
if(b != null) mObjectOrdinal = b.getInt("obj");
|
60
|
|
61
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
62
|
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
63
|
mScreenWidth =displaymetrics.widthPixels;
|
64
|
mScreenHeight=displaymetrics.heightPixels;
|
65
|
|
66
|
hideNavigationBar();
|
67
|
cutoutHack();
|
68
|
computeBarHeights();
|
69
|
}
|
70
|
|
71
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
// this does not include possible insets
|
73
|
|
74
|
private void computeBarHeights()
|
75
|
{
|
76
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
77
|
mHeightBar = barHeight;
|
78
|
|
79
|
LinearLayout layout = findViewById(R.id.lowerBar);
|
80
|
ViewGroup.LayoutParams params = layout.getLayoutParams();
|
81
|
params.height = barHeight;
|
82
|
layout.setLayoutParams(params);
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
|
87
|
private void hideNavigationBar()
|
88
|
{
|
89
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
90
|
|
91
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
92
|
{
|
93
|
final View decorView = getWindow().getDecorView();
|
94
|
|
95
|
decorView.setSystemUiVisibility(FLAGS);
|
96
|
|
97
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
98
|
{
|
99
|
@Override
|
100
|
public void onSystemUiVisibilityChange(int visibility)
|
101
|
{
|
102
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
103
|
{
|
104
|
decorView.setSystemUiVisibility(FLAGS);
|
105
|
}
|
106
|
}
|
107
|
});
|
108
|
}
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
// do not avoid cutouts
|
113
|
|
114
|
private void cutoutHack()
|
115
|
{
|
116
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
117
|
{
|
118
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
@Override
|
125
|
public void onWindowFocusChanged(boolean hasFocus)
|
126
|
{
|
127
|
super.onWindowFocusChanged(hasFocus);
|
128
|
|
129
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
130
|
{
|
131
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
132
|
}
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
@Override
|
138
|
protected void onPause()
|
139
|
{
|
140
|
super.onPause();
|
141
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
142
|
view.onPause();
|
143
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
@Override
|
149
|
protected void onResume()
|
150
|
{
|
151
|
super.onResume();
|
152
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
153
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
154
|
view.onResume();
|
155
|
|
156
|
if( mScreen==null ) mScreen = new ConfigScreen();
|
157
|
mScreen.onAttachedToWindow(this,mObjectOrdinal);
|
158
|
|
159
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
160
|
{
|
161
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
162
|
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
|
163
|
}
|
164
|
}
|
165
|
|
166
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167
|
|
168
|
@Override
|
169
|
protected void onDestroy()
|
170
|
{
|
171
|
super.onDestroy();
|
172
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
void OpenGLError()
|
178
|
{
|
179
|
RubikDialogError errDiag = new RubikDialogError();
|
180
|
errDiag.show(getSupportFragmentManager(), null);
|
181
|
}
|
182
|
|
183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184
|
|
185
|
private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
|
186
|
{
|
187
|
if( object!=null )
|
188
|
{
|
189
|
int iconMode = TwistyObject.MODE_NORM;
|
190
|
InputStream jsonStream = object.getObjectStream(this);
|
191
|
InputStream meshStream = object.getMeshStream(this);
|
192
|
String name = object.getUpperName();
|
193
|
InitAssets asset = new InitAssets(jsonStream,meshStream,null);
|
194
|
control.changeIfDifferent(ordinal,name,iconMode,asset);
|
195
|
}
|
196
|
}
|
197
|
|
198
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199
|
// PUBLIC API
|
200
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
201
|
|
202
|
public void changeObject(int ordinal)
|
203
|
{
|
204
|
mObjectOrdinal = ordinal;
|
205
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
206
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
207
|
ObjectControl control = view.getObjectControl();
|
208
|
changeIfDifferent(object,ordinal,control);
|
209
|
}
|
210
|
|
211
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212
|
|
213
|
public int getHeightBar()
|
214
|
{
|
215
|
return mHeightBar;
|
216
|
}
|
217
|
|
218
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219
|
|
220
|
public int getScreenWidthInPixels()
|
221
|
{
|
222
|
return mScreenWidth;
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
public int getScreenHeightInPixels()
|
228
|
{
|
229
|
return mScreenHeight;
|
230
|
}
|
231
|
|
232
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233
|
|
234
|
public ObjectControl getControl()
|
235
|
{
|
236
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
237
|
return view.getObjectControl();
|
238
|
}
|
239
|
}
|