Giter VIP home page Giter VIP logo

android-material-stepper's Introduction

Android Material Stepper CircleCI codecov Android Arsenal Android Weekly

This library allows to use Material steppers inside Android applications.

Quoting the documentation:

Steppers display progress through a sequence by breaking it up into multiple logical and numbered steps.

All of the code & features mentioned in Getting started and Advanced usage are showcased in the sample app. Moreover, you can find there other examples, e.g. how to persist state on rotation, display errors, change whether the user can go to the next step, etc. So please have a look!

Jump to section

Supported steppers

Mobile stepper with dots

  

Mobile stepper with progress bar

  

Mobile stepper without a progress indicator

Horizontal stepper

Supported features

  • color customisation of individual widgets inside of the stepper via View attributes or a style from a theme
  • custom texts of individual widgets inside of the stepper via View attributes or a style from a theme
  • embedding the stepper anywhere in the view hierarchy and changing the stepper type for various device configurations, e.g. phone/tablet, portrait/landscape
  • step validation
  • use with Fragments or Views
  • showing errors in tabs
  • showing stepper feedback for ongoing operations (see Stepper feedback)

Getting started

Download (from JCenter)

compile 'com.stepstone.stepper:material-stepper:4.3.1'

Note: This library adds a transitive dependency to AppCompat 25.4.0 which is the minimum Android Support library version compatible with the Stepper library.

Create layout in XML

<?xml version="1.0" encoding="utf-8"?>
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/stepperLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:ms_stepperType="progress_bar" />

For a complete list of StepperLayout attributes see [StepperLayout attributes](#StepperLayout attributes).

Create step Fragment(s)

Step fragments must extend android.support.v4.app.Fragment and implement com.stepstone.stepper.Step

public class StepFragmentSample extends Fragment implements Step {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.step, container, false);

        //initialize your UI

        return v;
    }

    @Override
    public VerificationError verifyStep() {
        //return null if the user can go to the next step, create a new VerificationError instance otherwise
        return null;
    }

    @Override
    public void onSelected() {
        //update UI when selected
    }

    @Override
    public void onError(@NonNull VerificationError error) {
        //handle error inside of the fragment, e.g. show error on EditText
    }
    
}

Extend AbstractFragmentStepAdapter

AbstractFragmentStepAdapter extends FragmentPagerAdapter but instead of overriding the method getItem(int) you must override the createStep(int) method.

public static class MyStepperAdapter extends AbstractFragmentStepAdapter {

    public MyStepperAdapter(FragmentManager fm, Context context) {
        super(fm, context);
    }

    @Override
    public Step createStep(int position) {
        final StepFragmentSample step = new StepFragmentSample();
        Bundle b = new Bundle();
        b.putInt(CURRENT_STEP_POSITION_KEY, position);
        step.setArguments(b);
        return step;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @NonNull
    @Override
    public StepViewModel getViewModel(@IntRange(from = 0) int position) {
        //Override this method to set Step title for the Tabs, not necessary for other stepper types
        return new StepViewModel.Builder(context)
                .setTitle(R.string.tab_title) //can be a CharSequence instead
                .create();
    }
}

Set adapter in Activity

public class StepperActivity extends AppCompatActivity {

    private StepperLayout mStepperLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout);
        mStepperLayout.setAdapter(new MyStepperAdapter(getSupportFragmentManager(), this));
    }
}

Add a StepperListener in the Activity (optional)

