Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigActivity.java @ 58fd2ec0

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.effect.MatrixEffectQuaternion;
24
import org.distorted.library.main.DistortedLibrary;
25
import org.distorted.main.MainActivity;
26
import org.distorted.main.R;
27
import org.distorted.objectlib.main.InitAssets;
28
import org.distorted.objectlib.main.ObjectControl;
29
import org.distorted.objectlib.main.TwistyObject;
30
import org.distorted.objects.RubikObject;
31
import org.distorted.objects.RubikObjectList;
32

    
33
import java.io.InputStream;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

    
43
    private static int mScreenWidth, mScreenHeight;
44
    private int mCurrentApiVersion;
45
    private ConfigScreen mScreen;
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

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

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

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

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

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

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

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
// PUBLIC API
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
    public ConfigRenderer getRenderer()
202
      {
203
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
204
      return view.getRenderer();
205
      }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
    public int getScreenWidthInPixels()
210
      {
211
      return mScreenWidth;
212
      }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
    public int getScreenHeightInPixels()
217
      {
218
      return mScreenHeight;
219
      }
220

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

    
223
    public ObjectControl getControl()
224
      {
225
      ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
226
      return view.getObjectControl();
227
      }
228
}
(1-1/6)