Example usage for android.widget TextView getMeasuredWidth

List of usage examples for android.widget TextView getMeasuredWidth

Introduction

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

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

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

private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView, final int x) {
    final TextView debugInfoView = mDebugInfoViews.get(positionInStrip);
    final CharSequence debugInfo = debugInfoView.getText();
    if (debugInfo == null) {
        return;/*from   w w w .  j  a v  a2s.  c o m*/
    }
    placerView.addView(debugInfoView);
    debugInfoView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int infoWidth = debugInfoView.getMeasuredWidth();
    final int y = debugInfoView.getMeasuredHeight();
    ViewLayoutUtils.placeViewAt(debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight());
}

From source file:net.naonedbus.card.impl.HoraireCard.java

private int getTextViewCount(final ViewGroup parent) {
    final TextView textView = (TextView) mLayoutInflater.inflate(R.layout.card_horaire_text, parent, false);
    final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00);
    final int padding = getContext().getResources().getDimensionPixelSize(R.dimen.padding_medium);
    textView.setText(FormatUtils.formatTimeAmPm(getContext(), mTimeFormat.format(noon.toDate())));

    final int specY = MeasureSpec.makeMeasureSpec(parent.getHeight(), MeasureSpec.UNSPECIFIED);
    final int specX = MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.UNSPECIFIED);
    textView.measure(specX, specY);//  w ww  .  j  av  a2 s .  c  om

    return (parent.getWidth() - padding) / textView.getMeasuredWidth();
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void correctCountWidth(final View v, final AdvancedOrderCategoryItemRow row) {
    mActivity.getMainService().postOnUIHandler(new SafeRunnable() {
        @Override/*from w w w.  j a va  2  s.  c  o  m*/
        protected void safeRun() throws Exception {
            TextView nameLbl = (TextView) v.findViewById(R.id.name);
            if (!row.name.equals(nameLbl.getText())) {
                return;
            }
            TextView countLbl = (TextView) v.findViewById(R.id.count);
            countLbl.measure(0, 0);
            int countWidth = countLbl.getMeasuredWidth();
            if (countWidth > 140) {
                ViewGroup.LayoutParams lpCount = countLbl.getLayoutParams();
                lpCount.width = 140;
                countLbl.setLayoutParams(lpCount);
                countLbl.requestLayout();
            }
        }
    });
}

From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int getHorairesCount(final Context context, final Bundle bundle) {

    synchronized (sLock) {
        if (sHoraireTextWidth == Integer.MIN_VALUE) {
            final TextView horaireTextView = new TextView(context);
            horaireTextView.setTextAppearance(horaireTextView.getContext(),
                    android.R.style.TextAppearance_Medium);

            final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00);
            final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
            horaireTextView.setText(/*from   w  w  w.  j a  v a 2  s. co m*/
                    FormatUtils.formatTimeAmPm(context, timeFormat.format(noon.toDate())) + " \u2022  ");
            final int specY = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            final int specX = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            horaireTextView.measure(specX, specY);
            sHoraireTextWidth = horaireTextView.getMeasuredWidth();
        }
    }

    final Resources r = context.getResources();
    final int padding = r.getDimensionPixelSize(R.dimen.padding_small);

    final int minWidth = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
    final int minWidthPixel = Math.round(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidth, r.getDisplayMetrics())) - padding;

    return (minWidthPixel / sHoraireTextWidth);
}

From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java

public int captureBitmapCache(String in) {
    TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview);
    String tvText = tv.getText().toString();
    float tvTextSize = tv.getTextSize();
    int tvColor = tv.getCurrentTextColor();
    Bitmap bitmap = null;//from  w ww. j  av a  2s . co m

    tv.setTextSize(36);
    tv.setTextColor(Color.CYAN);
    tv.setTypeface(Typeface.SANS_SERIF);

    tv.setText(in);

    while (bitmap == null) {
        // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null
        tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

        tv.setDrawingCacheEnabled(true);
        tv.buildDrawingCache(true);
        bitmap = Bitmap.createBitmap(tv.getDrawingCache());
        tv.destroyDrawingCache();
        tv.setDrawingCacheEnabled(false);
    }

    FileOutputStream fos = null;
    int res = -1;
    try {
        fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME);
        if (fos != null) {
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
            fos.close();
            res = 0;
        }
    } catch (Throwable e) {
        Log.i(MyApp.TAG, e.getMessage().toString());
        res = -1;
    }

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize);
    tv.setTypeface(Typeface.MONOSPACE);
    tv.setText(tvText);
    tv.setTextColor(tvColor);
    return res;
}

