Example usage for android.widget TextView getRight

List of usage examples for android.widget TextView getRight

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final int getRight() 

Source Link

Document

Right position of this view relative to its parent.

Usage

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];/* ww w .  ja va 2s .  com*/
        // 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:net.peterkuterna.android.apps.devoxxfrsched.ui.widget.ScrollableTabs.java

public void focusTab(int index) {
    final int tabCount = mHost.getChildCount();

    if (index < 0 || index > tabCount - 1) {
        return;//from ww w.ja va  2 s.co m
    }

    if (mCurrentTab != index) {
        final TextView tvOld = (TextView) mHost.getChildAt(mCurrentTab);
        if (tvOld != null) {
            tvOld.setSelected(false);
        }

        mCurrentTab = index;

        final TextView tvNew = (TextView) mHost.getChildAt(index);
        if (tvNew != null) {
            int right = tvNew.getRight();
            int left = tvNew.getLeft() + right;
            int width = getWidth();
            int i = (left - width) / 2;
            tvNew.setSelected(true);
            smoothScrollTo(i, 0);
        }
    }
}

From source file:za.jamie.soundstage.widgets.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;//from  w  w w .j av a2s. co  m
    }

    final int height = getHeight();

    // default: line below current tab
    TextView currentTab = (TextView) tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
        TextView nextTab = (TextView) tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);

        int currentTabColor = (Integer) tabTextColorEvaluator.evaluate(currentPositionOffset,
                tabSelectedTextColor, tabTextColor);
        currentTab.setTextColor(currentTabColor);

        int nextTabColor = (Integer) tabTextColorEvaluator.evaluate(currentPositionOffset, tabTextColor,
                tabSelectedTextColor);
        nextTab.setTextColor(nextTabColor);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, indicatorPaint);

    // draw underline
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, underlinePaint);

    // draw divider
    for (int i = 0; i < tabCount - 1; i++) {
        final int tabRight = tabsContainer.getChildAt(i).getRight();
        canvas.drawLine(tabRight, dividerPadding, tabRight, height - dividerPadding, dividerPaint);
    }
}

From source file:net.arvin.afbaselibrary.widgets.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;// www  . ja  v a2s. c  o m
    }

    final int height = getHeight();

    // draw underline
    if (clear) {
        rectPaint.setColor(Color.WHITE);
    } else {
        rectPaint.setColor(underlineColor);
    }

    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw indicator line
    if (clear) {
        rectPaint.setColor(Color.WHITE);
    } else {
        rectPaint.setColor(indicatorColor);
    }

    // default: line below current tab
    TextView currentTab = (TextView) tabsContainer.getChildAt(currentPosition);

    int textLength = currentTab.getText().length() * ScreenUtil.sp2px(tabTextSize);
    float lineLeft = (currentTab.getRight() - currentTab.getLeft() - textLength) / 2 + ScreenUtil.dp2px(4)
            + currentTab.getLeft();
    float lineRight = lineLeft + textLength - ScreenUtil.dp2px(4) * 2;

    if (tabAddWay == TabAddWay.ITEM_MATCH) {
        lineLeft = currentTab.getLeft();
        lineRight = currentTab.getRight();
    }

    // if there is an offset, start interpolating left and right coordinates
    // between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        float nextTabLeft = (nextTab.getRight() - nextTab.getLeft() - textLength) / 2 + ScreenUtil.dp2px(4)
                + nextTab.getLeft();
        float nextTabRight = nextTabLeft + textLength - ScreenUtil.dp2px(4) * 2;

        if (tabAddWay == TabAddWay.ITEM_MATCH) {
            nextTabLeft = nextTab.getLeft();
            nextTabRight = nextTab.getRight();
        }

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw divider

    if (clear) {
        dividerPaint.setColor(Color.WHITE);
    } else {
        dividerPaint.setColor(dividerColor);
    }
    if (isDrawDivider) {
        for (int i = 0; i < tabCount - 1; i++) {
            View tab = tabsContainer.getChildAt(i);
            canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding,
                    dividerPaint);
        }
    }
}

From source file:com.csdn.pagerslidingtabstrip.view.PagerSlidingTabStrip.java

