Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorial / TutorialActivity.java @ 344f290c

1 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.tutorial;
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.dialogs.RubikDialogError;
36 b6468abb Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
37 af88bf2e Leszek Koltunski
import org.distorted.main.R;
38
import org.distorted.objects.ObjectList;
39
import org.distorted.objects.TwistyObject;
40
import org.distorted.states.RubikStatePlay;
41
import org.distorted.states.StateList;
42
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45
public class TutorialActivity extends AppCompatActivity
46
{
47
    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
    public static final int FLAGS2=  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
57
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
58
59
    private boolean mIsLocked;
60
    private FirebaseAnalytics mFirebaseAnalytics;
61
    private static int mScreenWidth, mScreenHeight;
62
    private int mCurrentApiVersion;
63
    private WebView mWebView;
64 344f290c Leszek Koltunski
    private TutorialState mState;
65 af88bf2e Leszek Koltunski
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
68
    @Override
69
    protected void onCreate(Bundle savedState)
70
      {
71
      super.onCreate(savedState);
72 d7de3072 Leszek Koltunski
      DistortedLibrary.onCreate(1);
73 af88bf2e Leszek Koltunski
      setTheme(R.style.CustomActivityThemeNoActionBar);
74
      setContentView(R.layout.tutorial);
75
76
      mIsLocked = false;
77
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
78
79
      DisplayMetrics displaymetrics = new DisplayMetrics();
80
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
81
      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 344f290c Leszek Koltunski
      final float RATIO = 0.15f;
122 af88bf2e Leszek Koltunski
      float width = getScreenWidthInPixels();
123 344f290c Leszek Koltunski
124
      TutorialSurfaceView viewL = findViewById(R.id.tutorialSurfaceView);
125
      ViewGroup.LayoutParams paramsL = viewL.getLayoutParams();
126
      paramsL.width = (int)(width*(1.0f-RATIO));
127
      viewL.setLayoutParams(paramsL);
128
129
      LinearLayout viewR = findViewById(R.id.rightBar);
130
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
131
      paramsR.width = (int)(width*RATIO);
132
      viewR.setLayoutParams(paramsR);
133
134
      if( mState==null ) mState = new TutorialState();
135
136
      mState.createRightPane(this,width);
137 af88bf2e Leszek Koltunski
      }
138
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140
// do not avoid cutouts
141
142
    private void cutoutHack()
143
      {
144
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
145
        {
146
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
147
        }
148
      }
149
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152
    @Override
153
    public void onWindowFocusChanged(boolean hasFocus)
154
      {
155
      super.onWindowFocusChanged(hasFocus);
156
157
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
158
        {
159
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
160
        }
161
      }
162
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
    
165
    @Override
166
    protected void onPause() 
167
      {
168
      super.onPause();
169
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
170
      view.onPause();
171 d7de3072 Leszek Koltunski
      DistortedLibrary.onPause(1);
172 af88bf2e Leszek Koltunski
      }
173
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
    
176
    @Override
177
    protected void onResume() 
178
      {
179
      super.onResume();
180 d7de3072 Leszek Koltunski
      DistortedLibrary.onResume(1);
181 af88bf2e Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
182
      view.onResume();
183
      view.initialize();
184
185
      boolean success = false;
186
      RubikStatePlay play = (RubikStatePlay) StateList.PLAY.getStateClass();
187
      int object = play.getObject();
188
      int size   = play.getSize();
189
190
      if( object>=0 && object< ObjectList.NUM_OBJECTS )
191
        {
192
        ObjectList obj = ObjectList.getObject(object);
193
        int[] sizes = obj.getSizes();
194
        int sizeIndex = ObjectList.getSizeIndex(object,size);
195
196
        if( sizeIndex>=0 && sizeIndex<sizes.length )
197
          {
198
          success = true;
199
          view.getPreRender().changeObject(obj,size);
200
          }
201
        }
202
/*
203
      if( !success )
204
        {
205
        ObjectList obj = ObjectList.getObject(RubikStatePlay.DEF_OBJECT);
206
        int s = RubikStatePlay.DEF_SIZE;
207
208
        play.setObjectAndSize(this,obj,s);
209
        view.getPreRender().changeObject(obj,s);
210
        }
211
 */
212
      }
213
    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
    
216
    @Override
217
    protected void onDestroy() 
218
      {
219
      super.onDestroy();
220 d7de3072 Leszek Koltunski
      DistortedLibrary.onDestroy(1);
221 af88bf2e Leszek Koltunski
      }
222
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224
225
    void OpenGLError()
226
      {
227
      RubikDialogError errDiag = new RubikDialogError();
228
      errDiag.show(getSupportFragmentManager(), null);
229
      }
230
231 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
232
233
    TutorialState getState()
234
      {
235
      return mState;
236
      }
237
238 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
239
// PUBLIC API
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
242
    public FirebaseAnalytics getAnalytics()
243
      {
244
      return mFirebaseAnalytics;
245
      }
246
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249
    public TwistyObject getObject()
250
      {
251
      TutorialSurfaceView view = findViewById(R.id.rubikSurfaceView);
252
      TutorialPreRender pre = view.getPreRender();
253
      return pre.getObject();
254
      }
255
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257
258
    public int getScreenWidthInPixels()
259
      {
260
      return mScreenWidth;
261
      }
262
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264
265
    public int getScreenHeightInPixels()
266
      {
267
      return mScreenHeight;
268
      }
269
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271
272
    public TutorialPreRender getPreRender()
273
      {
274
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
275
      return view.getPreRender();
276
      }
277
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
280
    public static int getDrawableSize()
281
      {
282
      if( mScreenHeight<1000 )
283
        {
284
        return 0;
285
        }
286
      if( mScreenHeight<1600 )
287
        {
288
        return 1;
289
        }
290
      if( mScreenHeight<1900 )
291
        {
292
        return 2;
293
        }
294
295
      return 3;
296
      }
297
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
300
    public static int getDrawable(int small, int medium, int big, int huge)
301
      {
302
      int size = getDrawableSize();
303
304
      switch(size)
305
        {
306
        case 0 : return small;
307
        case 1 : return medium;
308
        case 2 : return big;
309
        default: return huge;
310
        }
311
      }
312
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314
315
    public boolean isVertical()
316
      {
317
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
318
      return view.isVertical();
319
      }
320
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
323
    public void toggleLock()
324
      {
325
      mIsLocked = !mIsLocked;
326
      }
327
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
330
    public boolean isLocked()
331
      {
332
      StateList state = StateList.getCurrentState();
333
334
      if( state== StateList.PLAY || state== StateList.READ || state== StateList.SOLV )
335
        {
336
        return mIsLocked;
337
        }
338
339
      return false;
340
      }
341
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343
344
    public boolean retLocked()
345
      {
346
      return mIsLocked;
347
      }
348
}