From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.DayPickerView.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    final TextView leftButton;
    final TextView rightButton;
    if (SUtils.isLayoutRtlCompat(this)) {
        leftButton = mNextButton;// w ww  . j a v  a 2  s . co m
        rightButton = mPrevButton;
    } else {
        leftButton = mPrevButton;
        rightButton = mNextButton;
    }

    final int width = right - left;
    final int height = bottom - top;
    mViewPager.layout(0, 0, width, height);

    final SimpleMonthView monthView = (SimpleMonthView) mViewPager.getChildAt(0).findViewById(R.id.month_view);
    final int monthHeight = monthView.getMonthHeight();
    //        final int monthHeight = 0;
    final int cellWidth = monthView.getCellWidth();

    // Vertically center the previous/next buttons within the month
    // header, horizontally center within the day cell.
    final int leftDW = leftButton.getMeasuredWidth();
    final int leftDH = leftButton.getMeasuredHeight();
    final int leftIconTop = monthView.getPaddingTop() + (monthHeight - leftDH) / 2;
    final int leftIconLeft = monthView.getPaddingLeft() + (cellWidth - leftDW) / 2;
    leftButton.layout(leftIconLeft, leftIconTop, leftIconLeft + leftDW, leftIconTop + leftDH);

    final int rightDW = rightButton.getMeasuredWidth();
    final int tvResetDW = tvReset.getMeasuredWidth();
    final int rightDH = rightButton.getMeasuredHeight();
    final int tvResetDH = tvReset.getMeasuredHeight();
    final int rightIconTop = monthView.getPaddingTop() + (monthHeight - rightDH) / 2;
    final int tvResetIconTop = monthView.getPaddingTop() + (monthHeight - tvResetDH) / 2;
    final int rightIconRight1 = width - monthView.getPaddingRight() - (cellWidth - rightDW) / 2 - 60;
    final int rightIconRight = leftIconLeft + 180;

    rightButton.layout(rightIconRight, rightIconTop, rightIconRight + rightDW, rightIconTop + rightDH);

    tvReset.layout(rightIconRight1 - tvResetDW, tvResetIconTop, rightIconRight1, tvResetIconTop + tvResetDH);
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) {
    mActivity.getMainService().postOnUIHandler(new SafeRunnable() {
        @Override//from   ww w .  j  ava 2s  .  c  o m
        protected void safeRun() throws Exception {
            TextView nameLbl = (TextView) v.findViewById(R.id.name);
            if (!row.name.equals(nameLbl.getText())) {
                return;
            }
            LinearLayout txtContainer = (LinearLayout) v.findViewById(R.id.text_container);
            txtContainer.measure(0, 0);
            int currentWidth = txtContainer.getMeasuredWidth();
            int maxWidth = txtContainer.getWidth() - UIUtils.convertDipToPixels(mActivity, 35);

            nameLbl.measure(0, 0);
            int nameWidth = nameLbl.getMeasuredWidth();
            int priceWidth = 0;
            if (row.hasPrice) {
                TextView priceLbl = (TextView) v.findViewById(R.id.price);
                priceLbl.measure(0, 0);
                priceWidth = priceLbl.getMeasuredWidth();
                ViewGroup.LayoutParams lpPrice = priceLbl.getLayoutParams();
                lpPrice.width = priceWidth;
                priceLbl.setLayoutParams(lpPrice);
                priceLbl.requestLayout();
            }

            ViewGroup.LayoutParams lpName = nameLbl.getLayoutParams();
            if (maxWidth > 0 && currentWidth < maxWidth) {
                if (maxWidth - priceWidth > nameWidth) {
                    lpName.width = nameWidth;
                } else {
                    lpName.width = maxWidth - priceWidth;
                }
            } else {
                lpName.width = maxWidth - priceWidth;
            }

            nameLbl.setLayoutParams(lpName);
            nameLbl.requestLayout();
        }
    });
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

private int computeStableWidth(TextView v, int maxNumber) {
    int maxWidth = 0;

    for (int i = 0; i < maxNumber; i++) {
        final String text = String.format("%02d", i);
        v.setText(text);//from   w  w  w . j a v  a 2  s. c o m
        v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

        final int width = v.getMeasuredWidth();
        if (width > maxWidth) {
            maxWidth = width;
        }
    }

    return maxWidth;
}

From source file:lewa.support.v7.internal.widget.ScrollingTabContainerView.java

public void smoothScrollTabIndicator(int position, float positionOffset, int positionOffsetPixels) {
    int width = mIndicatorView.getMeasuredWidth();
    if ((mStateIndicator == SCROLL_STATE_DRAGGING) && positionOffset != 0) {
        if (mCurrentPosition == position) {
            TabView tabViewCurr = (TabView) mTabLayout.getChildAt(position);
            TextView textViewCurr = (TextView) tabViewCurr.getTextView();
            float widthCurr = (float) (textViewCurr.getMeasuredWidth() * INDICATOR_WIDTH_SCAL_MIN);
            TabView tabViewNext = (TabView) mTabLayout.getChildAt(position + 1);
            TextView textViewNext = (TextView) tabViewNext.getTextView();
            float widthNext = (float) (textViewNext.getMeasuredWidth() * INDICATOR_WIDTH_SCAL_MIN);

            if (positionOffset <= INDICATOR_POSITIONOFFSET) {
                mIndicatorView.setPivotX(0);
                mIndicatorView.setScaleX(1 + positionOffset * mRateDrag);
                mLastPositionOffset = positionOffset;
                mDurationTrans = (int) (mTabViewWidth + widthCurr / 2 + widthNext / 2 - mMaxIndicatorWidth);

                if (mIsTabAdjust) {
                    mIsTabAdjust = false;
                    textViewCurr.setTextColor(mActiveTextColor.getColor());
                    textViewNext.setTextColor(mInActiveTextColor.getColor());
                }/*from  w ww.  ja  v a 2s.co  m*/
            } else {
                mIndicatorView.setPivotX(width);
                mIndicatorView.setScaleX(widthNext / widthCurr + (mMaxIndicatorWidth - widthNext) / widthCurr
                        * (1 - (positionOffset - mLastPositionOffset) / (1 - mLastPositionOffset)));
                mIndicatorView.setTranslationX((mMaxIndicatorWidth - widthCurr)
                        + (positionOffset - mLastPositionOffset) / (1 - mLastPositionOffset) * mDurationTrans);

                if (!mIsTabAdjust) {
                    mIsTabAdjust = true;
                    textViewCurr.setTextColor(mInActiveTextColor.getColor());
                    textViewNext.setTextColor(mActiveTextColor.getColor());
                }
            }

            if (mHasSecondaryTabIndexs.contains(position) && !mHasSecondaryTabIndexs.contains(position + 1)) {
                int alpha = SECONDARY_INDICATOR_TRANSPARENCY
                        - (int) (positionOffset * THRESHOLD_INDICATOR_TRANSPARENCY);
                mIndicatorView.setAlpha(alpha);
            }
            if (!mHasSecondaryTabIndexs.contains(position) && mHasSecondaryTabIndexs.contains(position + 1)) {
                int alpha = NORMAL_INDICATOR_TRANSPARENCY
                        + (int) (positionOffset * THRESHOLD_INDICATOR_TRANSPARENCY);
                mIndicatorView.setAlpha(alpha);
            }

            /*
            float size1 = map(positionOffset, 1f, 0f, mInActiveTextSize, mActiveTextSize);
            float size2 = map(positionOffset, 1f, 0f, mActiveTextSize, mInActiveTextSize);
            textViewCurr.setTextSize(size1);
            textViewNext.setTextSize(size2);
            */
            //int alpha1 = (int)map(positionOffset, 1f, 0f, (float)mInActiveTextColor.alpha, (float)mActiveTextColor.alpha);
            //int alpha2 = (int)map(positionOffset, 1f, 0f, (float)mActiveTextColor.alpha, (float)mInActiveTextColor.alpha);
            /*            int alpha1 = mActiveTextColor.alpha - (int)(mThresHoldAlpha * positionOffset);
                        int alpha2 = mInActiveTextColor.alpha + (int)(mThresHoldAlpha * positionOffset);
                        textViewCurr.setTextColor(mActiveTextColor.getColor(alpha1));
                        textViewNext.setTextColor(mInActiveTextColor.getColor(alpha2));
                    
                        textViewCurr.setScaleX((mActiveTextSize - mThresHoldSize * positionOffset) / mActiveTextSize);
                        textViewCurr.setScaleY((mActiveTextSize - mThresHoldSize * positionOffset) / mActiveTextSize);
                        textViewNext.setScaleX((mInActiveTextSize + mThresHoldSize * positionOffset) / mInActiveTextSize);
                        textViewNext.setScaleY((mInActiveTextSize + mThresHoldSize * positionOffset) / mInActiveTextSize);*/

            /*float size1 = mActiveTextSize - mThresHoldSize * positionOffset;
            float size2 = mInActiveTextSize + mThresHoldSize * positionOffset;
            int alpha1 = mActiveTextColor.alpha - (int)(mThresHoldAlpha * positionOffset);
            int alpha2 = mInActiveTextColor.alpha + (int)(mThresHoldAlpha * positionOffset);
                    
            textViewCurr.lewa_setTextSizeAndColor(size1, mActiveTextColor.getColor(alpha1));
            textViewNext.lewa_setTextSizeAndColor(size2, mActiveTextColor.getColor(alpha2));*/

        } else {
            float realPositionOffset = 1 - positionOffset;
            TabView tabViewCurr = (TabView) mTabLayout.getChildAt(position + 1);
            TextView textViewCurr = (TextView) tabViewCurr.getTextView();
            float widthCurr = (float) (textViewCurr.getMeasuredWidth() * INDICATOR_WIDTH_SCAL_MIN);
            TabView tabViewNext = (TabView) mTabLayout.getChildAt(position);
            TextView textViewNext = (TextView) tabViewNext.getTextView();
            float widthNext = (float) (textViewNext.getMeasuredWidth() * INDICATOR_WIDTH_SCAL_MIN);

            if (realPositionOffset <= INDICATOR_POSITIONOFFSET) {
                mIndicatorView.setPivotX(width);
                mIndicatorView.setScaleX(1 + realPositionOffset * mRateDrag);
                mLastPositionOffset = realPositionOffset;
                mDurationTrans = (int) (mTabViewWidth + widthCurr / 2 + widthNext / 2 - mMaxIndicatorWidth);

                if (mIsTabAdjust) {
                    mIsTabAdjust = false;
                    textViewCurr.setTextColor(mActiveTextColor.getColor());
                    textViewNext.setTextColor(mInActiveTextColor.getColor());
                }

            } else {
                //Log.v("jxli", "2222222111111, scaleX = " + (widthNext/widthCurr + (mMaxIndicatorWidth-widthNext)/widthCurr
                //                            * (1 - (realPositionOffset-mLastPositionOffset) / (1-mLastPositionOffset))));
                //Log.v("jxli", "2222222222222, translationX = " + ((mMaxIndicatorWidth - widthCurr) + (realPositionOffset - mLastPositionOffset) / (1-mLastPositionOffset)*mDurationTrans));
                mIndicatorView.setPivotX(0);
                mIndicatorView.setScaleX(widthNext / widthCurr + (mMaxIndicatorWidth - widthNext) / widthCurr
                        * (1 - (realPositionOffset - mLastPositionOffset) / (1 - mLastPositionOffset)));
                mIndicatorView.setTranslationX(
                        -((mMaxIndicatorWidth - widthCurr) + (realPositionOffset - mLastPositionOffset)
                                / (1 - mLastPositionOffset) * mDurationTrans));

                if (!mIsTabAdjust) {
                    mIsTabAdjust = true;
                    textViewCurr.setTextColor(mInActiveTextColor.getColor());
                    textViewNext.setTextColor(mActiveTextColor.getColor());
                }
            }

            if (mHasSecondaryTabIndexs.contains(position + 1) && !mHasSecondaryTabIndexs.contains(position)) {
                int alpha = SECONDARY_INDICATOR_TRANSPARENCY
                        - (int) (realPositionOffset * THRESHOLD_INDICATOR_TRANSPARENCY);
                mIndicatorView.setAlpha(alpha);
            }
            if (!mHasSecondaryTabIndexs.contains(position + 1) && mHasSecondaryTabIndexs.contains(position)) {
                int alpha = NORMAL_INDICATOR_TRANSPARENCY
                        + (int) (realPositionOffset * THRESHOLD_INDICATOR_TRANSPARENCY);
                mIndicatorView.setAlpha(alpha);
            }

            /*
            float size1 = map(realPositionOffset, 1f, 0f, mInActiveTextSize, mActiveTextSize);
            float size2 = map(realPositionOffset, 1f, 0f, mActiveTextSize, mInActiveTextSize);
            textViewCurr.setTextSize(size1);
            textViewNext.setTextSize(size2);
            */
            //int alpha1 = (int)map(realPositionOffset, 1f, 0f, (float)mInActiveTextColor.alpha, (float)mActiveTextColor.alpha);
            //int alpha2 = (int)map(realPositionOffset, 1f, 0f, (float)mActiveTextColor.alpha, (float)mInActiveTextColor.alpha);
            /*            int alpha1 = mActiveTextColor.alpha - (int)(mThresHoldAlpha * realPositionOffset);
                        int alpha2 = mInActiveTextColor.alpha + (int)(mThresHoldAlpha * realPositionOffset);
                        textViewCurr.setTextColor(mActiveTextColor.getColor(alpha1));
                        textViewNext.setTextColor(mInActiveTextColor.getColor(alpha2));
                    
                        textViewCurr.setScaleX((mActiveTextSize - mThresHoldSize * realPositionOffset) / mActiveTextSize);
                        textViewCurr.setScaleY((mActiveTextSize - mThresHoldSize * realPositionOffset) / mActiveTextSize);
                        textViewNext.setScaleX((mInActiveTextSize + mThresHoldSize * realPositionOffset) / mInActiveTextSize);
                        textViewNext.setScaleY((mInActiveTextSize + mThresHoldSize * realPositionOffset) / mInActiveTextSize);*/

            /*            float size1 = mActiveTextSize - mThresHoldSize * realPositionOffset;
                        float size2 = mInActiveTextSize + mThresHoldSize * realPositionOffset;
                        int alpha1 = mActiveTextColor.alpha - (int)(mThresHoldAlpha * realPositionOffset);
                        int alpha2 = mInActiveTextColor.alpha + (int)(mThresHoldAlpha * realPositionOffset);
                    
                        textViewCurr.lewa_setTextSizeAndColor(size1, mActiveTextColor.getColor(alpha1));
                        textViewNext.lewa_setTextSizeAndColor(size2, mActiveTextColor.getColor(alpha2));*/
        }
        ///LEWA BEGIN
        mHasScrolled = true;
        ///LEWA END
    }
}

From source file:com.mydatingapp.ui.base.SkBaseInnerActivity.java

public void setActionBarLogoCounter(int count) {
    ImageView logo = (ImageView) findViewById(android.R.id.home);

    if (count < 1) {
        currentLogoCounter = 0;//  w w  w .  j a v a  2 s  . c  om
        logo.setVisibility(View.GONE);
        return;
    } else {
        logo.setVisibility(View.VISIBLE);
    }

    currentLogoCounter = count;

    TextView v = new TextView(getApp());
    v.setText(new Integer(count).toString());
    v.setBackgroundResource(R.drawable.sidebar_menu_counterbg);
    v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    v.setDrawingCacheEnabled(true);
    v.setTextColor(Color.WHITE);
    v.setPadding(SKDimensions.convertDpToPixel(6, getApp()), 0, SKDimensions.convertDpToPixel(6, getApp()), 0);

    ActionBar.LayoutParams paramsExample = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, 1);
    paramsExample.setMargins(0, 0, 0, 0);
    v.setHeight(SKDimensions.convertDpToPixel(20, getApp()));
    v.setLayoutParams(paramsExample);

    // this is the important code :)
    // Without it the view will have a dimension of 0,0 and the bitmap will be null
    v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

    logo.setImageDrawable(new BitmapDrawable(getApp().getResources(), b));
    logo.setPadding(SKDimensions.convertDpToPixel(3, getApp()), 0, 0, 0);
}