Project

General

Profile

« Previous | Next » 

Revision a5972f92

Added by Leszek Koltunski about 2 months ago

common code from all activities to one BaseActivity

View differences:

src/main/java/org/distorted/purchase/PurchaseActivity.java
10 10
package org.distorted.purchase;
11 11

  
12 12
import android.content.SharedPreferences;
13
import android.os.Build;
14 13
import android.os.Bundle;
15
import android.util.DisplayMetrics;
16 14
import android.view.View;
17 15
import android.view.ViewGroup;
18
import android.view.WindowManager;
19 16

  
20
import androidx.appcompat.app.AppCompatActivity;
21 17
import androidx.preference.PreferenceManager;
22 18

  
23 19
import org.distorted.dialogs.RubikDialogError;
24 20
import org.distorted.external.RubikScores;
21
import org.distorted.helpers.BaseActivity;
25 22
import org.distorted.library.main.DistortedLibrary;
26
import org.distorted.main.MainActivity;
27 23
import org.distorted.main.R;
28 24
import org.distorted.objectlib.main.InitAssets;
29 25
import org.distorted.objectlib.main.ObjectControl;
......
35 31

  
36 32
///////////////////////////////////////////////////////////////////////////////////////////////////
37 33

  
38
public class PurchaseActivity extends AppCompatActivity
34
public class PurchaseActivity extends BaseActivity
39 35
{
40 36
    private static final int ACTIVITY_NUMBER = 3;
41 37
    private static final float RATIO_UBAR = 0.14f;
42 38
    private static final float RATIO_LBAR = 0.10f;
43 39
    private static final float RATIO_VIEW = 0.50f;
44
    public static final int FLAGS = MainActivity.FLAGS;
45 40

  
46
    private static int mScreenWidth, mScreenHeight;
47
    private int mCurrentApiVersion;
48 41
    private PurchaseScreen mScreen;
49 42
    private int mObjectOrdinal;
50 43

  
......
53 46
    @Override
54 47
    protected void onCreate(Bundle savedState)
55 48
      {
56
      setTheme(R.style.MaterialThemeNoActionBar);
57 49
      super.onCreate(savedState);
58 50
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
59 51
      setContentView(R.layout.purchase);
60 52

  
61 53
      Bundle b = getIntent().getExtras();
62

  
63 54
      if(b != null) mObjectOrdinal = b.getInt("obj");
64 55

  
65
      DisplayMetrics displaymetrics = new DisplayMetrics();
66
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
67
      mScreenWidth =displaymetrics.widthPixels;
68
      mScreenHeight=displaymetrics.heightPixels;
69

  
56
      computeScreenDimensions();
70 57
      hideNavigationBar();
71 58
      cutoutHack();
72 59
      setHeights();
......
103 90
      setViewHeight(R.id.purchaseLayoutAll  , layHeight);
104 91
      }
105 92

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
    private void hideNavigationBar()
109
      {
110
      mCurrentApiVersion = Build.VERSION.SDK_INT;
111

  
112
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
113
        {
114
        final View decorView = getWindow().getDecorView();
115

  
116
        decorView.setSystemUiVisibility(FLAGS);
117

  
118
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
119
          {
120
          @Override
121
          public void onSystemUiVisibilityChange(int visibility)
122
            {
123
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
124
              {
125
              decorView.setSystemUiVisibility(FLAGS);
126
              }
127
            }
128
          });
129
        }
130
      }
131

  
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
// do not avoid cutouts
134

  
135
    private void cutoutHack()
136
      {
137
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
138
        {
139
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
140
        }
141
      }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
    @Override
146
    public void onWindowFocusChanged(boolean hasFocus)
147
      {
148
      super.onWindowFocusChanged(hasFocus);
149

  
150
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
151
        {
152
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
153
        }
154
      }
155

  
156 93
///////////////////////////////////////////////////////////////////////////////////////////////////
157 94
    
158 95
    @Override
......
194 131
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
195 132
      }
196 133

  
197

  
198 134
///////////////////////////////////////////////////////////////////////////////////////////////////
199 135

  
200 136
    private void savePreferences()
......
233 169

  
234 170
///////////////////////////////////////////////////////////////////////////////////////////////////
235 171
// PUBLIC API
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
    public int getScreenWidthInPixels()
239
      {
240
      return mScreenWidth;
241
      }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
    public int getScreenHeightInPixels()
246
      {
247
      return mScreenHeight;
248
      }
249

  
250 172
///////////////////////////////////////////////////////////////////////////////////////////////////
251 173

  
252 174
    public ObjectControl getControl()

Also available in: Unified diff