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