From 26315a11f81acc746ecc67f0b1b10fa4713eb889 Mon Sep 17 00:00:00 2001 From: Ryan Orman Date: Wed, 24 Feb 2016 16:31:37 -0500 Subject: [PATCH 1/3] Added some attributes for further customization when the edittext is disabled. Added these attributes: - met_disabledBottomLineColor allows the user to specify a color for the disabled underline for the edit text. - met_disabledBottomLineDotted allows the user to turn off the dotted line functionality when the edit text is disabled. --- .../materialedittext/MaterialEditText.java | 26 ++++++++++++++++--- library/src/main/res/values/attrs.xml | 4 +++ .../materialedittext/sample/MainActivity.java | 2 ++ sample/src/main/res/layout/activity_main.xml | 9 +++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java b/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java index 77a84646..d4665444 100755 --- a/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java +++ b/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java @@ -148,6 +148,11 @@ public class MaterialEditText extends AppCompatEditText { */ private int errorColor; + /** + * the color for the disabled dotted underline. + */ + private int disabledUnderlineColor; + /** * min characters count limit. 0 means no limit. default is 0. NOTE: the character counter will increase the View's height. */ @@ -304,6 +309,7 @@ public class MaterialEditText extends AppCompatEditText { private ColorStateList textColorStateList; private ColorStateList textColorHintStateList; private ArgbEvaluator focusEvaluator = new ArgbEvaluator(); + private boolean dottedBottomLinesForDisabledState; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); StaticLayout textLayout; @@ -378,8 +384,10 @@ private void init(Context context, AttributeSet attrs) { primaryColor = typedArray.getColor(R.styleable.MaterialEditText_met_primaryColor, defaultPrimaryColor); setFloatingLabelInternal(typedArray.getInt(R.styleable.MaterialEditText_met_floatingLabel, 0)); errorColor = typedArray.getColor(R.styleable.MaterialEditText_met_errorColor, Color.parseColor("#e7492E")); + disabledUnderlineColor = typedArray.getColor(R.styleable.MaterialEditText_met_disabledBottomLineColor, -1); minCharacters = typedArray.getInt(R.styleable.MaterialEditText_met_minCharacters, 0); maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_met_maxCharacters, 0); + dottedBottomLinesForDisabledState = typedArray.getBoolean(R.styleable.MaterialEditText_met_disabledBottomLineDotted, true); singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_met_singleLineEllipsis, false); helperText = typedArray.getString(R.styleable.MaterialEditText_met_helperText); helperTextColor = typedArray.getColor(R.styleable.MaterialEditText_met_helperTextColor, -1); @@ -1316,11 +1324,21 @@ protected void onDraw(@NonNull Canvas canvas) { paint.setColor(errorColor); canvas.drawRect(startX, lineStartY, endX, lineStartY + getPixel(2), paint); } else if (!isEnabled()) { // disabled - paint.setColor(underlineColor != -1 ? underlineColor : baseColor & 0x00ffffff | 0x44000000); - float interval = getPixel(1); - for (float xOffset = 0; xOffset < getWidth(); xOffset += interval * 3) { - canvas.drawRect(startX + xOffset, lineStartY, startX + xOffset + interval, lineStartY + getPixel(1), paint); + int disabledLineColor = disabledUnderlineColor; + if (disabledUnderlineColor == -1){ + disabledLineColor = underlineColor != -1 ? underlineColor : baseColor; } + paint.setColor(disabledLineColor & 0x00ffffff | 0x44000000); + if (dottedBottomLinesForDisabledState){ + float interval = getPixel(1); + for (float xOffset = 0; xOffset < getWidth(); xOffset += interval * 3) { + canvas.drawRect(startX + xOffset, lineStartY, startX + xOffset + interval, lineStartY + getPixel(1), paint); + } + } + else{ + canvas.drawRect(startX, lineStartY, endX, lineStartY + getPixel(1), paint); + } + } else if (hasFocus()) { // focused paint.setColor(primaryColor); canvas.drawRect(startX, lineStartY, endX, lineStartY + getPixel(2), paint); diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index ce50f9a2..196e0b41 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -17,6 +17,10 @@ + + + + diff --git a/sample/src/main/java/com/rengwuxian/materialedittext/sample/MainActivity.java b/sample/src/main/java/com/rengwuxian/materialedittext/sample/MainActivity.java index 693d8e3f..66cf4174 100644 --- a/sample/src/main/java/com/rengwuxian/materialedittext/sample/MainActivity.java +++ b/sample/src/main/java/com/rengwuxian/materialedittext/sample/MainActivity.java @@ -24,6 +24,8 @@ protected void onCreate(Bundle savedInstanceState) { initSingleLineEllipsisEt(); initSetErrorEt(); initValidationEt(); + + findViewById(R.id.disabledSolidLine).setEnabled(false); } private void initEnableBt() { diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 4c45dc19..1cbfc7f5 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -429,6 +429,15 @@ app:met_iconPadding="0dp" app:met_maxCharacters="5" /> + + \ No newline at end of file From 6ed116fad753ec8500c6fe7d3e856ae081de62f1 Mon Sep 17 00:00:00 2001 From: Ryan Orman Date: Fri, 11 Mar 2016 09:19:56 -0500 Subject: [PATCH 2/3] Attr that allows full control over the floating labels color Disabling the alpha allows users like me to keep the floating labels consistent with other controls. --- .../materialedittext/MaterialEditText.java | 12 ++++++++++-- library/src/main/res/values/attrs.xml | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java b/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java index d4665444..b085eff8 100755 --- a/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java +++ b/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java @@ -153,6 +153,11 @@ public class MaterialEditText extends AppCompatEditText { */ private int disabledUnderlineColor; + /** + * The floating label's color fades. Defaults to true. If false, then the full floating label color is used. + */ + private boolean floatingLabelColorFades; + /** * min characters count limit. 0 means no limit. default is 0. NOTE: the character counter will increase the View's height. */ @@ -388,6 +393,7 @@ private void init(Context context, AttributeSet attrs) { minCharacters = typedArray.getInt(R.styleable.MaterialEditText_met_minCharacters, 0); maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_met_maxCharacters, 0); dottedBottomLinesForDisabledState = typedArray.getBoolean(R.styleable.MaterialEditText_met_disabledBottomLineDotted, true); + floatingLabelColorFades = typedArray.getBoolean(R.styleable.MaterialEditText_met_enabledFloatLabelColorShouldFade, true); singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_met_singleLineEllipsis, false); helperText = typedArray.getString(R.styleable.MaterialEditText_met_helperText); helperTextColor = typedArray.getColor(R.styleable.MaterialEditText_met_helperTextColor, -1); @@ -1397,8 +1403,10 @@ protected void onDraw(@NonNull Canvas canvas) { int floatingLabelStartY = (int) (innerPaddingTop + floatingLabelTextSize + floatingLabelPadding - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction) + getScrollY()); // calculate the alpha - int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction * (isEnabled() ? 1 : 0) + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f))); - textPaint.setAlpha(alpha); + if (floatingLabelColorFades){ + int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction * (isEnabled() ? 1 : 0) + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f))); + textPaint.setAlpha(alpha); + } // draw the floating label canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint); diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 196e0b41..9f800014 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -19,6 +19,8 @@ + + From 7c9c86124344a5c4da498c2bc4fff67a4de2379a Mon Sep 17 00:00:00 2001 From: Ryan Orman Date: Fri, 11 Mar 2016 09:23:53 -0500 Subject: [PATCH 3/3] Revert "Attr that allows full control over the floating labels color" This reverts commit 6ed116fad753ec8500c6fe7d3e856ae081de62f1. --- .../materialedittext/MaterialEditText.java | 12 ++---------- library/src/main/res/values/attrs.xml | 2 -- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java b/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java index b085eff8..d4665444 100755 --- a/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java +++ b/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java @@ -153,11 +153,6 @@ public class MaterialEditText extends AppCompatEditText { */ private int disabledUnderlineColor; - /** - * The floating label's color fades. Defaults to true. If false, then the full floating label color is used. - */ - private boolean floatingLabelColorFades; - /** * min characters count limit. 0 means no limit. default is 0. NOTE: the character counter will increase the View's height. */ @@ -393,7 +388,6 @@ private void init(Context context, AttributeSet attrs) { minCharacters = typedArray.getInt(R.styleable.MaterialEditText_met_minCharacters, 0); maxCharacters = typedArray.getInt(R.styleable.MaterialEditText_met_maxCharacters, 0); dottedBottomLinesForDisabledState = typedArray.getBoolean(R.styleable.MaterialEditText_met_disabledBottomLineDotted, true); - floatingLabelColorFades = typedArray.getBoolean(R.styleable.MaterialEditText_met_enabledFloatLabelColorShouldFade, true); singleLineEllipsis = typedArray.getBoolean(R.styleable.MaterialEditText_met_singleLineEllipsis, false); helperText = typedArray.getString(R.styleable.MaterialEditText_met_helperText); helperTextColor = typedArray.getColor(R.styleable.MaterialEditText_met_helperTextColor, -1); @@ -1403,10 +1397,8 @@ protected void onDraw(@NonNull Canvas canvas) { int floatingLabelStartY = (int) (innerPaddingTop + floatingLabelTextSize + floatingLabelPadding - distance * (floatingLabelAlwaysShown ? 1 : floatingLabelFraction) + getScrollY()); // calculate the alpha - if (floatingLabelColorFades){ - int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction * (isEnabled() ? 1 : 0) + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f))); - textPaint.setAlpha(alpha); - } + int alpha = ((int) ((floatingLabelAlwaysShown ? 1 : floatingLabelFraction) * 0xff * (0.74f * focusFraction * (isEnabled() ? 1 : 0) + 0.26f) * (floatingLabelTextColor != -1 ? 1 : Color.alpha(floatingLabelTextColor) / 256f))); + textPaint.setAlpha(alpha); // draw the floating label canvas.drawText(floatingLabelText.toString(), floatingLabelStartX, floatingLabelStartY, textPaint); diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 9f800014..196e0b41 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -19,8 +19,6 @@ - -