diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/IShowcaseListener.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/IShowcaseListener.java index c527b092..4f2fb8f0 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/IShowcaseListener.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/IShowcaseListener.java @@ -4,4 +4,8 @@ public interface IShowcaseListener { void onShowcaseDisplayed(MaterialShowcaseView showcaseView); void onShowcaseDismissed(MaterialShowcaseView showcaseView); + /** + * Notify when singleUse is enabled and showcase has been fired before + */ + void onShowcaseSkipped(MaterialShowcaseView showcaseView); } 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 07bc982d..28889baf 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java @@ -70,6 +70,7 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis private Handler mHandler; private long mDelayInMillis = ShowcaseConfig.DEFAULT_DELAY; private int mBottomMargin = 0; + private int mRightMargin = 0; private boolean mSingleUse = false; // should display only once private PrefsManager mPrefsManager; // used to store state doe single use mode List mListeners; // external listeners who want to observe when we show and dismiss @@ -226,6 +227,28 @@ private void notifyOnDisplayed() { } } + /** + * Notify when {@link #singleUse(String)} is enabled and showcase has been fired before + * @see #singleUse(String) + */ + private void notifyOnSkipped() { + + if(mListeners != null){ + for (IShowcaseListener listener : mListeners) { + listener.onShowcaseSkipped(this); + } + mListeners.clear(); + mListeners = null; + } + + /** + * internal listener used by sequence for storing progress within the sequence + */ + if (mDetachedListener != null) { + mDetachedListener.onShowcaseDetached(this, mWasDismissed); + } + } + private void notifyOnDismissed() { if (mListeners != null) { for (IShowcaseListener listener : mListeners) { @@ -274,10 +297,16 @@ public void setTarget(Target target) { */ if (!mRenderOverNav && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBottomMargin = getSoftButtonsBarSizePort((Activity) getContext()); + mRightMargin = getSoftButtonsBarHorizontalSizePort((Activity) getContext()); + FrameLayout.LayoutParams contentLP = (LayoutParams) getLayoutParams(); - if (contentLP != null && contentLP.bottomMargin != mBottomMargin) - contentLP.bottomMargin = mBottomMargin; + if (contentLP != null) { + if (contentLP.bottomMargin != mBottomMargin) + contentLP.bottomMargin = mBottomMargin; + if (contentLP.rightMargin != mRightMargin) + contentLP.rightMargin = mRightMargin; + } } // apply the target position @@ -682,6 +711,8 @@ public MaterialShowcaseView build() { throw new IllegalArgumentException("Unsupported shape type: " + shapeType); } } + if(showcaseView.mTitleTextView != null && showcaseView.mTitleTextView.getText().equals("")) + showcaseView.mTitleTextView.setVisibility(GONE); return showcaseView; } @@ -738,6 +769,7 @@ public boolean show(final Activity activity) { */ if (mSingleUse) { if (mPrefsManager.hasFired()) { + notifyOnSkipped(); return false; } else { mPrefsManager.setFired(); @@ -845,6 +877,23 @@ public static int getSoftButtonsBarSizePort(Activity activity) { } return 0; } + + public static int getSoftButtonsBarHorizontalSizePort(Activity activity) { + // getRealMetrics is only available with API 17 and + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + + DisplayMetrics metrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + int usableWidth = metrics.widthPixels; + activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); + int realWidth = metrics.widthPixels; + if (realWidth > usableWidth) + return realWidth - usableWidth; + else + return 0; + } + return 0; + } private void setRenderOverNavigationBar(boolean mRenderOverNav) { this.mRenderOverNav = mRenderOverNav;