public class StepperActivity extends AppCompatActivity implements StepperLayout.StepperListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //...
        mStepperLayout.setListener(this);
    }

    @Override
    public void onCompleted(View completeButton) {
        Toast.makeText(this, "onCompleted!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onError(VerificationError verificationError) {
        Toast.makeText(this, "onError! -> " + verificationError.getErrorMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStepSelected(int newStepPosition) {
        Toast.makeText(this, "onStepSelected! -> " + newStepPosition, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onReturn() {
        finish();
    }

}

Advanced usage

Making extra operations before going to the next step

After clicking on the Next button if the user wants to e.g.:

  • save something in the database
  • make a network call on a separate Thread
  • simply save the data from the current step to some other component or parent Activity (see 'Passing data between steps' in the sample app for more details)

he can perform these operations and then invoke the goToNextStep() method of the StepperLayout.OnNextClickedCallback in the current Step. If the user wants to perform these operations on the final step, when clicking on the Complete button, he needs to invoke the complete() method of the StepperLayout.OnCompleteClickedCallback. While operations are performed, and the user would like to go back you can cancel them and then invoke onBackClicked() method of the StepperLayout.OnBackClickedCallback.

To do so the fragment/view must implement BlockingStep instead of Step. Also, make sure that goToNextStep() and/or complete() get called on the main thread. Note: onNextClicked(StepperLayout.OnNextClickedCallback) and onCompleteClicked(StepperLayout.OnCompleteClickedCallback) methods get invoked after step verification. E.g.:

public class DelayedTransitionStepFragmentSample extends Fragment implements BlockingStep {

    //...

    @Override
    @UiThread
    public void onNextClicked(final StepperLayout.OnNextClickedCallback callback) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.goToNextStep();
            }
        }, 2000L);
    }

    @Override
    @UiThread
    public void onCompleteClicked(final StepperLayout.OnCompleteClickedCallback callback) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.complete();
            }
        }, 2000L);
    }

    @Override
    @UiThread
    public void onBackClicked(StepperLayout.OnBackClickedCallback callback) {
        Toast.makeText(this.getContext(), "Your custom back action. Here you should cancel currently running operations", Toast.LENGTH_SHORT).show();
        callback.goToPrevStep();
     }

}

Changing button labels & compound drawables per step

Sometimes you might want to have different labels on the Next/Complete and/or Back navigation buttons on different steps e.g. use the default labels on the first few steps, but display 'Summary' just before the last page. You might also want to use your custom icons instead of the default navigation button compound drawables or not show the compound drawables for some of the buttons.

In such case you need to override the `getViewModel(int)` method from the `StepAdapter` e.g.
    @NonNull
    @Override
    public StepViewModel getViewModel(@IntRange(from = 0) int position) {
        StepViewModel.Builder builder = new StepViewModel.Builder(context)
                .setTitle(R.string.tab_title);
        switch (position) {
            case 0:
                builder
                    .setEndButtonLabel("This way")
                    .setBackButtonLabel("Cancel")
                    .setNextButtonEndDrawableResId(R.drawable.ms_forward_arrow)
                    .setBackButtonStartDrawableResId(StepViewModel.NULL_DRAWABLE);
                break;
            case 1:
                builder
                    .setEndButtonLabel(R.string.go_to_summary)
                    .setBackButtonLabel("Go to first")
                    .setBackButtonStartDrawableResId(R.drawable.ms_back_arrow);
                break;
            case 2:
                builder
                    .setBackButtonLabel("Go back")
                    .setEndButtonLabel("I'm done!");
                break;
            default:
                throw new IllegalArgumentException("Unsupported position: " + position);
        }
        return builder.create();
    }

It is also possible to hide Back/Next/Complete buttons on each step if needed. To do so you need to call setBackButtonVisible(false) and/or setEndButtonVisible(false) on StepViewModel.Builder in your adapter.

Subtitles in tabs

You can set a subtitle for each step in stepper with tabs, e.g. to mark a step as optional. To do so you need to set the subtitle by calling StepViewModel.Builder#setSubtitle(int) or StepViewModel.Builder#setSubtitle(CharSequence) in your adapter's getViewModel method.

Custom styling

Basic styling can be done by choosing the active and inactive step colors. There are some additional properties which can be changed directly from StepperLayout's attributes e.g. the background of bottom navigation buttons (see StepperLayout attributes) For advanced styling you can use ms_stepperLayoutTheme StepperLayout's attribute and provide your custom style to be used. See 'Custom StepperLayout theme' in the sample app for an example.

Using same stepper styling across the application

If you have many steppers in your application in different activities/fragments you might want to set a common style in a theme. To do so, you need to set the ms_stepperStyle attribute in the theme, e.g.

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        ...
        
        <item name="ms_stepperStyle">@style/DotStepperStyle</item>
    </style>

and declare that style in the XML you keep your styles at, e.g.

    <style name="DotStepperStyle">
        <item name="ms_stepperType">dots</item>
        <item name="ms_activeStepColor">#FFFFFF</item>
        <item name="ms_inactiveStepColor">#006867</item>
        <item name="ms_bottomNavigationBackground">?attr/colorAccent</item>
    </style>

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 version="1.0" encoding="utf-8"?>
    <com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/stepperLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:ms_showBackButtonOnFirstStep="true"
        app:ms_stepperType="dots" />

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.

