Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayActivity.java @ 7cb8d4b0

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.bandaged;
21

    
22
import android.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.View;
26
import android.view.ViewGroup;
27
import android.view.WindowManager;
28
import android.widget.LinearLayout;
29

    
30
import androidx.appcompat.app.AppCompatActivity;
31

    
32
import com.google.firebase.analytics.FirebaseAnalytics;
33

    
34
import org.distorted.dialogs.RubikDialogError;
35
import org.distorted.library.main.DistortedLibrary;
36
import org.distorted.main.R;
37
import org.distorted.objectlib.main.ObjectControl;
38
import org.distorted.objectlib.main.TwistyObject;
39
import org.distorted.objects.RubikObject;
40
import org.distorted.objects.RubikObjectList;
41

    
42
import java.io.InputStream;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
public class BandagedPlayActivity extends AppCompatActivity
47
{
48
    private static final int ACTIVITY_NUMBER = 4;
49
    private static final float RATIO_BAR  = 0.10f;
50

    
51
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
52
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
53

    
54
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
55
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
56
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
57
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
58
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
59

    
60
    private FirebaseAnalytics mFirebaseAnalytics;
61
    private static int mScreenWidth, mScreenHeight;
62
    private int mCurrentApiVersion;
63
    private BandagedPlayScreen mScreen;
64
    private int mObjectOrdinal;
65
    private int mHeightBar;
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
    @Override
70
    protected void onCreate(Bundle savedState)
71
      {
72
      super.onCreate(savedState);
73
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
74
      setTheme(R.style.MaterialThemeNoActionBar);
75
      setContentView(R.layout.bandaged_play);
76

    
77
      Bundle b = getIntent().getExtras();
78

    
79
      if(b != null) mObjectOrdinal = b.getInt("obj");
80

    
81
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
82

    
83
      DisplayMetrics displaymetrics = new DisplayMetrics();
84
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
85
      mScreenWidth =displaymetrics.widthPixels;
86
      mScreenHeight=displaymetrics.heightPixels;
87
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
88
                                                  // which is not yet hidden.
89
                                                  // TODO: figure this out exactly.
90
      hideNavigationBar();
91
      cutoutHack();
92
      computeBarHeights();
93
      }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// this does not include possible insets
97

    
98
    private void computeBarHeights()
99
      {
100
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
101
      mHeightBar = barHeight;
102

    
103
      LinearLayout layout = findViewById(R.id.lowerBar);
104
      ViewGroup.LayoutParams params = layout.getLayoutParams();
105
      params.height = barHeight;
106
      layout.setLayoutParams(params);
107
      }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
    private void hideNavigationBar()
112
      {
113
      mCurrentApiVersion = Build.VERSION.SDK_INT;
114

    
115
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
116
        {
117
        final View decorView = getWindow().getDecorView();
118

    
119
        decorView.setSystemUiVisibility(FLAGS);
120

    
121
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
122
          {
123
          @Override
124
          public void onSystemUiVisibilityChange(int visibility)
125
            {
126
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
127
              {
128
              decorView.setSystemUiVisibility(FLAGS);
129
              }
130
            }
131
          });
132
        }
133
      }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
// do not avoid cutouts
137

    
138
    private void cutoutHack()
139
      {
140
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
141
        {
142
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
143
        }
144
      }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
    @Override
149
    public void onWindowFocusChanged(boolean hasFocus)
150
      {
151
      super.onWindowFocusChanged(hasFocus);
152

    
153
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
154
        {
155
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
156
        }
157
      }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
    
161
    @Override
162
    protected void onPause() 
163
      {
164
      super.onPause();
165
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
166
      view.onPause();
167
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
168
      }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
    
172
    @Override
173
    protected void onResume() 
174
      {
175
      super.onResume();
176
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
177
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
178
      view.onResume();
179

    
180
      if( mScreen==null ) mScreen = new BandagedPlayScreen();
181
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
182

    
183
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
184
        {
185
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
186
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
187
        }
188
      }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
    
192
    @Override
193
    protected void onDestroy() 
194
      {
195
      super.onDestroy();
196
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
197
      }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
    void OpenGLError()
202
      {
203
      RubikDialogError errDiag = new RubikDialogError();
204
      errDiag.show(getSupportFragmentManager(), null);
205
      }
206

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

    
209
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
210
      {
211
      if( object!=null )
212
        {
213
        int meshState          = object.getMeshState();
214
        int iconMode           = TwistyObject.MODE_NORM;
215
        InputStream jsonStream = object.getObjectStream(this);
216
        InputStream meshStream = object.getMeshStream(this);
217
        String name            = object.getUpperName();
218

    
219
        control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
220
        }
221
      }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224
// PUBLIC API
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
    public void changeObject(int ordinal)
228
      {
229
      mObjectOrdinal = ordinal;
230
      RubikObject object = RubikObjectList.getObject(ordinal);
231
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
232
      ObjectControl control = view.getObjectControl();
233
      changeIfDifferent(object,ordinal,control);
234
      }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
    public FirebaseAnalytics getAnalytics()
239
      {
240
      return mFirebaseAnalytics;
241
      }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
    public int getHeightBar()
246
      {
247
      return mHeightBar;
248
      }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
    public int getScreenWidthInPixels()
253
      {
254
      return mScreenWidth;
255
      }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

    
259
    public int getScreenHeightInPixels()
260
      {
261
      return mScreenHeight;
262
      }
263

    
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

    
266
    public ObjectControl getControl()
267
      {
268
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
269
      return view.getObjectControl();
270
      }
271

    
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

    
274
    public static int getDrawableSize()
275
      {
276
      if( mScreenHeight<1000 )
277
        {
278
        return 0;
279
        }
280
      if( mScreenHeight<1600 )
281
        {
282
        return 1;
283
        }
284
      if( mScreenHeight<1900 )
285
        {
286
        return 2;
287
        }
288

    
289
      return 3;
290
      }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
    public static int getDrawable(int small, int medium, int big, int huge)
295
      {
296
      int size = getDrawableSize();
297

    
298
      switch(size)
299
        {
300
        case 0 : return small;
301
        case 1 : return medium;
302
        case 2 : return big;
303
        default: return huge;
304
        }
305
      }
306

    
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

    
309
    public boolean isVertical()
310
      {
311
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
312
      return view.isVertical();
313
      }
314
}
(8-8/13)