1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// 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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.tutorials;
|
11
|
|
12
|
import java.io.InputStream;
|
13
|
|
14
|
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.webkit.WebView;
|
21
|
import android.widget.LinearLayout;
|
22
|
|
23
|
import androidx.appcompat.app.AppCompatActivity;
|
24
|
|
25
|
import org.distorted.dialogs.RubikDialogTutorialSingle;
|
26
|
import org.distorted.library.main.DistortedLibrary;
|
27
|
|
28
|
import org.distorted.main.MainActivity;
|
29
|
import org.distorted.objectlib.main.InitAssets;
|
30
|
import org.distorted.objectlib.main.ObjectControl;
|
31
|
import org.distorted.objectlib.main.TwistyObject;
|
32
|
|
33
|
import org.distorted.main.R;
|
34
|
import org.distorted.dialogs.RubikDialogError;
|
35
|
import org.distorted.objects.RubikObject;
|
36
|
import org.distorted.objects.RubikObjectList;
|
37
|
import org.distorted.os.OSInterface;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public class TutorialActivity extends AppCompatActivity
|
42
|
{
|
43
|
private static final String URL = "https://www.youtube.com/embed/";
|
44
|
private static final int ACTIVITY_NUMBER = 0;
|
45
|
public static final float BAR_RATIO = 0.17f;
|
46
|
public static final int FLAGS = MainActivity.FLAGS;
|
47
|
|
48
|
private static int mScreenWidth, mScreenHeight;
|
49
|
private int mCurrentApiVersion;
|
50
|
private TutorialScreen mScreen;
|
51
|
private int mObjectOrdinal;
|
52
|
private TutorialWebView mWebView;
|
53
|
private boolean mIsFree;
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
@Override
|
58
|
protected void onCreate(Bundle savedState)
|
59
|
{
|
60
|
super.onCreate(savedState);
|
61
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
62
|
setTheme(R.style.MaterialThemeNoActionBar);
|
63
|
setContentView(R.layout.tutorial);
|
64
|
|
65
|
mIsFree = true;
|
66
|
|
67
|
Bundle b = getIntent().getExtras();
|
68
|
|
69
|
if(b != null)
|
70
|
{
|
71
|
mObjectOrdinal = b.getInt("obj");
|
72
|
RubikObject obj= RubikObjectList.getObject(mObjectOrdinal);
|
73
|
mIsFree = (obj!=null && obj.isFree());
|
74
|
}
|
75
|
|
76
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
77
|
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
|
78
|
mScreenWidth =displaymetrics.widthPixels;
|
79
|
mScreenHeight=displaymetrics.heightPixels;
|
80
|
|
81
|
hideNavigationBar();
|
82
|
cutoutHack();
|
83
|
showDialog();
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
public void showDialog()
|
89
|
{
|
90
|
RubikObjectList.setCurrObject(mObjectOrdinal);
|
91
|
Bundle bundle = new Bundle();
|
92
|
bundle.putString("argument",RubikObjectList.getCurrentName());
|
93
|
RubikDialogTutorialSingle diag = new RubikDialogTutorialSingle();
|
94
|
diag.setArguments(bundle);
|
95
|
diag.show( getSupportFragmentManager(), RubikDialogTutorialSingle.getDialogTag() );
|
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
|
public void loadTutorial(String url)
|
127
|
{
|
128
|
if( mWebView==null )
|
129
|
{
|
130
|
WebView videoView = findViewById(R.id.tutorialVideoView);
|
131
|
mWebView = new TutorialWebView(videoView);
|
132
|
}
|
133
|
|
134
|
mWebView.load(URL+url);
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
// do not avoid cutouts
|
139
|
|
140
|
private void cutoutHack()
|
141
|
{
|
142
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
143
|
{
|
144
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
145
|
}
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
@Override
|
151
|
public void onWindowFocusChanged(boolean hasFocus)
|
152
|
{
|
153
|
super.onWindowFocusChanged(hasFocus);
|
154
|
|
155
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
156
|
{
|
157
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
|
163
|
@Override
|
164
|
protected void onPause()
|
165
|
{
|
166
|
super.onPause();
|
167
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
168
|
view.onPause();
|
169
|
|
170
|
if( mWebView!=null ) mWebView.onPause();
|
171
|
|
172
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
@Override
|
178
|
protected void onResume()
|
179
|
{
|
180
|
super.onResume();
|
181
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
182
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
183
|
view.onResume();
|
184
|
|
185
|
float width = getScreenWidthInPixels();
|
186
|
|
187
|
LinearLayout viewR = findViewById(R.id.tutorialRightBar);
|
188
|
ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
|
189
|
paramsR.width = (int)(width*BAR_RATIO);
|
190
|
viewR.setLayoutParams(paramsR);
|
191
|
|
192
|
if( mScreen==null ) mScreen = new TutorialScreen(mIsFree);
|
193
|
|
194
|
mScreen.createRightPane(this);
|
195
|
|
196
|
if( mWebView!=null ) mWebView.onResume();
|
197
|
|
198
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
199
|
{
|
200
|
changeIfDifferent(mObjectOrdinal,view.getObjectControl());
|
201
|
}
|
202
|
}
|
203
|
|
204
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
205
|
|
206
|
@Override
|
207
|
protected void onDestroy()
|
208
|
{
|
209
|
super.onDestroy();
|
210
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
211
|
}
|
212
|
|
213
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214
|
|
215
|
void OpenGLError()
|
216
|
{
|
217
|
RubikDialogError errDiag = new RubikDialogError();
|
218
|
errDiag.show(getSupportFragmentManager(), null);
|
219
|
}
|
220
|
|
221
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
222
|
|
223
|
private void changeIfDifferent(int ordinal,ObjectControl control)
|
224
|
{
|
225
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
226
|
int iconMode = TwistyObject.MODE_NORM;
|
227
|
InputStream jsonStream = object==null ? null : object.getObjectStream(this);
|
228
|
InputStream meshStream = object==null ? null : object.getMeshStream(this);
|
229
|
String name = object==null ? "NULL" : object.getUpperName();
|
230
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
231
|
OSInterface os = view.getInterface();
|
232
|
InitAssets asset = new InitAssets(jsonStream,meshStream,os);
|
233
|
control.changeIfDifferent(ordinal,name,iconMode,asset);
|
234
|
}
|
235
|
|
236
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
237
|
|
238
|
TutorialScreen getState()
|
239
|
{
|
240
|
return mScreen;
|
241
|
}
|
242
|
|
243
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
244
|
// PUBLIC API
|
245
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
246
|
|
247
|
public int getScreenWidthInPixels()
|
248
|
{
|
249
|
return mScreenWidth;
|
250
|
}
|
251
|
|
252
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
253
|
|
254
|
public int getScreenHeightInPixels()
|
255
|
{
|
256
|
return mScreenHeight;
|
257
|
}
|
258
|
|
259
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
260
|
|
261
|
public boolean getIsFree()
|
262
|
{
|
263
|
return mIsFree;
|
264
|
}
|
265
|
|
266
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267
|
|
268
|
public ObjectControl getControl()
|
269
|
{
|
270
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
271
|
return view.getObjectControl();
|
272
|
}
|
273
|
}
|