Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 97a4ae23

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.View;
26
import android.view.ViewGroup;
27
import android.view.WindowManager;
28
import android.widget.LinearLayout;
29

    
30
import androidx.appcompat.app.AppCompatActivity;
31

    
32
import com.google.firebase.analytics.FirebaseAnalytics;
33

    
34
import org.distorted.dialogs.RubikDialogError;
35
import org.distorted.dmesh.ObjectMesh;
36
import org.distorted.jsons.ObjectJson;
37
import org.distorted.library.main.DistortedLibrary;
38
import org.distorted.main.R;
39
import org.distorted.objectlib.main.ObjectControl;
40
import org.distorted.objectlib.main.ObjectType;
41

    
42
import java.io.InputStream;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

    
51
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
52
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
53

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

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
77
      Bundle b = getIntent().getExtras();
78

    
79
      if(b != null) mObjectOrdinal = b.getInt("obj");
80

    
81
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
82

    
83
      DisplayMetrics displaymetrics = new DisplayMetrics();
84
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
85
      mScreenWidth =displaymetrics.widthPixels;
86
      mScreenHeight=displaymetrics.heightPixels;
87
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
88
                                                  // which is not yet hidden.
89
                                                  // TODO: figure this out exactly.
90
      hideNavigationBar();
91
      cutoutHack();
92
      computeBarHeights();
93
      }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// this does not include possible insets
97

    
98
    private void computeBarHeights()
99
      {
100
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
101
      mHeightBar = barHeight;
102

    
103
      LinearLayout layout = findViewById(R.id.lowerBar);
104
      ViewGroup.LayoutParams params = layout.getLayoutParams();
105
      params.height = barHeight;
106
      layout.setLayoutParams(params);
107
      }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
    private void hideNavigationBar()
112
      {
113
      mCurrentApiVersion = Build.VERSION.SDK_INT;
114

    
115
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
116
        {
117
        final View decorView = getWindow().getDecorView();
118

    
119
        decorView.setSystemUiVisibility(FLAGS);
120

    
121
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
122
          {
123
          @Override
124
          public void onSystemUiVisibilityChange(int visibility)
125
            {
126
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
127
              {
128
              decorView.setSystemUiVisibility(FLAGS);
129
              }
130
            }
131
          });
132
        }
133
      }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
    @Override
138
    public void onAttachedToWindow()
139
      {
140
      super.onAttachedToWindow();
141

    
142
      if( mScreen==null ) mScreen = new ConfigScreen();
143
      mScreen.enterScreen(this,mObjectOrdinal);
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
// PUBLIC API
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
    public FirebaseAnalytics getAnalytics()
229
      {
230
      return mFirebaseAnalytics;
231
      }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
    public int getHeightBar()
236
      {
237
      return mHeightBar;
238
      }
239

    
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
///////////////////////////////////////////////////////////////////////////////////////////////////
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

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

    
307
    public void changeObject(ObjectType newObject)
308
      {
309
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
310
      ObjectControl control = view.getObjectControl();
311
      changeIfDifferent(newObject,control);
312
      }
313
}
(1-1/5)