Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 4bd09fe2

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 android.os.Build;
13
import android.os.Bundle;
14
import android.util.DisplayMetrics;
15
import android.view.View;
16
import android.view.ViewGroup;
17
import android.view.WindowManager;
18
import android.widget.LinearLayout;
19

    
20
import androidx.appcompat.app.AppCompatActivity;
21

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

    
32
import java.io.InputStream;
33

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

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

    
42
    private static int mScreenWidth, mScreenHeight;
43
    private ConfigScreen mScreen;
44
    private ConfigScreenPane mPane;
45
    private int mCurrentApiVersion;
46
    private int mObjectOrdinal;
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
      LinearLayout layout = findViewById(R.id.lowerBar);
79
      ViewGroup.LayoutParams params = layout.getLayoutParams();
80
      params.height = barHeight;
81
      layout.setLayoutParams(params);
82
      }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
    private void hideNavigationBar()
87
      {
88
      mCurrentApiVersion = Build.VERSION.SDK_INT;
89

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

    
94
        decorView.setSystemUiVisibility(FLAGS);
95

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

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
// do not avoid cutouts
112

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

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

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

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

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

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

    
155
      if( mScreen==null ) mScreen = new ConfigScreen();
156
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
157
      mPane = new ConfigScreenPane(this,mObjectOrdinal);
158

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

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
    void repaintPuzzleFace(int cubit, int face)
169
      {
170
      if( mPane!=null )
171
        {
172
        int color  = mPane.getCurrentColor();
173
        int borders= mPane.getCurrentBorders();
174
        int corners= mPane.getCurrentCorners();
175
        float border_step = ConfigScreenPane.BORDER_STEPS[borders];
176
        float corner_step = ConfigScreenPane.CORNER_STEPS[corners];
177

    
178
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
179
        ObjectControl control = view.getObjectControl();
180
        control.repaintPuzzleFace(cubit,face,color,border_step,corner_step);
181
        }
182
      }
183

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

    
186
    @Override
187
    protected void onDestroy() 
188
      {
189
      super.onDestroy();
190
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
191
      }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
    void OpenGLError()
196
      {
197
      RubikDialogError errDiag = new RubikDialogError();
198
      errDiag.show(getSupportFragmentManager(), null);
199
      }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
204
      {
205
      if( object!=null )
206
        {
207
        int iconMode           = TwistyObject.MODE_NORM;
208
        InputStream jsonStream = object.getObjectStream(this);
209
        InputStream meshStream = object.getMeshStream(this);
210
        String name            = object.getUpperName();
211
        InitAssets asset       = new InitAssets(jsonStream,meshStream,null);
212
        control.changeIfDifferent(ordinal,name,iconMode,asset);
213
        }
214
      }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217
// PUBLIC API
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

    
220
    public ConfigRenderer getRenderer()
221
      {
222
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
223
      return view.getRenderer();
224
      }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
    public void recreateStickers(int borders, int corners)
229
      {
230
      ObjectControl control = getControl();
231

    
232
      float border_step = ConfigScreenPane.BORDER_STEPS[borders];
233
      float corner_step = ConfigScreenPane.CORNER_STEPS[corners];
234

    
235
      control.recreateSticker(border_step,corner_step);
236
      }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
    public void resetUI()
241
      {
242
      mPane.resetUI(this);
243
      }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
    public int getScreenWidthInPixels()
248
      {
249
      return mScreenWidth;
250
      }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

    
254
    public int getScreenHeightInPixels()
255
      {
256
      return mScreenHeight;
257
      }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
    public ObjectControl getControl()
262
      {
263
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
264
      return view.getObjectControl();
265
      }
266
}
(1-1/6)