From 53cc96553b1f09c55ba458791eefd2941be8d1db Mon Sep 17 00:00:00 2001 From: Piotr Zawadzki Date: Wed, 27 Sep 2017 10:38:16 +0200 Subject: [PATCH] Tab tinting issue fix + navigation button colors set programmatically + version update * Fixed tab tinting when a color with transparency is used. * Added an option to set bottom navigation button colors programmatically. * Updated library version to 4.3.0. --- CHANGELOG.md | 11 +++ README.md | 8 +- build.gradle | 2 +- gradle.properties | 2 +- .../com/stepstone/stepper/StepperLayout.java | 57 ++++++++++++ .../stepper/internal/widget/StepTab.java | 17 ++-- .../stepstone/stepper/sample/SanityTest.java | 10 ++ ...ttonColorProgrammaticallyActivityTest.java | 93 +++++++++++++++++++ .../sample/test/matcher/CommonMatchers.java | 14 +++ sample/src/main/AndroidManifest.xml | 1 + .../stepper/sample/AbstractStepperActivity.kt | 16 ++-- .../sample/CustomNavigationButtonsActivity.kt | 14 +-- .../sample/CustomPageTransformerActivity.kt | 2 +- .../DelayedTransitionStepperActivity.kt | 10 +- .../stepstone/stepper/sample/MainActivity.kt | 3 +- .../stepper/sample/NoFragmentsActivity.kt | 16 ++-- .../sample/PassDataBetweenStepsActivity.kt | 20 ++-- .../sample/ProceedProgrammaticallyActivity.kt | 14 +-- .../SetButtonColorProgrammaticallyActivity.kt | 44 +++++++++ .../sample/ShowErrorOnBackTabActivity.kt | 4 +- .../stepper/sample/StepperFeedbackActivity.kt | 32 +++---- .../res/color/ms_custom_button_text_color.xml | 6 +- ...vity_set_button_color_programmatically.xml | 10 ++ .../main/res/layout/activity_styled_tabs.xml | 6 +- sample/src/main/res/values/colors.xml | 2 + sample/src/main/res/values/strings.xml | 2 + 26 files changed, 332 insertions(+), 84 deletions(-) create mode 100644 sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java create mode 100644 sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt create mode 100644 sample/src/main/res/layout/activity_set_button_color_programmatically.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fa205e..e777596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [4.3.0] +### Added +- A way to set bottom navigation button colors programmatically via: + `StepperLayout#setNextButtonColor(int)`/`StepperLayout#setNextButtonColor(ColorStateList)`, + `StepperLayout#setCompleteButtonColor(int)`/`StepperLayout#setCompleteButtonColor(ColorStateList)` and + `StepperLayout#setBackButtonColor(int)`/`StepperLayout#setBackButtonColor(ColorStateList)` (issue #132). + +### Fixed +- Tab circle background color so that it is possible now to use colors with transparency (issue #207). + ## [4.2.0] ### Added - A new artifact `espresso-material-stepper` with useful Espresso actions and matchers for testing `StepperLayout` with Espresso. @@ -30,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - **Breaking change:** Changed `setNextButtonLabel` methods in `StepViewModel.Builder` to `setEndButtonLabel` so that it works for both Next and Complete buttons (issue #107) - **Breaking change:** Split `content` stepper feedback type into `content_progress` and `content_fade`. +[4.3.0]: https://github.com/stepstone-tech/android-material-stepper/compare/v4.2.0...v4.3.0 [4.2.0]: https://github.com/stepstone-tech/android-material-stepper/compare/v4.1.0...v4.2.0 [4.1.0]: https://github.com/stepstone-tech/android-material-stepper/compare/v4.0.0...v4.1.0 [4.0.0]: https://github.com/stepstone-tech/android-material-stepper/compare/v3.3.0...v4.0.0 diff --git a/README.md b/README.md index 75d8e4c..be52491 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Moreover, you can find there other examples, e.g. how to persist state on rotati ### Download (from JCenter) ```groovy -compile 'com.stepstone.stepper:material-stepper:4.2.0' +compile 'com.stepstone.stepper:material-stepper:4.3.0' ``` *Note:* This library adds a transitive dependency to AppCompat `25.4.0` @@ -477,9 +477,9 @@ For advanced styling please see [StepperLayout style attributes](#stepperlayout- | 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 | -| *ms_nextButtonColor* | color or reference | NEXT button's text color | -| *ms_completeButtonColor* | color or reference | COMPLETE button's text color | +| *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 | diff --git a/build.gradle b/build.gradle index 9d4d348..5af78b3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.gradleAndroidVersion = '3.0.0-beta4' + ext.gradleAndroidVersion = '3.0.0-beta6' ext.kotlinVersion = '1.1.3-2' ext.bintrayVersion = '1.7.3' ext.mavenGradlePluginVersion = '2.0' diff --git a/gradle.properties b/gradle.properties index 4a81d3a..668bbf4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ POM_GROUP_ID=com.stepstone.stepper POM_ARTIFACT_ID=material-stepper POM_TEST_ARTIFACT_ID=espresso-material-stepper -POM_VERSION=4.2.0 +POM_VERSION=4.3.0 #Needed so that Robolectric is working: https://github.com/robolectric/robolectric/issues/3169 android.enableAapt2=false \ 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 f1a993c..c6e13d8 100644 --- a/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java +++ b/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java @@ -591,6 +591,63 @@ public void setTabNavigationEnabled(boolean tabNavigationEnabled) { mTabNavigationEnabled = tabNavigationEnabled; } + /** + * Changes the text and compound drawable color of the Next bottom navigation button. + * + * @param newButtonColor new color state list + */ + public void setNextButtonColor(@NonNull ColorStateList newButtonColor) { + mNextButtonColor = newButtonColor; + TintUtil.tintTextView(mNextNavigationButton, mNextButtonColor); + } + + /** + * Changes the text and compound drawable color of the Complete bottom navigation button. + * + * @param newButtonColor new color state list + */ + public void setCompleteButtonColor(@NonNull ColorStateList newButtonColor) { + mCompleteButtonColor = newButtonColor; + TintUtil.tintTextView(mCompleteNavigationButton, mCompleteButtonColor); + } + + /** + * Changes the text and compound drawable color of the Back bottom navigation button. + * + * @param newButtonColor new color state list + */ + public void setBackButtonColor(@NonNull ColorStateList newButtonColor) { + mBackButtonColor = newButtonColor; + TintUtil.tintTextView(mBackNavigationButton, mBackButtonColor); + } + + /** + * Changes the text and compound drawable color of the Next bottom navigation button. + * + * @param newButtonColor new color int + */ + public void setNextButtonColor(@ColorInt int newButtonColor) { + setNextButtonColor(ColorStateList.valueOf(newButtonColor)); + } + + /** + * Changes the text and compound drawable color of the Complete bottom navigation button. + * + * @param newButtonColor new color int + */ + public void setCompleteButtonColor(@ColorInt int newButtonColor) { + setCompleteButtonColor(ColorStateList.valueOf(newButtonColor)); + } + + /** + * Changes the text and compound drawable color of the Back bottom navigation button. + * + * @param newButtonColor new color int + */ + public void setBackButtonColor(@ColorInt int newButtonColor) { + setBackButtonColor(ColorStateList.valueOf(newButtonColor)); + } + /** * Updates the error state in the UI. * It does nothing if showing error state is disabled. diff --git a/material-stepper/src/main/java/com/stepstone/stepper/internal/widget/StepTab.java b/material-stepper/src/main/java/com/stepstone/stepper/internal/widget/StepTab.java index 2c6e65c..f0f9383 100644 --- a/material-stepper/src/main/java/com/stepstone/stepper/internal/widget/StepTab.java +++ b/material-stepper/src/main/java/com/stepstone/stepper/internal/widget/StepTab.java @@ -17,6 +17,7 @@ package com.stepstone.stepper.internal.widget; import android.content.Context; +import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; @@ -295,7 +296,7 @@ protected void changeToDone() { protected void changeToWarning(@Nullable CharSequence errorMessage) { mStepDoneIndicator.setVisibility(View.GONE); mStepNumberTextView.setVisibility(View.GONE); - mStepIconBackground.setColorFilter(mErrorColor); + mStepIconBackground.setColorFilter(mErrorColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setTextColor(mErrorColor); mStepSubtitleTextView.setTextColor(mErrorColor); updateSubtitle(errorMessage); @@ -330,7 +331,7 @@ class InactiveNumberState extends AbstractNumberState { @Override protected void changeToInactiveNumber() { - mStepIconBackground.setColorFilter(mUnselectedColor); + mStepIconBackground.setColorFilter(mUnselectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setTextColor(mTitleColor); mStepTitleTextView.setAlpha(ALPHA_INACTIVE_STEP_TITLE); mStepSubtitleTextView.setTextColor(mSubtitleColor); @@ -339,7 +340,7 @@ protected void changeToInactiveNumber() { @Override protected void changeToActiveNumber() { - mStepIconBackground.setColorFilter(mSelectedColor); + mStepIconBackground.setColorFilter(mSelectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setAlpha(ALPHA_ACTIVE_STEP_TITLE); super.changeToActiveNumber(); } @@ -357,7 +358,7 @@ class ActiveNumberState extends AbstractNumberState { @Override protected void changeToInactiveNumber() { - mStepIconBackground.setColorFilter(mUnselectedColor); + mStepIconBackground.setColorFilter(mUnselectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setAlpha(ALPHA_INACTIVE_STEP_TITLE); super.changeToInactiveNumber(); } @@ -370,7 +371,7 @@ class DoneState extends AbstractState { protected void changeToInactiveNumber() { mStepDoneIndicator.setVisibility(GONE); mStepNumberTextView.setVisibility(VISIBLE); - mStepIconBackground.setColorFilter(mUnselectedColor); + mStepIconBackground.setColorFilter(mUnselectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setAlpha(ALPHA_INACTIVE_STEP_TITLE); super.changeToInactiveNumber(); } @@ -398,7 +399,7 @@ class WarningState extends AbstractState { protected void changeToDone() { animateViewIn(mStepDoneIndicator); - mStepIconBackground.setColorFilter(mSelectedColor); + mStepIconBackground.setColorFilter(mSelectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setTextColor(mTitleColor); mStepSubtitleTextView.setTextColor(mSubtitleColor); super.changeToDone(); @@ -408,7 +409,7 @@ protected void changeToDone() { protected void changeToInactiveNumber() { animateViewIn(mStepNumberTextView); - mStepIconBackground.setColorFilter(mUnselectedColor); + mStepIconBackground.setColorFilter(mUnselectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setTextColor(mTitleColor); mStepTitleTextView.setAlpha(ALPHA_INACTIVE_STEP_TITLE); mStepSubtitleTextView.setTextColor(mSubtitleColor); @@ -420,7 +421,7 @@ protected void changeToInactiveNumber() { protected void changeToActiveNumber() { animateViewIn(mStepNumberTextView); - mStepIconBackground.setColorFilter(mSelectedColor); + mStepIconBackground.setColorFilter(mSelectedColor, PorterDuff.Mode.SRC_IN); mStepTitleTextView.setTextColor(mTitleColor); mStepSubtitleTextView.setTextColor(mSubtitleColor); super.changeToActiveNumber(); diff --git a/sample/src/androidTest/java/com/stepstone/stepper/sample/SanityTest.java b/sample/src/androidTest/java/com/stepstone/stepper/sample/SanityTest.java index 3af80d3..6ab1975 100644 --- a/sample/src/androidTest/java/com/stepstone/stepper/sample/SanityTest.java +++ b/sample/src/androidTest/java/com/stepstone/stepper/sample/SanityTest.java @@ -267,6 +267,16 @@ public void shouldOpenCustomStepperLayoutThemeActivity() { SpoonScreenshotAction.perform(getScreenshotTag(24, R.string.custom_stepperlayout_theme)); } + @Test + public void shouldOpenSetButtonColorProgrammaticallyActivity() { + //when + clickRowWithText(R.string.set_button_color_programmatically); + + //then + intended(hasComponent(SetButtonColorProgrammaticallyActivity.class.getName())); + SpoonScreenshotAction.perform(getScreenshotTag(25, R.string.set_button_color_programmatically)); + } + @NonNull private String getScreenshotTag(int position, @StringRes int titleResId) { return String.format(Locale.ENGLISH,"%02d", position) + ". " + intentsTestRule.getActivity().getString(titleResId); diff --git a/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java b/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java new file mode 100644 index 0000000..92e3687 --- /dev/null +++ b/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java @@ -0,0 +1,93 @@ +package com.stepstone.stepper.sample; + +import android.support.test.filters.LargeTest; + +import com.stepstone.stepper.sample.test.action.SpoonScreenshotAction; + +import org.junit.Test; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.doubleClick; +import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static com.stepstone.stepper.sample.test.matcher.CommonMatchers.checkBackButtonColor; +import static com.stepstone.stepper.sample.test.matcher.CommonMatchers.checkCompleteButtonColor; +import static com.stepstone.stepper.sample.test.matcher.CommonMatchers.checkCompleteButtonShown; +import static com.stepstone.stepper.sample.test.matcher.CommonMatchers.checkCurrentStepIs; +import static com.stepstone.stepper.sample.test.matcher.CommonMatchers.checkNextButtonColor; +import static com.stepstone.stepper.test.StepperNavigationActions.clickComplete; +import static com.stepstone.stepper.test.StepperNavigationActions.clickNext; +import static org.hamcrest.Matchers.allOf; + +/** + * Performs tests on a stepper on which we change the button colors in code. + * + * @author Piotr Zawadzki + */ +@LargeTest +public class SetButtonColorProgrammaticallyActivityTest extends AbstractActivityTest { + + @Test + public void shouldStayOnTheFirstStepWhenVerificationFails() { + //when + onView(withId(R.id.stepperLayout)).perform(clickNext()); + + //then + SpoonScreenshotAction.perform(getScreenshotTag(1, "Verification failure test")); + checkCurrentStepIs(0); + checkNextButtonColor(R.color.verification_failed_color); + } + + @Test + public void shouldGoToTheNextStepWhenVerificationSucceeds() { + //given + onView(allOf(withId(R.id.button), isCompletelyDisplayed())).perform(doubleClick()); + + //when + onView(withId(R.id.stepperLayout)).perform(clickNext()); + + //then + SpoonScreenshotAction.perform(getScreenshotTag(2, "Verification success test")); + checkCurrentStepIs(1); + checkNextButtonColor(R.color.ms_black); + checkBackButtonColor(R.color.ms_white); + } + + @Test + public void shouldShowCompleteButtonOnTheLastStep() { + //given + onView(allOf(withId(R.id.button), isCompletelyDisplayed())).perform(doubleClick()); + onView(withId(R.id.stepperLayout)).perform(clickNext()); + onView(allOf(withId(R.id.button), isCompletelyDisplayed())).perform(doubleClick()); + + //when + onView(withId(R.id.stepperLayout)).perform(clickNext()); + + //then + SpoonScreenshotAction.perform(getScreenshotTag(3, "Last step test")); + checkCurrentStepIs(2); + checkCompleteButtonShown(); + checkCompleteButtonColor(R.color.verification_failed_color); + checkBackButtonColor(R.color.ms_black); + } + + @Test + public void shouldCompleteStepperFlow() { + //given + onView(allOf(withId(R.id.button), isCompletelyDisplayed())).perform(doubleClick()); + onView(withId(R.id.stepperLayout)).perform(clickNext()); + onView(allOf(withId(R.id.button), isCompletelyDisplayed())).perform(doubleClick()); + onView(withId(R.id.stepperLayout)).perform(clickNext()); + onView(allOf(withId(R.id.button), isCompletelyDisplayed())).perform(doubleClick()); + + //when + onView(withId(R.id.stepperLayout)).perform(clickComplete()); + + //then + SpoonScreenshotAction.perform(getScreenshotTag(4, "Completion test")); + checkCurrentStepIs(2); + checkCompleteButtonColor(R.color.ms_black); + checkBackButtonColor(R.color.ms_black); + } + +} diff --git a/sample/src/androidTest/java/com/stepstone/stepper/sample/test/matcher/CommonMatchers.java b/sample/src/androidTest/java/com/stepstone/stepper/sample/test/matcher/CommonMatchers.java index 69667c4..3cab7fe 100644 --- a/sample/src/androidTest/java/com/stepstone/stepper/sample/test/matcher/CommonMatchers.java +++ b/sample/src/androidTest/java/com/stepstone/stepper/sample/test/matcher/CommonMatchers.java @@ -1,5 +1,6 @@ package com.stepstone.stepper.sample.test.matcher; +import android.support.annotation.ColorRes; import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.view.View; @@ -11,6 +12,7 @@ import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.hasTextColor; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static com.stepstone.stepper.sample.test.matcher.StepperLayoutTabStateMatcher.tabAtPositionIsInState; @@ -43,4 +45,16 @@ public static void checkCompleteButtonShown() { onView(withId(R.id.ms_stepCompleteButton)).check(matches(isDisplayed())); } + public static void checkBackButtonColor(@ColorRes int expectedColor) { + onView(withId(com.stepstone.stepper.R.id.ms_stepPrevButton)).check(matches(hasTextColor(expectedColor))); + } + + public static void checkNextButtonColor(@ColorRes int expectedColor) { + onView(withId(com.stepstone.stepper.R.id.ms_stepNextButton)).check(matches(hasTextColor(expectedColor))); + } + + public static void checkCompleteButtonColor(@ColorRes int expectedColor) { + onView(withId(com.stepstone.stepper.R.id.ms_stepCompleteButton)).check(matches(hasTextColor(expectedColor))); + } + } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index e6e4ed6..e122ed7 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -53,6 +53,7 @@ + \ No newline at end of file diff --git a/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.kt index 0ad03b8..e0ef03d 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/AbstractStepperActivity.kt @@ -36,7 +36,7 @@ abstract class AbstractStepperActivity : AppCompatActivity(), StepperLayout.Step } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout @get:LayoutRes protected abstract val layoutResId: Int @@ -49,20 +49,20 @@ abstract class AbstractStepperActivity : AppCompatActivity(), StepperLayout.Step ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 - mStepperLayout.setAdapter(SampleFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) + stepperLayout.setAdapter(SampleFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) - mStepperLayout.setListener(this) + stepperLayout.setListener(this) } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) super.onSaveInstanceState(outState) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { - mStepperLayout.onBackClicked() + stepperLayout.onBackClicked() } else { finish() } @@ -85,8 +85,8 @@ abstract class AbstractStepperActivity : AppCompatActivity(), StepperLayout.Step } override fun onChangeEndButtonsEnabled(enabled: Boolean) { - mStepperLayout.setNextButtonVerificationFailed(!enabled) - mStepperLayout.setCompleteButtonVerificationFailed(!enabled) + stepperLayout.setNextButtonVerificationFailed(!enabled) + stepperLayout.setCompleteButtonVerificationFailed(!enabled) } } diff --git a/sample/src/main/java/com/stepstone/stepper/sample/CustomNavigationButtonsActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/CustomNavigationButtonsActivity.kt index a14853a..e66fa52 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/CustomNavigationButtonsActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/CustomNavigationButtonsActivity.kt @@ -40,7 +40,7 @@ class CustomNavigationButtonsActivity : AppCompatActivity(), StepperLayout.Stepp } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -49,19 +49,19 @@ class CustomNavigationButtonsActivity : AppCompatActivity(), StepperLayout.Stepp setContentView(R.layout.activity_custom_navigation_buttons) ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 - mStepperLayout.setAdapter(CustomButtonsSampleFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) - mStepperLayout.setListener(this) + stepperLayout.setAdapter(CustomButtonsSampleFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) + stepperLayout.setListener(this) } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) super.onSaveInstanceState(outState) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { - mStepperLayout.onBackClicked() + stepperLayout.onBackClicked() } else { finish() } @@ -78,7 +78,7 @@ class CustomNavigationButtonsActivity : AppCompatActivity(), StepperLayout.Stepp } override fun onProceed() { - mStepperLayout.proceed() + stepperLayout.proceed() } } \ No newline at end of file diff --git a/sample/src/main/java/com/stepstone/stepper/sample/CustomPageTransformerActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/CustomPageTransformerActivity.kt index 1641dda..622a07a 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/CustomPageTransformerActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/CustomPageTransformerActivity.kt @@ -27,7 +27,7 @@ class CustomPageTransformerActivity : AbstractStepperActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - mStepperLayout.setPageTransformer(CrossFadePageTransformer()) + stepperLayout.setPageTransformer(CrossFadePageTransformer()) } private class CrossFadePageTransformer : ViewPager.PageTransformer { diff --git a/sample/src/main/java/com/stepstone/stepper/sample/DelayedTransitionStepperActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/DelayedTransitionStepperActivity.kt index 5e01300..7ae4b45 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/DelayedTransitionStepperActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/DelayedTransitionStepperActivity.kt @@ -33,7 +33,7 @@ class DelayedTransitionStepperActivity : AppCompatActivity() { } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -42,18 +42,18 @@ class DelayedTransitionStepperActivity : AppCompatActivity() { setContentView(R.layout.activity_delayed_transition) ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 - mStepperLayout.setAdapter(DelayedTransitionFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) + stepperLayout.setAdapter(DelayedTransitionFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) super.onSaveInstanceState(outState) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { - mStepperLayout.onBackClicked() + stepperLayout.onBackClicked() } else { finish() } diff --git a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt index 033b0ca..719f60b 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt @@ -76,7 +76,8 @@ class MainActivity : AppCompatActivity() { SampleItem(getString(R.string.passing_data_between_steps), getString(R.string.passing_data_between_steps_description), PassDataBetweenStepsActivity::class.java), SampleItem(getString(R.string.disabled_tab_navigation), getString(R.string.disabled_tab_navigation_description), DisabledTabNavigationActivity::class.java), SampleItem(getString(R.string.hidden_bottom_navigation), getString(R.string.hidden_bottom_navigation_description), HiddenBottomNavigationActivity::class.java), - SampleItem(getString(R.string.custom_stepperlayout_theme), getString(R.string.custom_stepperlayout_theme_description), CustomStepperLayoutThemeActivity::class.java) + SampleItem(getString(R.string.custom_stepperlayout_theme), getString(R.string.custom_stepperlayout_theme_description), CustomStepperLayoutThemeActivity::class.java), + SampleItem(getString(R.string.set_button_color_programmatically), getString(R.string.set_button_color_programmatically_description), SetButtonColorProgrammaticallyActivity::class.java) ) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SampleItemViewHolder { diff --git a/sample/src/main/java/com/stepstone/stepper/sample/NoFragmentsActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/NoFragmentsActivity.kt index 6c0ac6a..a6c8ce2 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/NoFragmentsActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/NoFragmentsActivity.kt @@ -20,7 +20,7 @@ class NoFragmentsActivity : AppCompatActivity(), StepperLayout.StepperListener, } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -28,21 +28,21 @@ class NoFragmentsActivity : AppCompatActivity(), StepperLayout.StepperListener, ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 val sampleStepAdapter = SampleStepAdapter(this) - mStepperLayout.setAdapter(sampleStepAdapter, startingStepPosition) - mStepperLayout.setListener(this) + stepperLayout.setAdapter(sampleStepAdapter, startingStepPosition) + stepperLayout.setListener(this) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { - mStepperLayout.onBackClicked() + stepperLayout.onBackClicked() } else { finish() } } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) super.onSaveInstanceState(outState) } @@ -63,8 +63,8 @@ class NoFragmentsActivity : AppCompatActivity(), StepperLayout.StepperListener, } override fun onChangeEndButtonsEnabled(enabled: Boolean) { - mStepperLayout.setNextButtonVerificationFailed(!enabled) - mStepperLayout.setCompleteButtonVerificationFailed(!enabled) + stepperLayout.setNextButtonVerificationFailed(!enabled) + stepperLayout.setCompleteButtonVerificationFailed(!enabled) } } diff --git a/sample/src/main/java/com/stepstone/stepper/sample/PassDataBetweenStepsActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/PassDataBetweenStepsActivity.kt index 0f5e8d8..c33a848 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/PassDataBetweenStepsActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/PassDataBetweenStepsActivity.kt @@ -36,9 +36,9 @@ class PassDataBetweenStepsActivity : AppCompatActivity(), DataManager { } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout - private var mData: String? = null + private var data: String? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -47,30 +47,30 @@ class PassDataBetweenStepsActivity : AppCompatActivity(), DataManager { setContentView(R.layout.activity_pass_data_between_steps) ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 - mData = savedInstanceState?.getString(DATA) - mStepperLayout.setAdapter(PassDataBetweenStepsFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) + data = savedInstanceState?.getString(DATA) + stepperLayout.setAdapter(PassDataBetweenStepsFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) - outState.putString(DATA, mData) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) + outState.putString(DATA, data) super.onSaveInstanceState(outState) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { - mStepperLayout.onBackClicked() + stepperLayout.onBackClicked() } else { finish() } } override fun saveData(data: String?) { - mData = data + this.data = data } override fun getData(): String? { - return mData + return data } } diff --git a/sample/src/main/java/com/stepstone/stepper/sample/ProceedProgrammaticallyActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/ProceedProgrammaticallyActivity.kt index a3f8e30..301e8f8 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/ProceedProgrammaticallyActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/ProceedProgrammaticallyActivity.kt @@ -36,7 +36,7 @@ class ProceedProgrammaticallyActivity : AppCompatActivity(), StepperLayout.Stepp } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,19 +45,19 @@ class ProceedProgrammaticallyActivity : AppCompatActivity(), StepperLayout.Stepp setContentView(R.layout.activity_default_dots) ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 - mStepperLayout.setAdapter(FormFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) - mStepperLayout.setListener(this) + stepperLayout.setAdapter(FormFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) + stepperLayout.setListener(this) } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) super.onSaveInstanceState(outState) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { - mStepperLayout.onBackClicked() + stepperLayout.onBackClicked() } else { finish() } @@ -74,6 +74,6 @@ class ProceedProgrammaticallyActivity : AppCompatActivity(), StepperLayout.Stepp override fun onReturn() {} override fun onProceed() { - mStepperLayout.proceed() + stepperLayout.proceed() } } diff --git a/sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt new file mode 100644 index 0000000..c44c6c9 --- /dev/null +++ b/sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt @@ -0,0 +1,44 @@ +package com.stepstone.stepper.sample + +import android.content.res.ColorStateList +import android.os.Bundle +import android.support.annotation.ColorInt +import android.view.View +import butterknife.BindColor + +/** + * @author Piotr Zawadzki + */ +class SetButtonColorProgrammaticallyActivity : AbstractStepperActivity() { + + @BindColor(R.color.ms_custom_button_text_color) + lateinit var customButtonColor: ColorStateList + + @ColorInt + @JvmField + @BindColor(R.color.ms_black) + var blackColorInt: Int = 0 + + override val layoutResId: Int + get() = R.layout.activity_set_button_color_programmatically + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + stepperLayout.setNextButtonColor(customButtonColor) + stepperLayout.setBackButtonColor(customButtonColor) + stepperLayout.setCompleteButtonColor(customButtonColor) + } + + override fun onStepSelected(newStepPosition: Int) { + super.onStepSelected(newStepPosition) + when (newStepPosition) { + 1 -> stepperLayout.setNextButtonColor(blackColorInt) + 2 -> stepperLayout.setBackButtonColor(blackColorInt) + } + } + + override fun onCompleted(completeButton: View) { + super.onCompleted(completeButton) + stepperLayout.setCompleteButtonColor(blackColorInt) + } +} diff --git a/sample/src/main/java/com/stepstone/stepper/sample/ShowErrorOnBackTabActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/ShowErrorOnBackTabActivity.kt index ac49e63..f299072 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/ShowErrorOnBackTabActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/ShowErrorOnBackTabActivity.kt @@ -13,8 +13,8 @@ class ShowErrorOnBackTabActivity : AbstractStepperActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - mStepperLayout.isShowErrorStateEnabled = true - mStepperLayout.isShowErrorStateOnBackEnabled = true + stepperLayout.isShowErrorStateEnabled = true + stepperLayout.isShowErrorStateOnBackEnabled = true } } \ No newline at end of file diff --git a/sample/src/main/java/com/stepstone/stepper/sample/StepperFeedbackActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/StepperFeedbackActivity.kt index da1493b..736c328 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/StepperFeedbackActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/StepperFeedbackActivity.kt @@ -36,9 +36,9 @@ class StepperFeedbackActivity : AppCompatActivity() { } @BindView(R.id.stepperLayout) - lateinit var mStepperLayout: StepperLayout + lateinit var stepperLayout: StepperLayout - private var mMenu: Menu? = null + private var menu: Menu? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -47,20 +47,20 @@ class StepperFeedbackActivity : AppCompatActivity() { setContentView(R.layout.activity_stepper_feedback) ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 - mStepperLayout.setAdapter(StepperFeedbackFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) + stepperLayout.setAdapter(StepperFeedbackFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) } override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(CURRENT_STEP_POSITION_KEY, mStepperLayout.currentStepPosition) + outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) super.onSaveInstanceState(outState) } override fun onBackPressed() { - val currentStepPosition = mStepperLayout.currentStepPosition + val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { //do nothing when operation is in progress - if (!mStepperLayout.isInProgress) { - mStepperLayout.onBackClicked() + if (!stepperLayout.isInProgress) { + stepperLayout.onBackClicked() } } else { finish() @@ -69,14 +69,14 @@ class StepperFeedbackActivity : AppCompatActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.activity_stepper_feedback, menu) - mMenu = menu + this.menu = menu return true } override fun onOptionsItemSelected(item: MenuItem): Boolean { val itemId = item.itemId - if (!mStepperLayout.isInProgress + if (!stepperLayout.isInProgress && (itemId == R.id.menu_feedback_content_progress || itemId == R.id.menu_feedback_content_fade || itemId == R.id.menu_feedback_content_overlay @@ -84,12 +84,12 @@ class StepperFeedbackActivity : AppCompatActivity() { || itemId == R.id.menu_feedback_nav || itemId == R.id.menu_feedback_content_interaction)) { toggleItem(item) - val tabsEnabled = mMenu?.findItem(R.id.menu_feedback_tabs)?.isChecked - val contentProgressEnabled = mMenu?.findItem(R.id.menu_feedback_content_progress)?.isChecked - val contentFadeEnabled = mMenu?.findItem(R.id.menu_feedback_content_fade)?.isChecked - val contentOverlayEnabled = mMenu?.findItem(R.id.menu_feedback_content_overlay)?.isChecked - val disablingBottomNavigationEnabled = mMenu?.findItem(R.id.menu_feedback_nav)?.isChecked - val disablingContentInteractionEnabled = mMenu?.findItem(R.id.menu_feedback_content_interaction)?.isChecked + val tabsEnabled = menu?.findItem(R.id.menu_feedback_tabs)?.isChecked + val contentProgressEnabled = menu?.findItem(R.id.menu_feedback_content_progress)?.isChecked + val contentFadeEnabled = menu?.findItem(R.id.menu_feedback_content_fade)?.isChecked + val contentOverlayEnabled = menu?.findItem(R.id.menu_feedback_content_overlay)?.isChecked + val disablingBottomNavigationEnabled = menu?.findItem(R.id.menu_feedback_nav)?.isChecked + val disablingContentInteractionEnabled = menu?.findItem(R.id.menu_feedback_content_interaction)?.isChecked var feedbackMask = 0 if (tabsEnabled == true) { @@ -113,7 +113,7 @@ class StepperFeedbackActivity : AppCompatActivity() { if (feedbackMask == 0) { feedbackMask = StepperFeedbackType.NONE } - mStepperLayout.setFeedbackType(feedbackMask) + stepperLayout.setFeedbackType(feedbackMask) return true } diff --git a/sample/src/main/res/color/ms_custom_button_text_color.xml b/sample/src/main/res/color/ms_custom_button_text_color.xml index 4d0902f..340b6a4 100644 --- a/sample/src/main/res/color/ms_custom_button_text_color.xml +++ b/sample/src/main/res/color/ms_custom_button_text_color.xml @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_set_button_color_programmatically.xml b/sample/src/main/res/layout/activity_set_button_color_programmatically.xml new file mode 100644 index 0000000..db706c8 --- /dev/null +++ b/sample/src/main/res/layout/activity_set_button_color_programmatically.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_styled_tabs.xml b/sample/src/main/res/layout/activity_styled_tabs.xml index d16a3b2..883a364 100644 --- a/sample/src/main/res/layout/activity_styled_tabs.xml +++ b/sample/src/main/res/layout/activity_styled_tabs.xml @@ -1,14 +1,16 @@ \ No newline at end of file + app:ms_bottomNavigationBackground="?attr/colorAccent" + tools:theme="@style/AppTheme" /> \ No newline at end of file diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml index bb9bc60..4d0f2da 100644 --- a/sample/src/main/res/values/colors.xml +++ b/sample/src/main/res/values/colors.xml @@ -18,4 +18,6 @@ #483f9ab1 + #30BDBDBD + diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 7267239..df77bb1 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ Disabled tab navigation Hidden bottom navigation Custom StepperLayout theme + Set button color programmatically The default implementation of a dotted stepper Dotted stepper styled through view attributes in the layout file @@ -50,6 +51,7 @@ Shows how to disable clicking on tabs in a tabbed stepper Shows how to hide bottom navigation Shows a styled stepper layout with custom fonts & colors + Shows how to set the color of bottom navigation button programmatically (instead of via XML) Tab title Lorem 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.