From f9233de9732616ca7d9c841fb9750f18db6d9a18 Mon Sep 17 00:00:00 2001 From: Hilal Alsibai <993832+xiphirx@users.noreply.github.com> Date: Thu, 5 Jul 2018 03:41:24 +0100 Subject: [PATCH] Fix decor related issues (#300) This fixes issues relating to transparent nav bars, status bars and multi window mode. The library will now detect when the window it is attached to has a transparent system bar and properly adjust its clip bounds. Fixes #233 --- .../taptargetview/TapTargetView.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/taptargetview/src/main/java/com/getkeepsafe/taptargetview/TapTargetView.java b/taptargetview/src/main/java/com/getkeepsafe/taptargetview/TapTargetView.java index f18e92e..10e5e16 100755 --- a/taptargetview/src/main/java/com/getkeepsafe/taptargetview/TapTargetView.java +++ b/taptargetview/src/main/java/com/getkeepsafe/taptargetview/TapTargetView.java @@ -426,6 +426,18 @@ public TapTargetView(final Context context, applyTargetOptions(context); + final boolean translucentStatusBar; + final boolean translucentNavigationBar; + if (Build.VERSION.SDK_INT >= 19 && context instanceof Activity) { + Activity activity = (Activity) context; + final int flags = activity.getWindow().getAttributes().flags; + translucentStatusBar = (flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0; + translucentNavigationBar = (flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0; + } else { + translucentStatusBar = false; + translucentNavigationBar = false; + } + globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { @@ -451,6 +463,15 @@ public void run() { final Rect rect = new Rect(); boundingParent.getWindowVisibleDisplayFrame(rect); + int[] parentLocation = new int[2]; + boundingParent.getLocationInWindow(parentLocation); + + if (translucentStatusBar) { + rect.top = parentLocation[1]; + } + if (translucentNavigationBar) { + rect.bottom = parentLocation[1] + boundingParent.getHeight(); + } // We bound the boundaries to be within the screen's coordinates to // handle the case where the layout bounds do not match