Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ eb49fa90

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