Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 1bafcba4

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

    
35
import org.distorted.library.main.DistortedScreen;
36
import org.distorted.objectlib.main.ObjectPreRender;
37
import org.distorted.objectlib.main.ObjectType;
38
import org.distorted.objectlib.main.TwistyObject;
39
import org.distorted.objectlib.helpers.BlockController;
40
import org.distorted.objectlib.helpers.TwistyActivity;
41

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

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

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

    
53
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
54
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
55

    
56
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
57
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
58
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
59
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
60
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
61

    
62
    private FirebaseAnalytics mFirebaseAnalytics;
63
    private static int mScreenWidth, mScreenHeight;
64
    private int mCurrentApiVersion;
65
    private TutorialScreen mState;
66
    private String mURL;
67
    private int mObjectOrdinal;
68
    private TutorialWebView mWebView;
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

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

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

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

    
88
      unlock();
89
      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
      final float RATIO = 0.15f;
134
      float width = getScreenWidthInPixels();
135

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

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

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

    
151
      mState.createRightPane(this,width);
152

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

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

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

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

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

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

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

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

    
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

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

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242
// PUBLIC API
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

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

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
    public TwistyObject getObject()
253
      {
254
      TutorialSurfaceView view = findViewById(R.id.rubikSurfaceView);
255
      ObjectPreRender pre = view.getPreRender();
256
      return pre.getObject();
257
      }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
    public int getScreenWidthInPixels()
262
      {
263
      return mScreenWidth;
264
      }
265

    
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

    
268
    public int getScreenHeightInPixels()
269
      {
270
      return mScreenHeight;
271
      }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
    public ObjectPreRender getPreRender()
276
      {
277
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
278
      return view.getPreRender();
279
      }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
    public DistortedScreen getScreen()
284
      {
285
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
286
      TutorialRenderer renderer = view.getRenderer();
287
      return renderer.getScreen();
288
      }
289

    
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291

    
292
    public boolean isLocked()
293
    {
294
    return retLocked();
295
    }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

    
299
    public static int getDrawableSize()
300
      {
301
      if( mScreenHeight<1000 )
302
        {
303
        return 0;
304
        }
305
      if( mScreenHeight<1600 )
306
        {
307
        return 1;
308
        }
309
      if( mScreenHeight<1900 )
310
        {
311
        return 2;
312
        }
313

    
314
      return 3;
315
      }
316

    
317
///////////////////////////////////////////////////////////////////////////////////////////////////
318

    
319
    public static int getDrawable(int small, int medium, int big, int huge)
320
      {
321
      int size = getDrawableSize();
322

    
323
      switch(size)
324
        {
325
        case 0 : return small;
326
        case 1 : return medium;
327
        case 2 : return big;
328
        default: return huge;
329
        }
330
      }
331

    
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

    
334
    public boolean isVertical()
335
      {
336
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
337
      return view.isVertical();
338
      }
339
}
(1-1/7)