Skip to content

Commit fed56b7

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
- Updated Android Support Library to 25.1.1
- Added an option to proceed to the next step/complete programmatically (issue #53)
1 parent 29afd86 commit fed56b7

File tree

13 files changed

+283
-6
lines changed

13 files changed

+283
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Quoting the [documentation](https://www.google.com/design/spec/components/steppe
1313
1414
## Download (from JCenter)
1515
```groovy
16-
compile 'com.stepstone.stepper:material-stepper:2.2.0'
16+
compile 'com.stepstone.stepper:material-stepper:2.3.0'
1717
```
1818

1919
## Supported steppers

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ configure(allprojects) {
2323
androidTargetSdkVersion = 25
2424
androidCompileSdkVersion = 25
2525
androidBuildToolsVersion = "25.0.2"
26-
androidSupportLibraryVersion = "25.1.0"
26+
androidSupportLibraryVersion = "25.1.1"
2727

2828
/* Sample only */
2929
butterknifeVersion = "7.0.1"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
POM_GROUP_ID=com.stepstone.stepper
2121
POM_ARTIFACT_ID=material-stepper
22-
POM_VERSION=2.2.0
22+
POM_VERSION=2.3.0

material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public void onClick(View v) {
237237
private OnClickListener mOnCompleteClickListener = new OnClickListener() {
238238
@Override
239239
public void onClick(View v) {
240-
onComplete(v);
240+
onComplete();
241241
}
242242
};
243243

@@ -325,6 +325,23 @@ public void onTabClicked(int position) {
325325
}
326326
}
327327

328+
/**
329+
* This is an equivalent of clicking the Next/Complete button from the bottom navigation.
330+
* Unlike {@link #setCurrentStepPosition(int)} this actually verifies the step.
331+
*/
332+
public void proceed() {
333+
if (isLastPosition(mCurrentStepPosition)) {
334+
onComplete();
335+
} else {
336+
onNext();
337+
}
338+
}
339+
340+
/**
341+
* Sets the current step to the one at the provided index.
342+
* This does not verify the current step.
343+
* @param currentStepPosition new current step position
344+
*/
328345
public void setCurrentStepPosition(int currentStepPosition) {
329346
this.mCurrentStepPosition = currentStepPosition;
330347
onUpdate(currentStepPosition, true);
@@ -593,13 +610,13 @@ private void onError(@NonNull VerificationError verificationError) {
593610
mListener.onError(verificationError);
594611
}
595612

596-
private void onComplete(View completeButton) {
613+
private void onComplete() {
597614
Step step = findCurrentStep();
598615
if (verifyCurrentStep(step)) {
599616
return;
600617
}
601618
mStepperType.setErrorStep(mCurrentStepPosition, false);
602-
mListener.onCompleted(completeButton);
619+
mListener.onCompleted(mCompleteNavigationButton);
603620
}
604621

605622
private void onUpdate(int newStepPosition, boolean animate) {

sample/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<activity android:name=".CustomNavigationButtonsStepperActivity" />
3434
<activity android:name=".ReturnButtonActivity" />
3535
<activity android:name=".NoFragmentsActivity" />
36+
<activity android:name=".ProceedProgrammaticallyActivity"
37+
android:windowSoftInputMode="stateVisible"/>
3638
<activity
3739
android:name=".CustomStepperLayoutThemeActivity"
3840
android:theme="@style/AppThemeDark" />

sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public void onNoFrag(View view){
113113
startActivity(new Intent(this, NoFragmentsActivity.class));
114114
}
115115

116+
@OnClick(R.id.proceedProgrammatically)
117+
public void onProceedProgrammatically(View view){
118+
startActivity(new Intent(this, ProceedProgrammaticallyActivity.class));
119+
}
120+
116121
@OnClick(R.id.customStepperLayoutTheme)
117122
public void onCustomStepperLayoutThemeWithTabs(View view){
118123
startActivity(new Intent(this, CustomStepperLayoutThemeActivity.class));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2016 StepStone Services
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.stepstone.stepper.sample;
18+
19+
public interface OnProceedListener {
20+
21+
void onProceed();
22+
23+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2017 StepStone Services
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.stepstone.stepper.sample;
18+
19+
import android.os.Bundle;
20+
import android.support.v7.app.AppCompatActivity;
21+
import android.view.View;
22+
import android.widget.Toast;
23+
24+
import com.stepstone.stepper.StepperLayout;
25+
import com.stepstone.stepper.VerificationError;
26+
import com.stepstone.stepper.sample.adapter.FormFragmentStepAdapter;
27+
28+
public class ProceedProgrammaticallyActivity extends AppCompatActivity implements StepperLayout.StepperListener, OnProceedListener {
29+
30+
private static final String CURRENT_STEP_POSITION_KEY = "position";
31+
32+
private StepperLayout mStepperLayout;
33+
34+
@Override
35+
protected void onCreate(Bundle savedInstanceState) {
36+
super.onCreate(savedInstanceState);
37+
setTitle("Stepper sample");
38+
39+
setContentView(R.layout.activity_default_dots);
40+
mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout);
41+
int startingStepPosition = savedInstanceState != null ? savedInstanceState.getInt(CURRENT_STEP_POSITION_KEY) : 0;
42+
mStepperLayout.setAdapter(new FormFragmentStepAdapter(getSupportFragmentManager(), this), startingStepPosition);
43+
mStepperLayout.setListener(this);
44+
}
45+
46+
@Override
47+
protected void onSaveInstanceState(Bundle outState) {
48+
outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.getCurrentStepPosition());
49+
super.onSaveInstanceState(outState);
50+
}
51+
52+
@Override
53+
public void onBackPressed() {
54+
final int currentStepPosition = mStepperLayout.getCurrentStepPosition();
55+
if (currentStepPosition > 0) {
56+
mStepperLayout.setCurrentStepPosition(currentStepPosition - 1);
57+
} else {
58+
finish();
59+
}
60+
}
61+
62+
@Override
63+
public void onCompleted(View completeButton) {
64+
Toast.makeText(this, "onCompleted!", Toast.LENGTH_SHORT).show();
65+
}
66+
67+
@Override
68+
public void onError(VerificationError verificationError) {
69+
}
70+
71+
@Override
72+
public void onStepSelected(int newStepPosition) {
73+
}
74+
75+
@Override
76+
public void onReturn() {
77+
}
78+
79+
@Override
80+
public void onProceed() {
81+
mStepperLayout.proceed();
82+
}
83+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.stepstone.stepper.sample.adapter;
2+
3+
import android.content.Context;
4+
import android.support.annotation.NonNull;
5+
import android.support.v4.app.FragmentManager;
6+
7+
import com.stepstone.stepper.Step;
8+
import com.stepstone.stepper.adapter.AbstractFragmentStepAdapter;
9+
import com.stepstone.stepper.sample.step.fragment.FormStepFragment;
10+
11+
public class FormFragmentStepAdapter extends AbstractFragmentStepAdapter {
12+
13+
public FormFragmentStepAdapter(@NonNull FragmentManager fm, @NonNull Context context) {
14+
super(fm, context);
15+
}
16+
17+
@Override
18+
public Step createStep(int position) {
19+
return FormStepFragment.newInstance();
20+
}
21+
22+
@Override
23+
public int getCount() {
24+
return 3;
25+
}
26+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2017 StepStone Services
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.stepstone.stepper.sample.step.fragment;
18+
19+
import android.content.Context;
20+
import android.os.Bundle;
21+
import android.support.annotation.NonNull;
22+
import android.support.annotation.Nullable;
23+
import android.support.v4.app.Fragment;
24+
import android.text.TextUtils;
25+
import android.view.KeyEvent;
26+
import android.view.LayoutInflater;
27+
import android.view.View;
28+
import android.view.ViewGroup;
29+
import android.view.animation.AnimationUtils;
30+
import android.view.inputmethod.EditorInfo;
31+
import android.widget.EditText;
32+
import android.widget.TextView;
33+
34+
import com.stepstone.stepper.Step;
35+
import com.stepstone.stepper.VerificationError;
36+
import com.stepstone.stepper.sample.OnProceedListener;
37+
import com.stepstone.stepper.sample.R;
38+
39+
import butterknife.Bind;
40+
import butterknife.ButterKnife;
41+
import butterknife.OnEditorAction;
42+
43+
public class FormStepFragment extends Fragment implements Step {
44+
45+
public static FormStepFragment newInstance() {
46+
FormStepFragment fragment = new FormStepFragment();
47+
return fragment;
48+
}
49+
50+
@Bind(R.id.editText)
51+
EditText editText;
52+
53+
@Nullable
54+
private OnProceedListener onProceedListener;
55+
56+
@Override
57+
public void onAttach(Context context) {
58+
super.onAttach(context);
59+
if (context instanceof OnProceedListener) {
60+
onProceedListener = (OnProceedListener) context;
61+
}
62+
}
63+
64+
@Override
65+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66+
View view = inflater.inflate(R.layout.fragment_form_step, container, false);
67+
ButterKnife.bind(this, view);
68+
return view;
69+
}
70+
71+
@Override
72+
public VerificationError verifyStep() {
73+
return TextUtils.isEmpty(editText.getText().toString())
74+
? new VerificationError("Password cannot be empty")
75+
: null;
76+
}
77+
78+
@Override
79+
public void onSelected() {
80+
}
81+
82+
@Override
83+
public void onError(@NonNull VerificationError error) {
84+
editText.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.shake_error));
85+
}
86+
87+
@OnEditorAction(R.id.editText)
88+
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
89+
if (actionId == EditorInfo.IME_ACTION_DONE && onProceedListener != null) {
90+
onProceedListener.onProceed();
91+
}
92+
return true;
93+
}
94+
}

0 commit comments

Comments
 (0)