Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorActivity.java @ bebd7af5

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.main.RubikActivity;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
public class BandagedCreatorActivity extends AppCompatActivity
42
{
43
    private static final int ACTIVITY_NUMBER = 3;
44
    private static final float RATIO_BAR   = 0.10f;
45
    private static final float RATIO_SCROLL= 0.30f;
46

    
47
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
48
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
49

    
50
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
51
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
52
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
53
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
54
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
55

    
56
    private FirebaseAnalytics mFirebaseAnalytics;
57
    private static int mScreenWidth, mScreenHeight;
58
    private int mCurrentApiVersion;
59
    private BandagedCreatorScreen mScreen;
60
    private int mHeightBar;
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
    @Override
65
    protected void onCreate(Bundle savedState)
66
      {
67
      super.onCreate(savedState);
68
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
69
      setTheme(R.style.MaterialThemeNoActionBar);
70
      setContentView(R.layout.bandaged);
71

    
72
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
73

    
74
      DisplayMetrics displaymetrics = new DisplayMetrics();
75
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
76
      mScreenWidth =displaymetrics.widthPixels;
77
      mScreenHeight=displaymetrics.heightPixels;
78
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
79
                                                  // which is not yet hidden.
80
                                                  // TODO: figure this out exactly.
81
      hideNavigationBar();
82
      cutoutHack();
83
      computeHeights();
84
      }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
// this does not include possible insets
88

    
89
    private void computeHeights()
90
      {
91
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
92
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
93
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL));
94
      mHeightBar = barHeight;
95

    
96
      LinearLayout layout = findViewById(R.id.lowerBar);
97
      ViewGroup.LayoutParams paramsL = layout.getLayoutParams();
98
      paramsL.height = barHeight;
99
      layout.setLayoutParams(paramsL);
100

    
101
      LinearLayout view = findViewById(R.id.bandagedCreatorView);
102
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
103
      paramsS.height = viewHeight;
104

    
105
      int p = (int)(mScreenHeight* RubikActivity.PADDING);
106
      view.setPadding(p,p,p,p);
107
      view.setLayoutParams(paramsS);
108

    
109
      BandagedCreatorView creator = findViewById(R.id.bandagedCreatorObjectView);
110
      ViewGroup.LayoutParams paramsC = creator.getLayoutParams();
111
      paramsC.height = objectHeight;
112
      creator.setLayoutParams(paramsC);
113
      }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
    private void hideNavigationBar()
118
      {
119
      mCurrentApiVersion = Build.VERSION.SDK_INT;
120

    
121
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
122
        {
123
        final View decorView = getWindow().getDecorView();
124

    
125
        decorView.setSystemUiVisibility(FLAGS);
126

    
127
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
128
          {
129
          @Override
130
          public void onSystemUiVisibilityChange(int visibility)
131
            {
132
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
133
              {
134
              decorView.setSystemUiVisibility(FLAGS);
135
              }
136
            }
137
          });
138
        }
139
      }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
// do not avoid cutouts
143

    
144
    private void cutoutHack()
145
      {
146
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
147
        {
148
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
149
        }
150
      }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
    @Override
155
    public void onWindowFocusChanged(boolean hasFocus)
156
      {
157
      super.onWindowFocusChanged(hasFocus);
158

    
159
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
160
        {
161
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
162
        }
163
      }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
    
167
    @Override
168
    protected void onPause() 
169
      {
170
      super.onPause();
171
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
172
      view.onPause();
173
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
174
      }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
    
178
    @Override
179
    protected void onResume() 
180
      {
181
      super.onResume();
182
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
183
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
184
      view.onResume();
185

    
186
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
187
      mScreen.onAttachedToWindow(this);
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
// PUBLIC API
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

    
211
    public FirebaseAnalytics getAnalytics()
212
      {
213
      return mFirebaseAnalytics;
214
      }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
    public int getHeightBar()
219
      {
220
      return mHeightBar;
221
      }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
    public int getScreenWidthInPixels()
226
      {
227
      return mScreenWidth;
228
      }
229

    
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
    public int getScreenHeightInPixels()
233
      {
234
      return mScreenHeight;
235
      }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

    
239
    public static int getDrawableSize()
240
      {
241
      if( mScreenHeight<1000 )
242
        {
243
        return 0;
244
        }
245
      if( mScreenHeight<1600 )
246
        {
247
        return 1;
248
        }
249
      if( mScreenHeight<1900 )
250
        {
251
        return 2;
252
        }
253

    
254
      return 3;
255
      }
256

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

    
259
    public static int getDrawable(int small, int medium, int big, int huge)
260
      {
261
      int size = getDrawableSize();
262

    
263
      switch(size)
264
        {
265
        case 0 : return small;
266
        case 1 : return medium;
267
        case 2 : return big;
268
        default: return huge;
269
        }
270
      }
271
}
(1-1/10)