From 833f0e728970bb0bc5bdd2071602a56a9076f89f Mon Sep 17 00:00:00 2001 From: Diego Fernando Murillo Valencia Date: Mon, 23 Oct 2017 09:36:00 -0700 Subject: [PATCH] Added some methods for styling programmatically Added methods for styling the selected and unselected colors and the background of the bottom navigation --- build.gradle | 2 +- .../com/stepstone/stepper/StepperLayout.java | 55 +++++++++++++++++++ .../stepstone/stepper/sample/SanityTest.java | 6 +- ...ttonColorProgrammaticallyActivityTest.java | 2 +- sample/src/main/AndroidManifest.xml | 2 +- .../stepstone/stepper/sample/MainActivity.kt | 2 +- ...y.kt => StyledProgrammaticallyActivity.kt} | 25 +++++++-- sample/src/main/res/values/colors.xml | 3 + sample/src/main/res/values/strings.xml | 4 +- 9 files changed, 88 insertions(+), 13 deletions(-) rename sample/src/main/java/com/stepstone/stepper/sample/{SetButtonColorProgrammaticallyActivity.kt => StyledProgrammaticallyActivity.kt} (57%) diff --git a/build.gradle b/build.gradle index 49c5761..dc5a913 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { google() } dependencies { - classpath "com.android.tools.build:gradle:$gradleAndroidVersion" + classpath 'com.android.tools.build:gradle:3.0.0-rc2' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintrayVersion" classpath "com.github.dcendents:android-maven-gradle-plugin:$mavenGradlePluginVersion" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 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 c6e13d8..34b6a02 100644 --- a/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java +++ b/material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java @@ -648,6 +648,61 @@ public void setBackButtonColor(@ColorInt int newButtonColor) { setBackButtonColor(ColorStateList.valueOf(newButtonColor)); } + /** + * Changes the color for an active step, applied to dotted or progress bars + * + * @param newActiveStepColor the active step color integer + */ + public void setActiveStepColor(@ColorInt int newActiveStepColor) { + mSelectedColor = newActiveStepColor; + mDottedProgressBar.setSelectedColor(newActiveStepColor); + mProgressBar.setProgressColor(newActiveStepColor); + } + + /** + * Changes the color for an inactive step, applied to dotted or progress bars + * + * @param newInactiveStepColor the inactive step color integer + */ + public void setInactiveStepColor(@ColorInt int newInactiveStepColor) { + mUnselectedColor = newInactiveStepColor; + mDottedProgressBar.setUnselectedColor(newInactiveStepColor); + mProgressBar.setProgressBackgroundColor(newInactiveStepColor); + } + + /** + * Changes the bottom navigation background using a drawable resource + * + * @param newBottomNavigationBackground the drawable resource id + */ + public void setBottomNavigationBackground(@DrawableRes int newBottomNavigationBackground){ + mBottomNavigationBackground = newBottomNavigationBackground; + mStepNavigation.setBackgroundResource(mBottomNavigationBackground); + } + + /** + * Changes the bottom navigation background using a drawable + * + * @param newBottomNavigationBackground the drawable + */ + public void setBottomNavigationBackground(@NonNull Drawable newBottomNavigationBackground){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + mStepNavigation.setBackground(newBottomNavigationBackground); + }else { + mStepNavigation.setBackgroundDrawable(newBottomNavigationBackground); + } + } + + /** + * Changes the bottom navigation background color + * + * @param newBottomNavigationBackground the color integer + */ + public void setBottomNavigationBackgroundColor(@ColorInt int newBottomNavigationBackground){ + mStepNavigation.setBackgroundColor(newBottomNavigationBackground); + } + + /** * Updates the error state in the UI. * It does nothing if showing error state is disabled. 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 6ab1975..669f4f6 100644 --- a/sample/src/androidTest/java/com/stepstone/stepper/sample/SanityTest.java +++ b/sample/src/androidTest/java/com/stepstone/stepper/sample/SanityTest.java @@ -270,11 +270,11 @@ public void shouldOpenCustomStepperLayoutThemeActivity() { @Test public void shouldOpenSetButtonColorProgrammaticallyActivity() { //when - clickRowWithText(R.string.set_button_color_programmatically); + clickRowWithText(R.string.set_styles_programmatically); //then - intended(hasComponent(SetButtonColorProgrammaticallyActivity.class.getName())); - SpoonScreenshotAction.perform(getScreenshotTag(25, R.string.set_button_color_programmatically)); + intended(hasComponent(StyledProgrammaticallyActivity.class.getName())); + SpoonScreenshotAction.perform(getScreenshotTag(25, R.string.set_styles_programmatically)); } @NonNull diff --git a/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java b/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java index 92e3687..f980940 100644 --- a/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java +++ b/sample/src/androidTest/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivityTest.java @@ -25,7 +25,7 @@ * @author Piotr Zawadzki */ @LargeTest -public class SetButtonColorProgrammaticallyActivityTest extends AbstractActivityTest { +public class SetButtonColorProgrammaticallyActivityTest extends AbstractActivityTest { @Test public void shouldStayOnTheFirstStepWhenVerificationFails() { diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index e122ed7..3db9179 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -53,7 +53,7 @@ - + \ No newline at end of file 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 719f60b..bd80f95 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/MainActivity.kt @@ -77,7 +77,7 @@ class MainActivity : AppCompatActivity() { 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.set_button_color_programmatically), getString(R.string.set_button_color_programmatically_description), SetButtonColorProgrammaticallyActivity::class.java) + SampleItem(getString(R.string.set_styles_programmatically), getString(R.string.set_styles_programmatically_description), StyledProgrammaticallyActivity::class.java) ) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SampleItemViewHolder { diff --git a/sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt b/sample/src/main/java/com/stepstone/stepper/sample/StyledProgrammaticallyActivity.kt similarity index 57% rename from sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt rename to sample/src/main/java/com/stepstone/stepper/sample/StyledProgrammaticallyActivity.kt index c44c6c9..3a32a7d 100644 --- a/sample/src/main/java/com/stepstone/stepper/sample/SetButtonColorProgrammaticallyActivity.kt +++ b/sample/src/main/java/com/stepstone/stepper/sample/StyledProgrammaticallyActivity.kt @@ -9,11 +9,23 @@ import butterknife.BindColor /** * @author Piotr Zawadzki */ -class SetButtonColorProgrammaticallyActivity : AbstractStepperActivity() { +class StyledProgrammaticallyActivity : AbstractStepperActivity() { @BindColor(R.color.ms_custom_button_text_color) lateinit var customButtonColor: ColorStateList + @BindColor(R.color.custom_active_step_color) + @JvmField + var customActiveStepColor: Int = 0 + + @BindColor(R.color.custom_inactive_step_color) + @JvmField + var customInactiveStepColor: Int = 0 + + @BindColor(R.color.custom_bottom_navigation_background_color) + @JvmField + var customBottomNativationBackgroundColor: Int = 0 + @ColorInt @JvmField @BindColor(R.color.ms_black) @@ -24,9 +36,14 @@ class SetButtonColorProgrammaticallyActivity : AbstractStepperActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - stepperLayout.setNextButtonColor(customButtonColor) - stepperLayout.setBackButtonColor(customButtonColor) - stepperLayout.setCompleteButtonColor(customButtonColor) + with(stepperLayout) { + setNextButtonColor(customButtonColor) + setBackButtonColor(customButtonColor) + setCompleteButtonColor(customButtonColor) + setActiveStepColor(customActiveStepColor) + setInactiveStepColor(customInactiveStepColor) + setBottomNavigationBackgroundColor(customBottomNativationBackgroundColor) + } } override fun onStepSelected(newStepPosition: Int) { diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml index 4d0f2da..7754d17 100644 --- a/sample/src/main/res/values/colors.xml +++ b/sample/src/main/res/values/colors.xml @@ -20,4 +20,7 @@ #30BDBDBD + #00ff00 + #ff0000 + #0000ff diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index df77bb1..351a9a4 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -25,7 +25,7 @@ Disabled tab navigation Hidden bottom navigation Custom StepperLayout theme - Set button color programmatically + Set styles programmatically The default implementation of a dotted stepper Dotted stepper styled through view attributes in the layout file @@ -51,7 +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) + Shows how to set styles and colors 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.