Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 1237d25d

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 android.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.DisplayCutout;
26
import android.view.View;
27
import android.view.ViewGroup;
28
import android.view.WindowManager;
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
import org.distorted.dmesh.ObjectMesh;
37
import org.distorted.jsons.ObjectJson;
38
import org.distorted.library.main.DistortedLibrary;
39
import org.distorted.main.R;
40
import org.distorted.objectlib.main.ObjectControl;
41
import org.distorted.objectlib.main.ObjectType;
42
import org.distorted.tutorials.TutorialScreen;
43

    
44
import java.io.InputStream;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
public class ConfigActivity extends AppCompatActivity
49
{
50
    private static final int ACTIVITY_NUMBER = 2;
51
    private static final float RATIO_INSET= 0.08f;
52
    public static final float BAR_RATIO = 0.17f;
53

    
54
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
55
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
56

    
57
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
58
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
60
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
61
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
62

    
63
    private FirebaseAnalytics mFirebaseAnalytics;
64
    private static int mScreenWidth, mScreenHeight;
65
    private int mCurrentApiVersion;
66
    private ConfigScreen mScreen;
67
    private int mObjectOrdinal;
68
    private int mHeightUpperBar;
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
    @Override
73
    protected void onCreate(Bundle savedState)
74
      {
75
      super.onCreate(savedState);
76
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
77
      setTheme(R.style.MaterialThemeNoActionBar);
78
      setContentView(R.layout.config);
79

    
80
      Bundle b = getIntent().getExtras();
81

    
82
      if(b != null) mObjectOrdinal = b.getInt("obj");
83

    
84
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
85

    
86
      DisplayMetrics displaymetrics = new DisplayMetrics();
87
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
88
      mScreenWidth =displaymetrics.widthPixels;
89
      mScreenHeight=displaymetrics.heightPixels;
90

    
91
      hideNavigationBar();
92
      cutoutHack();
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

    
123
    @Override
124
    public void onAttachedToWindow()
125
      {
126
      super.onAttachedToWindow();
127

    
128
      int insetHeight = 0;
129

    
130
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
131
        {
132
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
133
        insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
134
        }
135

    
136
      LinearLayout layoutHid = findViewById(R.id.hiddenBar);
137
      ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
138
      paramsHid.height = (int)(insetHeight*RATIO_INSET);
139
      layoutHid.setLayoutParams(paramsHid);
140
      mHeightUpperBar += paramsHid.height;
141

    
142
      if( mScreen==null ) mScreen = new ConfigScreen();
143
      mScreen.createScreen(this);
144
      }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
// do not avoid cutouts
148

    
149
    private void cutoutHack()
150
      {
151
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
152
        {
153
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
154
        }
155
      }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
    @Override
160
    public void onWindowFocusChanged(boolean hasFocus)
161
      {
162
      super.onWindowFocusChanged(hasFocus);
163

    
164
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
165
        {
166
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
167
        }
168
      }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
    
172
    @Override
173
    protected void onPause() 
174
      {
175
      super.onPause();
176
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
177
      view.onPause();
178
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
179
      }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
    
183
    @Override
184
    protected void onResume() 
185
      {
186
      super.onResume();
187
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
188
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
189
      view.onResume();
190

    
191
      if( mObjectOrdinal>=0 && mObjectOrdinal< ObjectType.NUM_OBJECTS )
192
        {
193
        ObjectType obj = ObjectType.getObject(mObjectOrdinal);
194
        changeIfDifferent(obj,view.getObjectControl());
195
        }
196
      }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
    
200
    @Override
201
    protected void onDestroy() 
202
      {
203
      super.onDestroy();
204
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
205
      }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
    void OpenGLError()
210
      {
211
      RubikDialogError errDiag = new RubikDialogError();
212
      errDiag.show(getSupportFragmentManager(), null);
213
      }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
    private void changeIfDifferent(ObjectType type,ObjectControl control)
218
      {
219
      InputStream jsonStream = ObjectJson.getStream(type,this);
220
      InputStream meshStream = ObjectMesh.getStream(type,this);
221
      control.changeIfDifferent(type.ordinal(),jsonStream,meshStream);
222
      }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
    ConfigScreen getState()
227
      {
228
      return mScreen;
229
      }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
// PUBLIC API
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
    public FirebaseAnalytics getAnalytics()
236
      {
237
      return mFirebaseAnalytics;
238
      }
239

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

    
242
    public int getHeightUpperBar()
243
      {
244
      return mHeightUpperBar;
245
      }
246

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

    
249
    public int getScreenWidthInPixels()
250
      {
251
      return mScreenWidth;
252
      }
253

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

    
256
    public ObjectControl getControl()
257
      {
258
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
259
      return view.getObjectControl();
260
      }
261

    
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

    
264
    public static int getDrawableSize()
265
      {
266
      if( mScreenHeight<1000 )
267
        {
268
        return 0;
269
        }
270
      if( mScreenHeight<1600 )
271
        {
272
        return 1;
273
        }
274
      if( mScreenHeight<1900 )
275
        {
276
        return 2;
277
        }
278

    
279
      return 3;
280
      }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

    
284
    public static int getDrawable(int small, int medium, int big, int huge)
285
      {
286
      int size = getDrawableSize();
287

    
288
      switch(size)
289
        {
290
        case 0 : return small;
291
        case 1 : return medium;
292
        case 2 : return big;
293
        default: return huge;
294
        }
295
      }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

    
299
    public boolean isVertical()
300
      {
301
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
302
      return view.isVertical();
303
      }
304
}
(1-1/5)