Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 588ace55

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