Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 62ec404d

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
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 com.google.firebase.analytics.FirebaseAnalytics;
32
33
import org.distorted.dialogs.RubikDialogError;
34 55e6be1d Leszek Koltunski
import org.distorted.helpers.TwistyActivity;
35
import org.distorted.helpers.TwistyPreRender;
36 b6468abb Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
37 af88bf2e Leszek Koltunski
import org.distorted.main.R;
38
import org.distorted.objects.ObjectList;
39
import org.distorted.objects.TwistyObject;
40
41 2e0258fe Leszek Koltunski
import static org.distorted.main.RubikRenderer.BRIGHTNESS;
42
43 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45 55e6be1d Leszek Koltunski
public class TutorialActivity extends TwistyActivity
46 af88bf2e Leszek Koltunski
{
47 2971588c Leszek Koltunski
    private static final String URL = "https://www.youtube.com/embed/";
48
49 af88bf2e Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
50
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
51
52
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
53
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
54
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
55
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
56
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
57
58
    private FirebaseAnalytics mFirebaseAnalytics;
59
    private static int mScreenWidth, mScreenHeight;
60
    private int mCurrentApiVersion;
61 344f290c Leszek Koltunski
    private TutorialState mState;
62 2971588c Leszek Koltunski
    private String mURL;
63 79bf5d8b Leszek Koltunski
    private int mObjectOrdinal, mObjectSize;
64 5b4eaf7e Leszek Koltunski
    private TutorialWebView mWebView;
65 af88bf2e Leszek Koltunski
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
68
    @Override
69
    protected void onCreate(Bundle savedState)
70
      {
71
      super.onCreate(savedState);
72 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(1);
73 af88bf2e Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
74
      setContentView(R.layout.tutorial);
75
76 2971588c Leszek Koltunski
      Bundle b = getIntent().getExtras();
77
78 79bf5d8b Leszek Koltunski
      if(b != null)
79
        {
80
        mURL           = b.getString("url");
81
        mObjectOrdinal = b.getInt("obj");
82
        mObjectSize    = b.getInt("siz");
83
        }
84 2971588c Leszek Koltunski
85 55e6be1d Leszek Koltunski
      unlock();
86 af88bf2e Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
87
88
      DisplayMetrics displaymetrics = new DisplayMetrics();
89
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
90
      mScreenWidth =displaymetrics.widthPixels;
91
      mScreenHeight=displaymetrics.heightPixels;
92
93
      hideNavigationBar();
94
      cutoutHack();
95
      }
96
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
    private void hideNavigationBar()
100
      {
101
      mCurrentApiVersion = Build.VERSION.SDK_INT;
102
103
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
104
        {
105
        final View decorView = getWindow().getDecorView();
106
107
        decorView.setSystemUiVisibility(FLAGS);
108
109
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
110
          {
111
          @Override
112
          public void onSystemUiVisibilityChange(int visibility)
113
            {
114
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
115
              {
116
              decorView.setSystemUiVisibility(FLAGS);
117
              }
118
            }
119
          });
120
        }
121
      }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
    @Override
126
    public void onAttachedToWindow()
127
      {
128
      super.onAttachedToWindow();
129
130 344f290c Leszek Koltunski
      final float RATIO = 0.15f;
131 af88bf2e Leszek Koltunski
      float width = getScreenWidthInPixels();
132 344f290c Leszek Koltunski
133
      TutorialSurfaceView viewL = findViewById(R.id.tutorialSurfaceView);
134
      ViewGroup.LayoutParams paramsL = viewL.getLayoutParams();
135
      paramsL.width = (int)(width*(1.0f-RATIO));
136
      viewL.setLayoutParams(paramsL);
137
138 2971588c Leszek Koltunski
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
139 344f290c Leszek Koltunski
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
140
      paramsR.width = (int)(width*RATIO);
141
      viewR.setLayoutParams(paramsR);
142
143 2e0258fe Leszek Koltunski
      final int color = (int)(BRIGHTNESS*255);
144
      viewR.setBackgroundColor( (0xFF<<24)+(color<<16)+(color<<8)+color);
145
146 344f290c Leszek Koltunski
      if( mState==null ) mState = new TutorialState();
147
148
      mState.createRightPane(this,width);
149 2971588c Leszek Koltunski
150
      WebView videoView = findViewById(R.id.tutorialVideoView);
151 55e6be1d Leszek Koltunski
      mWebView = new TutorialWebView(videoView);
152 5b4eaf7e Leszek Koltunski
      mWebView.load(URL+mURL);
153 af88bf2e Leszek Koltunski
      }
154
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156
// do not avoid cutouts
157
158
    private void cutoutHack()
159
      {
160
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
161
        {
162
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
163
        }
164
      }
165
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168
    @Override
169
    public void onWindowFocusChanged(boolean hasFocus)
170
      {
171
      super.onWindowFocusChanged(hasFocus);
172
173
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
174
        {
175
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
176
        }
177
      }
178
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
    
181
    @Override
182
    protected void onPause() 
183
      {
184
      super.onPause();
185
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
186
      view.onPause();
187 0de39b8e Leszek Koltunski
188
      if( mWebView!=null ) mWebView.onPause();
189
190 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(1);
191 af88bf2e Leszek Koltunski
      }
192
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
    
195
    @Override
196
    protected void onResume() 
197
      {
198
      super.onResume();
199 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(1);
200 af88bf2e Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
201
      view.onResume();
202
      view.initialize();
203
204 0de39b8e Leszek Koltunski
      if( mWebView!=null ) mWebView.onResume();
205
206 79bf5d8b Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectList.NUM_OBJECTS )
207 af88bf2e Leszek Koltunski
        {
208 79bf5d8b Leszek Koltunski
        ObjectList obj = ObjectList.getObject(mObjectOrdinal);
209 af88bf2e Leszek Koltunski
        int[] sizes = obj.getSizes();
210 79bf5d8b Leszek Koltunski
        int sizeIndex = ObjectList.getSizeIndex(mObjectOrdinal,mObjectSize);
211 af88bf2e Leszek Koltunski
212
        if( sizeIndex>=0 && sizeIndex<sizes.length )
213
          {
214 79bf5d8b Leszek Koltunski
          view.getPreRender().changeObject(obj,mObjectSize);
215 af88bf2e Leszek Koltunski
          }
216
        }
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
    TutorialState getState()
239
      {
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
      TutorialPreRender pre = view.getPreRender();
258
      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
    public TutorialPreRender getPreRender()
278
      {
279
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
280
      return view.getPreRender();
281
      }
282
283 55e6be1d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
284
285
    public TwistyPreRender getTwistyPreRender()
286
      {
287
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
288
      return view.getPreRender();
289
      }
290
291 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
292
293
    public static int getDrawableSize()
294
      {
295
      if( mScreenHeight<1000 )
296
        {
297
        return 0;
298
        }
299
      if( mScreenHeight<1600 )
300
        {
301
        return 1;
302
        }
303
      if( mScreenHeight<1900 )
304
        {
305
        return 2;
306
        }
307
308
      return 3;
309
      }
310
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
313
    public static int getDrawable(int small, int medium, int big, int huge)
314
      {
315
      int size = getDrawableSize();
316
317
      switch(size)
318
        {
319
        case 0 : return small;
320
        case 1 : return medium;
321
        case 2 : return big;
322
        default: return huge;
323
        }
324
      }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328
    public boolean isVertical()
329
      {
330
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
331
      return view.isVertical();
332
      }
333
}