Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button Type added for Dismiss Text #188

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 29 13:11:06 GMT 2019
#Thu Feb 06 22:30:22 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:28.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.graphics.Typeface;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.IntDef;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
Expand All @@ -22,9 +23,11 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,6 +39,8 @@
import uk.co.deanwild.materialshowcaseview.target.Target;
import uk.co.deanwild.materialshowcaseview.target.ViewTarget;

import static java.lang.annotation.RetentionPolicy.SOURCE;


/**
* Helper class to show a sequence of showcase views.
Expand All @@ -44,6 +49,9 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis

public static final int DEFAULT_SHAPE_PADDING = 10;
public static final int DEFAULT_TOOLTIP_MARGIN = 10;
public static final int DISMISS_TYPE_TEXT = 1;
public static final int DISMISS_TYPE_BUTTON = 2;
private int dismissType = DISMISS_TYPE_TEXT;
long DEFAULT_DELAY = 0;
long DEFAULT_FADE_TIME = 300;

Expand All @@ -63,7 +71,8 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis
private View mContentBox;
private TextView mTitleTextView;
private TextView mContentTextView;
private TextView mDismissButton;
private TextView mDismissText;
private Button mDismissButton;
private boolean mHasCustomGravity;
private TextView mSkipButton;
private int mGravity;
Expand Down Expand Up @@ -135,9 +144,10 @@ private void init(Context context) {
mContentBox = contentView.findViewById(R.id.content_box);
mTitleTextView = contentView.findViewById(R.id.tv_title);
mContentTextView = contentView.findViewById(R.id.tv_content);
mDismissButton = contentView.findViewById(R.id.tv_dismiss);
mDismissText = contentView.findViewById(R.id.tv_dismiss);
mDismissText.setOnClickListener(this);
mDismissButton = contentView.findViewById(R.id.btn_dismiss);
mDismissButton.setOnClickListener(this);

mSkipButton = contentView.findViewById(R.id.tv_skip);
mSkipButton.setOnClickListener(this);
}
Expand Down Expand Up @@ -267,7 +277,7 @@ private void notifyOnDismissed() {
*/
@Override
public void onClick(View v) {
if (v.getId() == R.id.tv_dismiss) {
if (v.getId() == R.id.tv_dismiss || v.getId()==R.id.btn_dismiss) {
hide();
} else if (v.getId() == R.id.tv_skip) {
skip();
Expand Down Expand Up @@ -447,6 +457,10 @@ private void setIsSequence(Boolean isSequenceB) {
}

private void setDismissText(CharSequence dismissText) {
if (mDismissText != null) {
mDismissText.setText(dismissText);
updateDismissButton();
}
if (mDismissButton != null) {
mDismissButton.setText(dismissText);
updateDismissButton();
Expand All @@ -461,12 +475,20 @@ private void setSkipText(CharSequence skipText) {
}

private void setDismissStyle(Typeface dismissStyle) {
if (mDismissText != null) {
mDismissText.setTypeface(dismissStyle);
updateDismissButton();
}
if (mDismissButton != null) {
mDismissButton.setTypeface(dismissStyle);
updateDismissButton();
}
}

private void setDismissType(int dismissType) {
this.dismissType = dismissType;
}

private void setSkipStyle(Typeface skipStyle) {
if (mSkipButton != null) {
mSkipButton.setTypeface(skipStyle);
Expand All @@ -487,11 +509,21 @@ private void setContentTextColor(int textColour) {
}

private void setDismissTextColor(int textColour) {
if (mDismissText != null) {
mDismissText.setTextColor(textColour);
}
if (mDismissButton != null) {
mDismissButton.setTextColor(textColour);
}
}

private void setDismissButtonColor(int btnColour) {
if (mDismissButton != null) {
mDismissButton.setBackgroundColor(btnColour);
}
}


private void setShapePadding(int padding) {
mShapePadding = padding;
}
Expand Down Expand Up @@ -563,51 +595,60 @@ public void setAnimationFactory(IAnimationFactory animationFactory) {
*/
public void setConfig(ShowcaseConfig config) {

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

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


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

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

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

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

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

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

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

void updateDismissButton() {
// hide or show button
if (mDismissButton != null) {
if (mDismissText != null && dismissType == DISMISS_TYPE_TEXT) {
if (TextUtils.isEmpty(mDismissText.getText())) {
mDismissText.setVisibility(GONE);
} else {
mDismissText.setVisibility(VISIBLE);
mDismissButton.setVisibility(GONE);
}
}
if (mDismissButton != null && dismissType == DISMISS_TYPE_BUTTON) {
if (TextUtils.isEmpty(mDismissButton.getText())) {
mDismissButton.setVisibility(GONE);
} else {
mDismissButton.setVisibility(VISIBLE);
mDismissText.setVisibility(GONE);
}
}
}
Expand Down Expand Up @@ -686,6 +727,17 @@ public Builder setSequence(Boolean isSequence) {
/**
* Set the dismiss button properties
*/

@Retention(SOURCE)
@IntDef({DISMISS_TYPE_TEXT, DISMISS_TYPE_BUTTON})
@interface DismissType {
}

public Builder setDismissType(@DismissType int dismissType) {
showcaseView.setDismissType(dismissType);
return this;
}

public Builder setDismissText(int resId) {
return setDismissText(activity.getString(resId));
}
Expand Down Expand Up @@ -805,6 +857,11 @@ public Builder setDismissTextColor(int textColour) {
return this;
}

public Builder setDismissButtonColor(int buttonColour) {
showcaseView.setDismissButtonColor(buttonColour);
return this;
}

public Builder setDelay(int delayInMillis) {
showcaseView.setDelay(delayInMillis);
return this;
Expand Down
15 changes: 15 additions & 0 deletions library/src/main/res/layout/showcase_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@
android:textSize="22dp"
android:visibility="gone" />

<Button
android:id="@+id/btn_dismiss"
android:background="?android:attr/selectableItemBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clickable="true"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textColor="@android:color/white"
android:textSize="22dp"
android:visibility="gone" />

<TextView
android:id="@+id/tv_skip"
android:background="?android:attr/selectableItemBackground"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.co.deanwild.materialshowcaseviewsample;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
Expand Down