Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 298f3977

1 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 9d51b9d6 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 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.config;
11
12 314e9ff0 Leszek Koltunski
import java.io.InputStream;
13
14 1237d25d Leszek Koltunski
import android.os.Build;
15
import android.os.Bundle;
16
import android.util.DisplayMetrics;
17
import android.view.View;
18
import android.view.ViewGroup;
19
import android.view.WindowManager;
20
import android.widget.LinearLayout;
21
import androidx.appcompat.app.AppCompatActivity;
22
import com.google.firebase.analytics.FirebaseAnalytics;
23
24
import org.distorted.library.main.DistortedLibrary;
25
import org.distorted.objectlib.main.ObjectControl;
26 314e9ff0 Leszek Koltunski
import org.distorted.main.R;
27
import org.distorted.dialogs.RubikDialogError;
28 7cb8d4b0 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
29 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObject;
30
import org.distorted.objects.RubikObjectList;
31 1237d25d Leszek Koltunski
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34
public class ConfigActivity extends AppCompatActivity
35
{
36
    private static final int ACTIVITY_NUMBER = 2;
37 97a4ae23 Leszek Koltunski
    private static final float RATIO_BAR  = 0.10f;
38 1237d25d Leszek Koltunski
39
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
40
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
41
42
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
43
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
44
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
45
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
46
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
47
48
    private FirebaseAnalytics mFirebaseAnalytics;
49
    private static int mScreenWidth, mScreenHeight;
50
    private int mCurrentApiVersion;
51
    private ConfigScreen mScreen;
52
    private int mObjectOrdinal;
53 97a4ae23 Leszek Koltunski
    private int mHeightBar;
54 1237d25d Leszek Koltunski
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
    @Override
58
    protected void onCreate(Bundle savedState)
59
      {
60
      super.onCreate(savedState);
61
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
62
      setTheme(R.style.MaterialThemeNoActionBar);
63
      setContentView(R.layout.config);
64
65
      Bundle b = getIntent().getExtras();
66
67
      if(b != null) mObjectOrdinal = b.getInt("obj");
68
69
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
70
71
      DisplayMetrics displaymetrics = new DisplayMetrics();
72 7fe59aa5 Leszek Koltunski
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
73 1237d25d Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
74
      mScreenHeight=displaymetrics.heightPixels;
75 7fe59aa5 Leszek Koltunski
76 1237d25d Leszek Koltunski
      hideNavigationBar();
77
      cutoutHack();
78 97a4ae23 Leszek Koltunski
      computeBarHeights();
79
      }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// this does not include possible insets
83
84
    private void computeBarHeights()
85
      {
86
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
87
      mHeightBar = barHeight;
88
89
      LinearLayout layout = findViewById(R.id.lowerBar);
90
      ViewGroup.LayoutParams params = layout.getLayoutParams();
91
      params.height = barHeight;
92
      layout.setLayoutParams(params);
93 1237d25d Leszek Koltunski
      }
94
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97
    private void hideNavigationBar()
98
      {
99
      mCurrentApiVersion = Build.VERSION.SDK_INT;
100
101
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
102
        {
103
        final View decorView = getWindow().getDecorView();
104
105
        decorView.setSystemUiVisibility(FLAGS);
106
107
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
108
          {
109
          @Override
110
          public void onSystemUiVisibilityChange(int visibility)
111
            {
112
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
113
              {
114
              decorView.setSystemUiVisibility(FLAGS);
115
              }
116
            }
117
          });
118
        }
119
      }
120
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
// do not avoid cutouts
123
124
    private void cutoutHack()
125
      {
126
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
127
        {
128
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
129
        }
130
      }
131
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134
    @Override
135
    public void onWindowFocusChanged(boolean hasFocus)
136
      {
137
      super.onWindowFocusChanged(hasFocus);
138
139
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
140
        {
141
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
142
        }
143
      }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
    
147
    @Override
148
    protected void onPause() 
149
      {
150
      super.onPause();
151
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
152
      view.onPause();
153
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
154
      }
155
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
    
158
    @Override
159
    protected void onResume() 
160
      {
161
      super.onResume();
162
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
163
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
164
      view.onResume();
165
166 280dc794 Leszek Koltunski
      if( mScreen==null ) mScreen = new ConfigScreen();
167
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
168
169 d433b50e Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
170 1237d25d Leszek Koltunski
        {
171 d433b50e Leszek Koltunski
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
172 d36d8517 Leszek Koltunski
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
173 1237d25d Leszek Koltunski
        }
174
      }
