Project

General

Profile

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

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

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
        ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
174
        ObjectControl control = view.getObjectControl();
175
        control.repaintPuzzleFace(cubit,face,color);
176
        }
177
      }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
    @Override
182
    protected void onDestroy() 
183
      {
184
      super.onDestroy();
185
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
186
      }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
    void OpenGLError()
191
      {
192
      RubikDialogError errDiag = new RubikDialogError();
193
      errDiag.show(getSupportFragmentManager(), null);
194
      }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212
// PUBLIC API
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
    public ConfigRenderer getRenderer()
216
      {
217
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
218
      return view.getRenderer();
219
      }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
    public void recreateStickers(int borders, int corners)
224
      {
225
      ObjectControl control = getControl();
226

    
227
      float border_step = ConfigScreenPane.BORDER_STEPS[borders];
228
      float corner_step = ConfigScreenPane.CORNER_STEPS[corners];
229

    
230
      control.recreateSticker(border_step,corner_step);
231
      }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
    public void resetUI()
236
      {
237
      mPane.resetUI();
238
      }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241

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

    
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

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

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

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