Using Views instead of Fragments as Steps

It is possible to use this library without the need to rely on Fragments. To do so you need to use AbstractStepAdapter instead of AbstractFragmentStepAdapter. For an example of how to use it with views please see the sample app.

Showing an error on tabs if step verification failed

To show an error in the tabbed stepper if step verification fails you need to set ms_showErrorStateEnabled attribute to true.

If you want to keep the error displayed when going back to the previous step you need to also set ms_showErrorStateOnBackEnabled to true. If you want display an error message below the step title you need to set ms_showErrorMessageEnabled to true. The message set in VerificationError will be then displayed.

Stepper feedback

It is possible to show stepper feedback for ongoing operations (see Stepper feedback). To do so you firstly need to set ms_stepperFeedbackType to one or more of:

  • tabs - shows a progress message instead of the tabs during operation.
  • content_progress - shows a progress bar on top of the steps' content.
  • content_fade - partially fades the content out during operation (should not be used together with content_overlay). You can change the default fade amount with ms_stepperFeedback_contentFadeAlpha attribute.
  • content_overlay - shows a dimmed overlay over the content during the operation (should not be used together with content_fade). You can change the overlay background with ms_stepperFeedback_contentOverlayBackground attribute.
  • disabled_bottom_navigation - disables the buttons in the bottom navigation during operation. In order to see that the buttons are disabled on the bottom navigation bar, make sure that the button colors are assigned using color selectors with a disabled state (see the sample app).
  • disabled_content_interaction - intercepts touch events on the steps' content and ignores them during operation.

The default is none which does nothing. It is possible to use multiple flags together.

After setting this to show the feedback you need to call StepperLayout#showProgress(@NonNull String progressMessage) and do hide the progress indicator you need to call StepperLayout#hideProgress().

E.g. In layout:

    <?xml version="1.0" encoding="utf-8"?>
    <com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/stepperLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:ms_backButtonColor="@color/ms_disabling_button_text_color_selector"
        app:ms_nextButtonColor="@color/ms_disabling_button_text_color_selector"
        app:ms_completeButtonColor="@color/ms_disabling_button_text_color_selector"
        app:ms_stepperType="tabs"
        app:ms_stepperFeedbackType="tabs|content|disabled_bottom_navigation" />

and in BlockingStep:

public class StepperFeedbackStepFragment extends Fragment implements BlockingStep {

    //...

    @Override
    @UiThread
    public void onNextClicked(final StepperLayout.OnNextClickedCallback callback) {
        callback.getStepperLayout().showProgress("Operation in progress, please wait...");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.goToNextStep();
                callback.getStepperLayout().hideProgress();
            }
        }, 2000L);
    }

    //...

Changing button text color when going to the next step should be disabled

It is possible to change the Next/Complete button's text color (together with right chevron's color) when all the criteria to go to the next step are not met. This color should indicate that the user cannot go to next step yet and look as if disabled. Clicking on the button will still perform the regular step verification. There is a custom state added since setting android:state_enabled to false in a color selector would disable the clicks and we want to have them so that we can show an info message for the user. In order to set that color:

  1. Create a new color selector in res/color
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
        <item app:state_verification_failed="true" android:color="#30BDBDBD"/>
        <item android:color="@color/ms_white"/>
    </selector>
  1. Change button's (text) color in layout file
    <?xml version="1.0" encoding="utf-8"?>
    <com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/stepperLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:ms_stepperType="dots"
        app:ms_nextButtonColor="@color/ms_custom_button_text_color"
        app:ms_completeButtonColor="@color/ms_custom_button_text_color" />
  1. Toggle the state in code
    mStepperLayout.setNextButtonVerificationFailed(!enabled);
    mStepperLayout.setCompleteButtonVerificationFailed(!enabled);

Hiding bottom navigation bar

Bottom navigation bar is shown by default. If in your UI you would like to hide the bottom navigation bar you can do that by either setting the ms_showBottomNavigation attribute in XML to false or by setting it programmatically by calling StepperLayout#setShowBottomNavigation(boolean) with false.

StepperLayout attributes

