Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.tutorials;
21

    
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
import androidx.appcompat.app.AppCompatActivity;
32

    
33
import com.google.firebase.analytics.FirebaseAnalytics;
34

    
35
import org.distorted.library.main.DistortedLibrary;
36
import org.distorted.library.main.DistortedScreen;
37

    
38
import org.distorted.objectlib.main.ObjectControl;
39
import org.distorted.objectlib.main.ObjectType;
40
import org.distorted.objectlib.helpers.BlockController;
41

    
42
import org.distorted.main.R;
43
import org.distorted.dialogs.RubikDialogError;
44

    
45
import static org.distorted.main.RubikRenderer.BRIGHTNESS;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
public class TutorialActivity extends AppCompatActivity
50
{
51
    private static final String URL = "https://www.youtube.com/embed/";
52

    
53
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
54
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
55

    
56
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
57
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
58
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
59
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
60
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
61

    
62
    private FirebaseAnalytics mFirebaseAnalytics;
63
    private static int mScreenWidth, mScreenHeight;
64
    private int mCurrentApiVersion;
65
    private TutorialScreen mState;
66
    private String mURL;
67
    private int mObjectOrdinal;
68
    private TutorialWebView mWebView;
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
    @Override
73
    protected void onCreate(Bundle savedState)
74
      {
75
      super.onCreate(savedState);
76
      DistortedLibrary.onCreate(1);
77
      setTheme(R.style.CustomActivityThemeNoActionBar);
78
      setContentView(R.layout.tutorial);
79

    
80
      Bundle b = getIntent().getExtras();
81

    
82
      if(b != null)
83
        {
84
        mURL           = b.getString("url");
85
        mObjectOrdinal = b.getInt("obj");
86
        }
87

    
88
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
89

    
90
      DisplayMetrics displaymetrics = new DisplayMetrics();
91
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
92
      mScreenWidth =displaymetrics.widthPixels;
93
      mScreenHeight=displaymetrics.heightPixels;
94

    
95
      hideNavigationBar();
96
      cutoutHack();
97
      }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
    private void hideNavigationBar()
102
      {
103
      mCurrentApiVersion = Build.VERSION.SDK_INT;
104

    
105
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
106
        {
107
        final View decorView = getWindow().getDecorView();
108

    
109
        decorView.setSystemUiVisibility(FLAGS);
110

    
111
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
112
          {
113
          @Override
114
          public void onSystemUiVisibilityChange(int visibility)
115
            {
116
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
117
              {
118
              decorView.setSystemUiVisibility(FLAGS);
119
              }
120
            }
121
          });
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
    @Override
128
    public void onAttachedToWindow()
129
      {
130
      super.onAttachedToWindow();
131

    
132
      final float RATIO = 0.15f;
133
      float width = getScreenWidthInPixels();
134

    
135
      TutorialSurfaceView viewL = findViewById(R.id.tutorialSurfaceView);
136
      ViewGroup.LayoutParams paramsL = viewL.getLayoutParams();
137
      paramsL.width = (int)(width*(1.0f-RATIO));
138
      viewL.setLayoutParams(paramsL);
139

    
140
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
141
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
142
      paramsR.width = (int)(width*RATIO);
143
      viewR.setLayoutParams(paramsR);
144

    
145
      final int color = (int)(BRIGHTNESS*255);
146
      viewR.setBackgroundColor( (0xFF<<24)+(color<<16)+(color<<8)+color);
147

    
148
      if( mState==null ) mState = new TutorialScreen();
149

    
150
      mState.createRightPane(this,width);
151

    
152
      WebView videoView = findViewById(R.id.tutorialVideoView);
153
      mWebView = new TutorialWebView(videoView);
154
      mWebView.load(URL+mURL);
155
      }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
// do not avoid cutouts
159

    
160
    private void cutoutHack()
161
      {
162
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
163
        {
164
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
165
        }
166
      }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
    @Override
171
    public void onWindowFocusChanged(boolean hasFocus)
172
      {
173
      super.onWindowFocusChanged(hasFocus);
174

    
175
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
176
        {
177
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
178
        }
179
      }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
    
183
    @Override
184
    protected void onPause() 
185
      {
186
      super.onPause();
187
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
188
      view.onPause();
189

    
190
      if( mWebView!=null ) mWebView.onPause();
191

    
192
      DistortedLibrary.onPause(1);
193
      BlockController.onPause();
194
      }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197
    
198
    @Override
199
    protected void onResume() 
200
      {
201
      super.onResume();
202
      DistortedLibrary.onResume(1);
203
      BlockController.onResume();
204
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
205
      view.onResume();
206

    
207
      if( mWebView!=null ) mWebView.onResume();
208

    
209
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
210
        {
211
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
212
        view.getObjectControl().changeObject(obj);
213
        }
214
      }
215
    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217
    
218
    @Override
219
    protected void onDestroy() 
220
      {
221
      super.onDestroy();
222
      DistortedLibrary.onDestroy(1);
223
      }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
    void OpenGLError()
228
      {
229
      RubikDialogError errDiag = new RubikDialogError();
230
      errDiag.show(getSupportFragmentManager(), null);
231
      }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
    TutorialScreen getState()
236
      {
237
      return mState;
238
      }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
// PUBLIC API
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
    public FirebaseAnalytics getAnalytics()
245
      {
246
      return mFirebaseAnalytics;
247
      }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
    public int getScreenWidthInPixels()
252
      {
253
      return mScreenWidth;
254
      }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
    public int getScreenHeightInPixels()
259
      {
260
      return mScreenHeight;
261
      }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
    public ObjectControl getControl()
266
      {
267
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
268
      return view.getObjectControl();
269
      }
270

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

    
273
    public DistortedScreen getScreen()
274
      {
275
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
276
      TutorialRenderer renderer = view.getRenderer();
277
      return renderer.getScreen();
278
      }
279

    
280
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}
(1-1/7)