Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 16003ca8

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

    
23
import org.distorted.library.main.DistortedLibrary;
24
import org.distorted.objectlib.main.ObjectControl;
25
import org.distorted.main.R;
26
import org.distorted.dialogs.RubikDialogError;
27
import org.distorted.objectlib.main.TwistyObject;
28
import org.distorted.objects.RubikObject;
29
import org.distorted.objects.RubikObjectList;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

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

    
38
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
39
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
40
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
41
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
42
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
43

    
44
    private static int mScreenWidth, mScreenHeight;
45
    private int mCurrentApiVersion;
46
    private ConfigScreen mScreen;
47
    private int mObjectOrdinal;
48
    private int mHeightBar;
49

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

    
52
    @Override
53
    protected void onCreate(Bundle savedState)
54
      {
55
      super.onCreate(savedState);
56
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
57
      setTheme(R.style.MaterialThemeNoActionBar);
58
      setContentView(R.layout.config);
59

    
60
      Bundle b = getIntent().getExtras();
61

    
62
      if(b != null) mObjectOrdinal = b.getInt("obj");
63

    
64
      DisplayMetrics displaymetrics = new DisplayMetrics();
65
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
66
      mScreenWidth =displaymetrics.widthPixels;
67
      mScreenHeight=displaymetrics.heightPixels;
68

    
69
      hideNavigationBar();
70
      cutoutHack();
71
      computeBarHeights();
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
// this does not include possible insets
76

    
77
    private void computeBarHeights()
78
      {
79
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
80
      mHeightBar = barHeight;
81

    
82
      LinearLayout layout = findViewById(R.id.lowerBar);
83
      ViewGroup.LayoutParams params = layout.getLayoutParams();
84
      params.height = barHeight;
85
      layout.setLayoutParams(params);
86
      }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
    private void hideNavigationBar()
91
      {
92
      mCurrentApiVersion = Build.VERSION.SDK_INT;
93

    
94
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
95
        {
96
        final View decorView = getWindow().getDecorView();
97

    
98
        decorView.setSystemUiVisibility(FLAGS);
99

    
100
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
101
          {
102
          @Override
103
          public void onSystemUiVisibilityChange(int visibility)
104
            {
105
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
106
              {
107
              decorView.setSystemUiVisibility(FLAGS);
108
              }
109
            }
110
          });
111
        }
112
      }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
// do not avoid cutouts
116

    
117
    private void cutoutHack()
118
      {
119
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
120
        {
121
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
122
        }
123
      }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
    @Override
128
    public void onWindowFocusChanged(boolean hasFocus)
129
      {
130
      super.onWindowFocusChanged(hasFocus);
131

    
132
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
133
        {
134
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
135
        }
136
      }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
    
140
    @Override
141
    protected void onPause() 
142
      {
143
      super.onPause();
144
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
145
      view.onPause();
146
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
147
      }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
    
151
    @Override
152
    protected void onResume() 
153
      {
154
      super.onResume();
155
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
156
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
157
      view.onResume();
158

    
159
      if( mScreen==null ) mScreen = new ConfigScreen();
160
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
161

    
162
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
163
        {
164
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
165
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
166
        }
167
      }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
    
171
    @Override
172
    protected void onDestroy() 
173
      {
174
      super.onDestroy();
175
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
176
      }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

    
180
    void OpenGLError()
181
      {
182
      RubikDialogError errDiag = new RubikDialogError();
183
      errDiag.show(getSupportFragmentManager(), null);
184
      }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
189
      {
190
      if( object!=null )
191
        {
192
        int meshState          = object.getMeshState();
193
        int iconMode           = TwistyObject.MODE_NORM;
194
        InputStream jsonStream = object.getObjectStream(this);
195
        InputStream meshStream = object.getMeshStream(this);
196
        String name            = object.getUpperName();
197

    
198
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
199
        }
200
      }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203
// PUBLIC API
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
    public void changeObject(int ordinal)
207
      {
208
      mObjectOrdinal = ordinal;
209
      RubikObject object = RubikObjectList.getObject(ordinal);
210
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
211
      ObjectControl control = view.getObjectControl();
212
      changeIfDifferent(object,ordinal,control);
213
      }
214

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

    
217
    public void changeMeshState(RubikObject object, int ordinal)
218
      {
219
      if( object!=null )
220
        {
221
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
222
        ObjectControl control = view.getObjectControl();
223

    
224
        int meshState          = object.getMeshState();
225
        int iconMode           = TwistyObject.MODE_NORM;
226
        InputStream jsonStream = object.getObjectStream(this);
227
        InputStream meshStream = object.getMeshStream(this);
228

    
229
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
230
        }
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
}
(1-1/6)