Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialActivity.java @ 1237d25d

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 java.io.InputStream;
23

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

    
35
import com.google.firebase.analytics.FirebaseAnalytics;
36

    
37
import org.distorted.dmesh.ObjectMesh;
38
import org.distorted.jsons.ObjectJson;
39
import org.distorted.library.main.DistortedLibrary;
40

    
41
import org.distorted.objectlib.main.ObjectControl;
42
import org.distorted.objectlib.main.ObjectType;
43

    
44
import org.distorted.main.R;
45
import org.distorted.dialogs.RubikDialogError;
46

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

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

    
53
    private static final int ACTIVITY_NUMBER = 1;
54
    public static final float BAR_RATIO = 0.17f;
55
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
56
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
57

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

    
64
    private FirebaseAnalytics mFirebaseAnalytics;
65
    private static int mScreenWidth, mScreenHeight;
66
    private int mCurrentApiVersion;
67
    private TutorialScreen mScreen;
68
    private String mURL;
69
    private int mObjectOrdinal;
70
    private TutorialWebView mWebView;
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
    @Override
75
    protected void onCreate(Bundle savedState)
76
      {
77
      super.onCreate(savedState);
78
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
79
      setTheme(R.style.MaterialThemeNoActionBar);
80
      setContentView(R.layout.tutorial);
81

    
82
      Bundle b = getIntent().getExtras();
83

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

    
90
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
91

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

    
97
      hideNavigationBar();
98
      cutoutHack();
99
      }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
    private void hideNavigationBar()
104
      {
105
      mCurrentApiVersion = Build.VERSION.SDK_INT;
106

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

    
111
        decorView.setSystemUiVisibility(FLAGS);
112

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

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
    @Override
130
    public void onAttachedToWindow()
131
      {
132
      super.onAttachedToWindow();
133

    
134
      float width = getScreenWidthInPixels();
135

    
136
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
137
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
138
      paramsR.width = (int)(width*BAR_RATIO);
139
      viewR.setLayoutParams(paramsR);
140

    
141
      if( mScreen==null ) mScreen = new TutorialScreen();
142

    
143
      mScreen.createRightPane(this);
144

    
145
      WebView videoView = findViewById(R.id.tutorialVideoView);
146
      mWebView = new TutorialWebView(videoView);
147
      mWebView.load(URL+mURL);
148
      }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
// do not avoid cutouts
152

    
153
    private void cutoutHack()
154
      {
155
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
156
        {
157
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
158
        }
159
      }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
    @Override
164
    public void onWindowFocusChanged(boolean hasFocus)
165
      {
166
      super.onWindowFocusChanged(hasFocus);
167

    
168
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
169
        {
170
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
171
        }
172
      }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
    
176
    @Override
177
    protected void onPause() 
178
      {
179
      super.onPause();
180
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
181
      view.onPause();
182

    
183
      if( mWebView!=null ) mWebView.onPause();
184

    
185
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
186
      }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
    
190
    @Override
191
    protected void onResume() 
192
      {
193
      super.onResume();
194
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
195
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
196
      view.onResume();
197

    
198
      if( mWebView!=null ) mWebView.onResume();
199

    
200
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
201
        {
202
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
203
        changeIfDifferent(obj,view.getObjectControl());
204
        }
205
      }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
    
209
    @Override
210
    protected void onDestroy() 
211
      {
212
      super.onDestroy();
213
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
214
      }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
    void OpenGLError()
219
      {
220
      RubikDialogError errDiag = new RubikDialogError();
221
      errDiag.show(getSupportFragmentManager(), null);
222
      }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
    private void changeIfDifferent(ObjectType type,ObjectControl control)
227
      {
228
      InputStream jsonStream = ObjectJson.getStream(type,this);
229
      InputStream meshStream = ObjectMesh.getStream(type,this);
230
      control.changeIfDifferent(type.ordinal(),jsonStream,meshStream);
231
      }
232

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

    
235
    TutorialScreen getState()
236
      {
237
      return mScreen;
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 static int getDrawableSize()
274
      {
275
      if( mScreenHeight<1000 )
276
        {
277
        return 0;
278
        }
279
      if( mScreenHeight<1600 )
280
        {
281
        return 1;
282
        }
283
      if( mScreenHeight<1900 )
284
        {
285
        return 2;
286
        }
287

    
288
      return 3;
289
      }
290

    
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

    
293
    public static int getDrawable(int small, int medium, int big, int huge)
294
      {
295
      int size = getDrawableSize();
296

    
297
      switch(size)
298
        {
299
        case 0 : return small;
300
        case 1 : return medium;
301
        case 2 : return big;
302
        default: return huge;
303
        }
304
      }
305

    
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

    
308
    public boolean isVertical()
309
      {
310
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
311
      return view.isVertical();
312
      }
313
}
(1-1/7)