Skip to content

Commit 4810ed4

Browse files
feat: enable notch support
1 parent fdc09ae commit 4810ed4

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ protected void onCreate(Bundle savedInstanceState) {
7777
params.width = config.width;
7878
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
7979
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
80-
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
81-
// params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
82-
// If this is disabled, UtilsDevice line 61 needs to be changed to subtract cutout always
83-
//}
80+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
81+
params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
82+
// If this is disabled, UtilsDevice line 61 needs to be changed to subtract cutout always
83+
}
8484
getWindow().setAttributes(params);
8585
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
8686

@@ -171,16 +171,13 @@ public void onDestroy() {
171171
}
172172

173173
private void hideSystemUI() {
174-
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
175-
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
176-
flags = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
174+
getWindow().getDecorView().setSystemUiVisibility(
175+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
176+
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
177177
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
178178
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
179179
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
180-
| View.SYSTEM_UI_FLAG_FULLSCREEN;
181-
}
182-
183-
getWindow().getDecorView().setSystemUiVisibility(flags);
180+
| View.SYSTEM_UI_FLAG_FULLSCREEN);
184181
}
185182

186183
private void resizeContentInternal() {

sdk/src/main/java/ly/count/android/sdk/UtilsDevice.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import android.view.WindowMetrics;
1414
import androidx.annotation.NonNull;
1515

16-
final class UtilsDevice {
16+
class UtilsDevice {
1717
private UtilsDevice() {
1818
}
1919

@@ -52,20 +52,20 @@ private static void applyWindowMetrics(@NonNull Context context,
5252
types |= WindowInsets.Type.statusBars();
5353
}
5454

55-
//boolean drawUnderCutout;
56-
//WindowManager.LayoutParams params = ((Activity) context).getWindow().getAttributes();
57-
//drawUnderCutout = params.layoutInDisplayCutoutMode
58-
// == WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
55+
boolean drawUnderCutout;
56+
WindowManager.LayoutParams params = ((Activity) context).getWindow().getAttributes();
57+
drawUnderCutout = params.layoutInDisplayCutoutMode
58+
== WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
5959

6060
// Only subtract display cutout insets when not allowed to draw under the cutout
61-
//if (!drawUnderCutout && windowInsets.isVisible(WindowInsets.Type.displayCutout())) {
62-
// types |= WindowInsets.Type.displayCutout();
63-
//} Cutout is always respected as safe area for now even in fullscreen mode
64-
}
65-
66-
// Only subtract display cutout insets when not allowed to draw under the cutout
67-
if (windowInsets.isVisible(WindowInsets.Type.displayCutout())) {
68-
types |= WindowInsets.Type.displayCutout();
61+
if (!drawUnderCutout && windowInsets.isVisible(WindowInsets.Type.displayCutout())) {
62+
types |= WindowInsets.Type.displayCutout();
63+
}
64+
// Cutout is always respected as safe area for now even in fullscreen mode
65+
// Only subtract display cutout insets when not allowed to draw under the cutout
66+
if (windowInsets.isVisible(WindowInsets.Type.displayCutout())) {
67+
types |= WindowInsets.Type.displayCutout();
68+
}
6969
}
7070

7171
final Insets insets = windowInsets.getInsets(types);
@@ -88,11 +88,7 @@ private static void applyWindowMetrics(@NonNull Context context,
8888
private static void applyLegacyMetrics(@NonNull WindowManager wm,
8989
@NonNull DisplayMetrics outMetrics) {
9090
final Display display = wm.getDefaultDisplay();
91-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
92-
display.getMetrics(outMetrics);
93-
} else {
94-
display.getRealMetrics(outMetrics);
95-
}
91+
display.getRealMetrics(outMetrics);
9692
//getMetrics gives us size minus navigation bar
9793
}
9894
}

0 commit comments

Comments
 (0)