Skip to content

Commit

Permalink
Fix decor related issues (#300)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xiphirx authored Jul 5, 2018
1 parent 8036db5 commit f9233de
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit f9233de

Please sign in to comment.