Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 2afc6754

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
      unlock();
88
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
89

    
90
      DisplayMetrics displaymetrics = new DisplayMetrics();
91
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
92
      mScreenWidth =displaymetrics.widthPixels;
93
      mScreenHeight=displaymetrics.heightPixels;
94

    
95
      hideNavigationBar();
96
      cutoutHack();
97
      }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
    private void hideNavigationBar()
102
      {
103
      mCurrentApiVersion = Build.VERSION.SDK_INT;
104

    
105
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
106
        {
107
        final View decorView = getWindow().getDecorView();
108

    
109
        decorView.setSystemUiVisibility(FLAGS);
110

    
111
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
112
          {
113
          @Override
114
          public void onSystemUiVisibilityChange(int visibility)
115
            {
116
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
117
              {
118
              decorView.setSystemUiVisibility(FLAGS);
119
              }
120
            }
121
          });
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
    @Override
128
    public void onAttachedToWindow()
129
      {
130
      super.onAttachedToWindow();
131

    
132
      final float RATIO = 0.15f;
133
      float width = getScreenWidthInPixels();
134

    
135
      TutorialSurfaceView viewL = findViewById(R.id.tutorialSurfaceView);
136
      ViewGroup.LayoutParams paramsL = viewL.getLayoutParams();
137
      paramsL.width = (int)(width*(1.0f-RATIO));
138
      viewL.setLayoutParams(paramsL);
139

    
140
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
141
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
142
      paramsR.width = (int)(width*RATIO);
143
      viewR.setLayoutParams(paramsR);
144

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

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

    
150
      mState.createRightPane(this,width);
151

    
152
      WebView videoView = findViewById(R.id.tutorialVideoView);
153
      mWebView = new TutorialWebView(videoView);
154
      mWebView.load(URL+mURL);
155
      }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
// do not avoid cutouts
159

    
160
    private void cutoutHack()
161
      {
162
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
163
        {
164
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
165
        }
166
      }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
    @Override
171
    public void onWindowFocusChanged(boolean hasFocus)
172
      {
173
      super.onWindowFocusChanged(hasFocus);
174

    
175
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
176
        {
177
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
178
        }
179
      }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
    
183
    @Override
184
    protected void onPause() 
185
      {
186
      super.onPause();
187
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
188
      view.onPause();
189

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

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

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

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

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

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

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

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

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

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
// PUBLIC API
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

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

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

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

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

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

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

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

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

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

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

    
282
    public boolean isLocked()
283
    {
284
    return retLocked();
285
    }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
    public static int getDrawableSize()
290
      {
291
      if( mScreenHeight<1000 )
292
        {
293
        return 0;
294
        }
295
      if( mScreenHeight<1600 )
296
        {
297
        return 1;
298
        }
299
      if( mScreenHeight<1900 )
300
        {
301
        return 2;
302
        }
303

    
304
      return 3;
305
      }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
    public static int getDrawable(int small, int medium, int big, int huge)
310
      {
311
      int size = getDrawableSize();
312

    
313
      switch(size)
314
        {
315
        case 0 : return small;
316
        case 1 : return medium;
317
        case 2 : return big;
318
        default: return huge;
319
        }
320
      }
321

    
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

    
324
    public boolean isVertical()
325
      {
326
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
327
      return view.isVertical();
328
      }
329
}
(1-1/7)