View attributes

A list of base StepperLayout attributes used for behaviour configuration & base UI configuration. For advanced styling please see StepperLayout style attributes.

Attribute name Format Description
ms_stepperType one of dots, progress_bar, tabs or none REQUIRED: Type of the stepper
ms_backButtonColor color or reference BACK button's text color, can be also set via StepperLayout#setBackButtonColor(int)/StepperLayout#setBackButtonColor(ColorStateList)
ms_nextButtonColor color or reference NEXT button's text color, can be also set via StepperLayout#setNextButtonColor(int)/StepperLayout#setNextButtonColor(ColorStateList)
ms_completeButtonColor color or reference COMPLETE button's text color, can be also set via StepperLayout#setCompleteButtonColor(int)/StepperLayout#setCompleteButtonColor(ColorStateList)
ms_activeStepColor color or reference Active step's color
ms_inactiveStepColor color or reference Inactive step's color
ms_bottomNavigationBackground reference Background of the bottom navigation
ms_backButtonBackground reference BACK button's background
ms_nextButtonBackground reference NEXT button's background
ms_completeButtonBackground reference COMPLETE button's background
ms_backButtonText string or reference BACK button's text
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.
ms_errorColor color or reference Error color in Tabs stepper
ms_showErrorStateEnabled boolean Flag indicating whether to show the error state. Only applicable for 'tabs' type. False by default.
ms_showErrorStateOnBackEnabled boolean Flag indicating whether to keep showing the error state when user moves back. Only applicable for 'tabs' type. False by default.
ms_tabNavigationEnabled boolean Flag indicating whether step navigation is possible by clicking on the tabs directly. Only applicable for 'tabs' type. True by default.
ms_stepperFeedbackType flag(s): none or tabs, content_progress, content_fade, content_overlay, disabled_bottom_navigation & disabled_content_interaction Type(s) of stepper feedback. Can be a combination of tabs, content_progress, content_fade, content_overlay, disabled_bottom_navigation & disabled_content_interaction. Default is none.
ms_stepperFeedback_contentFadeAlpha float An alpha value from 0 to 1.0f to be used for the faded out view if content_fade stepper feedback type is set. 0.5f by default.
ms_stepperFeedback_contentOverlayBackground reference Background to be used for the overlay on top of the content if content_overlay stepper feedback type is set.
ms_showBottomNavigation boolean Flag indicating if the Bottom Navigation bar should be shown on the layout. True by default.
ms_stepperLayoutTheme reference Theme to use for even more custom styling of the stepper layout. It is recommended that it should extend @style/MSDefaultStepperLayoutTheme, which is the default theme used.

StepperLayout style attributes

A list of ms_stepperLayoutTheme attributes responsible for styling of StepperLayout's child views.

Attribute name Description
ms_bottomNavigationStyle Used by ms_bottomNavigation in layout/ms_stepper_layout
ms_tabsContainerStyle Used by ms_stepTabsContainer in layout/ms_stepper_layout
ms_backNavigationButtonStyle Used by ms_stepPrevButton in layout/ms_stepper_layout
ms_nextNavigationButtonStyle Used by ms_stepNextButton in layout/ms_stepper_layout
ms_completeNavigationButtonStyle Used by ms_stepCompleteButton in layout/ms_stepper_layout
ms_colorableProgressBarStyle Used by ms_stepProgressBar in layout/ms_stepper_layout
ms_stepPagerProgressBarStyle Used by ms_stepPagerProgressBar in layout/ms_stepper_layout
ms_stepPagerOverlayStyle Used by ms_stepPagerOverlay in layout/ms_stepper_layout
ms_stepTabsScrollViewStyle Used by ms_stepTabsScrollView in layout/ms_tabs_container
ms_stepTabsInnerContainerStyle Used by ms_stepTabsInnerContainer in layout/ms_tabs_container
ms_stepTabsProgressMessageStyle Used by ms_stepTabsProgressMessage in layout/ms_tabs_container
ms_stepTabContainerStyle Used in layout/ms_step_tab_container
ms_stepTabNumberStyle Used by ms_stepNumber in layout/ms_step_tab
ms_stepTabDoneIndicatorStyle Used by ms_stepDoneIndicator in layout/ms_step_tab
ms_stepTabIconBackgroundStyle Used by ms_stepIconBackground in layout/ms_step_tab
ms_stepTabTitleStyle Used by ms_stepTitle in layout/ms_step_tab
ms_stepTabSubtitleStyle Used by ms_stepSubtitle in layout/ms_step_tab
ms_stepTabDividerStyle Used by ms_stepDivider in layout/ms_step_tab

