Example usage for android.widget TextView getCompoundPaddingRight

List of usage examples for android.widget TextView getCompoundPaddingRight

Introduction

In this page you can find the example usage for android.widget TextView getCompoundPaddingRight.

Prototype

public int getCompoundPaddingRight() 

Source Link

Document

Returns the right padding of the view, plus space for the right Drawable if any.

Usage

From source file:Main.java

public static int getTextWidth(TextView textView) {
    return textView.getMeasuredWidth() - textView.getCompoundPaddingLeft() - textView.getCompoundPaddingRight();
}

From source file:Main.java

public static boolean drawDrawables(Canvas canvas, @Nonnull TextView textView) {
    final int compoundPaddingLeft = textView.getCompoundPaddingLeft();
    final int compoundPaddingTop = textView.getCompoundPaddingTop();
    final int compoundPaddingRight = textView.getCompoundPaddingRight();
    final int compoundPaddingBottom = textView.getCompoundPaddingBottom();

    final int scrollX = textView.getScrollX();
    final int scrollY = textView.getScrollY();

    final int right = textView.getRight();
    final int left = textView.getLeft();
    final int bottom = textView.getBottom();
    final int top = textView.getTop();

    final Drawable[] drawables = textView.getCompoundDrawables();
    if (drawables != null) {

        int vspace = bottom - top - compoundPaddingBottom - compoundPaddingTop;
        int hspace = right - left - compoundPaddingRight - compoundPaddingLeft;

        Drawable topDr = drawables[1];// www  .  j a v a2s  .  c  o m
        // IMPORTANT: The coordinates computed are also used in invalidateDrawable()
        // Make sure to update invalidateDrawable() when changing this code.
        if (topDr != null) {
            canvas.save();
            canvas.translate(scrollX + compoundPaddingLeft + (hspace - topDr.getBounds().width()) / 2,
                    scrollY + textView.getPaddingTop() + vspace / 2);
            topDr.draw(canvas);
            canvas.restore();
            return true;
        }
    }

    return false;
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle,
        final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews,
        final ArrayList<TextView> debugInfoViews) {
    mWordViews = wordViews;//from   w  w  w .j  ava2s .c  om
    mDividerViews = dividerViews;
    mDebugInfoViews = debugInfoViews;

    final TextView wordView = wordViews.get(0);
    final View dividerView = dividerViews.get(0);
    mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight();
    dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mDividerWidth = dividerView.getMeasuredWidth();

    final Resources res = wordView.getResources();
    mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle,
            R.style.SuggestionStripView);
    mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
    mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
    mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
    mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
    mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
    mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
    mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip,
            DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
    mCenterSuggestionWeight = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE);
    mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
            DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
    mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
    a.recycle();

    mMoreSuggestionsHint = getMoreSuggestionsHint(res,
            res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect);
    mCenterPositionInStrip = mSuggestionsCountInStrip / 2;
    // Assuming there are at least three suggestions. Also, note that the suggestions are
    // laid out according to script direction, so this is left of the center for LTR scripts
    // and right of the center for RTL scripts.
    mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1;
    mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap);
    mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height);
}

From source file:com.udmurtlyk.extrainputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle,
        final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews,
        final ArrayList<TextView> debugInfoViews) {
    mWordViews = wordViews;/*ww  w  .  j av a  2 s  . c om*/
    mDividerViews = dividerViews;
    mDebugInfoViews = debugInfoViews;

    final TextView wordView = wordViews.get(0);
    final View dividerView = dividerViews.get(0);
    mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight();
    dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mDividerWidth = dividerView.getMeasuredWidth();

    final Resources res = wordView.getResources();
    mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle,
            R.style.SuggestionStripView);
    mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
    mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
    mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
    mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
    mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
    mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
    mColorShortcut = a.getColor(R.styleable.SuggestionStripView_colorShortcut, 0);
    mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip,
            DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
    mCenterSuggestionWeight = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE);
    mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
            DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
    mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
    a.recycle();

    mMoreSuggestionsHint = getMoreSuggestionsHint(res,
            res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect);
    mCenterPositionInStrip = mSuggestionsCountInStrip / 2;
    // Assuming there are at least three suggestions. Also, note that the suggestions are
    // laid out according to script direction, so this is left of the center for LTR scripts
    // and right of the center for RTL scripts.
    mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1;
    mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap);
    mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height);
}

From source file:com.mobiletin.inputmethod.indic.suggestions.SuggestionStripLayoutHelper.java

public SuggestionStripLayoutHelper(final Context context, final AttributeSet attrs, final int defStyle,
        final ArrayList<TextView> wordViews, final ArrayList<View> dividerViews,
        final ArrayList<TextView> debugInfoViews) {

    mWordViews = wordViews;/*from   w  w  w .  j a  va2  s.  co  m*/
    mDividerViews = dividerViews;
    mDebugInfoViews = debugInfoViews;
    final TextView wordView = wordViews.get(0);
    final View dividerView = dividerViews.get(0);
    mPadding = wordView.getCompoundPaddingLeft() + wordView.getCompoundPaddingRight();
    dividerView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mDividerWidth = dividerView.getMeasuredWidth();

    final Resources res = wordView.getResources();
    mSuggestionsStripHeight = res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuggestionStripView, defStyle,
            R.style.SuggestionStripView);
    mSuggestionStripOptions = a.getInt(R.styleable.SuggestionStripView_suggestionStripOptions, 0);
    mAlphaObsoleted = ResourceUtils.getFraction(a, R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
    mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
    mColorTypedWord = a.getColor(R.styleable.SuggestionStripView_colorTypedWord, 0);
    mColorAutoCorrect = a.getColor(R.styleable.SuggestionStripView_colorAutoCorrect, 0);
    mColorSuggested = a.getColor(R.styleable.SuggestionStripView_colorSuggested, 0);
    mSuggestionsCountInStrip = a.getInt(R.styleable.SuggestionStripView_suggestionsCountInStrip,
            DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
    mCenterSuggestionWeight = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_centerSuggestionPercentile, DEFAULT_CENTER_SUGGESTION_PERCENTILE);
    mMaxMoreSuggestionsRow = a.getInt(R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
            DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
    mMinMoreSuggestionsWidth = ResourceUtils.getFraction(a,
            R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
    a.recycle();

    mMoreSuggestionsHint = getMoreSuggestionsHint(res,
            res.getDimension(R.dimen.config_more_suggestions_hint_text_size), mColorAutoCorrect);
    mCenterPositionInStrip = mSuggestionsCountInStrip / 2;
    // Assuming there are at least three suggestions. Also, note that the suggestions are
    // laid out according to script direction, so this is left of the center for LTR scripts
    // and right of the center for RTL scripts.
    mTypedWordPositionWhenAutocorrect = mCenterPositionInStrip - 1;
    mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(R.dimen.config_more_suggestions_bottom_gap);
    mMoreSuggestionsRowHeight = res.getDimensionPixelSize(R.dimen.config_more_suggestions_row_height);
}