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/bandaged/BandagedActivity.java
17 17
import android.content.SharedPreferences;
18 18
import android.content.res.Configuration;
19 19
import android.graphics.Bitmap;
20
import android.os.Build;
21 20
import android.os.Bundle;
22
import android.util.DisplayMetrics;
23
import android.view.View;
24 21
import android.view.ViewGroup;
25
import android.view.WindowManager;
26 22
import android.widget.LinearLayout;
27 23

  
28
import androidx.appcompat.app.AppCompatActivity;
29 24
import androidx.preference.PreferenceManager;
30 25

  
31 26
import org.distorted.dialogs.RubikDialogError;
32 27
import org.distorted.dialogs.RubikDialogMessage;
33 28
import org.distorted.external.RubikFiles;
29
import org.distorted.helpers.BaseActivity;
34 30
import org.distorted.library.main.DistortedLibrary;
35
import org.distorted.main.MainActivity;
36 31
import org.distorted.main.R;
37 32
import org.distorted.objectlib.main.InitAssets;
38 33
import org.distorted.objectlib.main.TwistyJson;
......
42 37

  
43 38
///////////////////////////////////////////////////////////////////////////////////////////////////
44 39

  
45
public class BandagedActivity extends AppCompatActivity
40
public class BandagedActivity extends BaseActivity
46 41
{
47 42
    public static final float SPINNER_TEXT_SIZE = 0.03f;
48 43
    public static final float PADDING           = 0.010f;
49
    public static final int FLAGS               = MainActivity.FLAGS;
50 44
    public static final float RATIO_SCROLL      = 0.30f;
51 45

  
52 46
    private static final int ACTIVITY_NUMBER    = 2;
53
    private static final float RATIO_BAR        = MainActivity.RATIO_BAR;
54 47
    private static final float RATIO_BUT        = 0.07f;
55 48
    private static final int NUM_SCRAMBLES      = 300;
56 49

  
57
    private static int mScreenWidth, mScreenHeight;
58
    private int mCurrentApiVersion;
59 50
    private BandagedScreen mScreen;
60 51
    private boolean mRTL;
61 52
    private int mObjectOrdinal;
......
66 57
    @Override
67 58
    protected void onCreate(Bundle savedState)
68 59
      {
69
      setTheme(R.style.MaterialThemeNoActionBar);
70 60
      super.onCreate(savedState);
71 61

  
72
      Bundle b = getIntent().getExtras();
73
      mObjectOrdinal = (b != null) ? b.getInt("obj") : 0;
74

  
75 62
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
76 63
      setContentView(R.layout.bandaged);
77 64

  
78
      DisplayMetrics displaymetrics = new DisplayMetrics();
79
      getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics);
80
      mScreenWidth =displaymetrics.widthPixels;
81
      mScreenHeight=displaymetrics.heightPixels;
82

  
65
      Bundle b = getIntent().getExtras();
66
      mObjectOrdinal = (b != null) ? b.getInt("obj") : 0;
83 67
      mDisplayMessageDialog = true;
84 68

  
85 69
      final Configuration config = getResources().getConfiguration();
86 70
      final int layoutDirection = config.getLayoutDirection();
87 71
      mRTL = layoutDirection==LAYOUT_DIRECTION_RTL;
88 72

  
73
      computeScreenDimensions();
89 74
      hideNavigationBar();
90 75
      cutoutHack();
91 76
      computeHeights();
......
125 110
      creator.setLayoutParams(paramsC);
126 111
      }
127 112

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
    private void hideNavigationBar()
131
      {
132
      mCurrentApiVersion = Build.VERSION.SDK_INT;
133

  
134
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
135
        {
136
        final View decorView = getWindow().getDecorView();
137

  
138
        decorView.setSystemUiVisibility(FLAGS);
139

  
140
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
141
          {
142
          @Override
143
          public void onSystemUiVisibilityChange(int visibility)
144
            {
145
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
146
              {
147
              decorView.setSystemUiVisibility(FLAGS);
148
              }
149
            }
150
          });
151
        }
152
      }
153

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
// do not avoid cutouts
156

  
157
    private void cutoutHack()
158
      {
159
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
160
        {
161
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
162
        }
163
      }
164

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

  
167
    @Override
168
    public void onWindowFocusChanged(boolean hasFocus)
169
      {
170
      super.onWindowFocusChanged(hasFocus);
171

  
172
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
173
        {
174
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
175
        }
176
      }
177

  
178 113
///////////////////////////////////////////////////////////////////////////////////////////////////
179 114
    
180 115
    @Override
......
353 288
      mScreen.iconCreationDone(this,bmp);
354 289
      }
355 290

  
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357

  
358
    public int getScreenWidthInPixels()
359
      {
360
      return mScreenWidth;
361
      }
362

  
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

  
365
    public int getScreenHeightInPixels()
366
      {
367
      return mScreenHeight;
368
      }
369

  
370 291
///////////////////////////////////////////////////////////////////////////////////////////////////
371 292

  
372 293
    public int getObjectOrdinal()

Also available in: Unified diff