Changelog

See changelog

Espresso tests

If you wish to run Espresso tests on a screen containing a StepperLayout you might want to use espresso-material-stepper which contains useful Espresso actions and matchers such as clicking on navigation buttons & tabs. To do so add a Gradle dependency:

    androidTestCompile 'com.stepstone.stepper:espresso-material-stepper:X.X.X'

Please see the sample app which uses it in instrumentation tests for more details.

Contributing

All contributions are welcome and encouraged!

If you wish to contribute please create an issue first explaining the proposed changes.

Project is built on Circle CI on which we run static code analysis as well as unit & instrumentation tests to ensure that the latest changes don't break anything. To check if your changes pass execute:

./gradlew checkWithUiTests

Or on a device below Marshmallow:

./gradlew checkWithUiTests -Ptest.integration.options.adbInstallOptions=-r

License

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.

Maintained by

Stepstone

android-material-stepper's People

Contributors

albinekcom avatar enizbilgin avatar fabiozo avatar leonardo2204 avatar seasox avatar shalskar avatar yccheok avatar zawadz88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-material-stepper's Issues

Incompatibility with material-spinner

Both components contain attribute named ms_errorColor with different formats (types).
Therefore, it is impossible to use the 2 components at the same time.
Do you have any solution?

ms_errorcolor attribute

Abstract even more the Adapter

Hey guys, first of all, nice work ! Just found the lib and it seems pretty cool !
Since today a lot of devs (including me) are moving away from Frags to View-based Apps, I think it would be cool to abstract even more the StepAdapter, so people like me could still use the lib, implementing the abstract Adapter methods, not obligatory using Frags.
I'd be happy to drop a PR, if you guys are interested !

Thanks

Strange issue in createStep

I love your stepper but am now stumped with an issue. Here's how I am using your library and where I am getting stumped.

I have 7 steps in my wizard, each implemented by a Fragment that extends Step. In the overridden createStep method, I have this code.

    @Override
    public Fragment createStep(int position) {
        Logger.writeToLog("position=" + position);
        switch (position) {
            case 0:
                return new StepWelcome();
            case 1:
                return new StepSelectAccounts();
            case 2:
                return new StepPreTaxEarnings();
            case 3:
                return new StepTaxes();
            case 4:
                return new StepRetirals();
            case 5:
                return new StepStockPurchase();
            case 6:
                return new StepSummary();
            default:
                throw new IllegalArgumentException("Unsupported position: " + position);
        }
    }

I am returning 7 in getCount() in my AbstractStepAdapter extension

What I find funny is that the initial log print shows the following when the wizard is invoked. It should have ideally only printed upto position=6 and should have printed position=0 since we're now on the first step of the wizard when it is started. However, it prints position=1 as well when the stepper is now on the first step.

2016-12-14 19:29:48:position=0
2016-12-14 19:29:48:position=1
2016-12-14 19:29:48:position=2
2016-12-14 19:29:48:position=3
2016-12-14 19:29:48:position=4
2016-12-14 19:29:48:position=5
2016-12-14 19:29:48:position=6
2016-12-14 19:29:48:position=0
2016-12-14 19:29:48:position=1

Because of this issue, when I move through the steps, I am getting wrong behavior since the step positions are now already incremented by 1 because of the behavior above. I am happy to paste the entire code if needed. This is frustrating and I don't know what I did wrong

Custom font for StepperLayout tab title

Is there any way to set custom TypeFace for StepperLayout's tab title?

I have tried this way:

mStepperlayout.setAdapter(new CustomStepperAdapter(getChildFragmentManager()));
TextView mStepTitle = (TextView) mStepperLayout.findViewById(R.id.ms_stepTitle);
Typeface mFont = Typeface.createFromAsset(getActivity().getAssets(), "CustomFont.ttf");
mStepTitle.setTypeface(mFont);

This works for navigation bar buttons but does not work tab titles, any idea?

