Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 71cda061

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 float DIALOG_BUTTON_SIZE  = 0.06f;
39
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
40

    
41
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
42
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
43
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
44
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
45
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
46

    
47
    private static int mScreenWidth, mScreenHeight;
48
    private int mCurrentApiVersion;
49
    private ConfigScreen mScreen;
50
    private int mObjectOrdinal;
51
    private int mHeightBar;
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

    
63
      Bundle b = getIntent().getExtras();
64

    
65
      if(b != null) mObjectOrdinal = b.getInt("obj");
66

    
67
      DisplayMetrics displaymetrics = new DisplayMetrics();
68
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
69
      mScreenWidth =displaymetrics.widthPixels;
70
      mScreenHeight=displaymetrics.heightPixels;
71

    
72
      hideNavigationBar();
73
      cutoutHack();
74
      computeBarHeights();
75
      }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// this does not include possible insets
79

    
80
    private void computeBarHeights()
81
      {
82
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
83
      mHeightBar = barHeight;
84

    
85
      LinearLayout layout = findViewById(R.id.lowerBar);
86
      ViewGroup.LayoutParams params = layout.getLayoutParams();
87
      params.height = barHeight;
88
      layout.setLayoutParams(params);
89
      }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
    private void hideNavigationBar()
94
      {
95
      mCurrentApiVersion = Build.VERSION.SDK_INT;
96

    
97
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
98
        {
99
        final View decorView = getWindow().getDecorView();
100

    
101
        decorView.setSystemUiVisibility(FLAGS);
102

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

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
// do not avoid cutouts
119

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
    @Override
131
    public void onWindowFocusChanged(boolean hasFocus)
132
      {
133
      super.onWindowFocusChanged(hasFocus);
134

    
135
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
136
        {
137
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
138
        }
139
      }
140

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

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

    
162
      if( mScreen==null ) mScreen = new ConfigScreen();
163
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
164

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

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
    
174
    @Override
175
    protected void onDestroy() 
176
      {
177
      super.onDestroy();
178
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
179
      }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
    void OpenGLError()
184
      {
185
      RubikDialogError errDiag = new RubikDialogError();
186
      errDiag.show(getSupportFragmentManager(), null);
187
      }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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

    
201
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
202
        }
203
      }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
// PUBLIC API
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

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

    
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

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

    
227
        int meshState          = object.getMeshState();
228
        int iconMode           = TwistyObject.MODE_NORM;
229
        InputStream jsonStream = object.getObjectStream(this);
230
        InputStream meshStream = object.getMeshStream(this);
231

    
232
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
233
        }
234
      }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
    public int getHeightBar()
239
      {
240
      return mHeightBar;
241
      }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
    public int getScreenWidthInPixels()
246
      {
247
      return mScreenWidth;
248
      }
249

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

    
252
    public int getScreenHeightInPixels()
253
      {
254
      return mScreenHeight;
255
      }
256

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

    
259
    public ObjectControl getControl()
260
      {
261
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
262
      return view.getObjectControl();
263
      }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

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

    
282
      return 3;
283
      }
284

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

    
287
    public static int getDrawable(int small, int medium, int big, int huge)
288
      {
289
      int size = getDrawableSize();
290

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

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

    
302
    public boolean isVertical()
303
      {
304
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
305
      return view.isVertical();
306
      }
307
}
(1-1/6)