Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 8375250f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.config;
11

    
12
import java.io.InputStream;
13

    
14
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
import org.distorted.main.R;
27
import org.distorted.dialogs.RubikDialogError;
28
import org.distorted.objectlib.main.TwistyObject;
29
import org.distorted.objects.RubikObject;
30
import org.distorted.objects.RubikObjectList;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public class ConfigActivity extends AppCompatActivity
35
{
36
    private static final int ACTIVITY_NUMBER = 2;
37
    private static final float RATIO_BAR  = 0.10f;
38

    
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
    private int mHeightBar;
54

    
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
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
73
      mScreenWidth =displaymetrics.widthPixels;
74
      mScreenHeight=displaymetrics.heightPixels;
75

    
76
      hideNavigationBar();
77
      cutoutHack();
78
      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
      }
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
      if( mScreen==null ) mScreen = new ConfigScreen();
167
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
168

    
169
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
170
        {
171
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
172
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
173
        }
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
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
196
      {
197
      if( object!=null )
198
        {
199
        int meshState          = object.getMeshState();
200
        int iconMode           = TwistyObject.MODE_NORM;
201
        InputStream jsonStream = object.getObjectStream(this);
202
        InputStream meshStream = object.getMeshStream(this);
203
        String name            = object.getUpperName();
204

    
205
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
206
        }
207
      }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210
// PUBLIC API
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
    public void changeObject(int ordinal)
214
      {
215
      mObjectOrdinal = ordinal;
216
      RubikObject object = RubikObjectList.getObject(ordinal);
217
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
218
      ObjectControl control = view.getObjectControl();
219
      changeIfDifferent(object,ordinal,control);
220
      }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
    public void changeMeshState(RubikObject object, int ordinal)
225
      {
226
      if( object!=null )
227
        {
228
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
229
        ObjectControl control = view.getObjectControl();
230

    
231
        int meshState          = object.getMeshState();
232
        int iconMode           = TwistyObject.MODE_NORM;
233
        InputStream jsonStream = object.getObjectStream(this);
234
        InputStream meshStream = object.getMeshStream(this);
235

    
236
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
237
        }
238
      }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

    
242
    public FirebaseAnalytics getAnalytics()
243
      {
244
      return mFirebaseAnalytics;
245
      }
246

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

    
249
    public int getHeightBar()
250
      {
251
      return mHeightBar;
252
      }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

    
256
    public int getScreenWidthInPixels()
257
      {
258
      return mScreenWidth;
259
      }
260

    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

    
263
    public int getScreenHeightInPixels()
264
      {
265
      return mScreenHeight;
266
      }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}
(1-1/6)