Skip to content

Commit

Permalink
Added TextColor and TextAppearance Attributes to FormItem and tested …
Browse files Browse the repository at this point in the history
…them in the app

Tried to fix the validateTill issue but seems this is the behavior of the library when not validating all fields
  • Loading branch information
mhendy2001 committed Sep 11, 2017
1 parent 8aa2430 commit e0dd7ff
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@

import com.mobsandgeeks.saripaar.Validator;
import com.mobsandgeeks.saripaar.annotation.NotEmpty;
import com.mobsandgeeks.saripaar.annotation.Order;
import com.robustastudio.forms.utils.FormItemUtil;
import com.robustastudio.forms.validation.FormValidator;
import com.robustastudio.forms.widget.FormItem;

public class MainActivity extends AppCompatActivity {

@NotEmpty
@Order(0)
FormItem nameFormItem;
@Order(1)
@NotEmpty
FormItem passwordFormItem;

Expand All @@ -40,7 +43,7 @@ public void onValidationSucceeded() {
@Override
public void onClick(View v) {
FormItemUtil.removeErrorHintIfFound(nameFormItem, passwordFormItem);
validator.validate();
validator.validateTill(nameFormItem);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:layout_height="wrap_content"
android:hint="Name"
android:maxLength="10"
app:theme="@style/FormItemTheme"
android:text="Hello World!" />

<com.robustastudio.forms.widget.FormItem
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="FormItemTheme" parent="AppTheme">
<item name="colorPrimary">#FFFF00</item>
<item name="colorPrimaryDark">#00FF00</item>
<item name="colorAccent">#0000FF</item>
<item name="colorControlNormal">#0000FF</item> <!-- Used for the underline when not selected -->
<item name="colorControlActivated">#FF00FF</item> <!-- Underline and floating text when active -->
<item name="android:textColor">@android:color/holo_green_dark</item>
<item name="android:textColorHint">@android:color/holo_red_dark</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Large</item>
<item name="errorTextAppearance">@style/TextAppearance.AppCompat.Body1</item>
<item name="hintTextAppearance">@style/TextAppearance.AppCompat.Caption</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.support.design.widget.TextInputEditText
import android.support.design.widget.TextInputLayout
import android.support.v4.content.ContextCompat
import android.text.InputFilter
import android.text.TextUtils
import android.util.AttributeSet
Expand Down Expand Up @@ -43,6 +44,8 @@ open class FormItem @JvmOverloads constructor(context: Context,
val drawableRes = it.getResourceId(R.styleable.FormItem_drawable, -1)
val inputType = it.getInteger(R.styleable.FormItem_inputType, /* text input type */ 0x1)
val textAsDrawable = it.getString(R.styleable.FormItem_textAsDrawable)
val textColor = it.getColor(R.styleable.FormItem_android_textColor, Color.BLACK)
val textAppearanceRes = it.getResourceId(R.styleable.FormItem_android_textAppearance, -1)

editText.setLines(lines)
editText.inputType = inputType
Expand All @@ -65,6 +68,11 @@ open class FormItem @JvmOverloads constructor(context: Context,
this.isCounterEnabled = true
this.counterMaxLength = maxLength
}
if (textAppearanceRes != -1) {
editText.setTextAppearance(context, textAppearanceRes)
}
editText.setTextColor(textColor)

}
}

Expand Down
2 changes: 2 additions & 0 deletions forms/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change