From 6d12b2df86f3e9034772aaa22a43a60410418caa Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 30 Nov 2016 01:24:50 +0000 Subject: [PATCH] am 17c194e2: am 07f75828: am 45049689: am f72ee1a4: am 1bb61e03: am eb344aa3: Merge "TextInputLayout fixes" into lmp-mr1-ub-dev * commit '17c194e278b4468cdd715f1969685711e39a6d50': TextInputLayout fixes GitOrigin-RevId=b56067e8de4c981094c776cd3b395e3bb2091dd5 PiperOrigin-RevId: 140549343 --- api/current.txt | 2 ++ res/values/attrs.xml | 2 ++ .../design/widget/TextInputLayout.java | 33 +++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/api/current.txt b/api/current.txt index 654851c72..8be8c266d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -361,9 +361,11 @@ package android.support.design.widget { method public java.lang.CharSequence getError(); method public java.lang.CharSequence getHint(); method public boolean isErrorEnabled(); + method public boolean isHintAnimationEnabled(); method public void setError(java.lang.CharSequence); method public void setErrorEnabled(boolean); method public void setHint(java.lang.CharSequence); + method public void setHintAnimationEnabled(boolean); method public void setHintTextAppearance(int); method public void setTypeface(android.graphics.Typeface); } diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 9ad1f0a2d..437ec53d3 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -162,6 +162,8 @@ + + diff --git a/src/android/support/design/widget/TextInputLayout.java b/src/android/support/design/widget/TextInputLayout.java index 8981bea3e..6d45bdf11 100644 --- a/src/android/support/design/widget/TextInputLayout.java +++ b/src/android/support/design/widget/TextInputLayout.java @@ -69,6 +69,7 @@ public class TextInputLayout extends LinearLayout { private final CollapsingTextHelper mCollapsingTextHelper = new CollapsingTextHelper(this); + private boolean mHintAnimationEnabled; private ValueAnimatorCompat mAnimator; public TextInputLayout(Context context) { @@ -94,6 +95,8 @@ public class TextInputLayout extends LinearLayout { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr, R.style.Widget_Design_TextInputLayout); mHint = a.getText(R.styleable.TextInputLayout_android_hint); + mHintAnimationEnabled = a.getBoolean( + R.styleable.TextInputLayout_hintAnimationEnabled, true); if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) { mDefaultTextColor = mFocusedTextColor = @@ -153,6 +156,7 @@ public class TextInputLayout extends LinearLayout { // Use the EditText's typeface, and it's text size for our expanded text mCollapsingTextHelper.setTypeface(mEditText.getTypeface()); mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize()); + mCollapsingTextHelper.setExpandedTextGravity(mEditText.getGravity()); // Add a TextWatcher so that we know when the text input has changed mEditText.addTextChangedListener(new TextWatcher() { @@ -374,6 +378,7 @@ public class TextInputLayout extends LinearLayout { * * @see #setError(CharSequence) */ + @Nullable public CharSequence getError() { if (mErrorEnabled && mErrorView != null && mErrorView.getVisibility() == VISIBLE) { return mErrorView.getText(); @@ -381,6 +386,30 @@ public class TextInputLayout extends LinearLayout { return null; } + /** + * Returns whether any hint state changes, due to being focused or non-empty text, are + * animated. + * + * @see #setHintAnimationEnabled(boolean) + * + * @attr ref android.support.design.R.styleable#TextInputLayout_hintAnimationEnabled + */ + public boolean isHintAnimationEnabled() { + return mHintAnimationEnabled; + } + + /** + * Set whether any hint state changes, due to being focused or non-empty text, are + * animated. + * + * @see #isHintAnimationEnabled() + * + * @attr ref android.support.design.R.styleable#TextInputLayout_hintAnimationEnabled + */ + public void setHintAnimationEnabled(boolean enabled) { + mHintAnimationEnabled = enabled; + } + @Override public void draw(Canvas canvas) { super.draw(canvas); @@ -419,7 +448,7 @@ public class TextInputLayout extends LinearLayout { if (mAnimator != null && mAnimator.isRunning()) { mAnimator.cancel(); } - if (animate) { + if (animate && mHintAnimationEnabled) { animateToExpansionFraction(1f); } else { mCollapsingTextHelper.setExpansionFraction(1f); @@ -430,7 +459,7 @@ public class TextInputLayout extends LinearLayout { if (mAnimator != null && mAnimator.isRunning()) { mAnimator.cancel(); } - if (animate) { + if (animate && mHintAnimationEnabled) { animateToExpansionFraction(0f); } else { mCollapsingTextHelper.setExpansionFraction(0f);