Project

General

Profile

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

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

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 e48ad1af Leszek Koltunski
import android.widget.HorizontalScrollView;
32 9530f6b0 Leszek Koltunski
import android.widget.LinearLayout;
33
34
import androidx.appcompat.app.AppCompatActivity;
35
36
import com.google.firebase.analytics.FirebaseAnalytics;
37
38
import org.distorted.dialogs.RubikDialogError;
39 81493402 Leszek Koltunski
import org.distorted.external.RubikFiles;
40 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
41
import org.distorted.main.R;
42 48314d6a Leszek Koltunski
import org.distorted.main.RubikActivity;
43 9530f6b0 Leszek Koltunski
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
public class BandagedCreatorActivity extends AppCompatActivity
47
{
48
    private static final int ACTIVITY_NUMBER = 3;
49 28cb1607 Leszek Koltunski
    private static final float RATIO_BAR   = 0.10f;
50 83e021c5 Leszek Koltunski
    static final float RATIO_SCROLL= 0.30f;
51 9530f6b0 Leszek Koltunski
52
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
53
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
54
55
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
56
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
57
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
58
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
59
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
60
61
    private FirebaseAnalytics mFirebaseAnalytics;
62
    private static int mScreenWidth, mScreenHeight;
63
    private int mCurrentApiVersion;
64
    private BandagedCreatorScreen mScreen;
65
    private int mHeightBar;
66
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
    @Override
70
    protected void onCreate(Bundle savedState)
71
      {
72
      super.onCreate(savedState);
73
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
74
      setTheme(R.style.MaterialThemeNoActionBar);
75
      setContentView(R.layout.bandaged);
76
77
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
78
79
      DisplayMetrics displaymetrics = new DisplayMetrics();
80
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
81
      mScreenWidth =displaymetrics.widthPixels;
82
      mScreenHeight=displaymetrics.heightPixels;
83
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
84
                                                  // which is not yet hidden.
85
                                                  // TODO: figure this out exactly.
86
      hideNavigationBar();
87
      cutoutHack();
88
      computeHeights();
89
      }
90
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
// this does not include possible insets
93
94
    private void computeHeights()
95
      {
96
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
97 48314d6a Leszek Koltunski
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
98 bc7e49ec Leszek Koltunski
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
99 9530f6b0 Leszek Koltunski
      mHeightBar = barHeight;
100
101
      LinearLayout layout = findViewById(R.id.lowerBar);
102
      ViewGroup.LayoutParams paramsL = layout.getLayoutParams();
103
      paramsL.height = barHeight;
104
      layout.setLayoutParams(paramsL);
105
106 e48ad1af Leszek Koltunski
      HorizontalScrollView view = findViewById(R.id.bandagedCreatorScrollView);
107 48314d6a Leszek Koltunski
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
108
      paramsS.height = viewHeight;
109 9530f6b0 Leszek Koltunski
110 48314d6a Leszek Koltunski
      int p = (int)(mScreenHeight* RubikActivity.PADDING);
111
      view.setPadding(p,p,p,p);
112
      view.setLayoutParams(paramsS);
113
114
      BandagedCreatorView creator = findViewById(R.id.bandagedCreatorObjectView);
115
      ViewGroup.LayoutParams paramsC = creator.getLayoutParams();
116
      paramsC.height = objectHeight;
117
      creator.setLayoutParams(paramsC);
118 9530f6b0 Leszek Koltunski
      }
119
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
122
    private void hideNavigationBar()
123
      {
124
      mCurrentApiVersion = Build.VERSION.SDK_INT;
125
126
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
127
        {
128
        final View decorView = getWindow().getDecorView();
129
130
        decorView.setSystemUiVisibility(FLAGS);
131
132
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
133
          {
134
          @Override
135
          public void onSystemUiVisibilityChange(int visibility)
136
            {
137
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
138
              {
139
              decorView.setSystemUiVisibility(FLAGS);
140
              }
141
            }
142
          });
143
        }
144
      }
145
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
// do not avoid cutouts
148
149
    private void cutoutHack()
150
      {
151
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
152
        {
153
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
154
        }
155
      }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159
    @Override
160
    public void onWindowFocusChanged(boolean hasFocus)
161
      {
162
      super.onWindowFocusChanged(hasFocus);
163
164
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
165
        {
166
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
167
        }
168
      }
