Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some styling methods #222

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
google()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradleAndroidVersion"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, modify gradleAndroidVersion variable above.

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved to mStepperType and handled by each subtype of AbstractStepperType instead. This way each stepper type can change it as needed (including the tabbed stepper).

I would also remove

applied to dotted or progress bars

from the JavaDoc and implement it for the tabbed stepper instead as the corresponding XML attribute does change the color of the tabs (so that we don't have inconsistencies between XML attribute and Java method).

As described above the logic for that should probably be in TabsStepperType and include:

        mTabsContainer.setSelectedColor(stepperLayout.getSelectedColor());

+ what is done in TabsStepperType#onNewAdapter (tabs need to be recreated).

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ViewCompat.setBackground(mStepNavigation , newBottomNavigationBackground) instead.

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Piotr Zawadzki
*/
@LargeTest
public class SetButtonColorProgrammaticallyActivityTest extends AbstractActivityTest<SetButtonColorProgrammaticallyActivity> {
public class SetButtonColorProgrammaticallyActivityTest extends AbstractActivityTest<StyledProgrammaticallyActivity> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the test class name to StyledProgrammaticallyActivityTest


@Test
public void shouldStayOnTheFirstStepWhenVerificationFails() {
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<activity
android:name=".CustomStepperLayoutThemeActivity"
android:theme="@style/AppThemeDark" />
<activity android:name=".SetButtonColorProgrammaticallyActivity" />
<activity android:name=".StyledProgrammaticallyActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same code style as above using lateinit type modifier.


@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)
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

<color name="verification_failed_color">#30BDBDBD</color>

<color name="custom_active_step_color">#00ff00</color>
<color name="custom_inactive_step_color">#ff0000</color>
<color name="custom_bottom_navigation_background_color">#0000ff</color>
</resources>
4 changes: 2 additions & 2 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<string name="disabled_tab_navigation">Disabled tab navigation</string>
<string name="hidden_bottom_navigation">Hidden bottom navigation</string>
<string name="custom_stepperlayout_theme">Custom StepperLayout theme</string>
<string name="set_button_color_programmatically">Set button color programmatically</string>
<string name="set_styles_programmatically">Set styles programmatically</string>

<string name="default_dots_description">The default implementation of a dotted stepper</string>
<string name="styled_dots_description">Dotted stepper styled through view attributes in the layout file</string>
Expand All @@ -51,7 +51,7 @@
<string name="disabled_tab_navigation_description">Shows how to disable clicking on tabs in a tabbed stepper</string>
<string name="hidden_bottom_navigation_description">Shows how to hide bottom navigation</string>
<string name="custom_stepperlayout_theme_description">Shows a styled stepper layout with custom fonts &amp; colors</string>
<string name="set_button_color_programmatically_description">Shows how to set the color of bottom navigation button programmatically (instead of via XML)</string>
<string name="set_styles_programmatically_description">Shows how to set styles and colors programmatically (instead of via XML)</string>

<string name="tab_title">Tab title</string>
<string name="lorem_ipsum">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.</string>
Expand Down