Example usage for android.text Layout getLineWidth

List of usage examples for android.text Layout getLineWidth

Introduction

In this page you can find the example usage for android.text Layout getLineWidth.

Prototype

public float getLineWidth(int line) 

Source Link

Document

Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.

Usage

From source file:org.kontalk.ui.view.TextContentView.java

private float getMaxLineWidth(Layout layout) {
    float max_width = 0.0f;
    int lines = layout.getLineCount();
    for (int i = 0; i < lines; i++) {
        if (layout.getLineWidth(i) > max_width) {
            max_width = layout.getLineWidth(i);
        }//from   ww  w.j a  va 2 s .  c o m
    }
    return max_width;
}

From source file:org.kontalk.ui.view.TextContentView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (mMeasureHack) {
        int specModeW = MeasureSpec.getMode(widthMeasureSpec);
        if (specModeW != MeasureSpec.EXACTLY) {
            Layout layout = getLayout();
            int linesCount = layout.getLineCount();
            if (linesCount > 1) {
                float textRealMaxWidth = 0;
                for (int n = 0; n < linesCount; ++n) {
                    textRealMaxWidth = Math.max(textRealMaxWidth, layout.getLineWidth(n));
                }/*w w  w .ja  v  a2 s .  c o m*/
                int w = Math.round(textRealMaxWidth);
                if (w < getMeasuredWidth()) {
                    super.onMeasure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST), heightMeasureSpec);
                }
            }
        }
    }
}

From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java

private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
    int wid = tv.getPaddingLeft() + tv.getPaddingRight();
    int ht = tv.getPaddingTop() + tv.getPaddingBottom();

    //com.android.internal.R.dimen.textview_error_popup_default_width introduced after Gingerbread, only has one variant (240dip)
    int defaultWidthInPixels = mContext.getResources()
            .getDimensionPixelSize(R.dimen.textview_error_popup_default_width);
    Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0,
            true);/* w  w w  . j  a  v  a 2s. c  om*/

    float max = 0;
    for (int i = 0; i < l.getLineCount(); i++) {
        max = Math.max(max, l.getLineWidth(i));
    }

    if (DEBUG)
        Log.d(TAG, "max: " + max + ", height: " + l.getHeight());

    /*
     * Now set the popup size to be big enough for the text plus the border.
     */
    pop.setWidth(wid + (int) Math.ceil(max));
    pop.setHeight(ht + l.getHeight()); //TODO: buggy (the 2 shouldnt need to be there)
}

From source file:com.bitflake.counter.HorizontalPicker.java

private void startMarqueeIfNeeded() {

    stopMarqueeIfNeeded();/*w w  w . j a v a2 s .co m*/

    int item = getSelectedItem();

    if (layouts != null && layouts.length > item) {
        Layout layout = layouts[item];
        if (ellipsize == TextUtils.TruncateAt.MARQUEE && itemWidth < layout.getLineWidth(0)) {
            marquee = new Marquee(this, layout, isRtl(values[item]));
            marquee.start(marqueeRepeatLimit);
        }
    }

}

From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

private void startMarqueeIfNeeded() {

    stopMarqueeIfNeeded();// ww  w  .j ava 2s  .  c  om

    int item = getSelectedItem();

    if (mLayouts != null && mLayouts.length > item) {
        Layout layout = mLayouts[item];
        if (mEllipsize == TextUtils.TruncateAt.MARQUEE && mItemWidth < layout.getLineWidth(0)) {
            mMarquee = new Marquee(this, layout, isRtl(mValues[item]));
            mMarquee.start(mMarqueeRepeatLimit);
        }
    }

}

From source file:org.telegram.ui.ChatActivity.java

private boolean spanClicked(ListView list, View view, int textViewId) {
    final TextView widget = (TextView) view.findViewById(textViewId);
    if (widget == null) {
        return false;
    }/* w w w  .  j a v  a2  s  . co m*/
    try {
        list.offsetRectIntoDescendantCoords(widget, mLastTouch);
        int x = mLastTouch.right;
        int y = mLastTouch.bottom;

        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();
        x += widget.getScrollX();
        y += widget.getScrollY();

        final Layout layout = widget.getLayout();
        if (layout == null) {
            return false;
        }
        final int line = layout.getLineForVertical(y);
        final int off = layout.getOffsetForHorizontal(line, x);

        final float left = layout.getLineLeft(line);
        if (left > x || left + layout.getLineWidth(line) < x) {
            return false;
        }

        final Editable buffer = new SpannableStringBuilder(widget.getText());
        if (buffer == null) {
            return false;
        }
        final ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);

        if (link.length == 0) {
            return false;
        }

        link[0].onClick(widget);
        return true;
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        return false;
    }
}