Example usage for android.view Gravity VERTICAL_GRAVITY_MASK

List of usage examples for android.view Gravity VERTICAL_GRAVITY_MASK

Introduction

In this page you can find the example usage for android.view Gravity VERTICAL_GRAVITY_MASK.

Prototype

int VERTICAL_GRAVITY_MASK

To view the source code for android.view Gravity VERTICAL_GRAVITY_MASK.

Click Source Link

Document

Binary mask to get the vertical gravity of a gravity.

Usage

From source file:com.boha.malengagolf.library.util.PagerTitleStrip22.java

void updateTextPositions(int position, float positionOffset, boolean force) {
    if (position != mLastKnownCurrentPage) {
        updateText(position, mPager.getAdapter());
    } else if (!force && positionOffset == mLastKnownPositionOffset) {
        return;//w w  w  . jav a2 s  .  co m
    }

    mUpdatingPositions = true;

    final int prevWidth = mPrevText.getMeasuredWidth();
    final int currWidth = mCurrText.getMeasuredWidth();
    final int nextWidth = mNextText.getMeasuredWidth();
    final int halfCurrWidth = currWidth / 2;

    final int stripWidth = getWidth();
    final int stripHeight = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();
    final int textPaddedLeft = paddingLeft + halfCurrWidth;
    final int textPaddedRight = paddingRight + halfCurrWidth;
    final int contentWidth = stripWidth - textPaddedLeft - textPaddedRight;

    float currOffset = positionOffset + 0.5f;
    if (currOffset > 1.f) {
        currOffset -= 1.f;
    }
    final int currCenter = stripWidth - textPaddedRight - (int) (contentWidth * currOffset);
    final int currLeft = currCenter - currWidth / 2;
    final int currRight = currLeft + currWidth;

    final int prevBaseline = mPrevText.getBaseline();
    final int currBaseline = mCurrText.getBaseline();
    final int nextBaseline = mNextText.getBaseline();
    final int maxBaseline = Math.max(Math.max(prevBaseline, currBaseline), nextBaseline);
    final int prevTopOffset = maxBaseline - prevBaseline;
    final int currTopOffset = maxBaseline - currBaseline;
    final int nextTopOffset = maxBaseline - nextBaseline;
    final int alignedPrevHeight = prevTopOffset + mPrevText.getMeasuredHeight();
    final int alignedCurrHeight = currTopOffset + mCurrText.getMeasuredHeight();
    final int alignedNextHeight = nextTopOffset + mNextText.getMeasuredHeight();
    final int maxTextHeight = Math.max(Math.max(alignedPrevHeight, alignedCurrHeight), alignedNextHeight);

    final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int prevTop;
    int currTop;
    int nextTop;
    switch (vgrav) {
    default:
    case Gravity.TOP:
        prevTop = paddingTop + prevTopOffset;
        currTop = paddingTop + currTopOffset;
        nextTop = paddingTop + nextTopOffset;
        break;
    case Gravity.CENTER_VERTICAL:
        final int paddedHeight = stripHeight - paddingTop - paddingBottom;
        final int centeredTop = (paddedHeight - maxTextHeight) / 2;
        prevTop = centeredTop + prevTopOffset;
        currTop = centeredTop + currTopOffset;
        nextTop = centeredTop + nextTopOffset;
        break;
    case Gravity.BOTTOM:
        final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
        prevTop = bottomGravTop + prevTopOffset;
        currTop = bottomGravTop + currTopOffset;
        nextTop = bottomGravTop + nextTopOffset;
        break;
    }

    mCurrText.layout(currLeft, currTop, currRight, currTop + mCurrText.getMeasuredHeight());

    final int prevLeft = Math.min(paddingLeft, currLeft - mScaledTextSpacing - prevWidth);
    mPrevText.layout(prevLeft, prevTop, prevLeft + prevWidth, prevTop + mPrevText.getMeasuredHeight());

    final int nextLeft = Math.max(stripWidth - paddingRight - nextWidth, currRight + mScaledTextSpacing);
    mNextText.layout(nextLeft, nextTop, nextLeft + nextWidth, nextTop + mNextText.getMeasuredHeight());

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
}

From source file:android.support.design.widget.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;

    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);
    float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom;
        break;//from w  w w  . j  av  a 2s  .  c  o  m
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset;
        break;
    }
    switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }

    calculateUsingTextSize(mExpandedTextSize);
    width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom;
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
        break;
    }
    switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;
    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);
    float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom;
        break;//w w w.  j  a v a 2  s . com
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset;
        break;
    }
    switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }
    calculateUsingTextSize(mExpandedTextSize);
    width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom;
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
        break;
    }
    switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }
    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

