Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 05a244ad

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