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