-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added second button #386
base: master
Are you sure you want to change the base?
Added second button #386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ public class ShowcaseView extends RelativeLayout | |
| } | ||
|
|
||
| private Button mEndButton; | ||
| private Button mButtonTwo; | ||
| private final TextDrawer textDrawer; | ||
| private ShowcaseDrawer showcaseDrawer; | ||
| private final ShowcaseAreaCalculator showcaseAreaCalculator; | ||
|
|
@@ -121,6 +122,7 @@ protected ShowcaseView(Context context, AttributeSet attrs, int defStyle, boolea | |
| fadeOutMillis = getResources().getInteger(android.R.integer.config_mediumAnimTime); | ||
|
|
||
| mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null); | ||
| mButtonTwo = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null); | ||
| if (newStyle) { | ||
| showcaseDrawer = new NewShowcaseDrawer(getResources(), context.getTheme()); | ||
| } else { | ||
|
|
@@ -151,12 +153,29 @@ private void init() { | |
| addView(mEndButton); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| private boolean hasShot() { | ||
| return shotStateStore.hasShot(); | ||
| } | ||
|
|
||
|
|
||
| private void addButtonTwo() { | ||
| if (mButtonTwo.getParent() == null) { | ||
| int margin = (int) getResources().getDimension(R.dimen.button_margin); | ||
| RelativeLayout.LayoutParams lps = (LayoutParams) generateDefaultLayoutParams(); | ||
| lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); | ||
| lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT); | ||
| lps.setMargins(margin, margin, margin, margin); | ||
| mButtonTwo.setLayoutParams(lps); | ||
| mButtonTwo.setText(android.R.string.cancel); | ||
| if (!hasCustomClickListener) { | ||
| mButtonTwo.setOnClickListener(hideOnClickListener); | ||
| } | ||
| addView(mButtonTwo); | ||
| } | ||
| } | ||
| void setShowcasePosition(Point point) { | ||
| setShowcasePosition(point.x, point.y); | ||
| } | ||
|
|
@@ -261,6 +280,43 @@ public void overrideButtonClick(OnClickListener listener) { | |
| hasCustomClickListener = true; | ||
| } | ||
|
|
||
| public void overrideButtonTwoClick(OnClickListener listener) { | ||
| if (shotStateStore.hasShot()) { | ||
| return; | ||
| } | ||
| if (mButtonTwo != null) { | ||
| if (listener != null) { | ||
| mButtonTwo.setOnClickListener(listener); | ||
| } else { | ||
| mButtonTwo.setOnClickListener(hideOnClickListener); | ||
| } | ||
| } | ||
| hasCustomClickListener = true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public void overrideButtonsClick(OnClickListener listener1,OnClickListener listener2) { | ||
| if (shotStateStore.hasShot()) { | ||
| return; | ||
| } | ||
| if (mEndButton != null) { | ||
| if (listener1 != null) { | ||
| mEndButton.setOnClickListener(listener1); | ||
| } else { | ||
| mEndButton.setOnClickListener(hideOnClickListener); | ||
| } | ||
| } | ||
| if (mButtonTwo != null) { | ||
| if (listener2 != null) { | ||
| mButtonTwo.setOnClickListener(listener2); | ||
| } else { | ||
| mButtonTwo.setOnClickListener(hideOnClickListener); | ||
| } | ||
| } | ||
| hasCustomClickListener = true; | ||
| } | ||
|
|
||
| public void setOnShowcaseEventListener(OnShowcaseEventListener listener) { | ||
| if (listener != null) { | ||
| mEventListener = listener; | ||
|
|
@@ -275,6 +331,22 @@ public void setButtonText(CharSequence text) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Set text of BOTH buttons | ||
| * | ||
| * @param text1 Listener to listen to on click events for first button | ||
| * @param text2 Listener to listen to on click events for second button | ||
| */ | ||
| public void setButtonsText(CharSequence text1,CharSequence text2) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (mEndButton != null) { | ||
| mEndButton.setText(text1); | ||
| } | ||
| if (mButtonTwo != null) { | ||
| mButtonTwo.setText(text2); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private void recalculateText() { | ||
| boolean recalculatedCling = showcaseAreaCalculator.calculateShowcaseRect(showcaseX, showcaseY, showcaseDrawer); | ||
| boolean recalculateText = recalculatedCling || hasAlteredText; | ||
|
|
@@ -424,6 +496,14 @@ public void showButton() { | |
| mEndButton.setVisibility(VISIBLE); | ||
| } | ||
|
|
||
| public void hideButtonTwo() { | ||
| mButtonTwo.setVisibility(GONE); | ||
| } | ||
|
|
||
| public void showButtonTwo() { | ||
| mButtonTwo.setVisibility(VISIBLE); | ||
| } | ||
|
|
||
| /** | ||
| * Builder class which allows easier creation of {@link ShowcaseView}s. | ||
| * It is recommended that you use this Builder class. | ||
|
|
@@ -555,6 +635,16 @@ public Builder setOnClickListener(OnClickListener onClickListener) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder setOnClickListeners(OnClickListener onClickListener1,OnClickListener onClickListener2) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| showcaseView.overrideButtonsClick(onClickListener1,onClickListener2); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setOnClickButtonTwoListener(OnClickListener onClickListener) { | ||
| showcaseView.overrideButtonTwoClick(onClickListener); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Don't make the ShowcaseView block touches on itself. This doesn't | ||
| * block touches in the showcased area. | ||
|
|
@@ -628,6 +718,14 @@ public Builder replaceEndButton(Button button) { | |
| showcaseView.setEndButton(button); | ||
| return this; | ||
| } | ||
| /** | ||
| * Call addSecondButton first! | ||
| * | ||
| */ | ||
| public Builder replaceButtonTwo(Button button) { | ||
| showcaseView.setButtonTwo(button); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Replace the end button with the one provided. Note that this resets any OnClickListener provided | ||
|
|
@@ -640,6 +738,17 @@ public Builder replaceEndButton(int buttonResourceId) { | |
| } | ||
| return replaceEndButton((Button) view); | ||
| } | ||
| /** | ||
| * Call addSecondButton first! | ||
| * | ||
| */ | ||
| public Builder replaceButtonTwo(int buttonResourceId) { | ||
| View view = LayoutInflater.from(activity).inflate(buttonResourceId, showcaseView, false); | ||
| if (!(view instanceof Button)) { | ||
| throw new IllegalArgumentException("Attempted to replace showcase button with a layout which isn't a button"); | ||
| } | ||
| return replaceButtonTwo((Button) view); | ||
| } | ||
|
|
||
| /** | ||
| * Block any touch made on the ShowcaseView, even inside the showcase | ||
|
|
@@ -658,6 +767,14 @@ public Builder useDecorViewAsParent() { | |
| this.parentIndex = -1; | ||
| return this; | ||
| } | ||
| /** | ||
| * Call this first if you plan to use other Builder methods | ||
| * using the second button | ||
| */ | ||
| public Builder addSecondButton(){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so I think a better way of doing this would be to only have one method |
||
| showcaseView.addButtonTwo(); | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| private void setEndButton(Button button) { | ||
|
|
@@ -670,6 +787,27 @@ private void setEndButton(Button button) { | |
| addView(button); | ||
| } | ||
|
|
||
| private void setButtonTwo(Button button) { | ||
| LayoutParams copyParams = (LayoutParams) mButtonTwo.getLayoutParams(); | ||
| mButtonTwo.setOnClickListener(null); | ||
| removeView(mButtonTwo); | ||
| mButtonTwo = button; | ||
| button.setOnClickListener(hideOnClickListener); | ||
| button.setLayoutParams(copyParams); | ||
| addView(button); | ||
| } | ||
|
|
||
|
|
||
| private void setButtons(Button button1,Button button2) { | ||
| if(button1 != null) { | ||
| setEndButton(button1); | ||
| } | ||
|
|
||
| if(button2 != null) { | ||
| setButtonTwo(button2); | ||
| } | ||
| } | ||
|
|
||
| private void setShowcaseDrawer(ShowcaseDrawer showcaseDrawer) { | ||
| this.showcaseDrawer = showcaseDrawer; | ||
| this.showcaseDrawer.setBackgroundColour(backgroundColor); | ||
|
|
@@ -717,6 +855,14 @@ public void setButtonPosition(RelativeLayout.LayoutParams layoutParams) { | |
| mEndButton.setLayoutParams(layoutParams); | ||
| } | ||
|
|
||
| public void setButtonTwoPosition(RelativeLayout.LayoutParams layoutParams) { | ||
| mButtonTwo.setLayoutParams(layoutParams); | ||
| } | ||
|
|
||
| public void setButtonPositions(RelativeLayout.LayoutParams layoutParams1,RelativeLayout.LayoutParams layoutParams2) { | ||
| setButtonPosition(layoutParams1); | ||
| setButtonTwoPosition(layoutParams2); | ||
| } | ||
| /** | ||
| * Sets the text alignment of the detail text | ||
| */ | ||
|
|
@@ -803,6 +949,7 @@ private void updateStyle(TypedArray styled, boolean invalidate) { | |
| showcaseDrawer.setBackgroundColour(backgroundColor); | ||
| tintButton(showcaseColor, tintButton); | ||
| mEndButton.setText(buttonText); | ||
| mButtonTwo.setText(buttonText); | ||
| textDrawer.setTitleStyling(titleTextAppearance); | ||
| textDrawer.setDetailStyling(detailTextAppearance); | ||
| hasAlteredText = true; | ||
|
|
@@ -812,6 +959,26 @@ private void updateStyle(TypedArray styled, boolean invalidate) { | |
| } | ||
| } | ||
|
|
||
| private void tintButtons(int showcaseColor, boolean tintButton) { | ||
| if (tintButton) { | ||
| mEndButton.getBackground().setColorFilter(showcaseColor, PorterDuff.Mode.MULTIPLY); | ||
| mButtonTwo.getBackground().setColorFilter(showcaseColor, PorterDuff.Mode.MULTIPLY); | ||
| } else { | ||
| mEndButton.getBackground().setColorFilter(HOLO_BLUE, PorterDuff.Mode.MULTIPLY); | ||
| mButtonTwo.getBackground().setColorFilter(HOLO_BLUE, PorterDuff.Mode.MULTIPLY); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| private void tintButtonTwo(int showcaseColor, boolean tintButton) { | ||
| if (tintButton) { | ||
| mButtonTwo.getBackground().setColorFilter(showcaseColor, PorterDuff.Mode.MULTIPLY); | ||
| } else { | ||
| mButtonTwo.getBackground().setColorFilter(HOLO_BLUE, PorterDuff.Mode.MULTIPLY); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| private void tintButton(int showcaseColor, boolean tintButton) { | ||
| if (tintButton) { | ||
| mEndButton.getBackground().setColorFilter(showcaseColor, PorterDuff.Mode.MULTIPLY); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package com.github.amlcurran.showcaseview.sample; | ||
|
|
||
| import android.app.Activity; | ||
| import android.os.Bundle; | ||
| import android.view.MotionEvent; | ||
| import android.view.View; | ||
| import android.widget.Button; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.espian.showcaseview.sample.R; | ||
| import com.github.amlcurran.showcaseview.OnShowcaseEventListener; | ||
| import com.github.amlcurran.showcaseview.ShowcaseView; | ||
| import com.github.amlcurran.showcaseview.targets.ViewTarget; | ||
|
|
||
| /** | ||
| * Created by Kevin on 5/04/2016. | ||
| */ | ||
| public class ButtonTwoActivity extends Activity implements OnShowcaseEventListener { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this class is formatted inconsistently, can you reformat it correctly? |
||
|
|
||
|
|
||
| private ShowcaseView sv; | ||
| private boolean clickedButton1; | ||
| private boolean clickedButton2; | ||
| private TextView mTextView; | ||
| private Button mButtonAgain; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) | ||
| { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_two_buttons); | ||
| mTextView = (TextView) findViewById(R.id.Textview_two_buttons); | ||
| mButtonAgain = (Button) findViewById(R.id.Button_two_buttons); | ||
| mButtonAgain.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| showShowCase(); | ||
| mTextView.setText(R.string.two_buttons); | ||
| } | ||
| }); | ||
| showShowCase(); | ||
| } | ||
|
|
||
| private void showShowCase(){ | ||
| clickedButton1 = false; | ||
| clickedButton2 = false; | ||
| ViewTarget target = new ViewTarget(R.id.Textview_two_buttons, this); | ||
| sv = new ShowcaseView.Builder(this) | ||
| .withMaterialShowcase() | ||
| .hideOnTouchOutside() | ||
| .setTarget(target) | ||
| .setContentTitle(R.string.title_two_buttons) | ||
| .setContentText(R.string.showcase_twobuttons_message) | ||
| .setStyle(R.style.CustomShowcaseTheme2) | ||
| .setShowcaseEventListener(this) | ||
| .addSecondButton() | ||
| .replaceEndButton(R.layout.view_custom_button) | ||
| .replaceButtonTwo(R.layout.view_custom_button) | ||
| .build(); | ||
| sv.setButtonsText(getString(R.string.button1),getString(R.string.button2)); | ||
| sv.overrideButtonClick(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| clickedButton1 = true; | ||
| sv.hide(); | ||
| } | ||
| }); | ||
| sv.overrideButtonTwoClick(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| clickedButton2 = true; | ||
| sv.hide(); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onShowcaseViewHide(ShowcaseView showcaseView) { | ||
|
|
||
| if(clickedButton1){ | ||
| mTextView.setText(R.string.clicked_button1); | ||
| clickedButton1 = false; | ||
| } | ||
| else if(clickedButton2) { | ||
| mTextView.setText(R.string.clicked_button2); | ||
| clickedButton2 = false; | ||
| } | ||
| else{ | ||
| mTextView.setText(R.string.clicked_showcase); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onShowcaseViewDidHide(ShowcaseView showcaseView) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onShowcaseViewShow(ShowcaseView showcaseView) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onShowcaseViewTouchBlocked(MotionEvent motionEvent) { | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to have this method, just having the two
overrideButtonTwoClickandoverrideButtonClickmethods