Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorActivity.java @ 83e021c5

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.graphics.Bitmap;
23
import android.os.Build;
24
import android.os.Bundle;
25
import android.util.DisplayMetrics;
26
import android.view.View;
27
import android.view.ViewGroup;
28
import android.view.WindowManager;
29
import android.widget.HorizontalScrollView;
30
import android.widget.LinearLayout;
31

    
32
import androidx.appcompat.app.AppCompatActivity;
33

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

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

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

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

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

    
74
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
75

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

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

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

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

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

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

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

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

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

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

    
127
        decorView.setSystemUiVisibility(FLAGS);
128

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

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
// do not avoid cutouts
145

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

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

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

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

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

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

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

    
191
      BandagedCreatorWorkerThread.create(this);
192
      }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
    
196
    @Override
197
    protected void onDestroy() 
198
      {
199
      super.onDestroy();
200
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
201
      }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
    void OpenGLError()
206
      {
207
      RubikDialogError errDiag = new RubikDialogError();
208
      errDiag.show(getSupportFragmentManager(), null);
209
      }
210

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

    
215
    public FirebaseAnalytics getAnalytics()
216
      {
217
      return mFirebaseAnalytics;
218
      }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
    public BandagedCreatorRenderer getRenderer()
223
      {
224
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
225
      return view.getRenderer();
226
      }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
    public void addObject(String name)
231
      {
232
      mScreen.addObject(this,name);
233
      }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
    public void iconCreationDone(Bitmap bmp)
238
      {
239
      mScreen.iconCreationDone(this,bmp);
240
      }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
    public int getScreenWidthInPixels()
245
      {
246
      return mScreenWidth;
247
      }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

    
251
    public int getScreenHeightInPixels()
252
      {
253
      return mScreenHeight;
254
      }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

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

    
273
      return 3;
274
      }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

    
278
    public static int getDrawable(int small, int medium, int big, int huge)
279
      {
280
      int size = getDrawableSize();
281

    
282
      switch(size)
283
        {
284
        case 0 : return small;
285
        case 1 : return medium;
286
        case 2 : return big;
287
        default: return huge;
288
        }
289
      }
290
}
(1-1/13)