Project

General

Profile

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

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

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.HorizontalScrollView;
29
import android.widget.LinearLayout;
30

    
31
import androidx.appcompat.app.AppCompatActivity;
32

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

    
35
import org.distorted.dialogs.RubikDialogError;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.main.R;
38
import org.distorted.main.RubikActivity;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

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

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

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

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

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

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

    
73
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
74

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

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

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

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

    
102
      HorizontalScrollView view = findViewById(R.id.bandagedCreatorScrollView);
103
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
104
      paramsS.height = viewHeight;
105

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

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

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

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

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

    
126
        decorView.setSystemUiVisibility(FLAGS);
127

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

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
// do not avoid cutouts
144

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

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

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

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

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

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

    
187
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
188
      mScreen.onAttachedToWindow(this);
189
      }
190

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

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

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

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
// PUBLIC API
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

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

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
    public BandagedCreatorRenderer getRenderer()
220
      {
221
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
222
      return view.getRenderer();
223
      }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
    public void addObject(String name)
228
      {
229
      mScreen.addObject(this,name);
230
      }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
    public int getHeightBar()
235
      {
236
      return mHeightBar;
237
      }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

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

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

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

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
    public static int getDrawableSize()
256
      {
257
      if( mScreenHeight<1000 )
258
        {
259
        return 0;
260
        }
261
      if( mScreenHeight<1600 )
262
        {
263
        return 1;
264
        }
265
      if( mScreenHeight<1900 )
266
        {
267
        return 2;
268
        }
269

    
270
      return 3;
271
      }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
    public static int getDrawable(int small, int medium, int big, int huge)
276
      {
277
      int size = getDrawableSize();
278

    
279
      switch(size)
280
        {
281
        case 0 : return small;
282
        case 1 : return medium;
283
        case 2 : return big;
284
        default: return huge;
285
        }
286
      }
287
}
(1-1/12)