private void choose(int fromPosition, int toPosition) {
    TextView lastTab = (TextView) tabsContainer.getChildAt(fromPosition);
    lastTab.setTextColor(tabTextColor);/*w  w w  .  j a  va 2s. co  m*/

    TextView currentTab = (TextView) tabsContainer.getChildAt(toPosition);
    currentTab.setTextColor(selectedTabTextColor);

    currentPosition = toPosition;

    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    detalLeft = lineLeft - lastTab.getLeft();
    detalRight = lineRight - lastTab.getRight();

    final float minDetal = (lineRight - lineLeft) / 2;
    this.post(new Runnable() {
        @Override
        public void run() {

            if (Math.abs(detalLeft) > minDetal || Math.abs(detalRight) > minDetal) {

                if (Math.abs(detalLeft) > minDetal) {
                    detalLeft = detalLeft / minDetal;
                }

                if (Math.abs(detalRight) > minDetal) {
                    detalRight = detalRight / minDetal;
                }
                invalidate();
                PagerSlidingTabStrip.this.post(this);
            } else {
                invalidate();
            }
        }
    });
}

From source file:com.android.tv.menu.MenuLayoutManager.java

private void setTempTitleView(TextView dest, TextView src) {
    dest.setVisibility(View.VISIBLE);
    dest.setText(src.getText());/*from   ww w .  ja v  a 2  s .com*/
    dest.setTranslationY(0.0f);
    if (src.getVisibility() == View.VISIBLE) {
        dest.setAlpha(src.getAlpha());
        dest.setScaleX(src.getScaleX());
        dest.setScaleY(src.getScaleY());
    } else {
        dest.setAlpha(0.0f);
        dest.setScaleX(1.0f);
        dest.setScaleY(1.0f);
    }
    View parent = (View) src.getParent();
    dest.setLeft(src.getLeft() + parent.getLeft());
    dest.setRight(src.getRight() + parent.getLeft());
    dest.setTop(src.getTop() + parent.getTop());
    dest.setBottom(src.getBottom() + parent.getTop());
}

From source file:com.benefit.buy.library.viewpagerindicator.PagerSlidingTabStrip.java

@SuppressLint("NewApi")
@Override/*from  www  . j  a  v a 2s .  c  o m*/
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode() || (tabCount == 0)) {
        return;
    }
    final int height = getHeight();
    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
    // draw indicator line
    rectPaint.setColor(indicatorColor);
    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();
    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if ((currentPositionOffset > 0f) && (currentPosition < (tabCount - 1))) {
        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();
        lineLeft = ((currentPositionOffset * nextTabLeft) + ((1f - currentPositionOffset) * lineLeft));
        lineRight = ((currentPositionOffset * nextTabRight) + ((1f - currentPositionOffset) * lineRight));
    }
    if (currentTab.findViewById(R.id.img_click) != null) {
        int counts = tabsContainer.getChildCount();
        View vNow = currentTab.findViewById(R.id.tab_name);
        ImageView imgNowOn = (ImageView) currentTab.findViewById(R.id.img_click);
        View tabViewNext;
        View vNext;
        ImageView imgNextOn;
        if ((currentPosition + 1) == counts) {
            tabViewNext = tabsContainer.getChildAt(0);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        } else {
            tabViewNext = tabsContainer.getChildAt(currentPosition + 1);
            vNext = tabViewNext.findViewById(R.id.tab_name);
            imgNextOn = (ImageView) tabViewNext.findViewById(R.id.img_click);
        }
        int colorTo = ToolColor.getChangeColor(80, 84, 98, 255, 0, 0, currentPositionOffset);
        int colorRe = ToolColor.getChangeColor(255, 0, 0, 80, 84, 98, currentPositionOffset);
        TextView tab = (TextView) vNext;
        TextView tab2 = (TextView) vNow;
        tab.setTextColor(colorTo);
        tab2.setTextColor(colorRe);
        if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
            imgNextOn.setAlpha(currentPositionOffset);
            imgNowOn.setAlpha(1 - currentPositionOffset);
        }
    } else {
    }
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
    //         draw divider
    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < (tabCount - 1); i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.zhongsou.souyue.ui.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;//from ww w. j a  va 2  s .com
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);
        if (i == currentPosition) {
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                tab.setTextColor(textColor);
            }
        } else {
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTextColor(tabTextColor);
            }
        }
    }

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}