Project

General

Profile

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

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

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

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

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
public class TutorialActivity extends AppCompatActivity
47
{
48
    private static final String URL = "https://www.youtube.com/embed/";
49

    
50
    public static final float BAR_RATIO = 0.15f;
51
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
52
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
53

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

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

    
78
      Bundle b = getIntent().getExtras();
79

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

    
86
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
87

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

    
93
      hideNavigationBar();
94
      cutoutHack();
95
      }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
    private void hideNavigationBar()
100
      {
101
      mCurrentApiVersion = Build.VERSION.SDK_INT;
102

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

    
107
        decorView.setSystemUiVisibility(FLAGS);
108

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

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
    @Override
126
    public void onAttachedToWindow()
127
      {
128
      super.onAttachedToWindow();
129

    
130
      float width = getScreenWidthInPixels();
131

    
132
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
133
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
134
      paramsR.width = (int)(width*BAR_RATIO);
135
      viewR.setLayoutParams(paramsR);
136

    
137
      if( mState==null ) mState = new TutorialScreen();
138

    
139
      mState.createRightPane(this,width);
140

    
141
      WebView videoView = findViewById(R.id.tutorialVideoView);
142
      mWebView = new TutorialWebView(videoView);
143
      mWebView.load(URL+mURL);
144
      }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
// do not avoid cutouts
148

    
149
    private void cutoutHack()
150
      {
151
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
152
        {
153
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
154
        }
155
      }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
    @Override
160
    public void onWindowFocusChanged(boolean hasFocus)
161
      {
162
      super.onWindowFocusChanged(hasFocus);
163

    
164
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
165
        {
166
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
167
        }
168
      }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
    
172
    @Override
173
    protected void onPause() 
174
      {
175
      super.onPause();
176
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
177
      view.onPause();
178

    
179
      if( mWebView!=null ) mWebView.onPause();
180

    
181
      DistortedLibrary.onPause(1);
182
      }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185
    
186
    @Override
187
    protected void onResume() 
188
      {
189
      super.onResume();
190
      DistortedLibrary.onResume(1);
191
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
192
      view.onResume();
193

    
194
      if( mWebView!=null ) mWebView.onResume();
195

    
196
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
197
        {
198
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
199
        view.getObjectControl().changeObject(obj);
200
        }
201
      }
202
    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
    
205
    @Override
206
    protected void onDestroy() 
207
      {
208
      super.onDestroy();
209
      DistortedLibrary.onDestroy(1);
210
      }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
    void OpenGLError()
215
      {
216
      RubikDialogError errDiag = new RubikDialogError();
217
      errDiag.show(getSupportFragmentManager(), null);
218
      }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
    TutorialScreen getState()
223
      {
224
      return mState;
225
      }
226

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
// PUBLIC API
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

    
231
    public FirebaseAnalytics getAnalytics()
232
      {
233
      return mFirebaseAnalytics;
234
      }
235

    
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
    public ObjectControl getControl()
253
      {
254
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
255
      return view.getObjectControl();
256
      }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
    public DistortedScreen getScreen()
261
      {
262
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
263
      TutorialRenderer renderer = view.getRenderer();
264
      return renderer.getScreen();
265
      }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
    public static int getDrawableSize()
270
      {
271
      if( mScreenHeight<1000 )
272
        {
273
        return 0;
274
        }
275
      if( mScreenHeight<1600 )
276
        {
277
        return 1;
278
        }
279
      if( mScreenHeight<1900 )
280
        {
281
        return 2;
282
        }
283

    
284
      return 3;
285
      }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
    public static int getDrawable(int small, int medium, int big, int huge)
290
      {
291
      int size = getDrawableSize();
292

    
293
      switch(size)
294
        {
295
        case 0 : return small;
296
        case 1 : return medium;
297
        case 2 : return big;
298
        default: return huge;
299
        }
300
      }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
    public boolean isVertical()
305
      {
306
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
307
      return view.isVertical();
308
      }
309
}
(1-1/7)