am 54933dc7: am 871f7ae0: am 5a27940c: am 1cb0698d: Merge "Improvements to TextInputLayout" into lmp-mr1-ub-dev

* commit '54933dc742b11f6c2623ea12369719195e6c1bdb':
  Improvements to TextInputLayout

GitOrigin-RevId=2b5f7a8388a2c2de80b33fefd67fae98457efb64

PiperOrigin-RevId: 140548846
This commit is contained in:
Chris Banes 2016-11-30 01:20:02 +00:00 committed by Travis Collins
parent dd5bf43dc6
commit db024f09c5
3 changed files with 24 additions and 14 deletions

View File

@ -137,12 +137,10 @@ final class CollapsingTextHelper {
void setExpandedBounds(int left, int top, int right, int bottom) {
mExpandedBounds.set(left, top, right, bottom);
recalculate();
}
void setCollapsedBounds(int left, int top, int right, int bottom) {
mCollapsedBounds.set(left, top, right, bottom);
recalculate();
}
void setExpandedTextVerticalGravity(int gravity) {
@ -440,8 +438,8 @@ final class CollapsingTextHelper {
}
}
private void recalculate() {
if (ViewCompat.isLaidOut(mView)) {
public void recalculate() {
if (mView.getHeight() > 0 && mView.getWidth() > 0) {
// If we've already been laid out, calculate everything now otherwise we'll wait
// until a layout
calculateBaselines();
@ -474,10 +472,6 @@ final class CollapsingTextHelper {
}
}
public void onLayout(boolean changed, int left, int top, int right, int bottom) {
recalculate();
}
/**
* Returns true if {@code value} is 'close' to it's closest decimal value. Close is currently
* defined as it's difference being < 0.001.

View File

@ -332,9 +332,6 @@ public class CollapsingToolbarLayout extends FrameLayout {
getViewOffsetHelper(child).onViewLayout();
}
// Now let the collapsing text helper update itself
mCollapsingTextHelper.onLayout(changed, left, top, right, bottom);
ensureToolbar();
// Update the collapsed bounds by getting it's transformed bounds
@ -346,6 +343,8 @@ public class CollapsingToolbarLayout extends FrameLayout {
mCollapsingTextHelper.setExpandedBounds(left + mExpandedMarginLeft,
mTmpRect.bottom + mExpandedMarginTop, right - mExpandedMarginRight,
bottom - mExpandedMarginBottom);
mCollapsingTextHelper.recalculate();
}
// Finally, set our minimum height to enable proper AppBarLayout collapsing

View File

@ -50,6 +50,24 @@ import android.widget.TextView;
*
* Also supports showing an error via {@link #setErrorEnabled(boolean)} and
* {@link #setError(CharSequence)}.
*
* <p>Please note: this class sets a {@link android.view.View.OnFocusChangeListener} on the wrapped
* {@link EditText}. If you need to set your own listener, then you should wrap the existing one
* and forward the call like so:
* <pre>
* TextInputLayout inputLayout = ...;
* EditText editText = inputLayout.getEditText();
* final OnFocusChangeListener existing = editText.getOnFocusChangeListener();
*
* editText.setOnFocusChangeListener(new OnFocusChangeListener() {
* public void onFocusChange(View view, boolean focused) {
* existing.onFocusChange(view, focused);
*
* // Your custom logic
* }
* });
* </pre>
* </p>
*/
public class TextInputLayout extends LinearLayout {
@ -335,8 +353,6 @@ public class TextInputLayout extends LinearLayout {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
mCollapsingTextHelper.onLayout(changed, left, top, right, bottom);
if (mEditText != null) {
final int l = mEditText.getLeft() + mEditText.getCompoundPaddingLeft();
final int r = mEditText.getRight() - mEditText.getCompoundPaddingRight();
@ -349,6 +365,8 @@ public class TextInputLayout extends LinearLayout {
// EditText's editable area
mCollapsingTextHelper.setCollapsedBounds(l, getPaddingTop(),
r, bottom - top - getPaddingBottom());
mCollapsingTextHelper.recalculate();
}
}
@ -382,7 +400,6 @@ public class TextInputLayout extends LinearLayout {
} else if (mAnimator.isRunning()) {
mAnimator.cancel();
}
mAnimator.setFloatValues(mCollapsingTextHelper.getExpansionFraction(), target);
mAnimator.start();
}