Project

General

Profile

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

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

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 18d47965 Leszek Koltunski
import android.content.Intent;
15 af88bf2e Leszek Koltunski
import android.os.Build;
16
import android.os.Bundle;
17
import android.util.DisplayMetrics;
18
import android.view.View;
19
import android.view.ViewGroup;
20
import android.view.WindowManager;
21
import android.webkit.WebView;
22
import android.widget.LinearLayout;
23
24 e019c70b Leszek Koltunski
import androidx.appcompat.app.AppCompatActivity;
25
26 3f7a4363 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
27 2afc6754 Leszek Koltunski
28 1c04d054 leszek
import org.distorted.main_old.RubikActivity;
29 50e6c5d6 Leszek Koltunski
import org.distorted.objectlib.main.InitAssets;
30 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
31 7cb8d4b0 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
32 eaf46415 Leszek Koltunski
33 af88bf2e Leszek Koltunski
import org.distorted.main.R;
34 eaf46415 Leszek Koltunski
import org.distorted.dialogs.RubikDialogError;
35 09cf2a36 Leszek Koltunski
import org.distorted.objects.RubikObject;
36 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObjectList;
37 da57afae Leszek Koltunski
import org.distorted.os.OSInterface;
38 18d47965 Leszek Koltunski
import org.distorted.purchase.PurchaseActivity;
39 af88bf2e Leszek Koltunski
40 09cf2a36 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
41
42 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44 e019c70b Leszek Koltunski
public class TutorialActivity extends AppCompatActivity
45 af88bf2e Leszek Koltunski
{
46 2971588c Leszek Koltunski
    private static final String URL = "https://www.youtube.com/embed/";
47 1237d25d Leszek Koltunski
    private static final int ACTIVITY_NUMBER = 1;
48 943471aa Leszek Koltunski
    public static final float BAR_RATIO = 0.17f;
49 ada8ab26 leszek
    public static final int FLAGS = RubikActivity.FLAGS;
50 af88bf2e Leszek Koltunski
51
    private static int mScreenWidth, mScreenHeight;
52
    private int mCurrentApiVersion;
53 1237d25d Leszek Koltunski
    private TutorialScreen mScreen;
54 2971588c Leszek Koltunski
    private String mURL;
55 7ac0ee88 Leszek Koltunski
    private int mObjectOrdinal;
56 5b4eaf7e Leszek Koltunski
    private TutorialWebView mWebView;
57 ea036986 Leszek Koltunski
    private boolean mIsFree;
58 af88bf2e Leszek Koltunski
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
    @Override
62
    protected void onCreate(Bundle savedState)
63
      {
64
      super.onCreate(savedState);
65 1237d25d Leszek Koltunski
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
66 dd874ae8 Leszek Koltunski
      setTheme(R.style.MaterialThemeNoActionBar);
67 af88bf2e Leszek Koltunski
      setContentView(R.layout.tutorial);
68
69 ea036986 Leszek Koltunski
      mIsFree = true;
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 ea036986 Leszek Koltunski
        RubikObject obj= RubikObjectList.getObject(mObjectOrdinal);
78
        mIsFree = (obj!=null && obj.isFree());
79 79bf5d8b Leszek Koltunski
        }
80 2971588c Leszek Koltunski
81 af88bf2e Leszek Koltunski
      DisplayMetrics displaymetrics = new DisplayMetrics();
82 7fe59aa5 Leszek Koltunski
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
83 af88bf2e Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
84
      mScreenHeight=displaymetrics.heightPixels;
85
86
      hideNavigationBar();
87
      cutoutHack();
88
      }
89
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
    private void hideNavigationBar()
93
      {
94
      mCurrentApiVersion = Build.VERSION.SDK_INT;
95
96
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
97
        {
98
        final View decorView = getWindow().getDecorView();
99
100
        decorView.setSystemUiVisibility(FLAGS);
101
102
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
103
          {
104
          @Override
105
          public void onSystemUiVisibilityChange(int visibility)
106
            {
107
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
108
              {
109
              decorView.setSystemUiVisibility(FLAGS);
110
              }
111
            }
112
          });
113
        }
114
      }
115
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
    @Override
119
    public void onAttachedToWindow()
120
      {
121
      super.onAttachedToWindow();
122
123 280dc794 Leszek Koltunski
      if( mWebView==null )
124
        {
125
        WebView videoView = findViewById(R.id.tutorialVideoView);
126
        mWebView = new TutorialWebView(videoView);
127
        mWebView.load(URL+mURL);
128
        }
129 af88bf2e Leszek Koltunski
      }
