Skip to content

Commit

Permalink
handle config changes properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Wild committed Aug 24, 2015
1 parent d508ae1 commit 9253b4d
Showing 1 changed file with 36 additions and 26 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -388,10 +411,7 @@ private class UpdateOnGlobalLayout implements ViewTreeObserver.OnGlobalLayoutLis

@Override
public void onGlobalLayout() {
if (mShouldRedraw) {
mShouldRedraw = false;
setTarget(mTarget);
}
setTarget(mTarget);
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9253b4d

Please sign in to comment.