Project

General

Profile

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

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

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 2e0258fe Leszek Koltunski
import static org.distorted.main.RubikRenderer.BRIGHTNESS;
45
46 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48 e019c70b Leszek Koltunski
public class TutorialActivity extends AppCompatActivity
49 af88bf2e Leszek Koltunski
{
50 2971588c Leszek Koltunski
    private static final String URL = "https://www.youtube.com/embed/";
51
52 af88bf2e Leszek Koltunski
    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 dd1a65c1 Leszek Koltunski
    private TutorialScreen mState;
65 2971588c Leszek Koltunski
    private String mURL;
66 7ac0ee88 Leszek Koltunski
    private int mObjectOrdinal;
67 5b4eaf7e Leszek Koltunski
    private TutorialWebView mWebView;
68 af88bf2e Leszek Koltunski
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71
    @Override
72
    protected void onCreate(Bundle savedState)
73
      {
74
      super.onCreate(savedState);
75 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(1);
76 af88bf2e Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
77
      setContentView(R.layout.tutorial);
78
79 2971588c Leszek Koltunski
      Bundle b = getIntent().getExtras();
80
81 79bf5d8b Leszek Koltunski
      if(b != null)
82
        {
83
        mURL           = b.getString("url");
84
        mObjectOrdinal = b.getInt("obj");
85
        }
86 2971588c Leszek Koltunski
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 dd1a65c1 Leszek Koltunski
      if( mState==null ) mState = new TutorialScreen();
148 344f290c Leszek Koltunski
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 af88bf2e Leszek Koltunski
      }
193
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
    
196
    @Override
197
    protected void onResume() 
198
      {
199
      super.onResume();
200 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(1);
201 af88bf2e Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
202
      view.onResume();
203
204 0de39b8e Leszek Koltunski
      if( mWebView!=null ) mWebView.onResume();
205
206 318c0a7d Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
207 af88bf2e Leszek Koltunski
        {
208 318c0a7d Leszek Koltunski
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
209 2afc6754 Leszek Koltunski
        view.getObjectControl().changeObject(obj);
210 af88bf2e Leszek Koltunski
        }
211
      }
212
    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
    
215
    @Override
216
    protected void onDestroy() 
217
      {
218
      super.onDestroy();
219 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(1);
220 af88bf2e Leszek Koltunski
      }
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224
    void OpenGLError()
225
      {
226
      RubikDialogError errDiag = new RubikDialogError();
227
      errDiag.show(getSupportFragmentManager(), null);
228
      }
229
230 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
231
232 dd1a65c1 Leszek Koltunski
    TutorialScreen getState()
233 344f290c Leszek Koltunski
      {
234
      return mState;
235
      }
236
237 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
238
// PUBLIC API
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240
241
    public FirebaseAnalytics getAnalytics()
242
      {
243
      return mFirebaseAnalytics;
244
      }
245
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247
248
    public int getScreenWidthInPixels()
249
      {
250
      return mScreenWidth;
251
      }
252
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255
    public int getScreenHeightInPixels()
256
      {
257
      return mScreenHeight;
258
      }
259
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261
262 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
263 55e6be1d Leszek Koltunski
      {
264
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
265 2afc6754 Leszek Koltunski
      return view.getObjectControl();
266 55e6be1d Leszek Koltunski
      }
267
268 05c20dad Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
269
270
    public DistortedScreen getScreen()
271
      {
272
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
273
      TutorialRenderer renderer = view.getRenderer();
274
      return renderer.getScreen();
275
      }
276
277 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
278
279
    public static int getDrawableSize()
280
      {
281
      if( mScreenHeight<1000 )
282
        {
283
        return 0;
284
        }
285
      if( mScreenHeight<1600 )
286
        {
287
        return 1;
288
        }
289
      if( mScreenHeight<1900 )
290
        {
291
        return 2;
292
        }
293
294
      return 3;
295
      }
296
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
299
    public static int getDrawable(int small, int medium, int big, int huge)
300
      {
301
      int size = getDrawableSize();
302
303
      switch(size)
304
        {
305
        case 0 : return small;
306
        case 1 : return medium;
307
        case 2 : return big;
308
        default: return huge;
309
        }
310
      }
311
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313
314
    public boolean isVertical()
315
      {
316
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
317
      return view.isVertical();
318
      }
319
}