130
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132
// do not avoid cutouts
133
134
    private void cutoutHack()
135
      {
136
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
137
        {
138
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
139
        }
140
      }
141
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
144
    @Override
145
    public void onWindowFocusChanged(boolean hasFocus)
146
      {
147
      super.onWindowFocusChanged(hasFocus);
148
149
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
150
        {
151
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
152
        }
153
      }
154
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156
    
157
    @Override
158
    protected void onPause() 
159
      {
160
      super.onPause();
161
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
162
      view.onPause();
163 0de39b8e Leszek Koltunski
164
      if( mWebView!=null ) mWebView.onPause();
165
166 1237d25d Leszek Koltunski
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
167 af88bf2e Leszek Koltunski
      }
168
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
    
171
    @Override
172
    protected void onResume() 
173
      {
174
      super.onResume();
175 1237d25d Leszek Koltunski
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
176 af88bf2e Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
177
      view.onResume();
178
179 280dc794 Leszek Koltunski
      float width = getScreenWidthInPixels();
180
181
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
182
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
183
      paramsR.width = (int)(width*BAR_RATIO);
184
      viewR.setLayoutParams(paramsR);
185
186 ea036986 Leszek Koltunski
      if( mScreen==null ) mScreen = new TutorialScreen(mIsFree);
187 280dc794 Leszek Koltunski
188
      mScreen.createRightPane(this);
189
190 0de39b8e Leszek Koltunski
      if( mWebView!=null ) mWebView.onResume();
191
192 d433b50e Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
193 af88bf2e Leszek Koltunski
        {
194 d433b50e Leszek Koltunski
        changeIfDifferent(mObjectOrdinal,view.getObjectControl());
195 af88bf2e Leszek Koltunski
        }
196
      }
197 b20e89d2 Leszek Koltunski
198 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
199
    
200
    @Override
201
    protected void onDestroy() 
202
      {
203
      super.onDestroy();
204 1237d25d Leszek Koltunski
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
205 af88bf2e Leszek Koltunski
      }
206
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
209
    void OpenGLError()
210
      {
211
      RubikDialogError errDiag = new RubikDialogError();
212
      errDiag.show(getSupportFragmentManager(), null);
213
      }
214
215 b20e89d2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 09cf2a36 Leszek Koltunski
    private void changeIfDifferent(int ordinal,ObjectControl control)
218 b20e89d2 Leszek Koltunski
      {
219 09cf2a36 Leszek Koltunski
      RubikObject object = RubikObjectList.getObject(ordinal);
220
      int meshState = object!=null ? object.getMeshState() : MESH_NICE;
221 7cb8d4b0 Leszek Koltunski
      int iconMode  = TwistyObject.MODE_NORM;
222 314e9ff0 Leszek Koltunski
      InputStream jsonStream = object==null ? null : object.getObjectStream(this);
223
      InputStream meshStream = object==null ? null : object.getMeshStream(this);
224 aec421fd Leszek Koltunski
      String name = object==null ? "NULL" : object.getUpperName();
225 da57afae Leszek Koltunski
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
226
      OSInterface os = view.getInterface();
227
      InitAssets asset = new InitAssets(jsonStream,meshStream,os);
228 50e6c5d6 Leszek Koltunski
      control.changeIfDifferent(ordinal,name,meshState,iconMode,asset);
229 b20e89d2 Leszek Koltunski
      }
230
231 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
232
233 dd1a65c1 Leszek Koltunski
    TutorialScreen getState()
234 344f290c Leszek Koltunski
      {
235 1237d25d Leszek Koltunski
      return mScreen;
236 344f290c Leszek Koltunski
      }
237
238 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
239
// PUBLIC API
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
242
    public int getScreenWidthInPixels()
243
      {
244
      return mScreenWidth;
245
      }
246
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249
    public int getScreenHeightInPixels()
250
      {
251
      return mScreenHeight;
252
      }
253
254 ea036986 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
255
256
    public boolean getIsFree()
257
      {
258
      return mIsFree;
259
      }
260
261 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
262
263 2afc6754 Leszek Koltunski
    public ObjectControl getControl()
264 55e6be1d Leszek Koltunski
      {
265
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
266 2afc6754 Leszek Koltunski
      return view.getObjectControl();
267 55e6be1d Leszek Koltunski
      }
268
269 18d47965 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271
    public void switchToPurchase()
272
      {
273
      Intent intent = new Intent(this, PurchaseActivity.class);
274
      intent.putExtra("obj", mObjectOrdinal);
275
      startActivity(intent);
276
      }
277 af88bf2e Leszek Koltunski
}