diff --git a/README.md b/README.md index 966c799..d3c2a35 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Add the library to your project via Gradle: ``` dependencies { - implementation 'com.ernestoyaquello.stepperform:vertical-stepper-form:2.1.1' + implementation 'com.ernestoyaquello.stepperform:vertical-stepper-form:2.2.0' } ``` @@ -242,6 +242,11 @@ public void onRestoreInstanceState(Bundle savedInstanceState) { ## Further Details Check out the [sample application code](https://github.com/ernestoyaquello/VerticalStepperForm/tree/master/app/src/main/java/verticalstepperform/ernestoyaquello/com/verticalstepperform) to see a more complete example of how this library can be used to create vertical stepper forms. +## Support this library +The creation (and maintenance) of this library requires time and effort. If you find it useful and want to support it, please use the link below: + +[![Buy me a coffee!](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/ernestoyaquello) + ## Contribution Feel free to contribute to this library, any help will be welcomed! diff --git a/build.gradle b/build.gradle index 27e6b02..e648911 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' + classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c3510d6..f86819a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Sat Apr 27 11:15:07 BST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/vertical-stepper-form/build.gradle b/vertical-stepper-form/build.gradle index 9a03092..922b7f7 100644 --- a/vertical-stepper-form/build.gradle +++ b/vertical-stepper-form/build.gradle @@ -15,7 +15,7 @@ ext { siteUrl = 'https://github.com/ernestoyaquello/VerticalStepperForm' gitUrl = 'https://github.com/ernestoyaquello/VerticalStepperForm.git' - libraryVersion = '2.1.1' + libraryVersion = '2.2.0' developerId = 'ernestoyaquello' developerName = 'Julio Ernesto Rodríguez Cabañas' @@ -32,7 +32,7 @@ android { defaultConfig { minSdkVersion 19 targetSdkVersion 28 - versionCode 13 + versionCode 14 versionName libraryVersion } diff --git a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java index 425870f..be60234 100644 --- a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java +++ b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/Builder.java @@ -272,6 +272,19 @@ public Builder leftVerticalLineThicknessSizeInPx(int leftVerticalLineThicknessSi return this; } + /** + * Sets the horizontal margin between the step numbers and the step content. + * + * @param marginFromStepNumbersToContentInPx The horizontal margin between the step numbers and + * the step content. + * @return The builder instance. + */ + public Builder marginFromStepNumbersToContentInPx(int marginFromStepNumbersToContentInPx) { + formView.style.marginFromStepNumbersToContentInPx = marginFromStepNumbersToContentInPx; + + return this; + } + /** * Specifies whether or not the bottom navigation bar will be displayed. * diff --git a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java index fd72a16..62afe9d 100644 --- a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java +++ b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/StepHelper.java @@ -1,7 +1,6 @@ package ernestoyaquello.com.verticalstepperform; import android.content.Context; -import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; @@ -10,10 +9,12 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import com.google.android.material.button.MaterialButton; +import androidx.annotation.LayoutRes; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import ernestoyaquello.com.verticalstepperform.VerticalStepperFormView.FormStyle; @@ -44,6 +45,8 @@ class StepHelper implements Step.InternalFormStepListener { private View lineView2; private View stepAndButtonView; private View errorMessageContainerView; + private View titleAndSubtitleContainerView; + private View errorContentAndButtonContainerView; StepHelper(Step.InternalFormStepListener formListener, @NonNull Step step) { this(formListener, step, false); @@ -55,13 +58,13 @@ class StepHelper implements Step.InternalFormStepListener { this.step.addListenerInternal(formListener); } - View initialize(VerticalStepperFormView form, ViewGroup parent, int position, boolean isLast) { + View initialize(VerticalStepperFormView form, ViewGroup parent, @LayoutRes int stepLayoutResourceId, int position, boolean isLast) { if (step.getEntireStepLayout() == null) { formStyle = form.style; Context context = form.getContext(); LayoutInflater inflater = LayoutInflater.from(context); - View stepLayout = inflater.inflate(R.layout.step_layout, parent, false); + View stepLayout = inflater.inflate(stepLayoutResourceId, parent, false); step.initializeStepInternal(stepLayout, form, position); step.setContentLayoutInternal(step.createStepContentLayout()); @@ -99,6 +102,8 @@ private void setupStepViews( lineView2 = stepLayout.findViewById(R.id.line2); stepAndButtonView = step.getEntireStepLayout().findViewById(R.id.step_content_and_button); errorMessageContainerView = step.getEntireStepLayout().findViewById(R.id.step_error_container); + titleAndSubtitleContainerView = step.getEntireStepLayout().findViewById(R.id.title_subtitle_container); + errorContentAndButtonContainerView = step.getEntireStepLayout().findViewById(R.id.error_content_button_container); titleView.setTextColor(formStyle.stepTitleTextColor); subtitleView.setTextColor(formStyle.stepSubtitleTextColor); @@ -106,10 +111,12 @@ private void setupStepViews( doneIconView.setColorFilter(formStyle.stepNumberTextColor); errorMessageView.setTextColor(formStyle.errorMessageTextColor); errorIconView.setColorFilter(formStyle.errorMessageTextColor); + Drawable circleDrawable = ContextCompat.getDrawable(form.getContext(), R.drawable.circle_step_done); circleDrawable.setColorFilter( new PorterDuffColorFilter(formStyle.stepNumberBackgroundColor, PorterDuff.Mode.SRC_IN)); stepNumberCircleView.setBackground(circleDrawable); + UIHelper.setButtonColor( nextButtonView, formStyle.nextButtonBackgroundColor, @@ -127,12 +134,25 @@ private void setupStepViews( layoutParamsCircle.width = formStyle.leftCircleSizeInPx; layoutParamsCircle.height = formStyle.leftCircleSizeInPx; stepNumberCircleView.setLayoutParams(layoutParamsCircle); + ViewGroup.LayoutParams layoutParamsLine1 = lineView1.getLayoutParams(); layoutParamsLine1.width = formStyle.leftVerticalLineThicknessSizeInPx; lineView1.setLayoutParams(layoutParamsLine1); + ViewGroup.LayoutParams layoutParamsLine2 = lineView2.getLayoutParams(); layoutParamsLine2.width = formStyle.leftVerticalLineThicknessSizeInPx; lineView2.setLayoutParams(layoutParamsLine2); + + LinearLayout.LayoutParams titleAndSubtitleContainerLayoutParams = + (LinearLayout.LayoutParams) titleAndSubtitleContainerView.getLayoutParams(); + titleAndSubtitleContainerLayoutParams.setMarginStart(formStyle.marginFromStepNumbersToContentInPx); + titleAndSubtitleContainerView.setLayoutParams(titleAndSubtitleContainerLayoutParams); + + LinearLayout.LayoutParams errorContentAndButtonContainerLayoutParams = + (LinearLayout.LayoutParams) errorContentAndButtonContainerView.getLayoutParams(); + errorContentAndButtonContainerLayoutParams.setMarginStart(formStyle.marginFromStepNumbersToContentInPx); + errorContentAndButtonContainerView.setLayoutParams(errorContentAndButtonContainerLayoutParams); + stepNumberTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, formStyle.leftCircleTextSizeInPx); titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, formStyle.stepTitleTextSizeInPx); subtitleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, formStyle.stepSubtitleTextSizeInPx); diff --git a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java index 97b123f..816e3a2 100644 --- a/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java +++ b/vertical-stepper-form/src/main/java/ernestoyaquello/com/verticalstepperform/VerticalStepperFormView.java @@ -4,6 +4,7 @@ import android.content.res.TypedArray; import android.graphics.Rect; +import androidx.annotation.LayoutRes; import androidx.appcompat.widget.AppCompatImageButton; import android.os.Bundle; @@ -478,6 +479,8 @@ private void onConstructed(Context context, AttributeSet attrs, int defStyleAttr getResources().getDimensionPixelSize(R.dimen.vertical_stepper_form_text_size_error_message); style.leftVerticalLineThicknessSizeInPx = getResources().getDimensionPixelSize(R.dimen.vertical_stepper_form_width_vertical_line); + style.marginFromStepNumbersToContentInPx = + getResources().getDimensionPixelSize(R.dimen.vertical_stepper_form_space_between_numbers_and_content); style.backgroundColorOfDisabledElements = ContextCompat.getColor(context, R.color.vertical_stepper_form_background_color_disabled_elements); style.stepNumberBackgroundColor = @@ -566,6 +569,9 @@ private void onConstructed(Context context, AttributeSet attrs, int defStyleAttr style.leftVerticalLineThicknessSizeInPx = vars.getDimensionPixelSize( R.styleable.VerticalStepperFormView_form_vertical_line_width, style.leftVerticalLineThicknessSizeInPx); + style.marginFromStepNumbersToContentInPx = vars.getDimensionPixelSize( + R.styleable.VerticalStepperFormView_form_horizontal_margin_from_step_numbers_to_content, + style.marginFromStepNumbersToContentInPx); style.backgroundColorOfDisabledElements = vars.getColor( R.styleable.VerticalStepperFormView_form_disabled_elements_background_color, style.backgroundColorOfDisabledElements); @@ -671,8 +677,15 @@ void initializeForm(StepperFormListener listener, StepHelper[] stepsArray) { private View initializeStepHelper(int position) { StepHelper stepHelper = stepHelpers.get(position); boolean isLast = (position + 1) == stepHelpers.size(); + int stepLayoutResourceId = getStepLayoutResourceId(position, isLast); - return stepHelper.initialize(this, formContentView, position, isLast); + return stepHelper.initialize(this, formContentView, stepLayoutResourceId, position, isLast); + } + + @LayoutRes + protected int getStepLayoutResourceId(int position, boolean isLast) { + // This could be overridden to use a custom step layout + return R.layout.step_layout; } private synchronized void openStep(int stepToOpenPosition, boolean useAnimations) { @@ -986,6 +999,7 @@ class FormStyle { int stepSubtitleTextSizeInPx; int stepErrorMessageTextSizeInPx; int leftVerticalLineThicknessSizeInPx; + int marginFromStepNumbersToContentInPx; int backgroundColorOfDisabledElements; int stepNumberBackgroundColor; int nextButtonBackgroundColor; diff --git a/vertical-stepper-form/src/main/res/layout/step_layout.xml b/vertical-stepper-form/src/main/res/layout/step_layout.xml index 3de4e9d..1f625f4 100644 --- a/vertical-stepper-form/src/main/res/layout/step_layout.xml +++ b/vertical-stepper-form/src/main/res/layout/step_layout.xml @@ -61,11 +61,12 @@ + android:layout_marginStart="@dimen/vertical_stepper_form_space_between_numbers_and_content"> + diff --git a/vertical-stepper-form/src/main/res/values/dimens.xml b/vertical-stepper-form/src/main/res/values/dimens.xml index 25d3a62..58f5a5d 100644 --- a/vertical-stepper-form/src/main/res/values/dimens.xml +++ b/vertical-stepper-form/src/main/res/values/dimens.xml @@ -6,5 +6,6 @@ 14sp 16sp 2dp + 16dp