SteperLayout#onComplete does not respect BlockingStep flow

What I'm trying to do :

  • create several steps to collect info from user
  • upload all user info using a BlockingStep when the user taps "Complete" (on the last step)

The problem :

  • onNextClicked() method is not being called in the last step

Cause:

  • StepperLayout#onComplete() does not check for BlockingSteps

Android API 19: Binary XML file line #17: invalid drawable tag vector

Hello stepstone team,
thanks for sharing this library. I want to use it with API Level 19 and I always get this error:
Binary XML file line #17: invalid drawable tag vector
I use: compile 'com.android.support:appcompat-v7:25.0.0'
Also tried: vectorDrawables.useSupportLibrary = true

But didn't solve the Problem.

Seems to be this issue:stackoverflow

Can you say something about supported API Levels or do you know how to fix this error?
Here the complete output of console:

Unable to start activity ComponentInfo{com.projecttango.experiments.planefittingsample/com.projecttango.examples.java.planefitting.ui.stepper.StepperActivity}: 
android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2196)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2246)
at android.app.ActivityThread.access$800(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5030)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
at android.content.res.Resources.loadDrawable(Resources.java:2096)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.support.v7.widget.VectorEnabledTintResources.superGetDrawable(VectorEnabledTintResources.java:74)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:435)
at android.support.v7.widget.VectorEnabledTintResources.getDrawable(VectorEnabledTintResources.java:67)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
                                                                                                     at com.projecttango.examples.java.planefitting.ui.stepper.StepperActivity.onCreate(StepperActivity.java:50)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2160)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2246) 
at android.app.ActivityThread.access$800(ActivityThread.java:136) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5030) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2092)
at android.content.res.Resources.getDrawable(Resources.java:700) 
at android.support.v7.widget.VectorEnabledTintResources.superGetDrawable(VectorEnabledTintResources.java:74) 
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:435) 
at android.support.v7.widget.VectorEnabledTintResources.getDrawable(VectorEnabledTintResources.java:67) 
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:374) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188) 
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193) 
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81) 
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127) 
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147) 
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27) 
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185) 
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525) 
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74) 
                                                                                                     at com.projecttango.examples.java.planefitting.ui.stepper.StepperActivity.onCreate(StepperActivity.java:50) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2160) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2246) 
at android.app.ActivityThread.access$800(ActivityThread.java:136) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5030) 
at java.lang.reflect.Method.invoke(Native Method)

Thank you.

Can't access fragment instances in adapter

AbstractFragmentStepAdapter.findStep(ViewPager, int) requires ViewPager as first attribute and uses its getId(), which, as I see it it, always resolves to R.id.ms_stepPager. Would it be possible to remove ViewPager from findStep or provide an overloaded findStep(int)?

My actual issue is that AbstractFragmentStepAdapter.getItem() calls createStep() internally, so I cannot access the actual fragment instances in my adapter, since they are recreated in createStep(). I also can't use findStep, since I cannot get the ViewPager from StepperLayout.

A getter for StepperLayout.mPager would do the job, too.

Another solution to this issue might be to change the implementation of AbstractFragmentStepAdapter.getItem(int) to check findStep() != null before calling createStep

I could file a PR if you agree.

