Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorActivity.java @ 13a3dfa9

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
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 7cb8d4b0 Leszek Koltunski
import android.graphics.Bitmap;
23 9530f6b0 Leszek Koltunski
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 e48ad1af Leszek Koltunski
import android.widget.HorizontalScrollView;
30 9530f6b0 Leszek Koltunski
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 48314d6a Leszek Koltunski
import org.distorted.main.RubikActivity;
40 9530f6b0 Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43
public class BandagedCreatorActivity extends AppCompatActivity
44
{
45
    private static final int ACTIVITY_NUMBER = 3;
46 28cb1607 Leszek Koltunski
    private static final float RATIO_BAR   = 0.10f;
47 83e021c5 Leszek Koltunski
    static final float RATIO_SCROLL= 0.30f;
48 9530f6b0 Leszek Koltunski
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 48314d6a Leszek Koltunski
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
95 bc7e49ec Leszek Koltunski
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
96 9530f6b0 Leszek Koltunski
      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 e48ad1af Leszek Koltunski
      HorizontalScrollView view = findViewById(R.id.bandagedCreatorScrollView);
104 48314d6a Leszek Koltunski
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
105
      paramsS.height = viewHeight;
106 9530f6b0 Leszek Koltunski
107 48314d6a Leszek Koltunski
      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 9530f6b0 Leszek Koltunski
      }
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 48314d6a Leszek Koltunski
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
174 9530f6b0 Leszek Koltunski
      view.onPause();
175
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
176 13a3dfa9 Leszek Koltunski
      savePreferences();
177 9530f6b0 Leszek Koltunski
      }
178
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
    
181
    @Override
182
    protected void onResume() 
183
      {
184
      super.onResume();
185
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
186 48314d6a Leszek Koltunski
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
187 9530f6b0 Leszek Koltunski
      view.onResume();
188 13a3dfa9 Leszek Koltunski
      restorePreferences();
189 9530f6b0 Leszek Koltunski
190
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
191 bebd7af5 Leszek Koltunski
      mScreen.onAttachedToWindow(this);
192 7cb8d4b0 Leszek Koltunski
193
      BandagedCreatorWorkerThread.create(this);
194 9530f6b0 Leszek Koltunski
      }
195
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197
    
198
    @Override
199
    protected void onDestroy() 
200
      {
201
      super.onDestroy();
202
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
203
      }
204
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
207
    void OpenGLError()
208
      {
209
      RubikDialogError errDiag = new RubikDialogError();
210
      errDiag.show(getSupportFragmentManager(), null);
211
      }
212
213 13a3dfa9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
214
215
    private void savePreferences()
216
      {
217
      /*
218
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
219
      SharedPreferences.Editor editor = preferences.edit();
220
221
      editor.putBoolean("policyAccepted", mPolicyAccepted);
222
      editor.putString("appVersion", getAppVers() );
223
224
      editor.apply();
225
       */
226
      }
227
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
230
    private void restorePreferences()
231
      {
232
      /*
233
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
234
235
      mPolicyAccepted = preferences.getBoolean("policyAccepted", false);
236
      String oldVersion = preferences.getString("appVersion","");
237
       */
238
      }
239
240 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
241
// PUBLIC API
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
    public FirebaseAnalytics getAnalytics()
245
      {
246
      return mFirebaseAnalytics;
247
      }
248
249 50ec342b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
250
251
    public BandagedCreatorRenderer getRenderer()
252
      {
253
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
254
      return view.getRenderer();
255
      }
256
257 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
258
259
    public void addObject(String name)
260
      {
261
      mScreen.addObject(this,name);
262
      }
263
264 d3d639b1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
265
266
    public void deleteObject(String name)
267
      {
268
      mScreen.deleteObject(this,name);
269
      }
270
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272
273
    public void playObject(String name)
274
      {
275
276
      }
277
278 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
279
280 7cb8d4b0 Leszek Koltunski
    public void iconCreationDone(Bitmap bmp)
281 9530f6b0 Leszek Koltunski
      {
282 20b60ad9 Leszek Koltunski
      mScreen.iconCreationDone(this,bmp);
283 9530f6b0 Leszek Koltunski
      }
284
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286
287
    public int getScreenWidthInPixels()
288
      {
289
      return mScreenWidth;
290
      }
291
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293
294
    public int getScreenHeightInPixels()
295
      {
296
      return mScreenHeight;
297
      }
298
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
301
    public static int getDrawableSize()
302
      {
303
      if( mScreenHeight<1000 )
304
        {
305
        return 0;
306
        }
307
      if( mScreenHeight<1600 )
308
        {
309
        return 1;
310
        }
311
      if( mScreenHeight<1900 )
312
        {
313
        return 2;
314
        }
315
316
      return 3;
317
      }
318
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
321
    public static int getDrawable(int small, int medium, int big, int huge)
322
      {
323
      int size = getDrawableSize();
324
325
      switch(size)
326
        {
327
        case 0 : return small;
328
        case 1 : return medium;
329
        case 2 : return big;
330
        default: return huge;
331
        }
332
      }
333
}