1313import android .view .Gravity ;
1414import android .view .View ;
1515import android .view .ViewGroup ;
16- import android .view .WindowInsets ;
1716import android .view .WindowManager ;
1817import android .webkit .WebSettings ;
1918import android .webkit .WebView ;
@@ -47,8 +46,6 @@ protected void onCreate(Bundle savedInstanceState) {
4746
4847 // there is a stripe at the top of the screen for contents
4948 // we eliminate it with hiding the system ui
50- hideSystemUI ();
51- subscribeForSystemUiChanges ();
5249 super .onCreate (savedInstanceState );
5350 overridePendingTransition (0 , 0 );
5451
@@ -73,13 +70,16 @@ protected void onCreate(Bundle savedInstanceState) {
7370
7471 // Configure window layout parameters
7572 WindowManager .LayoutParams params = new WindowManager .LayoutParams ();
76- params .gravity = Gravity .TOP | Gravity .LEFT ; // try out START
73+ params .gravity = Gravity .TOP | Gravity .START ; // try out START
7774 params .x = config .x ;
7875 params .y = config .y ;
7976 params .height = config .height ;
8077 params .width = config .width ;
8178 params .flags = WindowManager .LayoutParams .FLAG_NOT_TOUCH_MODAL
8279 | 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+ }
8383 getWindow ().setAttributes (params );
8484 getWindow ().setBackgroundDrawableResource (android .R .color .transparent );
8585
@@ -95,7 +95,7 @@ protected void onCreate(Bundle savedInstanceState) {
9595 }
9696
9797 private TransparentActivityConfig setupConfig (@ Nullable TransparentActivityConfig config ) {
98- final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this , false );
98+ final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this );
9999
100100 if (config == null ) {
101101 Log .w (Countly .TAG , "[TransparentActivity] setupConfig, Config is null, using default values with full screen size" );
@@ -151,7 +151,7 @@ public void onConfigurationChanged(android.content.res.Configuration newConfig)
151151
152152 private void resizeContent () {
153153 // CHANGE SCREEN SIZE
154- final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this , false );
154+ final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this );
155155 int scaledWidth = (int ) Math .ceil (metrics .widthPixels / metrics .density );
156156 int scaledHeight = (int ) Math .ceil (metrics .heightPixels / metrics .density );
157157
@@ -170,33 +170,14 @@ public void onDestroy() {
170170 }
171171
172172 private void hideSystemUI () {
173- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
174- getWindow ().setDecorFitsSystemWindows (false );
175- if (getWindow ().getDecorView ().getWindowInsetsController () != null ) {
176- getWindow ().getDecorView ().getWindowInsetsController ().hide (WindowInsets .Type .statusBars ());
177- }
178- } else {
179- getWindow ().getDecorView ().setSystemUiVisibility (
180- View .SYSTEM_UI_FLAG_LAYOUT_STABLE
181- | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
182- | View .SYSTEM_UI_FLAG_FULLSCREEN
183- );
184- }
185- }
186-
187- private void subscribeForSystemUiChanges () {
188- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
189- View root = getWindow ().getDecorView ();
190- root .setOnApplyWindowInsetsListener ((v , insets ) -> {
191- resizeContent ();
192- return insets ;
193- });
194- } else {
195- View decorView = getWindow ().getDecorView ();
196- decorView .setOnSystemUiVisibilityChangeListener (visibility -> {
197- resizeContent ();
198- });
199- }
173+ getWindow ().getDecorView ().setSystemUiVisibility (
174+ View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY
175+ | View .SYSTEM_UI_FLAG_LAYOUT_STABLE
176+ | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
177+ | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
178+ | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
179+ | View .SYSTEM_UI_FLAG_FULLSCREEN
180+ );
200181 }
201182
202183 private void resizeContentInternal () {
@@ -312,7 +293,7 @@ private void resizeMeAction(Map<String, Object> query) {
312293 return ;
313294 }
314295 try {
315- final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this , false );
296+ final DisplayMetrics metrics = UtilsDevice .getDisplayMetrics (this );
316297 float density = metrics .density ;
317298
318299 JSONObject resizeMeJson = (JSONObject ) resizeMe ;
@@ -457,6 +438,7 @@ private WebView createWebView(TransparentActivityConfig config) {
457438 Countly .sharedInstance ().moduleContent .notifyAfterContentIsClosed ();
458439 }
459440 } else {
441+ hideSystemUI ();
460442 webView .setVisibility (View .VISIBLE );
461443 }
462444 }
0 commit comments