Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 7fe59aa5

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.config;
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.widget.LinearLayout;
31
import androidx.appcompat.app.AppCompatActivity;
32
import com.google.firebase.analytics.FirebaseAnalytics;
33

    
34
import org.distorted.library.main.DistortedLibrary;
35
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.main.R;
37
import org.distorted.dialogs.RubikDialogError;
38
import org.distorted.objectlib.main.TwistyObject;
39
import org.distorted.objects.RubikObject;
40
import org.distorted.objects.RubikObjectList;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class ConfigActivity extends AppCompatActivity
45
{
46
    private static final int ACTIVITY_NUMBER = 2;
47
    private static final float RATIO_BAR  = 0.10f;
48

    
49
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
50
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
51

    
52
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
53
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
54
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
55
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
56
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
57

    
58
    private FirebaseAnalytics mFirebaseAnalytics;
59
    private static int mScreenWidth, mScreenHeight;
60
    private int mCurrentApiVersion;
61
    private ConfigScreen mScreen;
62
    private int mObjectOrdinal;
63
    private int mHeightBar;
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
    @Override
68
    protected void onCreate(Bundle savedState)
69
      {
70
      super.onCreate(savedState);
71
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
72
      setTheme(R.style.MaterialThemeNoActionBar);
73
      setContentView(R.layout.config);
74

    
75
      Bundle b = getIntent().getExtras();
76

    
77
      if(b != null) mObjectOrdinal = b.getInt("obj");
78

    
79
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
80

    
81
      DisplayMetrics displaymetrics = new DisplayMetrics();
82
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
83
      mScreenWidth =displaymetrics.widthPixels;
84
      mScreenHeight=displaymetrics.heightPixels;
85

    
86
      hideNavigationBar();
87
      cutoutHack();
88
      computeBarHeights();
89
      }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
// this does not include possible insets
93

    
94
    private void computeBarHeights()
95
      {
96
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
97
      mHeightBar = barHeight;
98

    
99
      LinearLayout layout = findViewById(R.id.lowerBar);
100
      ViewGroup.LayoutParams params = layout.getLayoutParams();
101
      params.height = barHeight;
102
      layout.setLayoutParams(params);
103
      }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
    private void hideNavigationBar()
108
      {
109
      mCurrentApiVersion = Build.VERSION.SDK_INT;
110

    
111
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
112
        {
113
        final View decorView = getWindow().getDecorView();
114

    
115
        decorView.setSystemUiVisibility(FLAGS);
116

    
117
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
118
          {
119
          @Override
120
          public void onSystemUiVisibilityChange(int visibility)
121
            {
122
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
123
              {
124
              decorView.setSystemUiVisibility(FLAGS);
125
              }
126
            }
127
          });
128
        }
129
      }
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
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
162
      view.onPause();
163
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
164
      }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
    
168
    @Override
169
    protected void onResume() 
170
      {
171
      super.onResume();
172
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
173
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
174
      view.onResume();
175

    
176
      if( mScreen==null ) mScreen = new ConfigScreen();
177
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
178

    
179
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
180
        {
181
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
182
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
183
        }
184
      }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187
    
188
    @Override
189
    protected void onDestroy() 
190
      {
191
      super.onDestroy();
192
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
193
      }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
    void OpenGLError()
198
      {
199
      RubikDialogError errDiag = new RubikDialogError();
200
      errDiag.show(getSupportFragmentManager(), null);
201
      }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
206
      {
207
      if( object!=null )
208
        {
209
        int meshState          = object.getMeshState();
210
        int iconMode           = TwistyObject.MODE_NORM;
211
        InputStream jsonStream = object.getObjectStream(this);
212
        InputStream meshStream = object.getMeshStream(this);
213
        String name            = object.getUpperName();
214

    
215
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
216
        }
217
      }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220
// PUBLIC API
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
    public void changeObject(int ordinal)
224
      {
225
      mObjectOrdinal = ordinal;
226
      RubikObject object = RubikObjectList.getObject(ordinal);
227
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
228
      ObjectControl control = view.getObjectControl();
229
      changeIfDifferent(object,ordinal,control);
230
      }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
    public void changeMeshState(RubikObject object, int ordinal)
235
      {
236
      if( object!=null )
237
        {
238
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
239
        ObjectControl control = view.getObjectControl();
240

    
241
        int meshState          = object.getMeshState();
242
        int iconMode           = TwistyObject.MODE_NORM;
243
        InputStream jsonStream = object.getObjectStream(this);
244
        InputStream meshStream = object.getMeshStream(this);
245

    
246
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
247
        }
248
      }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
    public FirebaseAnalytics getAnalytics()
253
      {
254
      return mFirebaseAnalytics;
255
      }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

    
259
    public int getHeightBar()
260
      {
261
      return mHeightBar;
262
      }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

    
266
    public int getScreenWidthInPixels()
267
      {
268
      return mScreenWidth;
269
      }
270

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

    
273
    public int getScreenHeightInPixels()
274
      {
275
      return mScreenHeight;
276
      }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

    
280
    public ObjectControl getControl()
281
      {
282
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
283
      return view.getObjectControl();
284
      }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

    
288
    public static int getDrawableSize()
289
      {
290
      if( mScreenHeight<1000 )
291
        {
292
        return 0;
293
        }
294
      if( mScreenHeight<1600 )
295
        {
296
        return 1;
297
        }
298
      if( mScreenHeight<1900 )
299
        {
300
        return 2;
301
        }
302

    
303
      return 3;
304
      }
305

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

    
308
    public static int getDrawable(int small, int medium, int big, int huge)
309
      {
310
      int size = getDrawableSize();
311

    
312
      switch(size)
313
        {
314
        case 0 : return small;
315
        case 1 : return medium;
316
        case 2 : return big;
317
        default: return huge;
318
        }
319
      }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

    
323
    public boolean isVertical()
324
      {
325
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
326
      return view.isVertical();
327
      }
328
}
(1-1/6)