From source file:com.aries.ui.view.title.util.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;

    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);
    float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom - mTextPaint.descent();
        break;/*w  ww  .j a va  2 s.  co m*/
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset;
        break;
    }
    switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }

    calculateUsingTextSize(mExpandedTextSize);
    width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom - mTextPaint.descent();
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
        break;
    }
    switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

From source file:org.telegram.ui.Components.Switch.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    wasLayout = true;/*www .ja v  a 2s.  c o m*/
    int opticalInsetLeft = 0;
    int opticalInsetRight = 0;
    if (mThumbDrawable != null) {
        final Rect trackPadding = mTempRect;
        if (mTrackDrawable != null) {
            mTrackDrawable.getPadding(trackPadding);
        } else {
            trackPadding.setEmpty();
        }

        final Insets insets = Insets.NONE;
        opticalInsetLeft = Math.max(0, insets.left - trackPadding.left);
        opticalInsetRight = Math.max(0, insets.right - trackPadding.right);
    }

    final int switchRight;
    final int switchLeft;
    if (LocaleController.isRTL) {
        switchLeft = getPaddingLeft() + opticalInsetLeft;
        switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight;
    } else {
        switchRight = getWidth() - getPaddingRight() - opticalInsetRight;
        switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight;
    }

    final int switchTop;
    final int switchBottom;
    switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
    default:
    case Gravity.TOP:
        switchTop = getPaddingTop();
        switchBottom = switchTop + mSwitchHeight;
        break;

    case Gravity.CENTER_VERTICAL:
        switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2;
        switchBottom = switchTop + mSwitchHeight;
        break;

    case Gravity.BOTTOM:
        switchBottom = getHeight() - getPaddingBottom();
        switchTop = switchBottom - mSwitchHeight;
        break;
    }

    mSwitchLeft = switchLeft;
    mSwitchTop = switchTop;
    mSwitchBottom = switchBottom;
    mSwitchRight = switchRight;
}

From source file:com.jakewharton.behavior.drawer.BehaviorDelegate.java

boolean onLayoutChild() {
    int width = parent.getMeasuredWidth();
    int height = parent.getMeasuredHeight();
    int childWidth = child.getMeasuredWidth();
    int childHeight = child.getMeasuredHeight();

    int childLeft;
    float newOffset;
    if (isLeft) {
        childLeft = -childWidth + (int) (childWidth * onScreen);
        newOffset = (float) (childWidth + childLeft) / childWidth;
    } else {//from   w  ww  . j  a  v a  2s  .  c om
        childLeft = width - (int) (childWidth * onScreen);
        newOffset = (float) (width - childLeft) / childWidth;
    }

    boolean changeOffset = newOffset != onScreen;

    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

    switch (vgrav) {
    default:
    case Gravity.TOP: {
        child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight);
        break;
    }

    case Gravity.BOTTOM: {
        child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth,
                height - lp.bottomMargin);
        break;
    }

    case Gravity.CENTER_VERTICAL: {
        int childTop = (height - childHeight) / 2;

        // Offset for margins. If things don't fit right because of
        // bad measurement before, oh well.
        if (childTop < lp.topMargin) {
            childTop = lp.topMargin;
        } else if (childTop + childHeight > height - lp.bottomMargin) {
            childTop = height - lp.bottomMargin - childHeight;
        }
        child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
        break;
    }
    }

    if (changeOffset) {
        setDrawerViewOffset(newOffset);
    }

    int newVisibility = onScreen > 0 ? VISIBLE : INVISIBLE;
    if (child.getVisibility() != newVisibility) {
        child.setVisibility(newVisibility);
    }
    return true;
}

From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;
    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);

    // BEGIN MODIFICATION: set mTextToDrawCollapsed and calculate width using it
    mTextToDrawCollapsed = mTextToDraw;//w  ww .  j a  v  a  2  s  .c  o  m
    float width = mTextToDrawCollapsed != null
            ? mTextPaint.measureText(mTextToDrawCollapsed, 0, mTextToDrawCollapsed.length())
            : 0;
    // END MODIFICATION

    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);

    // BEGIN MODIFICATION: calculate height and Y position using mTextLayout
    float textHeight = mTextLayout != null ? mTextLayout.getHeight() : 0;

    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom - textHeight;
        break;
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top;
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textOffset = (textHeight / 2);
        mCollapsedDrawY = mCollapsedBounds.centerY() - textOffset;
        break;
    }
    // END MODIFICATION

    switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }

    calculateUsingTextSize(mExpandedTextSize);

    // BEGIN MODIFICATION: calculate width using mTextLayout based on first line and store that padding
    width = mTextLayout != null ? mTextLayout.getLineWidth(0) : 0;
    mExpandedFirstLineDrawX = mTextLayout != null ? mTextLayout.getLineLeft(0) : 0;
    // END MODIFICATION

    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);

    // BEGIN MODIFICATION: calculate height and Y position using mTextLayout
    textHeight = mTextLayout != null ? mTextLayout.getHeight() : 0;
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom - textHeight;
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top;
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textOffset = (textHeight / 2);
        mExpandedDrawY = mExpandedBounds.centerY() - textOffset;
        break;
    }
    // END MODIFICATION

    switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

