Skip to content

Commit

Permalink
Merge pull request #80 from ernestoyaquello/develop
Browse files Browse the repository at this point in the history
Fixed #78 and #79
  • Loading branch information
ernestoyaquello authored Apr 27, 2019
2 parents 7bf7985 + 94df639 commit 0ed9519
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 13 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down Expand Up @@ -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!

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions vertical-stepper-form/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -32,7 +32,7 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 13
versionCode 14
versionName libraryVersion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -99,17 +102,21 @@ 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);
stepNumberTextView.setTextColor(formStyle.stepNumberTextColor);
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,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -986,6 +999,7 @@ class FormStyle {
int stepSubtitleTextSizeInPx;
int stepErrorMessageTextSizeInPx;
int leftVerticalLineThicknessSizeInPx;
int marginFromStepNumbersToContentInPx;
int backgroundColorOfDisabledElements;
int stepNumberBackgroundColor;
int nextButtonBackgroundColor;
Expand Down
6 changes: 4 additions & 2 deletions vertical-stepper-form/src/main/res/layout/step_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@
</LinearLayout>

<LinearLayout
android:id="@+id/title_subtitle_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginStart="16dp"
android:layout_marginStart="@dimen/vertical_stepper_form_space_between_numbers_and_content"
android:paddingBottom="8dp">

<FrameLayout
Expand Down Expand Up @@ -134,11 +135,12 @@
</FrameLayout>

<LinearLayout
android:id="@+id/error_content_button_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginStart="16dp">
android:layout_marginStart="@dimen/vertical_stepper_form_space_between_numbers_and_content">

<LinearLayout
android:id="@+id/step_error_container"
Expand Down
1 change: 1 addition & 0 deletions vertical-stepper-form/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<attr name="form_subtitle_text_size" format="dimension" />
<attr name="form_error_message_text_size" format="dimension" />
<attr name="form_vertical_line_width" format="dimension" />
<attr name="form_horizontal_margin_from_step_numbers_to_content" format="dimension" />
<attr name="form_disabled_elements_background_color" format="color" />
<attr name="form_circle_background_color" format="color" />
<attr name="form_next_button_background_color" format="color" />
Expand Down
1 change: 1 addition & 0 deletions vertical-stepper-form/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<dimen name="vertical_stepper_form_text_size_subtitle">14sp</dimen>
<dimen name="vertical_stepper_form_text_size_error_message">16sp</dimen>
<dimen name="vertical_stepper_form_width_vertical_line">2dp</dimen>
<dimen name="vertical_stepper_form_space_between_numbers_and_content">16dp</dimen>

</resources>

0 comments on commit 0ed9519

Please sign in to comment.