Revision a5972f92
Added by Leszek Koltunski about 2 months ago
src/main/java/org/distorted/patternui/PatternActivity.java | ||
---|---|---|
12 | 12 |
import android.content.SharedPreferences; |
13 | 13 |
import android.os.Build; |
14 | 14 |
import android.os.Bundle; |
15 |
import android.util.DisplayMetrics; |
|
16 | 15 |
import android.view.DisplayCutout; |
17 |
import android.view.View; |
|
18 | 16 |
import android.view.ViewGroup; |
19 |
import android.view.WindowManager; |
|
20 | 17 |
import android.widget.LinearLayout; |
21 | 18 |
|
22 |
import androidx.appcompat.app.AppCompatActivity; |
|
23 | 19 |
import androidx.preference.PreferenceManager; |
24 | 20 |
|
25 | 21 |
import org.distorted.dialogs.RubikDialogError; |
22 |
import org.distorted.helpers.BaseActivity; |
|
26 | 23 |
import org.distorted.library.main.DistortedLibrary; |
27 | 24 |
import org.distorted.library.main.DistortedScreen; |
28 |
import org.distorted.main.MainActivity; |
|
29 | 25 |
import org.distorted.main.R; |
30 | 26 |
import org.distorted.objectlib.main.InitAssets; |
31 | 27 |
import org.distorted.objectlib.main.ObjectControl; |
... | ... | |
38 | 34 |
|
39 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 36 |
|
41 |
public class PatternActivity extends AppCompatActivity
|
|
37 |
public class PatternActivity extends BaseActivity
|
|
42 | 38 |
{ |
43 |
public static final float RATIO_BAR = 0.100f;
|
|
39 |
public static final float RATIO_UPP = 0.100f;
|
|
44 | 40 |
public static final float PADDING = 0.010f; |
45 | 41 |
public static final float SMALL_MARGIN = 0.004f; |
46 | 42 |
public static final float BUTTON_TEXT_SIZE= 0.050f; |
... | ... | |
49 | 45 |
private static final int ACTIVITY_NUMBER = 5; |
50 | 46 |
private static final float RATIO_INSET= 0.09f; |
51 | 47 |
|
52 |
private static int mScreenWidth, mScreenHeight; |
|
53 |
private int mCurrentApiVersion; |
|
54 |
private int mHeightUpperBar; |
|
55 | 48 |
private int mObjectOrdinal; |
56 | 49 |
|
57 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
59 | 52 |
@Override |
60 | 53 |
protected void onCreate(Bundle savedState) |
61 | 54 |
{ |
62 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
63 | 55 |
super.onCreate(savedState); |
64 | 56 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
65 | 57 |
setContentView(R.layout.pattern); |
66 |
hideNavigationBar(); |
|
67 | 58 |
|
68 | 59 |
Bundle b = getIntent().getExtras(); |
69 | 60 |
mObjectOrdinal = b!=null ? b.getInt("obj") : 0; |
70 | 61 |
|
71 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
72 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
73 |
mScreenWidth =displaymetrics.widthPixels; |
|
74 |
mScreenHeight=displaymetrics.heightPixels; |
|
75 |
|
|
62 |
computeScreenDimensions(); |
|
63 |
hideNavigationBar(); |
|
76 | 64 |
cutoutHack(); |
77 |
computeBarHeights(); |
|
78 |
} |
|
79 |
|
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
// this does not include possible insets |
|
82 |
|
|
83 |
private void computeBarHeights() |
|
84 |
{ |
|
85 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
86 |
mHeightUpperBar = barHeight; |
|
87 |
|
|
88 |
LinearLayout layoutTop = findViewById(R.id.upperBar); |
|
89 |
LinearLayout layoutBot = findViewById(R.id.lowerBar); |
|
90 |
|
|
91 |
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams(); |
|
92 |
paramsTop.height = mHeightUpperBar; |
|
93 |
layoutTop.setLayoutParams(paramsTop); |
|
94 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
|
95 |
paramsBot.height = barHeight; |
|
96 |
layoutBot.setLayoutParams(paramsBot); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
private void hideNavigationBar() |
|
102 |
{ |
|
103 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
104 |
|
|
105 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
106 |
{ |
|
107 |
final View decorView = getWindow().getDecorView(); |
|
108 |
|
|
109 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
110 |
|
|
111 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
112 |
{ |
|
113 |
@Override |
|
114 |
public void onSystemUiVisibilityChange(int visibility) |
|
115 |
{ |
|
116 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
117 |
{ |
|
118 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
119 |
} |
|
120 |
} |
|
121 |
}); |
|
122 |
} |
|
65 |
computeLowerBarHeight(RATIO_BAR); |
|
66 |
computeUpperBarHeight(RATIO_UPP); |
|
123 | 67 |
} |
124 | 68 |
|
125 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
138 | 82 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
139 | 83 |
paramsHid.height = (int)(insetHeight*RATIO_INSET); |
140 | 84 |
layoutHid.setLayoutParams(paramsHid); |
141 |
mHeightUpperBar += paramsHid.height; |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
// do not avoid cutouts |
|
147 |
|
|
148 |
private void cutoutHack() |
|
149 |
{ |
|
150 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
151 |
{ |
|
152 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
157 |
|
|
158 |
@Override |
|
159 |
public void onWindowFocusChanged(boolean hasFocus) |
|
160 |
{ |
|
161 |
super.onWindowFocusChanged(hasFocus); |
|
162 |
|
|
163 |
if( mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus ) |
|
164 |
{ |
|
165 |
getWindow().getDecorView().setSystemUiVisibility(MainActivity.FLAGS); |
|
166 | 85 |
} |
167 | 86 |
} |
168 | 87 |
|
... | ... | |
263 | 182 |
return view.getObjectControl(); |
264 | 183 |
} |
265 | 184 |
|
266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
267 |
|
|
268 |
public int getScreenWidthInPixels() |
|
269 |
{ |
|
270 |
return mScreenWidth; |
|
271 |
} |
|
272 |
|
|
273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
274 |
|
|
275 |
public int getScreenHeightInPixels() |
|
276 |
{ |
|
277 |
return mScreenHeight; |
|
278 |
} |
|
279 |
|
|
280 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
281 | 186 |
|
282 | 187 |
public int getObjectOrdinal() |
Also available in: Unified diff
common code from all activities to one BaseActivity