Project

General

Profile

Download (11.6 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ eaf46415

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