Project

General

Profile

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

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

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.content.SharedPreferences;
23
import android.graphics.Bitmap;
24
import android.os.Build;
25
import android.os.Bundle;
26
import android.preference.PreferenceManager;
27
import android.util.DisplayMetrics;
28
import android.view.View;
29
import android.view.ViewGroup;
30
import android.view.WindowManager;
31
import android.widget.HorizontalScrollView;
32
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
import org.distorted.external.RubikFiles;
40
import org.distorted.library.main.DistortedLibrary;
41
import org.distorted.main.R;
42
import org.distorted.main.RubikActivity;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
public class BandagedCreatorActivity extends AppCompatActivity
47
{
48
    private static final int ACTIVITY_NUMBER = 3;
49
    private static final float RATIO_BAR   = 0.10f;
50
    static final float RATIO_SCROLL= 0.30f;
51

    
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
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
98
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
99
      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
      HorizontalScrollView view = findViewById(R.id.bandagedCreatorScrollView);
107
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
108
      paramsS.height = viewHeight;
109

    
110
      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
      }
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
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
177
      view.onPause();
178
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
179
      savePreferences();
180
      }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183
    
184
    @Override
185
    protected void onResume() 
186
      {
187
      super.onResume();
188
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
189
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
190
      view.onResume();
191

    
192
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
193
      mScreen.onAttachedToWindow(this);
194

    
195
      restorePreferences();
196
      BandagedCreatorWorkerThread.create(this);
197
      }
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
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
    private void savePreferences()
219
      {
220
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
221
      SharedPreferences.Editor editor = preferences.edit();
222
      String objects = mScreen.generateObjectStrings();
223
      editor.putString("bandagedObjects", objects );
224
      editor.apply();
225
      }
226

    
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

    
229
    private void restorePreferences()
230
      {
231
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
232
      String objects = preferences.getString("bandagedObjects","");
233
      mScreen.addObjects(this,objects);
234
      }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237
// PUBLIC API
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
    public FirebaseAnalytics getAnalytics()
241
      {
242
      return mFirebaseAnalytics;
243
      }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
    public BandagedCreatorRenderer getRenderer()
248
      {
249
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
250
      return view.getRenderer();
251
      }
252

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

    
255
    public void addObject(String name)
256
      {
257
      if( mScreen.objectDoesntExist(name) )
258
        {
259
        mScreen.addObject(this,name);
260
        }
261
      }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
    public void deleteObject(String name)
266
      {
267
      mScreen.deleteObject(this,name);
268

    
269
      RubikFiles files = RubikFiles.getInstance();
270
      files.deleteIcon(this,name);
271
      files.deleteJsonObject(this,name);
272
      }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
    public void playObject(String name)
277
      {
278

    
279
      }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
    public void iconCreationDone(Bitmap bmp)
284
      {
285
      mScreen.iconCreationDone(this,bmp);
286
      }
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
}
(1-1/13)