Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorActivity.java @ 58d6a40d

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 a41e3c94 Leszek Koltunski
import android.content.SharedPreferences;
23 7cb8d4b0 Leszek Koltunski
import android.graphics.Bitmap;
24 9530f6b0 Leszek Koltunski
import android.os.Build;
25
import android.os.Bundle;
26 a41e3c94 Leszek Koltunski
import android.preference.PreferenceManager;
27 9530f6b0 Leszek Koltunski
import android.util.DisplayMetrics;
28
import android.view.View;
29
import android.view.ViewGroup;
30
import android.view.WindowManager;
31
import android.widget.LinearLayout;
32
33
import androidx.appcompat.app.AppCompatActivity;
34
35
import com.google.firebase.analytics.FirebaseAnalytics;
36
37
import org.distorted.dialogs.RubikDialogError;
38 81493402 Leszek Koltunski
import org.distorted.external.RubikFiles;
39 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
40
import org.distorted.main.R;
41 48314d6a Leszek Koltunski
import org.distorted.main.RubikActivity;
42 9530f6b0 Leszek Koltunski
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45
public class BandagedCreatorActivity extends AppCompatActivity
46
{
47
    private static final int ACTIVITY_NUMBER = 3;
48 28cb1607 Leszek Koltunski
    private static final float RATIO_BAR   = 0.10f;
49 83e021c5 Leszek Koltunski
    static final float RATIO_SCROLL= 0.30f;
50 9530f6b0 Leszek Koltunski
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 BandagedCreatorScreen mScreen;
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67
    @Override
68
    protected void onCreate(Bundle savedState)
69
      {
70
      super.onCreate(savedState);
71
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
72
      setTheme(R.style.MaterialThemeNoActionBar);
73
      setContentView(R.layout.bandaged);
74
75
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
76
77
      DisplayMetrics displaymetrics = new DisplayMetrics();
78
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
79
      mScreenWidth =displaymetrics.widthPixels;
80
      mScreenHeight=displaymetrics.heightPixels;
81
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
82
                                                  // which is not yet hidden.
83
                                                  // TODO: figure this out exactly.
84
      hideNavigationBar();
85
      cutoutHack();
86
      computeHeights();
87
      }
88
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
// this does not include possible insets
91
92
    private void computeHeights()
93
      {
94
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
95 48314d6a Leszek Koltunski
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
96 bc7e49ec Leszek Koltunski
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
97 9530f6b0 Leszek Koltunski
98
      LinearLayout layout = findViewById(R.id.lowerBar);
99
      ViewGroup.LayoutParams paramsL = layout.getLayoutParams();
100
      paramsL.height = barHeight;
101
      layout.setLayoutParams(paramsL);
102
103 9f8d4c92 Leszek Koltunski
      LinearLayout topLayout = findViewById(R.id.bandagedCreatorTopView);
104
      ViewGroup.LayoutParams paramsT = topLayout.getLayoutParams();
105
      paramsT.height = viewHeight;
106 9530f6b0 Leszek Koltunski
107 48314d6a Leszek Koltunski
      int p = (int)(mScreenHeight* RubikActivity.PADDING);
108 9f8d4c92 Leszek Koltunski
      topLayout.setPadding(p,p,p,p);
109
      topLayout.setLayoutParams(paramsT);
110 48314d6a Leszek Koltunski
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
189
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
190 bebd7af5 Leszek Koltunski
      mScreen.onAttachedToWindow(this);
191 7cb8d4b0 Leszek Koltunski
192 a41e3c94 Leszek Koltunski
      restorePreferences();
193 7cb8d4b0 Leszek Koltunski
      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
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
218
      SharedPreferences.Editor editor = preferences.edit();
219 a41e3c94 Leszek Koltunski
      String objects = mScreen.generateObjectStrings();
220
      editor.putString("bandagedObjects", objects );
221 13a3dfa9 Leszek Koltunski
      editor.apply();
222
      }
223
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225
226
    private void restorePreferences()
227
      {
228
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
229 a41e3c94 Leszek Koltunski
      String objects = preferences.getString("bandagedObjects","");
230
      mScreen.addObjects(this,objects);
231 13a3dfa9 Leszek Koltunski
      }
232
233 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
234
// PUBLIC API
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237
    public FirebaseAnalytics getAnalytics()
238
      {
239
      return mFirebaseAnalytics;
240
      }
241
242 50ec342b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
    public BandagedCreatorRenderer getRenderer()
245
      {
246
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
247
      return view.getRenderer();
248
      }
249
250 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
251
252
    public void addObject(String name)
253
      {
254 a41e3c94 Leszek Koltunski
      if( mScreen.objectDoesntExist(name) )
255
        {
256
        mScreen.addObject(this,name);
257
        }
258 e48ad1af Leszek Koltunski
      }
259
260 d3d639b1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
261
262
    public void deleteObject(String name)
263
      {
264
      mScreen.deleteObject(this,name);
265 81493402 Leszek Koltunski
266
      RubikFiles files = RubikFiles.getInstance();
267
      files.deleteIcon(this,name);
268
      files.deleteJsonObject(this,name);
269 d3d639b1 Leszek Koltunski
      }
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
}