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
This commit is contained in:
Chris Banes 2016-11-30 01:24:50 +00:00 committed by Travis Collins
parent 89f63e4521
commit 6d12b2df86
3 changed files with 35 additions and 2 deletions

View File

@ -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);
}

View File

@ -162,6 +162,8 @@
<!-- TextAppearance of any error message displayed -->
<attr name="errorTextAppearance" format="reference"/>
<attr name="android:textColorHint"/>
<!-- Whether to animate hint state changes. -->
<attr name="hintAnimationEnabled" format="boolean"/>
</declare-styleable>
<declare-styleable name="SnackbarLayout">

View File

@ -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);