Project

General

Profile

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

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

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 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 97a4ae23 Leszek Koltunski
    private int mHeightBar;
49 1237d25d Leszek Koltunski
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 7fe59aa5 Leszek Koltunski
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
66 1237d25d Leszek Koltunski
      mScreenWidth =displaymetrics.widthPixels;
67
      mScreenHeight=displaymetrics.heightPixels;
68 7fe59aa5 Leszek Koltunski
69 1237d25d Leszek Koltunski
      hideNavigationBar();
70
      cutoutHack();
71 97a4ae23 Leszek Koltunski
      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 1237d25d Leszek Koltunski
      }
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 280dc794 Leszek Koltunski
      if( mScreen==null ) mScreen = new ConfigScreen();
160
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
161
162 d433b50e Leszek Koltunski
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
163 1237d25d Leszek Koltunski
        {
164 d433b50e Leszek Koltunski
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
165 d36d8517 Leszek Koltunski
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
166 1237d25d Leszek Koltunski
        }
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 d36d8517 Leszek Koltunski
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
189 1237d25d Leszek Koltunski
      {
190 d433b50e Leszek Koltunski
      if( object!=null )
191
        {
192 314e9ff0 Leszek Koltunski
        int meshState          = object.getMeshState();
193 7cb8d4b0 Leszek Koltunski
        int iconMode           = TwistyObject.MODE_NORM;
194 314e9ff0 Leszek Koltunski
        InputStream jsonStream = object.getObjectStream(this);
195
        InputStream meshStream = object.getMeshStream(this);
196 aec421fd Leszek Koltunski
        String name            = object.getUpperName();
197 09cf2a36 Leszek Koltunski
198 7cb8d4b0 Leszek Koltunski
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
199 d433b50e Leszek Koltunski
        }
200 1237d25d Leszek Koltunski
      }
201
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203
// PUBLIC API
204 09cf2a36 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
205
206 280dc794 Leszek Koltunski
    public void changeObject(int ordinal)
207 09cf2a36 Leszek Koltunski
      {
208 280dc794 Leszek Koltunski
      mObjectOrdinal = ordinal;
209
      RubikObject object = RubikObjectList.getObject(ordinal);
210 09cf2a36 Leszek Koltunski
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
211
      ObjectControl control = view.getObjectControl();
212 d36d8517 Leszek Koltunski
      changeIfDifferent(object,ordinal,control);
213 09cf2a36 Leszek Koltunski
      }
214
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 d36d8517 Leszek Koltunski
    public void changeMeshState(RubikObject object, int ordinal)
218 09cf2a36 Leszek Koltunski
      {
219
      if( object!=null )
220
        {
221
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
222
        ObjectControl control = view.getObjectControl();
223
224 314e9ff0 Leszek Koltunski
        int meshState          = object.getMeshState();
225 7cb8d4b0 Leszek Koltunski
        int iconMode           = TwistyObject.MODE_NORM;
226 314e9ff0 Leszek Koltunski
        InputStream jsonStream = object.getObjectStream(this);
227
        InputStream meshStream = object.getMeshStream(this);
228 09cf2a36 Leszek Koltunski
229 7cb8d4b0 Leszek Koltunski
        control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
230 09cf2a36 Leszek Koltunski
        }
231
      }
232
233 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
234
235 97a4ae23 Leszek Koltunski
    public int getHeightBar()
236 1237d25d Leszek Koltunski
      {
237 97a4ae23 Leszek Koltunski
      return mHeightBar;
238 1237d25d Leszek Koltunski
      }
239
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
242
    public int getScreenWidthInPixels()
243
      {
244
      return mScreenWidth;
245
      }
246
247 97a4ae23 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249
    public int getScreenHeightInPixels()
250
      {
251
      return mScreenHeight;
252
      }
253
254 1237d25d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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
}