Revision a5972f92
Added by Leszek Koltunski about 2 months ago
src/main/java/org/distorted/config/ConfigActivity.java | ||
---|---|---|
10 | 10 |
package org.distorted.config; |
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 |
import android.view.View; |
|
17 |
import android.view.ViewGroup; |
|
18 |
import android.view.WindowManager; |
|
19 |
import android.widget.LinearLayout; |
|
20 | 14 |
|
21 |
import androidx.appcompat.app.AppCompatActivity; |
|
22 | 15 |
import androidx.preference.PreferenceManager; |
23 | 16 |
|
24 | 17 |
import org.distorted.dialogs.RubikDialogError; |
25 | 18 |
import org.distorted.dialogs.RubikDialogMessage; |
19 |
import org.distorted.helpers.BaseActivity; |
|
26 | 20 |
import org.distorted.library.main.DistortedLibrary; |
27 |
import org.distorted.main.MainActivity; |
|
28 | 21 |
import org.distorted.main.R; |
29 | 22 |
import org.distorted.objectlib.main.InitAssets; |
30 | 23 |
import org.distorted.objectlib.main.ObjectControl; |
... | ... | |
37 | 30 |
|
38 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 32 |
|
40 |
public class ConfigActivity extends AppCompatActivity
|
|
33 |
public class ConfigActivity extends BaseActivity
|
|
41 | 34 |
{ |
42 | 35 |
private static final int ACTIVITY_NUMBER = 7; |
43 |
private static final float RATIO_BAR = MainActivity.RATIO_BAR; |
|
44 |
public static final int FLAGS = MainActivity.FLAGS; |
|
45 |
|
|
46 |
private static int mScreenWidth, mScreenHeight; |
|
47 | 36 |
private ConfigScreen mScreen; |
48 | 37 |
private ConfigScreenPane mPane; |
49 |
private int mCurrentApiVersion; |
|
50 | 38 |
private int mObjectOrdinal; |
51 | 39 |
private boolean mSupportsAdjColors; |
52 | 40 |
private boolean mDisplayMessageDialog; |
... | ... | |
56 | 44 |
@Override |
57 | 45 |
protected void onCreate(Bundle savedState) |
58 | 46 |
{ |
59 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
60 | 47 |
super.onCreate(savedState); |
61 | 48 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
62 | 49 |
setContentView(R.layout.config); |
... | ... | |
66 | 53 |
|
67 | 54 |
mDisplayMessageDialog = true; |
68 | 55 |
|
69 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
70 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
71 |
mScreenWidth =displaymetrics.widthPixels; |
|
72 |
mScreenHeight=displaymetrics.heightPixels; |
|
73 |
|
|
56 |
computeScreenDimensions(); |
|
74 | 57 |
hideNavigationBar(); |
75 | 58 |
cutoutHack(); |
76 |
computeBarHeights(); |
|
77 |
} |
|
78 |
|
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
// this does not include possible insets |
|
81 |
|
|
82 |
private void computeBarHeights() |
|
83 |
{ |
|
84 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
85 |
LinearLayout layout = findViewById(R.id.lowerBar); |
|
86 |
ViewGroup.LayoutParams params = layout.getLayoutParams(); |
|
87 |
params.height = barHeight; |
|
88 |
layout.setLayoutParams(params); |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
private void hideNavigationBar() |
|
94 |
{ |
|
95 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
96 |
|
|
97 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
98 |
{ |
|
99 |
final View decorView = getWindow().getDecorView(); |
|
100 |
|
|
101 |
decorView.setSystemUiVisibility(FLAGS); |
|
102 |
|
|
103 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
104 |
{ |
|
105 |
@Override |
|
106 |
public void onSystemUiVisibilityChange(int visibility) |
|
107 |
{ |
|
108 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
109 |
{ |
|
110 |
decorView.setSystemUiVisibility(FLAGS); |
|
111 |
} |
|
112 |
} |
|
113 |
}); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
118 |
// do not avoid cutouts |
|
119 |
|
|
120 |
private void cutoutHack() |
|
121 |
{ |
|
122 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
123 |
{ |
|
124 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
|
|
130 |
@Override |
|
131 |
public void onWindowFocusChanged(boolean hasFocus) |
|
132 |
{ |
|
133 |
super.onWindowFocusChanged(hasFocus); |
|
134 |
|
|
135 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) |
|
136 |
{ |
|
137 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
138 |
} |
|
59 |
computeLowerBarHeight(RATIO_BAR); |
|
139 | 60 |
} |
140 | 61 |
|
141 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
305 | 226 |
mPane.resetUI(this); |
306 | 227 |
} |
307 | 228 |
|
308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
309 |
|
|
310 |
public int getScreenWidthInPixels() |
|
311 |
{ |
|
312 |
return mScreenWidth; |
|
313 |
} |
|
314 |
|
|
315 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
316 |
|
|
317 |
public int getScreenHeightInPixels() |
|
318 |
{ |
|
319 |
return mScreenHeight; |
|
320 |
} |
|
321 |
|
|
322 | 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
323 | 230 |
|
324 | 231 |
public ObjectControl getControl() |
Also available in: Unified diff
common code from all activities to one BaseActivity