Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 3f7a4363

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