Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorActivity.java @ 48314d6a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.View;
26
import android.view.ViewGroup;
27
import android.view.WindowManager;
28
import android.widget.LinearLayout;
29

    
30
import androidx.appcompat.app.AppCompatActivity;
31

    
32
import com.google.firebase.analytics.FirebaseAnalytics;
33

    
34
import org.distorted.dialogs.RubikDialogError;
35
import org.distorted.library.main.DistortedLibrary;
36
import org.distorted.main.R;
37
import org.distorted.main.RubikActivity;
38
import org.distorted.objectlib.main.ObjectControl;
39
import org.distorted.objects.RubikObject;
40
import org.distorted.objects.RubikObjectList;
41

    
42
import java.io.InputStream;
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
    private 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 mObjectOrdinal;
66
    private int mHeightBar;
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
    @Override
71
    protected void onCreate(Bundle savedState)
72
      {
73
      super.onCreate(savedState);
74
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
75
      setTheme(R.style.MaterialThemeNoActionBar);
76
      setContentView(R.layout.bandaged);
77

    
78
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
79

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

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
// this does not include possible insets
94

    
95
    private void computeHeights()
96
      {
97
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
98
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
99
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL));
100
      mHeightBar = barHeight;
101

    
102
      LinearLayout layout = findViewById(R.id.lowerBar);
103
      ViewGroup.LayoutParams paramsL = layout.getLayoutParams();
104
      paramsL.height = barHeight;
105
      layout.setLayoutParams(paramsL);
106

    
107
      LinearLayout view = findViewById(R.id.bandagedCreatorView);
108
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
109
      paramsS.height = viewHeight;
110

    
111
      int p = (int)(mScreenHeight* RubikActivity.PADDING);
112
      view.setPadding(p,p,p,p);
113
      view.setLayoutParams(paramsS);
114

    
115
      BandagedCreatorView creator = findViewById(R.id.bandagedCreatorObjectView);
116
      ViewGroup.LayoutParams paramsC = creator.getLayoutParams();
117
      paramsC.height = objectHeight;
118
      creator.setLayoutParams(paramsC);
119
      }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
    private void hideNavigationBar()
124
      {
125
      mCurrentApiVersion = Build.VERSION.SDK_INT;
126

    
127
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
128
        {
129
        final View decorView = getWindow().getDecorView();
130

    
131
        decorView.setSystemUiVisibility(FLAGS);
132

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

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
// do not avoid cutouts
149

    
150
    private void cutoutHack()
151
      {
152
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
153
        {
154
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
155
        }
156
      }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
    @Override
161
    public void onWindowFocusChanged(boolean hasFocus)
162
      {
163
      super.onWindowFocusChanged(hasFocus);
164

    
165
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
166
        {
167
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
168
        }
169
      }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
    
173
    @Override
174
    protected void onPause() 
175
      {
176
      super.onPause();
177
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView);
178
      view.onPause();
179
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
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,mObjectOrdinal);
194
      }
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
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
216
      {
217
      if( object!=null )
218
        {
219
        int meshState          = object.getMeshState();
220
        InputStream jsonStream = object.getObjectStream(this);
221
        InputStream meshStream = object.getMeshStream(this);
222
        String name            = object.getUpperName();
223

    
224
        control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream);
225
        }
226
      }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
// PUBLIC API
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

    
232
    public void changeObject(int ordinal)
233
      {
234
      mObjectOrdinal = ordinal;
235
      RubikObject object = RubikObjectList.getObject(ordinal);
236
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorView);
237
      }
238

    
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

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

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
    public int getHeightBar()
249
      {
250
      return mHeightBar;
251
      }
252

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

    
255
    public int getScreenWidthInPixels()
256
      {
257
      return mScreenWidth;
258
      }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

    
262
    public int getScreenHeightInPixels()
263
      {
264
      return mScreenHeight;
265
      }
266

    
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

    
269
    public static int getDrawableSize()
270
      {
271
      if( mScreenHeight<1000 )
272
        {
273
        return 0;
274
        }
275
      if( mScreenHeight<1600 )
276
        {
277
        return 1;
278
        }
279
      if( mScreenHeight<1900 )
280
        {
281
        return 2;
282
        }
283

    
284
      return 3;
285
      }
286

    
287
///////////////////////////////////////////////////////////////////////////////////////////////////
288

    
289
    public static int getDrawable(int small, int medium, int big, int huge)
290
      {
291
      int size = getDrawableSize();
292

    
293
      switch(size)
294
        {
295
        case 0 : return small;
296
        case 1 : return medium;
297
        case 2 : return big;
298
        default: return huge;
299
        }
300
      }
301
}
(1-1/9)