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