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