Project

General

Profile

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

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

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.main.MainActivity;
25
import org.distorted.main_old.RubikActivity;
26
import org.distorted.objectlib.main.InitAssets;
27
import org.distorted.objectlib.main.ObjectControl;
28
import org.distorted.main.R;
29
import org.distorted.dialogs.RubikDialogError;
30
import org.distorted.objectlib.main.TwistyObject;
31
import org.distorted.objects.RubikObject;
32
import org.distorted.objects.RubikObjectList;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class ConfigActivity extends AppCompatActivity
37
{
38
    private static final int ACTIVITY_NUMBER = 2;
39
    private static final float RATIO_BAR  = MainActivity.RATIO_BAR;
40
    public static final int FLAGS = RubikActivity.FLAGS;
41

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

    
58
      Bundle b = getIntent().getExtras();
59

    
60
      if(b != null) mObjectOrdinal = b.getInt("obj");
61

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

    
67
      hideNavigationBar();
68
      cutoutHack();
69
      computeBarHeights();
70
      }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
// this does not include possible insets
74

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

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

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
    private void hideNavigationBar()
89
      {
90
      mCurrentApiVersion = Build.VERSION.SDK_INT;
91

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

    
96
        decorView.setSystemUiVisibility(FLAGS);
97

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

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
// do not avoid cutouts
114

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

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

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

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

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

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

    
157
      if( mScreen==null ) mScreen = new ConfigScreen();
158
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
159

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

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

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

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

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

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

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201
// PUBLIC API
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

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

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

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

    
222
        int meshState          = object.getMeshState();
223
        int iconMode           = TwistyObject.MODE_NORM;
224
        InputStream jsonStream = object.getObjectStream(this);
225
        InputStream meshStream = object.getMeshStream(this);
226
        InitAssets asset       = new InitAssets(jsonStream,meshStream,null);
227

    
228
        control.changeObject(ordinal,meshState,iconMode,asset);
229
        }
230
      }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
    public int getHeightBar()
235
      {
236
      return mHeightBar;
237
      }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

    
241
    public int getScreenWidthInPixels()
242
      {
243
      return mScreenWidth;
244
      }
245

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
    public int getScreenHeightInPixels()
249
      {
250
      return mScreenHeight;
251
      }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
    public ObjectControl getControl()
256
      {
257
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
258
      return view.getObjectControl();
259
      }
260
}
(1-1/6)