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