diff --git a/README.md b/README.md
index c220207..949c6ac 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ Quoting the [documentation](https://www.google.com/design/spec/components/steppe
## Download (from JCenter)
```groovy
-compile 'com.stepstone.stepper:material-stepper:1.0.3'
+compile 'com.stepstone.stepper:material-stepper:1.1.0'
```
## Supported steppers
@@ -158,6 +158,11 @@ public class StepperActivity extends AppCompatActivity implements StepperLayout.
Toast.makeText(this, "onStepSelected! -> " + newStepPosition, Toast.LENGTH_SHORT).show();
}
+ @Override
+ public void onReturn() {
+ finish();
+ }
+
}
```
@@ -265,6 +270,21 @@ and declare that style in the XML you keep your styles at, e.g.
```
+### Showing a Back button on first step
+By default if the user is on the first step then the Back button in the bottom navigation is hidden.
+This behaviour can be changed by setting ```ms_showBackButtonOnFirstStep``` to ```true```, e.g.
+```xml
+
+
+```
+To get a callback when this button was pressed you need set a ```StepperListener``` and write your own custom return logic in the ```onReturn()``` method to e.g. close the Activity.
+
### Advanced usage
For other examples, e.g. persisting state on rotation, displaying errors, changing whether the user can go to the next step, etc. check out the sample app.
@@ -285,6 +305,7 @@ For other examples, e.g. persisting state on rotation, displaying errors, changi
| *ms_nextButtonText* | string or reference | NEXT button's text |
| *ms_completeButtonText* | string or reference | COMPLETE button's text |
| *ms_tabStepDividerWidth* | dimension or reference | The width of the horizontal tab divider used in tabs stepper type |
+| *ms_showBackButtonOnFirstStep* | boolean | Flag indicating if the Back (Previous step) button should be shown on the first step. False by default. |
## Missing features
- support for non-linear steppers
diff --git a/gradle.properties b/gradle.properties
index a0df1e5..8a5c542 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -19,4 +19,4 @@
POM_GROUP_ID=com.stepstone.stepper
POM_ARTIFACT_ID=material-stepper
-POM_VERSION=1.0.3
\ No newline at end of file
+POM_VERSION=1.1.0
\ No newline at end of file
diff --git a/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java b/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java
index 797c369..ac9c47e 100644
--- a/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java
+++ b/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java
@@ -85,6 +85,12 @@ public interface StepperListener {
*/
void onStepSelected(int newStepPosition);
+ /**
+ * Called when the Previous step button was pressed while on the first step
+ * (the button is not present by default on first step).
+ */
+ void onReturn();
+
StepperListener NULL = new StepperListener() {
@Override
public void onCompleted(View completeButton) {
@@ -97,6 +103,10 @@ public void onError(VerificationError verificationError) {
@Override
public void onStepSelected(int newStepPosition) {
}
+
+ @Override
+ public void onReturn() {
+ }
};
}
@@ -163,6 +173,8 @@ public final void goToNextStep() {
private String mCompleteButtonText;
+ private boolean mShowBackButtonOnFirstStep;
+
private int mTypeIdentifier = AbstractStepperType.PROGRESS_BAR;
private AbstractStepAdapter mStepAdapter;
@@ -413,6 +425,8 @@ private void extractValuesFromAttributes(AttributeSet attrs, @AttrRes int defSty
mTabStepDividerWidth = a.getDimensionPixelOffset(R.styleable.StepperLayout_ms_tabStepDividerWidth, -1);
}
+ mShowBackButtonOnFirstStep = a.getBoolean(R.styleable.StepperLayout_ms_showBackButtonOnFirstStep, false);
+
if (a.hasValue(R.styleable.StepperLayout_ms_stepperType)) {
mTypeIdentifier = a.getInt(R.styleable.StepperLayout_ms_stepperType, DEFAULT_TAB_DIVIDER_WIDTH);
}
@@ -441,9 +455,12 @@ private Step findCurrentStep() {
}
private void onPrevious() {
- if (mCurrentStepPosition <= 0)
+ if (mCurrentStepPosition <= 0) {
+ if (mShowBackButtonOnFirstStep) {
+ mListener.onReturn();
+ }
return;
-
+ }
mCurrentStepPosition--;
onUpdate(mCurrentStepPosition);
}
@@ -494,7 +511,7 @@ private void onUpdate(int newStepPosition) {
boolean isFirst = newStepPosition == 0;
mNextNavigationButton.setVisibility(isLast ? View.GONE : View.VISIBLE);
mCompleteNavigationButton.setVisibility(!isLast ? View.GONE : View.VISIBLE);
- mBackNavigationButton.setVisibility(isFirst ? View.GONE : View.VISIBLE);
+ mBackNavigationButton.setVisibility(isFirst && !mShowBackButtonOnFirstStep ? View.GONE : View.VISIBLE);
if (!isLast) {
int nextButtonTextForStep = mStepAdapter.getNextButtonText(newStepPosition);
diff --git a/material-stepper/src/main/res/values/attrs.xml b/material-stepper/src/main/res/values/attrs.xml
index fe88483..1e1c6e5 100644
--- a/material-stepper/src/main/res/values/attrs.xml
+++ b/material-stepper/src/main/res/values/attrs.xml
@@ -46,6 +46,9 @@ limitations under the License.
+
+
+
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 4f604fe..50df485 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -35,6 +35,8 @@
+
+
diff --git a/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.java b/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.java
index c94d2d6..876f940 100644
--- a/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.java
+++ b/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.java
@@ -83,6 +83,11 @@ public void onStepSelected(int newStepPosition) {
Toast.makeText(this, "onStepSelected! -> " + newStepPosition, Toast.LENGTH_SHORT).show();
}
+ @Override
+ public void onReturn() {
+ finish();
+ }
+
@Override
public void onChangeEndButtonsEnabled(boolean enabled) {
mStepperLayout.setNextButtonVerificationFailed(!enabled);
diff --git a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java
index 46bcbac..2b6e1d5 100644
--- a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java
+++ b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java
@@ -88,4 +88,9 @@ public void onDifferentNextButtons(View view) {
startActivity(new Intent(this, DifferentNextButtonStepperActivity.class));
}
+ @OnClick(R.id.showReturnButtonOnFirstStep)
+ public void onShowReturnButton(View view) {
+ startActivity(new Intent(this, ReturnButtonActivity.class));
+ }
+
}
diff --git a/sample/src/main/java/com/stepstone/stepper/sample/ReturnButtonActivity.java b/sample/src/main/java/com/stepstone/stepper/sample/ReturnButtonActivity.java
new file mode 100644
index 0000000..c28afcf
--- /dev/null
+++ b/sample/src/main/java/com/stepstone/stepper/sample/ReturnButtonActivity.java
@@ -0,0 +1,26 @@
+/*
+Copyright 2016 StepStone Services
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+
+package com.stepstone.stepper.sample;
+
+public class ReturnButtonActivity extends AbstractStepperActivity {
+
+ @Override
+ protected int getLayoutResId() {
+ return R.layout.activity_return_button;
+ }
+
+}
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
index 095e7a4..c8b83eb 100644
--- a/sample/src/main/res/layout/activity_main.xml
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -82,5 +82,11 @@
android:layout_height="wrap_content"
android:text="@string/different_next_buttons" />
+
+
\ No newline at end of file
diff --git a/sample/src/main/res/layout/activity_return_button.xml b/sample/src/main/res/layout/activity_return_button.xml
new file mode 100644
index 0000000..cc8d240
--- /dev/null
+++ b/sample/src/main/res/layout/activity_return_button.xml
@@ -0,0 +1,9 @@
+
+
\ No newline at end of file
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
index eff10ea..6c69817 100644
--- a/sample/src/main/res/values/strings.xml
+++ b/sample/src/main/res/values/strings.xml
@@ -11,6 +11,7 @@
Custom PageTransformerDelayed transitionDifferent next buttons
+ Show Back button on first stepTab titleLorem ipsum dolor sit amet, sale viris intellegam usu eu, persius patrioque sea at. Ne salutandi repudiandae mei, cu mollis accusam mediocrem mea. Altera dolorem praesent at vis. Torquatos philosophia ad quo. Omnis adipiscing has ea, mel no hinc iudico percipit.