175
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
    
178
    @Override
179
    protected void onDestroy() 
180
      {
181
      super.onDestroy();
182
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
183
      }
184
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186
187
    void OpenGLError()
188
      {
189
      RubikDialogError errDiag = new RubikDialogError();
190
      errDiag.show(getSupportFragmentManager(), null);
191
      }
192
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
195 d36d8517 Leszek Koltunski
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
196 1237d25d Leszek Koltunski
      {
197 d433b50e Leszek Koltunski
      if( object!=null )
198
        {
199 314e9ff0 Leszek Koltunski
        int meshState          = object.getMeshState();
200 7cb8d4b0 Leszek Koltunski
        int iconMode           = TwistyObject.MODE_NORM;
201 314e9ff0 Leszek Koltunski
        InputStream jsonStream = object.getObjectStream(this);
202
        InputStream meshStream = object.getMeshStream(this);
203 aec421fd Leszek Koltunski
        String name            = object.getUpperName();
204 09cf2a36 Leszek Koltunski
205 7cb8d4b0 Leszek Koltunski
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
206 d433b50e Leszek Koltunski
        }
207 1237d25d Leszek Koltunski
      }
208
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
// PUBLIC API
211 09cf2a36 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
212
213 280dc794 Leszek Koltunski
    public void changeObject(int ordinal)
214 09cf2a36 Leszek Koltunski
      {
215 280dc794 Leszek Koltunski
      mObjectOrdinal = ordinal;
216
      RubikObject object = RubikObjectList.getObject(ordinal);
217 09cf2a36 Leszek Koltunski
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
218
      ObjectControl control = view.getObjectControl();
219 d36d8517 Leszek Koltunski
      changeIfDifferent(object,ordinal,control);
220 09cf2a36 Leszek Koltunski
      }
221
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224 d36d8517 Leszek Koltunski
    public void changeMeshState(RubikObject object, int ordinal)
225 09cf2a36 Leszek Koltunski
      {
226
      if( object!=null )
227
        {
228
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
229
        ObjectControl control = view.getObjectControl();
230
231 314e9ff0 Leszek Koltunski
        int meshState          = object.getMeshState();
232 7cb8d4b0 Leszek Koltunski
        int iconMode           = TwistyObject.MODE_NORM;
233 314e9ff0 Leszek Koltunski
        InputStream jsonStream = object.getObjectStream(this);
234
        InputStream meshStream = object.getMeshStream(this);
235 09cf2a36 Leszek Koltunski
236 7cb8d4b0 Leszek Koltunski
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
237 09cf2a36 Leszek Koltunski
        }
238
      }
239
240 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
241
242
    public FirebaseAnalytics getAnalytics()
243
      {
244
      return mFirebaseAnalytics;
245
      }
246
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249 97a4ae23 Leszek Koltunski
    public int getHeightBar()
250 1237d25d Leszek Koltunski
      {
251 97a4ae23 Leszek Koltunski
      return mHeightBar;
252 1237d25d Leszek Koltunski
      }
253
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
256
    public int getScreenWidthInPixels()
257
      {
258
      return mScreenWidth;
259
      }
260
261 97a4ae23 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
262
263
    public int getScreenHeightInPixels()
264
      {
265
      return mScreenHeight;
266
      }
267
268 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
269
270
    public ObjectControl getControl()
271
      {
272
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
273
      return view.getObjectControl();
274
      }
275
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277
278
    public static int getDrawableSize()
279
      {
280
      if( mScreenHeight<1000 )
281
        {
282
        return 0;
283
        }
284
      if( mScreenHeight<1600 )
285
        {
286
        return 1;
287
        }
288
      if( mScreenHeight<1900 )
289
        {
290
        return 2;
291
        }
292
293
      return 3;
294
      }
295
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297
298
    public static int getDrawable(int small, int medium, int big, int huge)
299
      {
300
      int size = getDrawableSize();
301
302
      switch(size)
303
        {
304
        case 0 : return small;
305
        case 1 : return medium;
306
        case 2 : return big;
307
        default: return huge;
308
        }
309
      }
310
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
313
    public boolean isVertical()
314
      {
315
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
316
      return view.isVertical();
317
      }
318
}