Skip to content

Commit

Permalink
Merge pull request #66 from krimin-killr21/master
Browse files Browse the repository at this point in the history
Add optional title to showcase
  • Loading branch information
Dean Wild committed Mar 15, 2016
2 parents 37e5d37 + 946068b commit 5f82343
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ proguard/

# Log Files
*.log

#.idea
/.idea

#imls
*.iml
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:1.5.0'
// This does not break the build when Android Studio is missing the JRebel for Android plugin.
classpath 'com.zeroturnaround.jrebel.android:jr-android-gradle:0.8.+'

Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23"
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 14
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ public MaterialShowcaseSequence(Activity activity, String sequenceID) {
}

public MaterialShowcaseSequence addSequenceItem(View targetView, String content, String dismissText) {
addSequenceItem(targetView, "", content, dismissText);
return this;
}

public MaterialShowcaseSequence addSequenceItem(View targetView, String title, String content, String dismissText) {

MaterialShowcaseView sequenceItem = new MaterialShowcaseView.Builder(mActivity)
.setTarget(targetView)
.setTitleText(title)
.setDismissText(dismissText)
.setContentText(content)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis
private int mShapePadding = ShowcaseConfig.DEFAULT_SHAPE_PADDING;

private View mContentBox;
private TextView mTitleTextView;
private TextView mContentTextView;
private TextView mDismissButton;
private int mGravity;
Expand All @@ -73,6 +74,8 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis
List<IShowcaseListener> mListeners; // external listeners who want to observe when we show and dismiss
private UpdateOnGlobalLayout mLayoutListener;
private IDetachedListener mDetachedListener;
private boolean mTargetTouchable = false;
private boolean mDismissOnTargetTouch = true;

public MaterialShowcaseView(Context context) {
super(context);
Expand Down Expand Up @@ -117,6 +120,7 @@ private void init(Context context) {

View contentView = LayoutInflater.from(getContext()).inflate(R.layout.showcase_content, this, true);
mContentBox = contentView.findViewById(R.id.content_box);
mTitleTextView = (TextView) contentView.findViewById(R.id.tv_title);
mContentTextView = (TextView) contentView.findViewById(R.id.tv_content);
mDismissButton = (TextView) contentView.findViewById(R.id.tv_dismiss);
mDismissButton.setOnClickListener(this);
Expand Down Expand Up @@ -200,6 +204,12 @@ public boolean onTouch(View v, MotionEvent event) {
if (mDismissOnTouch) {
hide();
}
if(mTargetTouchable && mTarget.getBounds().contains((int)event.getX(), (int)event.getY())){
if(mDismissOnTargetTouch){
hide();
}
return false;
}
return true;
}

Expand Down Expand Up @@ -342,6 +352,13 @@ void setPosition(int x, int y) {
mYPosition = y;
}

private void setTitleText(CharSequence contentText) {
if (mTitleTextView != null && !contentText.equals("")) {
mContentTextView.setAlpha(0.5F);
mTitleTextView.setText(contentText);
}
}

private void setContentText(CharSequence contentText) {
if (mContentTextView != null) {
mContentTextView.setText(contentText);
Expand All @@ -356,6 +373,12 @@ private void setDismissText(CharSequence dismissText) {
}
}

private void setTitleTextColor(int textColour) {
if (mTitleTextView != null) {
mTitleTextView.setTextColor(textColour);
}
}

private void setContentTextColor(int textColour) {
if (mContentTextView != null) {
mContentTextView.setTextColor(textColour);
Expand Down Expand Up @@ -392,6 +415,14 @@ private void setFadeDuration(long fadeDurationInMillis) {
mFadeDurationInMillis = fadeDurationInMillis;
}

private void setTargetTouchable(boolean targetTouchable){
mTargetTouchable = targetTouchable;
}

private void setDismissOnTargetTouch(boolean dismissOnTargetTouch){
mDismissOnTargetTouch = dismissOnTargetTouch;
}

public void addShowcaseListener(IShowcaseListener showcaseListener) {

if(mListeners != null)
Expand Down Expand Up @@ -498,7 +529,7 @@ public Builder setDismissText(CharSequence dismissText) {
}

/**
* Set the title text shown on the ShowcaseView.
* Set the content text shown on the ShowcaseView.
*/
public Builder setContentText(int resId) {
return setContentText(activity.getString(resId));
Expand All @@ -512,6 +543,40 @@ public Builder setContentText(CharSequence text) {
return this;
}

/**
* Set the title text shown on the ShowcaseView.
*/
public Builder setTitleText(int resId) {
return setTitleText(activity.getString(resId));
}

/**
* Set the descriptive text shown on the ShowcaseView as the title.
*/
public Builder setTitleText(CharSequence text) {
showcaseView.setTitleText(text);
return this;
}

/**
* Set whether or not the target view can be touched while the showcase is visible.
*
* False by default.
*/
public Builder setTargetTouchable(boolean targetTouchable){
showcaseView.setTargetTouchable(targetTouchable);
return this;
}

/**
* Set whether or not the showcase should dismiss when the target is touched.
*
* True by default.
*/
public Builder setDismissOnTargetTouch(boolean dismissOnTargetTouch){
showcaseView.setDismissOnTargetTouch(dismissOnTargetTouch);
return this;
}

public Builder setDismissOnTouch(boolean dismissOnTouch) {
showcaseView.setDismissOnTouch(dismissOnTouch);
Expand All @@ -523,6 +588,11 @@ public Builder setMaskColour(int maskColour) {
return this;
}

public Builder setTitleTextColor(int textColour) {
showcaseView.setTitleTextColor(textColour);
return this;
}

public Builder setContentTextColor(int textColour) {
showcaseView.setContentTextColor(textColour);
return this;
Expand Down
9 changes: 9 additions & 0 deletions library/src/main/res/layout/showcase_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:paddingLeft="5dp"
android:textSize="30dp"
android:layout_marginBottom="15dp" />

<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
Expand Down
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ apply plugin: 'com.zeroturnaround.jrebel.android'

android {
compileSdkVersion 23
buildToolsVersion "23"
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "uk.co.deanwild.materialshowcaseviewsample"
minSdkVersion 14
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
Expand All @@ -23,6 +23,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void onClick(View v) {
private void presentShowcaseView(int withDelay) {
new MaterialShowcaseView.Builder(this)
.setTarget(mButtonShow)
.setTitleText("Hello")
.setDismissText("GOT IT")
.setContentText("This is some amazing feature you should know about")
.setDelay(withDelay) // optional but starting animations immediately in onCreate can make them choppy
Expand Down

0 comments on commit 5f82343

Please sign in to comment.