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.tutorial;
|
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.webkit.WebView;
|
29
|
import android.widget.LinearLayout;
|
30
|
|
31
|
import androidx.appcompat.app.AppCompatActivity;
|
32
|
|
33
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
34
|
|
35
|
import org.distorted.dialogs.RubikDialogError;
|
36
|
import org.distorted.library.main.DistortedLibrary;
|
37
|
import org.distorted.main.R;
|
38
|
import org.distorted.objects.ObjectList;
|
39
|
import org.distorted.objects.TwistyObject;
|
40
|
import org.distorted.states.StateList;
|
41
|
|
42
|
import static org.distorted.main.RubikRenderer.BRIGHTNESS;
|
43
|
|
44
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45
|
|
46
|
public class TutorialActivity extends AppCompatActivity
|
47
|
{
|
48
|
private static final String URL = "https://www.youtube.com/embed/";
|
49
|
|
50
|
public static final float DIALOG_BUTTON_SIZE = 0.06f;
|
51
|
public static final float MENU_BIG_TEXT_SIZE = 0.05f;
|
52
|
|
53
|
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
54
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
55
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
56
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
57
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
58
|
|
59
|
public static final int FLAGS2= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
60
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
61
|
|
62
|
private boolean mIsLocked;
|
63
|
private FirebaseAnalytics mFirebaseAnalytics;
|
64
|
private static int mScreenWidth, mScreenHeight;
|
65
|
private int mCurrentApiVersion;
|
66
|
private TutorialState mState;
|
67
|
private String mURL;
|
68
|
private int mObjectOrdinal, mObjectSize;
|
69
|
private TutorialWebView mWebView;
|
70
|
|
71
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
|
73
|
@Override
|
74
|
protected void onCreate(Bundle savedState)
|
75
|
{
|
76
|
super.onCreate(savedState);
|
77
|
DistortedLibrary.onCreate(1);
|
78
|
setTheme(R.style.CustomActivityThemeNoActionBar);
|
79
|
setContentView(R.layout.tutorial);
|
80
|
|
81
|
Bundle b = getIntent().getExtras();
|
82
|
|
83
|
if(b != null)
|
84
|
{
|
85
|
mURL = b.getString("url");
|
86
|
mObjectOrdinal = b.getInt("obj");
|
87
|
mObjectSize = b.getInt("siz");
|
88
|
}
|
89
|
|
90
|
mIsLocked = false;
|
91
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
92
|
|
93
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
94
|
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
95
|
mScreenWidth =displaymetrics.widthPixels;
|
96
|
mScreenHeight=displaymetrics.heightPixels;
|
97
|
|
98
|
hideNavigationBar();
|
99
|
cutoutHack();
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
private void hideNavigationBar()
|
105
|
{
|
106
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
107
|
|
108
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
109
|
{
|
110
|
final View decorView = getWindow().getDecorView();
|
111
|
|
112
|
decorView.setSystemUiVisibility(FLAGS);
|
113
|
|
114
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
115
|
{
|
116
|
@Override
|
117
|
public void onSystemUiVisibilityChange(int visibility)
|
118
|
{
|
119
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
120
|
{
|
121
|
decorView.setSystemUiVisibility(FLAGS);
|
122
|
}
|
123
|
}
|
124
|
});
|
125
|
}
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
@Override
|
131
|
public void onAttachedToWindow()
|
132
|
{
|
133
|
super.onAttachedToWindow();
|
134
|
|
135
|
final float RATIO = 0.15f;
|
136
|
float width = getScreenWidthInPixels();
|
137
|
|
138
|
TutorialSurfaceView viewL = findViewById(R.id.tutorialSurfaceView);
|
139
|
ViewGroup.LayoutParams paramsL = viewL.getLayoutParams();
|
140
|
paramsL.width = (int)(width*(1.0f-RATIO));
|
141
|
viewL.setLayoutParams(paramsL);
|
142
|
|
143
|
LinearLayout viewR = findViewById(R.id.tutorialRightBar);
|
144
|
ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
|
145
|
paramsR.width = (int)(width*RATIO);
|
146
|
viewR.setLayoutParams(paramsR);
|
147
|
|
148
|
final int color = (int)(BRIGHTNESS*255);
|
149
|
viewR.setBackgroundColor( (0xFF<<24)+(color<<16)+(color<<8)+color);
|
150
|
|
151
|
if( mState==null ) mState = new TutorialState();
|
152
|
|
153
|
mState.createRightPane(this,width);
|
154
|
|
155
|
WebView videoView = findViewById(R.id.tutorialVideoView);
|
156
|
mWebView = new TutorialWebView(this,videoView);
|
157
|
mWebView.load(URL+mURL);
|
158
|
}
|
159
|
|
160
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161
|
// do not avoid cutouts
|
162
|
|
163
|
private void cutoutHack()
|
164
|
{
|
165
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
166
|
{
|
167
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
168
|
}
|
169
|
}
|
170
|
|
171
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172
|
|
173
|
@Override
|
174
|
public void onWindowFocusChanged(boolean hasFocus)
|
175
|
{
|
176
|
super.onWindowFocusChanged(hasFocus);
|
177
|
|
178
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
179
|
{
|
180
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
181
|
}
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
|
186
|
@Override
|
187
|
protected void onPause()
|
188
|
{
|
189
|
super.onPause();
|
190
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
191
|
view.onPause();
|
192
|
|
193
|
if( mWebView!=null ) mWebView.onPause();
|
194
|
|
195
|
DistortedLibrary.onPause(1);
|
196
|
}
|
197
|
|
198
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
199
|
|
200
|
@Override
|
201
|
protected void onResume()
|
202
|
{
|
203
|
super.onResume();
|
204
|
DistortedLibrary.onResume(1);
|
205
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
206
|
view.onResume();
|
207
|
view.initialize();
|
208
|
|
209
|
if( mWebView!=null ) mWebView.onResume();
|
210
|
|
211
|
if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectList.NUM_OBJECTS )
|
212
|
{
|
213
|
ObjectList obj = ObjectList.getObject(mObjectOrdinal);
|
214
|
int[] sizes = obj.getSizes();
|
215
|
int sizeIndex = ObjectList.getSizeIndex(mObjectOrdinal,mObjectSize);
|
216
|
|
217
|
if( sizeIndex>=0 && sizeIndex<sizes.length )
|
218
|
{
|
219
|
view.getPreRender().changeObject(obj,mObjectSize);
|
220
|
}
|
221
|
}
|
222
|
}
|
223
|
|
224
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
225
|
|
226
|
@Override
|
227
|
protected void onDestroy()
|
228
|
{
|
229
|
super.onDestroy();
|
230
|
DistortedLibrary.onDestroy(1);
|
231
|
}
|
232
|
|
233
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
234
|
|
235
|
void OpenGLError()
|
236
|
{
|
237
|
RubikDialogError errDiag = new RubikDialogError();
|
238
|
errDiag.show(getSupportFragmentManager(), null);
|
239
|
}
|
240
|
|
241
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
242
|
|
243
|
TutorialState getState()
|
244
|
{
|
245
|
return mState;
|
246
|
}
|
247
|
|
248
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249
|
// PUBLIC API
|
250
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
251
|
|
252
|
public FirebaseAnalytics getAnalytics()
|
253
|
{
|
254
|
return mFirebaseAnalytics;
|
255
|
}
|
256
|
|
257
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
258
|
|
259
|
public TwistyObject getObject()
|
260
|
{
|
261
|
TutorialSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
262
|
TutorialPreRender pre = view.getPreRender();
|
263
|
return pre.getObject();
|
264
|
}
|
265
|
|
266
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267
|
|
268
|
public int getScreenWidthInPixels()
|
269
|
{
|
270
|
return mScreenWidth;
|
271
|
}
|
272
|
|
273
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274
|
|
275
|
public int getScreenHeightInPixels()
|
276
|
{
|
277
|
return mScreenHeight;
|
278
|
}
|
279
|
|
280
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
281
|
|
282
|
public TutorialPreRender getPreRender()
|
283
|
{
|
284
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
285
|
return view.getPreRender();
|
286
|
}
|
287
|
|
288
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
289
|
|
290
|
public static int getDrawableSize()
|
291
|
{
|
292
|
if( mScreenHeight<1000 )
|
293
|
{
|
294
|
return 0;
|
295
|
}
|
296
|
if( mScreenHeight<1600 )
|
297
|
{
|
298
|
return 1;
|
299
|
}
|
300
|
if( mScreenHeight<1900 )
|
301
|
{
|
302
|
return 2;
|
303
|
}
|
304
|
|
305
|
return 3;
|
306
|
}
|
307
|
|
308
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
309
|
|
310
|
public static int getDrawable(int small, int medium, int big, int huge)
|
311
|
{
|
312
|
int size = getDrawableSize();
|
313
|
|
314
|
switch(size)
|
315
|
{
|
316
|
case 0 : return small;
|
317
|
case 1 : return medium;
|
318
|
case 2 : return big;
|
319
|
default: return huge;
|
320
|
}
|
321
|
}
|
322
|
|
323
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
324
|
|
325
|
public boolean isVertical()
|
326
|
{
|
327
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
328
|
return view.isVertical();
|
329
|
}
|
330
|
|
331
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
332
|
|
333
|
public void toggleLock()
|
334
|
{
|
335
|
mIsLocked = !mIsLocked;
|
336
|
}
|
337
|
|
338
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
339
|
|
340
|
public boolean isLocked()
|
341
|
{
|
342
|
StateList state = StateList.getCurrentState();
|
343
|
|
344
|
if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
|
345
|
{
|
346
|
return mIsLocked;
|
347
|
}
|
348
|
|
349
|
return false;
|
350
|
}
|
351
|
|
352
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
353
|
|
354
|
public boolean retLocked()
|
355
|
{
|
356
|
return mIsLocked;
|
357
|
}
|
358
|
}
|