Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 99cedf39

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 b20e89d2 Leszek Koltunski
import java.io.InputStream;
23
24 af88bf2e Leszek Koltunski
import android.os.Build;
25
import android.os.Bundle;
26
import android.util.DisplayMetrics;
27
import android.view.View;
28
import android.view.ViewGroup;
29
import android.view.WindowManager;
30
import android.webkit.WebView;
31
import android.widget.LinearLayout;
32
33 e019c70b Leszek Koltunski
import androidx.appcompat.app.AppCompatActivity;
34
35 af88bf2e Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
36
37 b20e89d2 Leszek Koltunski
import org.distorted.dmesh.ObjectMesh;
38
import org.distorted.jsons.ObjectJson;
39 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
40 2afc6754 Leszek Koltunski
41
import org.distorted.objectlib.main.ObjectControl;
42 318c0a7d Leszek Koltunski
import org.distorted.objectlib.main.ObjectType;
43 eaf46415 Leszek Koltunski
44 af88bf2e Leszek Koltunski
import org.distorted.main.R;
45 eaf46415 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
46 af88bf2e Leszek Koltunski
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49 e019c70b Leszek Koltunski
public class TutorialActivity extends AppCompatActivity
50 af88bf2e Leszek Koltunski
{
51 2971588c Leszek Koltunski
    private static final String URL = "https://www.youtube.com/embed/";
52
53 eb49fa90 Leszek Koltunski
    public static final float BAR_RATIO = 0.15f;
54 af88bf2e Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
55
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
56
57
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
58
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
60
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
61
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
62
63
    private FirebaseAnalytics mFirebaseAnalytics;
64
    private static int mScreenWidth, mScreenHeight;
65
    private int mCurrentApiVersion;
66 dd1a65c1 Leszek Koltunski
    private TutorialScreen mState;
67 2971588c Leszek Koltunski
    private String mURL;
68 7ac0ee88 Leszek Koltunski
    private int mObjectOrdinal;
69 5b4eaf7e Leszek Koltunski
    private TutorialWebView mWebView;
70 af88bf2e Leszek Koltunski
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
73
    @Override
74
    protected void onCreate(Bundle savedState)
75
      {
76
      super.onCreate(savedState);
77 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(1);
78 af88bf2e Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
79
      setContentView(R.layout.tutorial);
80
81 2971588c Leszek Koltunski
      Bundle b = getIntent().getExtras();
82
83 79bf5d8b Leszek Koltunski
      if(b != null)
84
        {
85
        mURL           = b.getString("url");
86
        mObjectOrdinal = b.getInt("obj");
87
        }
88 2971588c Leszek Koltunski
89 af88bf2e Leszek Koltunski
      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
      float width = getScreenWidthInPixels();
134 344f290c Leszek Koltunski
135 2971588c Leszek Koltunski
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
136 344f290c Leszek Koltunski
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
137 eb49fa90 Leszek Koltunski
      paramsR.width = (int)(width*BAR_RATIO);
138 344f290c Leszek Koltunski
      viewR.setLayoutParams(paramsR);
139
140 dd1a65c1 Leszek Koltunski
      if( mState==null ) mState = new TutorialScreen();
141 344f290c Leszek Koltunski
142
      mState.createRightPane(this,width);
143 2971588c Leszek Koltunski
144
      WebView videoView = findViewById(R.id.tutorialVideoView);
145 55e6be1d Leszek Koltunski
      mWebView = new TutorialWebView(videoView);
146 5b4eaf7e Leszek Koltunski
      mWebView.load(URL+mURL);
147 af88bf2e Leszek Koltunski
      }
148
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
// do not avoid cutouts
151
152
    private void cutoutHack()
153
      {
154
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
155
        {
156
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
157
        }
158
      }
159
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
    @Override
163
    public void onWindowFocusChanged(boolean hasFocus)
164
      {
165
      super.onWindowFocusChanged(hasFocus);
166
167
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
168
        {
169
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
170
        }
171
      }
172
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
    
175
    @Override
176
    protected void onPause() 
177
      {
178
      super.onPause();
179
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
180
      view.onPause();
181 0de39b8e Leszek Koltunski
182
      if( mWebView!=null ) mWebView.onPause();
183
184 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(1);
185 af88bf2e Leszek Koltunski
      }
186
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
    
189
    @Override
190
    protected void onResume() 
191
      {
192
      super.onResume();
193 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(1);
194 af88bf2e Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
195
      view.onResume();
196
197 0de39b8e Leszek Koltunski
      if( mWebView!=null ) mWebView.onResume();
198
199 318c0a7d Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
200 af88bf2e Leszek Koltunski
        {
201 318c0a7d Leszek Koltunski
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
202 b20e89d2 Leszek Koltunski
        changeIfDifferent(obj,view.getObjectControl());
203 af88bf2e Leszek Koltunski
        }
204
      }
205 b20e89d2 Leszek Koltunski
206 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
207
    
208
    @Override
209
    protected void onDestroy() 
210
      {
211
      super.onDestroy();
212 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(1);
213 af88bf2e Leszek Koltunski
      }
214
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217
    void OpenGLError()
218
      {
219
      RubikDialogError errDiag = new RubikDialogError();
220
      errDiag.show(getSupportFragmentManager(), null);
221
      }
222
223 b20e89d2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
224
225
    private void changeIfDifferent(ObjectType type,ObjectControl control)
226
      {
227
      InputStream jsonStream = ObjectJson.getStream(type,this);
228
      InputStream meshStream = ObjectMesh.getStream(type,this);
229
      control.changeIfDifferent(type.ordinal(),jsonStream,meshStream);
230
      }
231
232 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
233
234 dd1a65c1 Leszek Koltunski
    TutorialScreen getState()
235 344f290c Leszek Koltunski
      {
236
      return mState;
237
      }
238
239 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
265 55e6be1d Leszek Koltunski
      {
266
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
267 2afc6754 Leszek Koltunski
      return view.getObjectControl();
268 55e6be1d Leszek Koltunski
      }
269
270 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
271
272
    public static int getDrawableSize()
273
      {
274
      if( mScreenHeight<1000 )
275
        {
276
        return 0;
277
        }
278
      if( mScreenHeight<1600 )
279
        {
280
        return 1;
281
        }
282
      if( mScreenHeight<1900 )
283
        {
284
        return 2;
285
        }
286
287
      return 3;
288
      }
289
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291
292
    public static int getDrawable(int small, int medium, int big, int huge)
293
      {
294
      int size = getDrawableSize();
295
296
      switch(size)
297
        {
298
        case 0 : return small;
299
        case 1 : return medium;
300
        case 2 : return big;
301
        default: return huge;
302
        }
303
      }
304
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306
307
    public boolean isVertical()
308
      {
309
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
310
      return view.isVertical();
311
      }
312
}