Skip to content

Commit

Permalink
don't allow a config object to overwrite settings in an already confi…
Browse files Browse the repository at this point in the history
…gured showcase
  • Loading branch information
Dean Wild committed Apr 3, 2019
1 parent 66a14db commit bfa1971
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
Expand Up @@ -42,6 +42,11 @@
*/
public class MaterialShowcaseView extends FrameLayout implements View.OnTouchListener, View.OnClickListener {

public static final int DEFAULT_SHAPE_PADDING = 10;
public static final int DEFAULT_TOOLTIP_MARGIN = 10;
long DEFAULT_DELAY = 0;
long DEFAULT_FADE_TIME = 300;

private int mOldHeight;
private int mOldWidth;
private Bitmap mBitmap;// = new WeakReference<>(null);
Expand All @@ -52,8 +57,8 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis
private int mXPosition;
private int mYPosition;
private boolean mWasDismissed = false, mWasSkipped = false;
private int mShapePadding = ShowcaseConfig.DEFAULT_SHAPE_PADDING;
private int tooltipMargin = ShowcaseConfig.DEFAULT_TOOLTIP_MARGIN;
private int mShapePadding = DEFAULT_SHAPE_PADDING;
private int tooltipMargin = DEFAULT_TOOLTIP_MARGIN;

private View mContentBox;
private TextView mTitleTextView;
Expand All @@ -71,9 +76,9 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis
private IAnimationFactory mAnimationFactory;
private boolean mShouldAnimate = true;
private boolean mUseFadeAnimation = false;
private long mFadeDurationInMillis = ShowcaseConfig.DEFAULT_FADE_TIME;
private long mFadeDurationInMillis = DEFAULT_FADE_TIME;
private Handler mHandler;
private long mDelayInMillis = ShowcaseConfig.DEFAULT_DELAY;
private long mDelayInMillis = DEFAULT_DELAY;
private int mBottomMargin = 0;
private boolean mSingleUse = false; // should display only once
private PrefsManager mPrefsManager; // used to store state doe single use mode
Expand Down Expand Up @@ -557,16 +562,43 @@ public void setAnimationFactory(IAnimationFactory animationFactory) {
* @param config
*/
public void setConfig(ShowcaseConfig config) {
setDelay(config.getDelay());
setFadeDuration(config.getFadeDuration());
setContentTextColor(config.getContentTextColor());
setDismissTextColor(config.getDismissTextColor());
setDismissStyle(config.getDismissTextStyle());

setMaskColour(config.getMaskColor());
setShape(config.getShape());
setShapePadding(config.getShapePadding());
setRenderOverNavigationBar(config.getRenderOverNavigationBar());

if(config.getDelay() > -1){
setDelay(config.getDelay());
}

if(config.getFadeDuration() > 0){
setFadeDuration(config.getFadeDuration());
}


if(config.getContentTextColor() > 0){
setContentTextColor(config.getContentTextColor());
}

if(config.getDismissTextColor() > 0){
setDismissTextColor(config.getDismissTextColor());
}

if(config.getDismissTextStyle() != null){
setDismissStyle(config.getDismissTextStyle());
}

if(config.getMaskColor() > 0){
setMaskColour(config.getMaskColor());
}

if(config.getShape() != null){
setShape(config.getShape());
}

if(config.getShapePadding() > -1){
setShapePadding(config.getShapePadding());
}

if(config.getRenderOverNavigationBar() != null){
setRenderOverNavigationBar(config.getRenderOverNavigationBar());
}
}

void updateDismissButton() {
Expand Down Expand Up @@ -851,6 +883,7 @@ public MaterialShowcaseView build() {
showcaseView.setShape(new RectangleShape(showcaseView.mTarget.getBounds(), fullWidth));
break;
}
default:
case CIRCLE_SHAPE: {
showcaseView.setShape(new CircleShape(showcaseView.mTarget));
break;
Expand All @@ -863,8 +896,6 @@ public MaterialShowcaseView build() {
showcaseView.setShape(new OvalShape(showcaseView.mTarget));
break;
}
default:
throw new IllegalArgumentException("Unsupported shape type: " + shapeType);
}
}

Expand Down
Expand Up @@ -10,22 +10,17 @@
public class ShowcaseConfig {

public static final String DEFAULT_MASK_COLOUR = "#dd335075";
public static final long DEFAULT_FADE_TIME = 300;
public static final long DEFAULT_DELAY = 0;
public static final Shape DEFAULT_SHAPE = new CircleShape();
public static final int DEFAULT_SHAPE_PADDING = 10;
public static final int DEFAULT_TOOLTIP_MARGIN = 10;

private long mDelay = DEFAULT_DELAY;
private long mDelay = -1;
private int mMaskColour;
private Typeface mDismissTextStyle = Typeface.DEFAULT_BOLD;
private Typeface mDismissTextStyle;

private int mContentTextColor;
private int mDismissTextColor;
private long mFadeDuration = DEFAULT_FADE_TIME;
private Shape mShape = DEFAULT_SHAPE;
private int mShapePadding = DEFAULT_SHAPE_PADDING;
private boolean renderOverNav = false;
private long mFadeDuration = -1;
private Shape mShape = null;
private int mShapePadding = -1;
private Boolean renderOverNav;

public ShowcaseConfig() {
mMaskColour = Color.parseColor(ShowcaseConfig.DEFAULT_MASK_COLOUR);
Expand Down Expand Up @@ -97,7 +92,7 @@ public int getShapePadding() {
return mShapePadding;
}

public boolean getRenderOverNavigationBar() {
public Boolean getRenderOverNavigationBar() {
return renderOverNav;
}

Expand Down
Expand Up @@ -11,6 +11,7 @@

import uk.co.deanwild.materialshowcaseview.MaterialShowcaseSequence;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
import uk.co.deanwild.materialshowcaseview.ShowcaseConfig;
import uk.co.deanwild.materialshowcaseview.ShowcaseTooltip;


Expand Down Expand Up @@ -61,8 +62,13 @@ public void onClick(View v) {

void presentShowcaseView() {


ShowcaseConfig config = new ShowcaseConfig();
config.setDelay(500);

MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, SHOWCASE_ID);

//sequence.setConfig(config);

ShowcaseTooltip toolTip1 = ShowcaseTooltip.build(this)
.corner(30)
Expand Down

0 comments on commit bfa1971

Please sign in to comment.