Project

General

Profile

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

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

1 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 bb62ca3f Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
11 af88bf2e Leszek Koltunski
12 b20e89d2 Leszek Koltunski
import java.io.InputStream;
13
14 af88bf2e Leszek Koltunski
import android.os.Build;
15
import android.os.Bundle;
16
import android.util.DisplayMetrics;
17
import android.view.View;
18
import android.view.ViewGroup;
19
import android.view.WindowManager;
20
import android.webkit.WebView;
21
import android.widget.LinearLayout;
22
23 e019c70b Leszek Koltunski
import androidx.appcompat.app.AppCompatActivity;
24
25 af88bf2e Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
26
27 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
28 2afc6754 Leszek Koltunski
29
import org.distorted.objectlib.main.ObjectControl;
30 7cb8d4b0 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
31 eaf46415 Leszek Koltunski
32 af88bf2e Leszek Koltunski
import org.distorted.main.R;
33 eaf46415 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
34 09cf2a36 Leszek Koltunski
import org.distorted.objects.RubikObject;
35 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObjectList;
36 af88bf2e Leszek Koltunski
37 09cf2a36 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
38
39 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41 e019c70b Leszek Koltunski
public class TutorialActivity extends AppCompatActivity
42 af88bf2e Leszek Koltunski
{
43 2971588c Leszek Koltunski
    private static final String URL = "https://www.youtube.com/embed/";
44
45 1237d25d Leszek Koltunski
    private static final int ACTIVITY_NUMBER = 1;
46 943471aa Leszek Koltunski
    public static final float BAR_RATIO = 0.17f;
47 af88bf2e Leszek Koltunski
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
48
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
49
50
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
51
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
52
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
53
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
54
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
55
56
    private FirebaseAnalytics mFirebaseAnalytics;
57
    private static int mScreenWidth, mScreenHeight;
58
    private int mCurrentApiVersion;
59 1237d25d Leszek Koltunski
    private TutorialScreen mScreen;
60 2971588c Leszek Koltunski
    private String mURL;
61 7ac0ee88 Leszek Koltunski
    private int mObjectOrdinal;
62 5b4eaf7e Leszek Koltunski
    private TutorialWebView mWebView;
63 af88bf2e Leszek Koltunski
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
66
    @Override
67
    protected void onCreate(Bundle savedState)
68
      {
69
      super.onCreate(savedState);
70 1237d25d Leszek Koltunski
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
71 dd874ae8 Leszek Koltunski
      setTheme(R.style.MaterialThemeNoActionBar);
72 af88bf2e Leszek Koltunski
      setContentView(R.layout.tutorial);
73
74 2971588c Leszek Koltunski
      Bundle b = getIntent().getExtras();
75
76 79bf5d8b Leszek Koltunski
      if(b != null)
77
        {
78
        mURL           = b.getString("url");
79
        mObjectOrdinal = b.getInt("obj");
80
        }
81 2971588c Leszek Koltunski
82 af88bf2e Leszek Koltunski
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
83
84
      DisplayMetrics displaymetrics = new DisplayMetrics();
85 7fe59aa5 Leszek Koltunski
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
86 af88bf2e Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
87
      mScreenHeight=displaymetrics.heightPixels;
88
89
      hideNavigationBar();
90
      cutoutHack();
91
      }
92
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
95
    private void hideNavigationBar()
96
      {
97
      mCurrentApiVersion = Build.VERSION.SDK_INT;
98
99
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
100
        {
101
        final View decorView = getWindow().getDecorView();
102
103
        decorView.setSystemUiVisibility(FLAGS);
104
105
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
106
          {
107
          @Override
108
          public void onSystemUiVisibilityChange(int visibility)
109
            {
110
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
111
              {
112
              decorView.setSystemUiVisibility(FLAGS);
113
              }
114
            }
115
          });
116
        }
117
      }
118
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121
    @Override
122
    public void onAttachedToWindow()
123
      {
124
      super.onAttachedToWindow();
125
126 280dc794 Leszek Koltunski
      if( mWebView==null )
127
        {
128
        WebView videoView = findViewById(R.id.tutorialVideoView);
129
        mWebView = new TutorialWebView(videoView);
130
        mWebView.load(URL+mURL);
131
        }
132 af88bf2e Leszek Koltunski
      }
133
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
// do not avoid cutouts
136
137
    private void cutoutHack()
138
      {
139
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
140
        {
141
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
142
        }
143
      }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
    @Override
148
    public void onWindowFocusChanged(boolean hasFocus)
149
      {
150
      super.onWindowFocusChanged(hasFocus);
151
152
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
153
        {
154
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
155
        }
156
      }
157
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
    
160
    @Override
161
    protected void onPause() 
162
      {
163
      super.onPause();
164
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
165
      view.onPause();
166 0de39b8e Leszek Koltunski
167
      if( mWebView!=null ) mWebView.onPause();
168
169 1237d25d Leszek Koltunski
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
170 af88bf2e Leszek Koltunski
      }
171
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
    
174
    @Override
175
    protected void onResume() 
176
      {
177
      super.onResume();
178 1237d25d Leszek Koltunski
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
179 af88bf2e Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
180
      view.onResume();
181
182 280dc794 Leszek Koltunski
      float width = getScreenWidthInPixels();
183
184
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
185
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
186
      paramsR.width = (int)(width*BAR_RATIO);
187
      viewR.setLayoutParams(paramsR);
188
189
      if( mScreen==null ) mScreen = new TutorialScreen();
190
191
      mScreen.createRightPane(this);
192
193 0de39b8e Leszek Koltunski
      if( mWebView!=null ) mWebView.onResume();
194
195 d433b50e Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
196 af88bf2e Leszek Koltunski
        {
197 d433b50e Leszek Koltunski
        changeIfDifferent(mObjectOrdinal,view.getObjectControl());
198 af88bf2e Leszek Koltunski
        }
199
      }
200 b20e89d2 Leszek Koltunski
201 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
202
    
203
    @Override
204
    protected void onDestroy() 
205
      {
206
      super.onDestroy();
207 1237d25d Leszek Koltunski
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
208 af88bf2e Leszek Koltunski
      }
209
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
212
    void OpenGLError()
213
      {
214
      RubikDialogError errDiag = new RubikDialogError();
215
      errDiag.show(getSupportFragmentManager(), null);
216
      }
217
218 b20e89d2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220 09cf2a36 Leszek Koltunski
    private void changeIfDifferent(int ordinal,ObjectControl control)
221 b20e89d2 Leszek Koltunski
      {
222 09cf2a36 Leszek Koltunski
      RubikObject object = RubikObjectList.getObject(ordinal);
223
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
224 7cb8d4b0 Leszek Koltunski
      int iconMode  = TwistyObject.MODE_NORM;
225 314e9ff0 Leszek Koltunski
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
226
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
227 aec421fd Leszek Koltunski
      String name = object==null ? "NULL" : object.getUpperName();
228 09cf2a36 Leszek Koltunski
229 7cb8d4b0 Leszek Koltunski
      control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
230 b20e89d2 Leszek Koltunski
      }
231
232 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
233
234 dd1a65c1 Leszek Koltunski
    TutorialScreen getState()
235 344f290c Leszek Koltunski
      {
236 1237d25d Leszek Koltunski
      return mScreen;
237 344f290c Leszek Koltunski
      }
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
}