Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 2cf21fdc

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