Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 9523ae28

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.tutorials;
21

    
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.library.main.DistortedLibrary;
34
import org.distorted.library.main.DistortedScreen;
35

    
36
import org.distorted.objectlib.main.ObjectControl;
37
import org.distorted.objectlib.main.ObjectType;
38
import org.distorted.objectlib.helpers.BlockController;
39
import org.distorted.objectlib.helpers.TwistyActivity;
40

    
41
import org.distorted.main.R;
42
import org.distorted.dialogs.RubikDialogError;
43

    
44
import static org.distorted.main.RubikRenderer.BRIGHTNESS;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
public class TutorialActivity extends TwistyActivity
49
{
50
    private static final String URL = "https://www.youtube.com/embed/";
51

    
52
    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
    private TutorialScreen mState;
65
    private String mURL;
66
    private int mObjectOrdinal;
67
    private TutorialWebView mWebView;
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
    @Override
72
    protected void onCreate(Bundle savedState)
73
      {
74
      super.onCreate(savedState);
75
      DistortedLibrary.onCreate(1);
76
      setTheme(R.style.CustomActivityThemeNoActionBar);
77
      setContentView(R.layout.tutorial);
78

    
79
      Bundle b = getIntent().getExtras();
80

    
81
      if(b != null)
82
        {
83
        mURL           = b.getString("url");
84
        mObjectOrdinal = b.getInt("obj");
85
        }
86

    
87
      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
      final float RATIO = 0.15f;
132
      float width = getScreenWidthInPixels();
133

    
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
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
140
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
141
      paramsR.width = (int)(width*RATIO);
142
      viewR.setLayoutParams(paramsR);
143

    
144
      final int color = (int)(BRIGHTNESS*255);
145
      viewR.setBackgroundColor( (0xFF<<24)+(color<<16)+(color<<8)+color);
146

    
147
      if( mState==null ) mState = new TutorialScreen();
148

    
149
      mState.createRightPane(this,width);
150

    
151
      WebView videoView = findViewById(R.id.tutorialVideoView);
152
      mWebView = new TutorialWebView(videoView);
153
      mWebView.load(URL+mURL);
154
      }
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

    
189
      if( mWebView!=null ) mWebView.onPause();
190

    
191
      DistortedLibrary.onPause(1);
192
      BlockController.onPause();
193
      }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
    
197
    @Override
198
    protected void onResume() 
199
      {
200
      super.onResume();
201
      DistortedLibrary.onResume(1);
202
      BlockController.onResume();
203
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
204
      view.onResume();
205

    
206
      if( mWebView!=null ) mWebView.onResume();
207

    
208
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
209
        {
210
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
211
        view.getObjectControl().changeObject(obj);
212
        }
213
      }
214
    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
    
217
    @Override
218
    protected void onDestroy() 
219
      {
220
      super.onDestroy();
221
      DistortedLibrary.onDestroy(1);
222
      }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
    void OpenGLError()
227
      {
228
      RubikDialogError errDiag = new RubikDialogError();
229
      errDiag.show(getSupportFragmentManager(), null);
230
      }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
    TutorialScreen getState()
235
      {
236
      return mState;
237
      }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240
// PUBLIC API
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
    public FirebaseAnalytics getAnalytics()
244
      {
245
      return mFirebaseAnalytics;
246
      }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
    public int getScreenWidthInPixels()
251
      {
252
      return mScreenWidth;
253
      }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
    public int getScreenHeightInPixels()
258
      {
259
      return mScreenHeight;
260
      }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
    public ObjectControl getControl()
265
      {
266
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
267
      return view.getObjectControl();
268
      }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
    public DistortedScreen getScreen()
273
      {
274
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
275
      TutorialRenderer renderer = view.getRenderer();
276
      return renderer.getScreen();
277
      }
278

    
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

    
281
    public static int getDrawableSize()
282
      {
283
      if( mScreenHeight<1000 )
284
        {
285
        return 0;
286
        }
287
      if( mScreenHeight<1600 )
288
        {
289
        return 1;
290
        }
291
      if( mScreenHeight<1900 )
292
        {
293
        return 2;
294
        }
295

    
296
      return 3;
297
      }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
    public static int getDrawable(int small, int medium, int big, int huge)
302
      {
303
      int size = getDrawableSize();
304

    
305
      switch(size)
306
        {
307
        case 0 : return small;
308
        case 1 : return medium;
309
        case 2 : return big;
310
        default: return huge;
311
        }
312
      }
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
    public boolean isVertical()
317
      {
318
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
319
      return view.isVertical();
320
      }
321
}
(1-1/7)