refactored

This commit is contained in:
Elena Bobkova 2017-03-06 19:20:01 +03:00
parent 98842a6bbc
commit cbaf06ca3d
2 changed files with 15 additions and 4 deletions

View File

@ -25,7 +25,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.SingleLineTransformationMethod;
@ -163,7 +162,7 @@ public class TypefacedEditText extends AppCompatEditText {
"inputType required parameter");
final int inputType = typedArray.getInt(AttributesUtils.getField(androidRes, "TextView_inputType"), -1);
if (inputType == InputType.TYPE_CLASS_NUMBER || inputType == InputType.TYPE_DATETIME_VARIATION_NORMAL) {
if (AttributesUtils.isNumberInputType(inputType)) {
errors.add("use inputType phone instead of number");
}
@ -308,8 +307,9 @@ public class TypefacedEditText extends AppCompatEditText {
@Override
public void setInputType(final int type) {
if (type == InputType.TYPE_CLASS_NUMBER || type == InputType.TYPE_NUMBER_VARIATION_NORMAL) {
Lc.assertion(new IllegalStateException(AttributesUtils.viewError(this, "Do not specify number InputType for EditText, use phone instead")));
if (AttributesUtils.isNumberInputType(type)) {
Lc.assertion(new IllegalStateException(AttributesUtils.viewError(this,
"Do not specify number InputType for EditText, use phone instead")));
}
super.setInputType(type);
}

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.StyleableRes;
import android.text.InputType;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
@ -149,6 +150,16 @@ public final class AttributesUtils {
return "Errors for view id=" + UiUtils.OfViews.getViewIdString(view) + ":\n" + errorText;
}
/**
* Returns true if input type equals number input type.
*
* @param inputType Input type to check;
* @return true if input type equals number input type.
*/
public static boolean isNumberInputType(final int inputType) {
return inputType == InputType.TYPE_CLASS_NUMBER || inputType == InputType.TYPE_DATETIME_VARIATION_NORMAL;
}
private AttributesUtils() {
}