diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java index 106dfae8..88571d6e 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java @@ -51,7 +51,6 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis private int mContentBottomMargin; private int mContentTopMargin; private boolean mDismissOnTouch = false; - private boolean mShouldRedraw = true; private boolean mShouldRender = false; // flag to decide when we should actually render private int mMaskColour; private AnimationFactory mAnimationFactory; @@ -213,7 +212,7 @@ private void notifyOnDismissed() { /** * internal listener used by sequence for storing progress within the sequence */ - if(mDetachedListener!=null){ + if (mDetachedListener != null) { mDetachedListener.onShowcaseDetached(this, mWasDismissed); } } @@ -240,6 +239,17 @@ public void setTarget(Target target) { if (mTarget != null) { + /** + * If we're on lollipop then make sure we don't draw over the nav bar + */ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mBottomMargin = getSoftButtonsBarSizePort((Activity) getContext()); + FrameLayout.LayoutParams contentLP = (LayoutParams) getLayoutParams(); + + if (contentLP!=null && contentLP.bottomMargin != mBottomMargin) + contentLP.bottomMargin = mBottomMargin; + } + // apply the target position Point targetPoint = mTarget.getPoint(); setPosition(targetPoint); @@ -274,17 +284,30 @@ private void applyLayoutParams() { if (mContentBox != null && mContentBox.getLayoutParams() != null) { FrameLayout.LayoutParams contentLP = (LayoutParams) mContentBox.getLayoutParams(); - contentLP.bottomMargin = mContentBottomMargin; - contentLP.topMargin = mContentTopMargin; - contentLP.gravity = mGravity; - mContentBox.setLayoutParams(contentLP); - } - } - @Override - public void invalidate() { - mShouldRedraw = true; - super.invalidate(); + boolean layoutParamsChanged = false; + + if (contentLP.bottomMargin != mContentBottomMargin) { + contentLP.bottomMargin = mContentBottomMargin; + layoutParamsChanged = true; + } + + if (contentLP.topMargin != mContentTopMargin) { + contentLP.topMargin = mContentTopMargin; + layoutParamsChanged = true; + } + + if (contentLP.gravity != mGravity) { + contentLP.gravity = mGravity; + layoutParamsChanged = true; + } + + /** + * Only apply the layout params if we've actually changed them, otherwise we'll get stuck in a layout loop + */ + if (layoutParamsChanged) + mContentBox.setLayoutParams(contentLP); + } } /** @@ -388,10 +411,7 @@ private class UpdateOnGlobalLayout implements ViewTreeObserver.OnGlobalLayoutLis @Override public void onGlobalLayout() { - if (mShouldRedraw) { - mShouldRedraw = false; - setTarget(mTarget); - } + setTarget(mTarget); } } @@ -571,16 +591,6 @@ public boolean show(final Activity activity) { setShouldRender(true); - - /** - * If we're on lollipop then make sure we don't draw over the nav bar - */ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - mBottomMargin = getSoftButtonsBarSizePort(activity); - FrameLayout.LayoutParams contentLP = (LayoutParams) getLayoutParams(); - contentLP.bottomMargin = mBottomMargin; - } - mHandler = new Handler(); mHandler.postDelayed(new Runnable() { @Override