//edit:
I can access the fragments using FragmentManager (as proposed in #39), but this still involves R.id.ms_stepPager. Accessing the fragments using their adapter would be cleaner, IMHO.

Functionality question

It is possible to take the "next button" or trigger the "onNextClicked" method programmatically?

Sorry for my English, Thanks so much for this awesome library

Update screenshots from the app

The existing screenshots/GIFs referenced in README are outdated and should be replaced with new ones from the current version of the library.

Can't determine actual step position to apply logic...

I'm actually becoming crazy with this library...

I'm trying to implement it on my app. I decided to use the Styled Tabs version. I have the three fragments you provide on sample edited for the use I need, so on the main one I show a list, a Spinner on the second and another list on the third one.

But as I've read on other issue,

By default, ViewPager if you're on page N will create page N - 1 and N + 1. So if you're starting with the first page it will create the first and the second Fragment.

So, when I try to populate the list on the first fragment, or the spinner on the second, as it doesn't exists on the others, it gives me a null exception... I'm doing this on StyledTabsActivity because here it is where I found at the example that you apply the logics to the button that appears, but you have the same button with same id on the three fragments...

How or where I am supposed to be able to populate this elements?

Question about Verifying

Can anybody help me with this?
How can I verify edittexts inside my Step?

I have diferrent verification methods for each edittext
`Hello @zawadz88 !

Just a question, how can I implement this to verifyStep()?

`

class VerifyAppNameTask extends AsyncTask<String, Void, String> {
    // use doInBackground() to make network calls, the returned value is
    // sent to onPostExecute()
    @Override
    protected String doInBackground(String... data) {

        if (sAppName.replace(" ","").isEmpty())
        {
            return "1";
        }
        else if (sAppName.length() > 25)
        {
            return "2";
        }
        else if (checkAppName(data[0]))
        {
            return "3";
        }
        else
        {
            return "4";
        }


    }
    @Override
    protected void onPostExecute(String result) {
        tilAppName.setErrorEnabled(true);
        switch(result)
        {
            case "1":   {tilAppName.setError("You can't leave this empty.");break;}
            case "2":   {tilAppName.setError("Maximum of 25 characters.");break;}
            case "3":   {tilAppName.setError("No spaces allowed");break;}
            case "4":   {tilAppName.setError(null);tilAppName.setErrorEnabled(false);break;}

        }

    }
}`

above code is one of my error traps

My problem is how can I verify edittexts then when there's no more error, Next > button will enable again. Thank you so much for you help!

How to collect data from steps?

Hi - I have a newbie question, but this wasn't clear to me from the other questions or from the examples.
I have a stepper with three steps. Whenever I press the next button, I want to save information from the current step and move on to the next one. At the end, when I press complete, I want to consolidate the information from the three steps and make a REST API call. What's the best way to do this?

As an example - in my first step, I want the user to input a location. In the second, I want the user to choose a category. In the third, I want the user to provide a description. Finally, when the user presses complete, I want to make a REST call using the location, category and description.

Change icons for back/nextButton

Hello,

First of all, thanks for your awesome library !
We are using it to provide a nice register flow for our users.

Is it possible to add the possibility to change icons for next/back button thanks to getViewModel(...) in the adapter ?
It could help us to let the user understand more precisely what he is going (sometimes, text isn't enough ;) )

Thanks a lot,

Tom

Remove Arrow

Hi,
I tried to find where I can remove the arrow icon from the options but I didn't find it. I read in another issue that it has that option.

I want to remove it from the first step having the option CANCEL without the <

Option to disable navigation via tabs

Good day. I couldn't find a way to disable navigation via step tabs. I think an option to enable/disable this via both xml and java would seem reasonable.

Jump one step conditionally

Hi,
just a question, not an issue (and maybe a stupid question...).

Lets say in a wizard I have to show 3 steps (1st, 2nd and 3rd) and at runtime I want conditionally jump the 2nd step (so that the user will see the 1st and 3rd steps only).

For example... The 2nd step is where, in a wizard, we ask for app's permissions or something similar.

Scenario 1:
The user already set all permissions in a previous wizard session. He runs the wizard again. The 2nd step should not be shown at all.

Scenario 2:
The first time the wizard runs, all 3 steps are shown. In the 2nd step the user allows all permissions. Then he goes to the 3rd step and clicks "Back"... the 2nd step should be not shown at all (all permissions were already set).

How can I do this?
Many thanks

More control over step traversal

Would be nice to see the ability to make the next/back/completed buttons Visibility.gone, and expose methods on the StepperLayout class to allow me to programmatically advance to the next step. This would allow for things like where a step requires a user select a button out of a choice of buttons for example, and the code does something on button click, and once done, advance the step. No need to have the user also click next. Also, add the ability to prevent the tabs from updating the steps along the same lines.

While I can just grab the buttons and tabs container and set the button onClickListener to null, and overload the tabContainers listener to achieve the same result, I'd have to make the buttons text the same color as the nav bar, and use some styling to get the chevrons to be the same color effectively making them disappear. However the bar is still there on the ui, which sucks if it's unneeded to begin with.

I can't just hide the buttons unfortunately since you update the visibility inside onUpdate, so would be nice to add a && shouldBeVisibile style able or something along those lines inside onUpdate, so I can just use styles in a theme to change the behavior base on individual stepperlayouts in my views.

I'm guessing in the mean time, I can grab the listeners before I set them to null so I can have access to the StepperLayouts private methods for actually advancing the steps?

Setting error state programmatically

Good day! Thanks for implementing 'error state' feature, works great. But I couldn't find a way to set the error state programmatically. Is it supported by the library?

Next button skip blockingstep

Here i have used 3 fragments. When i am on first fragment and i click twice on NEXT button it's go to 2nd then 3rd step even i not called callback.gotoNextStep in second fragment.

Fragment destruction

I'm using this library with three fragment. It seems that the first fragment is recreated (losing values etc...) if I return back from the third to the first fragment. Is there a way to prevent the fragment to be destroyed?
I found this on StackOverflow: mViewPager.setOffscreenPageLimit(2);. Is there a way to implement this solution?

Is there a way to enable/ disable back button click operation

Currently, by pressing COMPLETE button, I'm going to launch a async task, to perform a long running operation. During that time, I would like to prevent user from clicking the back button. Is there any way to disable back button click operation, programmatically?

Thank.
Cheok

Step limit

Is there a limit to the number of steps that can be added?

next and back arrows

is it any way to change arrows for next and back button? OR hide next and back arrow?

because it is not support right to left!

any help?

More than 3 Fragment recreate Fragment Created

Hi @zawadz88

I had a issue while adding more than 3 fragments. the first fragment automatically recreates.

With this the data will not be stable in the first fragment as the view is recreated

So i pulled your code and added a line in to your code in setAdapter method

mPager.setOffscreenPageLimit(stepAdapter.getCount());

How to add more steps?

I'm confused and I have no idea on how will I add more steps to the stepper? Can someone teach me how to do that? Should I make another class for step 2 and so on? Thank you so much.

Tabs are not visible on next or preview action

Hi, tnx for this great lib.
I have a problem with a tab visibility.
f.e. If you have lots of tabs and some of them are off screen, the next or prev button does not slide (show) to the current page (tab) and you have to manually scroll to it.

Kind regards

Is it possible to change the behavior of Android system back softkey

Currently, by pressing the Android system back softkey, it will quit the entire wizard activity.

However, is there possibility, that we can change such behavior in the way.

  1. If we are in step 2, step 3, ... , pressing Android system back softkey, will enable us to back to page step 1, step 2, ...

  2. If we are in step 1, pressing Android system back softkey, will enable us to quit the entire wizard activity.

Thank you

Remove a Fragment or layout

Hi,

I have removed a fragment dynamically from the Stepper adapter and i used notifyDataSetChanged(); to update Stepper adapter.

But it is not reflected back to StepperLayout.

Please let me know if there is any other method to remove view from stepper layout.

Thank you

Not able to change toolbar title/subtitle

@zawadz88 Your library is very useful i like it can you please enhance one feature to set toolbar title and subtitle according to active fragment. If this feature already available on your library than can you please guide me how i use that?

How programmatically onCompleted call

In last Step i want to done payment procedure on click on Complete button if payment done succesfully then it's call onComplete method code how can i do this can you please guide me with this ? Through any custom method

Setting StepTabsContainer background via attribute.

Good day. There is a nice attribute ms_bottomNavigationBackground in StepperLayout to change bottom navigation background. But I couldn't find similar attribute for StepTabs. Instead we need to define a style for ms_tabsContainerStyle with android:background in it and assign it to ms_stepperLayoutTheme. It would be nice to be able to have a simple attribute instead of defing numerous styles just for that. Thank you!

How to perform time consuming task in last step fragment

Hi,

I know we can perform time consuming task, in non-last step fragment, by using BlockingStep.

However, when I use BlockingStep as the last step fragment, the onNextClicked is not triggered when I click on DONE button.

I was wondering, what is the proper way, to perform time consuming task in last step fragment?

Thanks.
Cheok

onActivityResult Not being called

HI.

I'm trying to perform some actions after calling an activity in one of my fragments. However, the method onActivityResult is being called in the Activity but not in the active Fragment.

I'm calling super.onActivityResult on my Activity so that's not the problem.

What can be happening?

Feature request: Error state annimation

Good day! I think it would be nice if error state triangle would wobble a bit horizontally for a sec (just like the button in the sample app) when error state just occurs. Also would be nice to enable/disable this option via both xml and java.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.