169
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
    
172
    @Override
173
    protected void onPause() 
174
      {
175
      super.onPause();
176 48314d6a Leszek Koltunski
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
177 9530f6b0 Leszek Koltunski
      view.onPause();
178
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
179 13a3dfa9 Leszek Koltunski
      savePreferences();
180 9530f6b0 Leszek Koltunski
      }
181
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183
    
184
    @Override
185
    protected void onResume() 
186
      {
187
      super.onResume();
188
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
189 48314d6a Leszek Koltunski
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
190 9530f6b0 Leszek Koltunski
      view.onResume();
191
192
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
193 bebd7af5 Leszek Koltunski
      mScreen.onAttachedToWindow(this);
194 7cb8d4b0 Leszek Koltunski
195 a41e3c94 Leszek Koltunski
      restorePreferences();
196 7cb8d4b0 Leszek Koltunski
      BandagedCreatorWorkerThread.create(this);
197 9530f6b0 Leszek Koltunski
      }
198
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200
    
201
    @Override
202
    protected void onDestroy() 
203
      {
204
      super.onDestroy();
205
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
206
      }
207
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210
    void OpenGLError()
211
      {
212
      RubikDialogError errDiag = new RubikDialogError();
213
      errDiag.show(getSupportFragmentManager(), null);
214
      }
215
216 13a3dfa9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
217
218
    private void savePreferences()
219
      {
220
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
221
      SharedPreferences.Editor editor = preferences.edit();
222 a41e3c94 Leszek Koltunski
      String objects = mScreen.generateObjectStrings();
223
      editor.putString("bandagedObjects", objects );
224 13a3dfa9 Leszek Koltunski
      editor.apply();
225
      }
226
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228
229
    private void restorePreferences()
230
      {
231
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
232 a41e3c94 Leszek Koltunski
      String objects = preferences.getString("bandagedObjects","");
233
      mScreen.addObjects(this,objects);
234 13a3dfa9 Leszek Koltunski
      }
235
236 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
237
// PUBLIC API
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239
240
    public FirebaseAnalytics getAnalytics()
241
      {
242
      return mFirebaseAnalytics;
243
      }
244
245 50ec342b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
246
247
    public BandagedCreatorRenderer getRenderer()
248
      {
249
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
250
      return view.getRenderer();
251
      }
252
253 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255
    public void addObject(String name)
256
      {
257 a41e3c94 Leszek Koltunski
      if( mScreen.objectDoesntExist(name) )
258
        {
259
        mScreen.addObject(this,name);
260
        }
261 e48ad1af Leszek Koltunski
      }
262
263 d3d639b1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
264
265
    public void deleteObject(String name)
266
      {
267
      mScreen.deleteObject(this,name);
268 81493402 Leszek Koltunski
269
      RubikFiles files = RubikFiles.getInstance();
270
      files.deleteIcon(this,name);
271
      files.deleteJsonObject(this,name);
272 d3d639b1 Leszek Koltunski
      }
273
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275
276
    public void playObject(String name)
277
      {
278
279
      }
280
281 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
282
283 7cb8d4b0 Leszek Koltunski
    public void iconCreationDone(Bitmap bmp)
284 9530f6b0 Leszek Koltunski
      {
285 20b60ad9 Leszek Koltunski
      mScreen.iconCreationDone(this,bmp);
286 9530f6b0 Leszek Koltunski
      }
287
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
290
    public int getScreenWidthInPixels()
291
      {
292
      return mScreenWidth;
293
      }
294
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296
297
    public int getScreenHeightInPixels()
298
      {
299
      return mScreenHeight;
300
      }
301
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303
304
    public static int getDrawableSize()
305
      {
306
      if( mScreenHeight<1000 )
307
        {
308
        return 0;
309
        }
310
      if( mScreenHeight<1600 )
311
        {
312
        return 1;
313
        }
314
      if( mScreenHeight<1900 )
315
        {
316
        return 2;
317
        }
318
319
      return 3;
320
      }
321
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323
324
    public static int getDrawable(int small, int medium, int big, int huge)
325
      {
326
      int size = getDrawableSize();
327
328
      switch(size)
329
        {
330
        case 0 : return small;
331
        case 1 : return medium;
332
        case 2 : return big;
333
        default: return huge;
334
        }
335
      }
336
}