From source file:android.support.design.widget.TextInputLayout.java

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }//from  w w  w  .j  a  va  2  s.co  m

    if (!(editText instanceof TextInputEditText)) {
        Log.i(LOG_TAG,
                "EditText added is not a TextInputEditText. Please switch to using that" + " class instead.");
    }

    mEditText = editText;

    final boolean hasPasswordTransformation = hasPasswordTransformation();

    // Use the EditText's typeface, and it's text size for our expanded text
    if (!hasPasswordTransformation) {
        // We don't want a monospace font just because we have a password field
        mCollapsingTextHelper.setTypefaces(mEditText.getTypeface());
    }
    mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize());

    final int editTextGravity = mEditText.getGravity();
    mCollapsingTextHelper
            .setCollapsedTextGravity(Gravity.TOP | (editTextGravity & ~Gravity.VERTICAL_GRAVITY_MASK));
    mCollapsingTextHelper.setExpandedTextGravity(editTextGravity);

    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            updateLabelState(!mRestoringSavedState);
            if (mCounterEnabled) {
                updateCounter(s.length());
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    // Use the EditText's hint colors if we don't have one set
    if (mDefaultTextColor == null) {
        mDefaultTextColor = mEditText.getHintTextColors();
    }

    // If we do not have a valid hint, try and retrieve it from the EditText, if enabled
    if (mHintEnabled && TextUtils.isEmpty(mHint)) {
        setHint(mEditText.getHint());
        // Clear the EditText's hint as we will display it ourselves
        mEditText.setHint(null);
    }

    if (mCounterView != null) {
        updateCounter(mEditText.getText().length());
    }

    if (mIndicatorArea != null) {
        adjustIndicatorPadding();
    }

    updatePasswordToggleView();

    // Update the label visibility with no animation, but force a state change
    updateLabelState(false, true);
}

From source file:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }// ww  w .ja v a  2 s  . com

    if (!(editText instanceof TextInputEditText)) {
        Log.i(LOG_TAG,
                "EditText added is not a TextInputEditText. Please switch to using that" + " class instead.");
    }

    mEditText = editText;

    final boolean hasPasswordTransformation = hasPasswordTransformation();

    // Use the EditText's typeface, and it's text size for our expanded text
    if (!hasPasswordTransformation) {
        // We don't want a monospace font just because we have a password field
        mCollapsingTextHelper.setTypefaces(mEditText.getTypeface());
    }
    mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize());

    final int editTextGravity = mEditText.getGravity();
    mCollapsingTextHelper
            .setCollapsedTextGravity(Gravity.TOP | (editTextGravity & ~Gravity.VERTICAL_GRAVITY_MASK));
    mCollapsingTextHelper.setExpandedTextGravity(editTextGravity);

    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            updateLabelState(!mRestoringSavedState);
            if (mCounterEnabled) {
                updateCounter(s.length());
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    // Use the EditText's hint colors if we don't have one set
    if (mDefaultTextColor == null) {
        mDefaultTextColor = mEditText.getHintTextColors();
    }

    // If we do not have a valid hint, try and retrieve it from the EditText, if enabled
    if (mHintEnabled && TextUtils.isEmpty(mHint)) {
        // Save the hint so it can be restored on dispatchProvideAutofillStructure();
        mOriginalHint = mEditText.getHint();
        setHint(mOriginalHint);
        // Clear the EditText's hint as we will display it ourselves
        mEditText.setHint(null);
    }

    if (mCounterView != null) {
        updateCounter(mEditText.getText().length());
    }

    if (mIndicatorArea != null) {
        adjustIndicatorPadding();
    }

    updatePasswordToggleView();

    // Update the label visibility with no animation, but force a state change
    updateLabelState(false, true);
}

From source file:com.scoreflex.ScoreflexView.java

public void startOpeningAnimation() {
    int gravity = getLayoutGravity();
    int anim = (Gravity.TOP == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? R.anim.scoreflex_enter_slide_down
            : R.anim.scoreflex_enter_slide_up;
    Animation animation = AnimationUtils.loadAnimation(mParentActivity, anim);
    this.startAnimation(animation);
}