Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 7fe59aa5

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