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.Bundle;
|
15
|
import android.view.ViewGroup;
|
16
|
import android.webkit.WebView;
|
17
|
import android.widget.LinearLayout;
|
18
|
|
19
|
import org.distorted.dialogs.RubikDialogTutorial;
|
20
|
import org.distorted.helpers.BaseActivity;
|
21
|
import org.distorted.library.main.DistortedLibrary;
|
22
|
|
23
|
import org.distorted.objectlib.main.InitAssets;
|
24
|
import org.distorted.objectlib.main.ObjectControl;
|
25
|
import org.distorted.objectlib.main.TwistyObject;
|
26
|
|
27
|
import org.distorted.main.R;
|
28
|
import org.distorted.dialogs.RubikDialogError;
|
29
|
import org.distorted.objects.RubikObject;
|
30
|
import org.distorted.objects.RubikObjectList;
|
31
|
import org.distorted.os.OSInterface;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class TutorialActivity extends BaseActivity
|
36
|
{
|
37
|
private static final String URL = "https://www.youtube.com/embed/";
|
38
|
private static final int ACTIVITY_NUMBER = 0;
|
39
|
public static final float BAR_RATIO = 0.17f;
|
40
|
|
41
|
private TutorialScreen mScreen;
|
42
|
private int mObjectOrdinal;
|
43
|
private TutorialWebView mWebView;
|
44
|
private boolean mIsFree;
|
45
|
private boolean mErrorLoadingWebView;
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
@Override
|
50
|
protected void onCreate(Bundle savedState)
|
51
|
{
|
52
|
super.onCreate(savedState);
|
53
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
54
|
|
55
|
try
|
56
|
{
|
57
|
setContentView(R.layout.tutorial);
|
58
|
mErrorLoadingWebView = false;
|
59
|
}
|
60
|
catch(Exception e)
|
61
|
{
|
62
|
setContentView(R.layout.tutorial_no_webview);
|
63
|
mErrorLoadingWebView = true;
|
64
|
}
|
65
|
|
66
|
mIsFree = true;
|
67
|
|
68
|
Bundle b = getIntent().getExtras();
|
69
|
|
70
|
if(b != null)
|
71
|
{
|
72
|
mObjectOrdinal = b.getInt("obj");
|
73
|
RubikObject obj= RubikObjectList.getObject(mObjectOrdinal);
|
74
|
mIsFree = (obj!=null && obj.isFree());
|
75
|
}
|
76
|
|
77
|
computeScreenDimensions();
|
78
|
hideNavigationBar();
|
79
|
cutoutHack();
|
80
|
showDialog();
|
81
|
}
|
82
|
|
83
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84
|
|
85
|
public void showDialog()
|
86
|
{
|
87
|
if( !mErrorLoadingWebView )
|
88
|
{
|
89
|
Bundle bundle = new Bundle();
|
90
|
bundle.putString("argument", String.valueOf(mObjectOrdinal));
|
91
|
RubikDialogTutorial diag = new RubikDialogTutorial();
|
92
|
diag.setArguments(bundle);
|
93
|
diag.show(getSupportFragmentManager(), RubikDialogTutorial.getDialogTag());
|
94
|
}
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
|
99
|
public void loadTutorial(String url)
|
100
|
{
|
101
|
if( !mErrorLoadingWebView )
|
102
|
{
|
103
|
if(mWebView==null)
|
104
|
{
|
105
|
WebView videoView = findViewById(R.id.tutorialVideoView);
|
106
|
mWebView = new TutorialWebView(videoView);
|
107
|
}
|
108
|
|
109
|
mWebView.load(URL+url);
|
110
|
}
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
@Override
|
116
|
protected void onPause()
|
117
|
{
|
118
|
super.onPause();
|
119
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
120
|
view.onPause();
|
121
|
|
122
|
if( mWebView!=null ) mWebView.onPause();
|
123
|
|
124
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
@Override
|
130
|
protected void onResume()
|
131
|
{
|
132
|
super.onResume();
|
133
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
134
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
135
|
view.onResume();
|
136
|
|
137
|
float width = getScreenWidthInPixels();
|
138
|
|
139
|
LinearLayout viewR = findViewById(R.id.tutorialRightBar);
|
140
|
ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
|
141
|
paramsR.width = (int)(width*BAR_RATIO);
|
142
|
viewR.setLayoutParams(paramsR);
|
143
|
|
144
|
if( mScreen==null ) mScreen = new TutorialScreen(mIsFree);
|
145
|
|
146
|
mScreen.createRightPane(this);
|
147
|
|
148
|
if( mWebView!=null ) mWebView.onResume();
|
149
|
|
150
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
151
|
{
|
152
|
changeIfDifferent(mObjectOrdinal,view.getObjectControl());
|
153
|
}
|
154
|
}
|
155
|
|
156
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157
|
|
158
|
@Override
|
159
|
protected void onDestroy()
|
160
|
{
|
161
|
super.onDestroy();
|
162
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
void OpenGLError()
|
168
|
{
|
169
|
RubikDialogError errDiag = new RubikDialogError();
|
170
|
errDiag.show(getSupportFragmentManager(), null);
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
private void changeIfDifferent(int ordinal,ObjectControl control)
|
176
|
{
|
177
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
178
|
int iconMode = TwistyObject.MODE_NORM;
|
179
|
InputStream jsonStream = object==null ? null : object.getObjectStream(this);
|
180
|
InputStream meshStream = object==null ? null : object.getMeshStream(this);
|
181
|
String name = object==null ? "NULL" : object.getUpperName();
|
182
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
183
|
OSInterface os = view.getInterface();
|
184
|
InitAssets asset = new InitAssets(jsonStream,meshStream,os);
|
185
|
control.changeIfDifferent(ordinal,name,iconMode,asset);
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
TutorialScreen getState()
|
191
|
{
|
192
|
return mScreen;
|
193
|
}
|
194
|
|
195
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196
|
// PUBLIC API
|
197
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198
|
|
199
|
public boolean getIsFree()
|
200
|
{
|
201
|
return mIsFree;
|
202
|
}
|
203
|
|
204
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
205
|
|
206
|
public ObjectControl getControl()
|
207
|
{
|
208
|
TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
|
209
|
return view.getObjectControl();
|
210
|
}
|
211
|
}
|