Skip to content
This repository was archived by the owner on Apr 24, 2018. It is now read-only.

Commit a73660a

Browse files
committed
Merge pull request #307 from amlcurran/custom-button
Custom button
2 parents f0cb303 + ae61f4c commit a73660a

File tree

6 files changed

+72
-3
lines changed

6 files changed

+72
-3
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# limitations under the License.
1515
#
1616

17-
VERSION_CODE=50102
18-
VERSION_NAME=5.1.1-SNAPSHOT
17+
VERSION_CODE=50200
18+
VERSION_NAME=5.2.0-SNAPSHOT
1919
GROUP=com.github.amlcurran.showcaseview
2020

2121
POM_DESCRIPTION=Highlight the best bits of your app to users quickly, simply, and cool...ly

library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ShowcaseView extends RelativeLayout
4848

4949
private static final int HOLO_BLUE = Color.parseColor("#33B5E5");
5050

51-
private final Button mEndButton;
51+
private Button mEndButton;
5252
private final TextDrawer textDrawer;
5353
private ShowcaseDrawer showcaseDrawer;
5454
private final ShowcaseAreaCalculator showcaseAreaCalculator;
@@ -563,6 +563,37 @@ public Builder setContentTitlePaint(TextPaint textPaint) {
563563
showcaseView.setContentTitlePaint(textPaint);
564564
return this;
565565
}
566+
567+
/**
568+
* Replace the end button with the one provided. Note that this resets any OnClickListener provided
569+
* by {@link #setOnClickListener(OnClickListener)}, so call this method before that one.
570+
*/
571+
public Builder replaceEndButton(Button button) {
572+
showcaseView.setEndButton(button);
573+
return this;
574+
}
575+
576+
/**
577+
* Replace the end button with the one provided. Note that this resets any OnClickListener provided
578+
* by {@link #setOnClickListener(OnClickListener)}, so call this method before that one.
579+
*/
580+
public Builder replaceEndButton(int buttonResourceId) {
581+
View view = LayoutInflater.from(activity).inflate(buttonResourceId, showcaseView, false);
582+
if (!(view instanceof Button)) {
583+
throw new IllegalArgumentException("Attempted to replace showcase button with a layout which isn't a button");
584+
}
585+
return replaceEndButton((Button) view);
586+
}
587+
}
588+
589+
private void setEndButton(Button button) {
590+
LayoutParams copyParams = (LayoutParams) mEndButton.getLayoutParams();
591+
mEndButton.setOnClickListener(null);
592+
removeView(mEndButton);
593+
mEndButton = button;
594+
button.setOnClickListener(hideOnClickListener);
595+
button.setLayoutParams(copyParams);
596+
addView(button);
566597
}
567598

568599
private void setShowcaseDrawer(ShowcaseDrawer showcaseDrawer) {

sample/src/main/java/com/github/amlcurran/showcaseview/sample/SampleActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void onCreate(Bundle savedInstanceState) {
7676
.setContentText(R.string.showcase_main_message)
7777
.setStyle(R.style.CustomShowcaseTheme2)
7878
.setShowcaseEventListener(this)
79+
.replaceEndButton(R.layout.view_custom_button)
7980
.build();
8081
sv.setButtonPosition(lps);
8182
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:color="#ffffff">
4+
5+
<item
6+
android:id="@android:id/mask"
7+
android:drawable="@android:color/white"/>
8+
9+
</ripple>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:state_pressed="true">
4+
<shape android:shape="rectangle">
5+
<solid android:color="#ccffffff" />
6+
</shape>
7+
</item>
8+
<item android:state_focused="true">
9+
<shape android:shape="rectangle">
10+
<stroke android:color="@android:color/white" />
11+
</shape>
12+
</item>
13+
<item android:drawable="@android:color/transparent" />
14+
</selector>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Button xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:text="Got it"
7+
android:textStyle="bold"
8+
android:background="@drawable/material_showcase_button_bg"
9+
android:textSize="13sp"
10+
android:textAllCaps="true"
11+
android:textColor="@android:color/white"
12+
>
13+
14+
</Button>

0 commit comments

Comments
 (0)