Revision e8f6670f
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
107 | 107 |
mIsLocked = false; |
108 | 108 |
|
109 | 109 |
hideNavigationBar(); |
110 |
|
|
111 |
// huaweiHack(); |
|
110 |
cutoutHack(); |
|
112 | 111 |
// askForPermissions(); |
113 | 112 |
} |
114 | 113 |
|
... | ... | |
145 | 144 |
{ |
146 | 145 |
super.onAttachedToWindow(); |
147 | 146 |
|
147 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
148 |
{ |
|
149 |
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); |
|
150 |
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0; |
|
151 |
|
|
152 |
LinearLayout layoutHid = findViewById(R.id.hiddenBar); |
|
153 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
|
154 |
paramsHid.height = (int)(0.8f*insetHeight); |
|
155 |
layoutHid.setLayoutParams(paramsHid); |
|
156 |
} |
|
157 |
|
|
148 | 158 |
final float RATIO = 0.10f; |
149 | 159 |
float height = getScreenHeightInPixels(); |
150 | 160 |
|
... | ... | |
157 | 167 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
158 | 168 |
paramsBot.height = (int)(height*RATIO); |
159 | 169 |
layoutBot.setLayoutParams(paramsBot); |
160 |
|
|
161 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
162 |
{ |
|
163 |
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); |
|
164 |
int inset = cutout!=null ? cutout.getSafeInsetTop() : 0; |
|
165 |
RubikStatePlay.setSafeInsetTop(inset); |
|
166 |
} |
|
167 | 170 |
} |
168 | 171 |
|
169 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
170 |
// on some Huawei devices ( P40, P40 Pro, Mate 30 Pro, Mate 30, Nova 5T, P30 ) this has to be called |
|
171 |
// so that the App enters fullscreen mode. Otherwise there's a black bar at the top. See |
|
172 |
// https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201361898979080302&fid=0101246461018590361 |
|
173 |
// do not avoid cutouts |
|
173 | 174 |
|
174 |
private void huaweiHack()
|
|
175 |
private void cutoutHack()
|
|
175 | 176 |
{ |
176 | 177 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
177 | 178 |
{ |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
55 | 55 |
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about }; |
56 | 56 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
57 | 57 |
|
58 |
private static int mSafeInsetTop; |
|
59 |
|
|
60 | 58 |
private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton, mLockButton; |
61 | 59 |
private Button mPlayButton; |
62 | 60 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
... | ... | |
176 | 174 |
View popupView = mObjectPopup.getContentView(); |
177 | 175 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
178 | 176 |
|
179 |
mObjectPopup.showAsDropDown(view, margin, margin + mSafeInsetTop);
|
|
177 |
mObjectPopup.showAsDropDown(view, margin, margin); |
|
180 | 178 |
mObjectPopup.update(view, mObjectSize*mColCount, mObjectSize*mRowCount); |
181 | 179 |
|
182 | 180 |
mObjectPopup.setFocusable(true); |
... | ... | |
215 | 213 |
final int maxLevel = ObjectList.getMaxLevel(mObject, sizeIndex); |
216 | 214 |
final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN); |
217 | 215 |
|
218 |
mPlayPopup.showAsDropDown(view, margin, margin + mSafeInsetTop);
|
|
216 |
mPlayPopup.showAsDropDown(view, margin, margin); |
|
219 | 217 |
mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin)); |
220 | 218 |
|
221 | 219 |
mPlayPopup.setFocusable(true); |
... | ... | |
252 | 250 |
View popupView = mMenuPopup.getContentView(); |
253 | 251 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
254 | 252 |
|
255 |
mMenuPopup.showAsDropDown(view, (int)(-width/12), margin + mSafeInsetTop);
|
|
253 |
mMenuPopup.showAsDropDown(view, (int)(-width/12), margin); |
|
256 | 254 |
mMenuPopup.update(view, mMenuLayoutWidth, mMenuLayoutHeight); |
257 | 255 |
|
258 | 256 |
mMenuPopup.setFocusable(true); |
... | ... | |
663 | 661 |
} |
664 | 662 |
} |
665 | 663 |
|
666 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
667 |
|
|
668 |
public static void setSafeInsetTop(int top) |
|
669 |
{ |
|
670 |
mSafeInsetTop = top; |
|
671 |
} |
|
672 |
|
|
673 | 664 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
674 | 665 |
|
675 | 666 |
public int getLevel() |
src/main/res/layout/main.xml | ||
---|---|---|
12 | 12 |
android:layout_alignParentTop="true"/> |
13 | 13 |
|
14 | 14 |
<LinearLayout |
15 |
android:id="@+id/upperBar"
|
|
15 |
android:id="@+id/hiddenBar"
|
|
16 | 16 |
android:layout_alignParentTop="true" |
17 | 17 |
android:layout_width="fill_parent" |
18 | 18 |
android:layout_height="0dp" |
... | ... | |
21 | 21 |
android:background="@android:color/transparent"> |
22 | 22 |
</LinearLayout> |
23 | 23 |
|
24 |
<LinearLayout |
|
25 |
android:id="@+id/upperBar" |
|
26 |
android:layout_below="@id/hiddenBar" |
|
27 |
android:layout_width="fill_parent" |
|
28 |
android:layout_height="0dp" |
|
29 |
android:gravity="center" |
|
30 |
android:orientation="horizontal" |
|
31 |
android:background="@android:color/transparent"> |
|
32 |
</LinearLayout> |
|
33 |
|
|
24 | 34 |
<LinearLayout |
25 | 35 |
android:id="@+id/lowerBar" |
26 | 36 |
android:layout_alignParentBottom="true" |
Also available in: Unified diff
Avoid cutouts in a new way