Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ b2a1b787

1 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 9d51b9d6 Leszek Koltunski
// 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 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.config;
11
12 314e9ff0 Leszek Koltunski
import java.io.InputStream;
13
14 1237d25d Leszek Koltunski
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 314e9ff0 Leszek Koltunski
import org.distorted.main.R;
26
import org.distorted.dialogs.RubikDialogError;
27 7cb8d4b0 Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
28 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObject;
29
import org.distorted.objects.RubikObjectList;
30 1237d25d Leszek Koltunski
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33
public class ConfigActivity extends AppCompatActivity
34
{
35
    private static final int ACTIVITY_NUMBER = 2;
36 97a4ae23 Leszek Koltunski
    private static final float RATIO_BAR  = 0.10f;
37 1237d25d Leszek Koltunski
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 97a4ae23 Leszek Koltunski
    private int mHeightBar;
52 1237d25d Leszek Koltunski
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 7fe59aa5 Leszek Koltunski
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
69 1237d25d Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
70
      mScreenHeight=displaymetrics.heightPixels;
71 7fe59aa5 Leszek Koltunski
72 1237d25d Leszek Koltunski
      hideNavigationBar();
73
      cutoutHack();
74 97a4ae23 Leszek Koltunski
      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 1237d25d Leszek Koltunski
      }
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 280dc794 Leszek Koltunski
      if( mScreen==null ) mScreen = new ConfigScreen();
163
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
164
165 d433b50e Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
166 1237d25d Leszek Koltunski
        {
167 d433b50e Leszek Koltunski
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
168 d36d8517 Leszek Koltunski
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
169 1237d25d Leszek Koltunski
        }
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 d36d8517 Leszek Koltunski
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
192 1237d25d Leszek Koltunski
      {
193 d433b50e Leszek Koltunski
      if( object!=null )
194
        {
195 314e9ff0 Leszek Koltunski
        int meshState          = object.getMeshState();
196 7cb8d4b0 Leszek Koltunski
        int iconMode           = TwistyObject.MODE_NORM;
197 314e9ff0 Leszek Koltunski
        InputStream jsonStream = object.getObjectStream(this);
198
        InputStream meshStream = object.getMeshStream(this);
199 aec421fd Leszek Koltunski
        String name            = object.getUpperName();
200 09cf2a36 Leszek Koltunski
201 7cb8d4b0 Leszek Koltunski
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
202 d433b50e Leszek Koltunski
        }
203 1237d25d Leszek Koltunski
      }
204
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
// PUBLIC API
207 09cf2a36 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
208
209 280dc794 Leszek Koltunski
    public void changeObject(int ordinal)
210 09cf2a36 Leszek Koltunski
      {
211 280dc794 Leszek Koltunski
      mObjectOrdinal = ordinal;
212
      RubikObject object = RubikObjectList.getObject(ordinal);
213 09cf2a36 Leszek Koltunski
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
214
      ObjectControl control = view.getObjectControl();
215 d36d8517 Leszek Koltunski
      changeIfDifferent(object,ordinal,control);
216 09cf2a36 Leszek Koltunski
      }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220 d36d8517 Leszek Koltunski
    public void changeMeshState(RubikObject object, int ordinal)
221 09cf2a36 Leszek Koltunski
      {
222
      if( object!=null )
223
        {
224
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
225
        ObjectControl control = view.getObjectControl();
226
227 314e9ff0 Leszek Koltunski
        int meshState          = object.getMeshState();
228 7cb8d4b0 Leszek Koltunski
        int iconMode           = TwistyObject.MODE_NORM;
229 314e9ff0 Leszek Koltunski
        InputStream jsonStream = object.getObjectStream(this);
230
        InputStream meshStream = object.getMeshStream(this);
231 09cf2a36 Leszek Koltunski
232 7cb8d4b0 Leszek Koltunski
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
233 09cf2a36 Leszek Koltunski
        }
234
      }
235
236 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
237
238 97a4ae23 Leszek Koltunski
    public int getHeightBar()
239 1237d25d Leszek Koltunski
      {
240 97a4ae23 Leszek Koltunski
      return mHeightBar;
241 1237d25d Leszek Koltunski
      }
242
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
245
    public int getScreenWidthInPixels()
246
      {
247
      return mScreenWidth;
248
      }
249
250 97a4ae23 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
251
252
    public int getScreenHeightInPixels()
253
      {
254
      return mScreenHeight;
255
      }
256
257 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}