Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 45516ed2

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.library.type.Static4D;
39
import org.distorted.main.R;
40
import org.distorted.objectlib.main.ObjectControl;
41
import org.distorted.objectlib.main.ShapeDodecahedron;
42
import org.distorted.objectlib.main.ShapeHexahedron;
43
import org.distorted.objectlib.main.ShapeOctahedron;
44
import org.distorted.objectlib.main.ShapeTetrahedron;
45
import org.distorted.objects.RubikObject;
46
import org.distorted.objects.RubikObjectList;
47

    
48
import java.io.InputStream;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
public class ConfigActivity extends AppCompatActivity
53
{
54
    private static final int ACTIVITY_NUMBER = 2;
55
    private static final float RATIO_BAR  = 0.10f;
56

    
57
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
58
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
59

    
60
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
61
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
62
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
63
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
64
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
65

    
66
    private FirebaseAnalytics mFirebaseAnalytics;
67
    private static int mScreenWidth, mScreenHeight;
68
    private int mCurrentApiVersion;
69
    private ConfigScreen mScreen;
70
    private int mObjectOrdinal;
71
    private int mHeightBar;
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

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

    
83
      Bundle b = getIntent().getExtras();
84

    
85
      if(b != null) mObjectOrdinal = b.getInt("obj");
86

    
87
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
88

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

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
// this does not include possible insets
103

    
104
    private void computeBarHeights()
105
      {
106
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
107
      mHeightBar = barHeight;
108

    
109
      LinearLayout layout = findViewById(R.id.lowerBar);
110
      ViewGroup.LayoutParams params = layout.getLayoutParams();
111
      params.height = barHeight;
112
      layout.setLayoutParams(params);
113
      }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
    private void hideNavigationBar()
118
      {
119
      mCurrentApiVersion = Build.VERSION.SDK_INT;
120

    
121
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
122
        {
123
        final View decorView = getWindow().getDecorView();
124

    
125
        decorView.setSystemUiVisibility(FLAGS);
126

    
127
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
128
          {
129
          @Override
130
          public void onSystemUiVisibilityChange(int visibility)
131
            {
132
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
133
              {
134
              decorView.setSystemUiVisibility(FLAGS);
135
              }
136
            }
137
          });
138
        }
139
      }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
    @Override
144
    public void onAttachedToWindow()
145
      {
146
      super.onAttachedToWindow();
147

    
148
      if( mScreen==null ) mScreen = new ConfigScreen();
149
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
150
      }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
// do not avoid cutouts
154

    
155
    private void cutoutHack()
156
      {
157
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
158
        {
159
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
160
        }
161
      }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
    @Override
166
    public void onWindowFocusChanged(boolean hasFocus)
167
      {
168
      super.onWindowFocusChanged(hasFocus);
169

    
170
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
171
        {
172
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
173
        }
174
      }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
    
178
    @Override
179
    protected void onPause() 
180
      {
181
      super.onPause();
182
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
183
      view.onPause();
184
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
185
      }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
    
189
    @Override
190
    protected void onResume() 
191
      {
192
      super.onResume();
193
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
194
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
195
      view.onResume();
196

    
197
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
198
        {
199
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
200
        changeIfDifferent(object,view.getObjectControl());
201
        }
202
      }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205
    
206
    @Override
207
    protected void onDestroy() 
208
      {
209
      super.onDestroy();
210
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
211
      }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
    void OpenGLError()
216
      {
217
      RubikDialogError errDiag = new RubikDialogError();
218
      errDiag.show(getSupportFragmentManager(), null);
219
      }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
    private void changeIfDifferent(RubikObject object,ObjectControl control)
224
      {
225
      if( object!=null )
226
        {
227
        int jsonID = object.getJsonID();
228
        int meshID = object.getMeshID();
229

    
230
        int meshState = object.getMeshState();
231

    
232
        InputStream jsonStream = ObjectJson.getStream(jsonID,this);
233
        InputStream meshStream = ObjectMesh.getStream(meshID,this);
234

    
235
        control.changeIfDifferent(object.getOrdinal(),meshState,jsonStream,meshStream);
236
        }
237
      }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240
// PUBLIC API
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
    public void changeObject(RubikObject object)
244
      {
245
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
246
      ObjectControl control = view.getObjectControl();
247
      changeIfDifferent(object,control);
248
      }
249

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

    
252
    public void changeMeshState(RubikObject object)
253
      {
254
      if( object!=null )
255
        {
256
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
257
        ObjectControl control = view.getObjectControl();
258

    
259
        int jsonID = object.getJsonID();
260
        int meshID = object.getMeshID();
261

    
262
        int meshState = object.getMeshState();
263

    
264
        InputStream jsonStream = ObjectJson.getStream(jsonID,this);
265
        InputStream meshStream = ObjectMesh.getStream(meshID,this);
266

    
267
        control.changeObject(object.getOrdinal(),meshState,jsonStream,meshStream);
268
        }
269
      }
270

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

    
273
    public FirebaseAnalytics getAnalytics()
274
      {
275
      return mFirebaseAnalytics;
276
      }
277

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

    
280
    public int getHeightBar()
281
      {
282
      return mHeightBar;
283
      }
284

    
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286

    
287
    public int getScreenWidthInPixels()
288
      {
289
      return mScreenWidth;
290
      }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
    public int getScreenHeightInPixels()
295
      {
296
      return mScreenHeight;
297
      }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
    public ObjectControl getControl()
302
      {
303
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
304
      return view.getObjectControl();
305
      }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
    public static int getDrawableSize()
310
      {
311
      if( mScreenHeight<1000 )
312
        {
313
        return 0;
314
        }
315
      if( mScreenHeight<1600 )
316
        {
317
        return 1;
318
        }
319
      if( mScreenHeight<1900 )
320
        {
321
        return 2;
322
        }
323

    
324
      return 3;
325
      }
326

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328

    
329
    public static int getDrawable(int small, int medium, int big, int huge)
330
      {
331
      int size = getDrawableSize();
332

    
333
      switch(size)
334
        {
335
        case 0 : return small;
336
        case 1 : return medium;
337
        case 2 : return big;
338
        default: return huge;
339
        }
340
      }
341

    
342
///////////////////////////////////////////////////////////////////////////////////////////////////
343

    
344
    public boolean isVertical()
345
      {
346
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
347
      return view.isVertical();
348
      }
349
}
(1-1/6)