Example usage for android.widget TextView getTotalPaddingLeft

List of usage examples for android.widget TextView getTotalPaddingLeft

Introduction

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

Prototype

public int getTotalPaddingLeft() 

Source Link

Document

Returns the total left padding of the view, including the left Drawable if any.

Usage

From source file:Main.java

public static void setTextWithLinks(TextView textView, String htmlText) {
    setHtmlText(textView, htmlText);/*w  w w .j av  a 2  s . co m*/
    textView.setOnTouchListener((v, event) -> {
        int action = event.getAction();
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
            int x = (int) event.getX();
            int y = (int) event.getY();

            TextView widget = (TextView) v;
            x -= widget.getTotalPaddingLeft();
            y -= widget.getTotalPaddingTop();

            x += widget.getScrollX();
            y += widget.getScrollY();

            Layout layout = widget.getLayout();
            int line = layout.getLineForVertical(y);
            int off = layout.getOffsetForHorizontal(line, x);

            ClickableSpan[] link = Spannable.Factory.getInstance().newSpannable(widget.getText()).getSpans(off,
                    off, ClickableSpan.class);

            if (link.length != 0) {
                if (action == MotionEvent.ACTION_UP) {
                    link[0].onClick(widget);
                }
                return true;
            }
        }
        return false;
    });
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static void setTextWithLinks(TextView textView, CharSequence html) {
    textView.setText(html);/*from w  w  w . j  a v  a  2 s.com*/
    // TODO https://code.google.com/p/android/issues/detail?id=191430
    //noinspection Convert2Lambda
    textView.setOnTouchListener(new View.OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
                int x = (int) event.getX();
                int y = (int) event.getY();

                TextView widget = (TextView) v;
                x -= widget.getTotalPaddingLeft();
                y -= widget.getTotalPaddingTop();

                x += widget.getScrollX();
                y += widget.getScrollY();

                Layout layout = widget.getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);

                ClickableSpan[] link = Spannable.Factory.getInstance().newSpannable(widget.getText())
                        .getSpans(off, off, ClickableSpan.class);

                if (link.length != 0) {
                    if (action == MotionEvent.ACTION_UP) {
                        link[0].onClick(widget);
                    }
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:im.zico.fancy.common.widget.HackyMovementMethod.java

@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    if (mGray == null) {
        mGray = new BackgroundColorSpan(
                ContextCompat.getColor(widget.getContext(), R.color.alpha_spannable_pressed));
    }/* ww w. ja v a  2  s.c  o m*/

    mIsLinkHit = false;

    int action = event.getAction();

    if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();
        x += widget.getScrollX();
        y += widget.getScrollY();

        int line = widget.getLayout().getLineForVertical(y);
        int offset = widget.getLayout().getOffsetForHorizontal(line, x);

        ClickableSpan[] spans = buffer.getSpans(offset, offset, ClickableSpan.class);

        if (spans.length != 0) {
            int start = buffer.getSpanStart(spans[0]);
            int end = buffer.getSpanEnd(spans[0]);
            mIsLinkHit = true;
            if (action == MotionEvent.ACTION_DOWN) {
                buffer.setSpan(mGray, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else if (action == MotionEvent.ACTION_UP) {
                spans[0].onClick(widget);
                buffer.removeSpan(mGray);
            }
            return true;
        }
    } else {
        buffer.removeSpan(mGray);
    }

    return Touch.onTouchEvent(widget, buffer, event);
}

From source file:com.resonos.apps.library.tabviewpager.TabPageIndicator.java

/**
 * Does a bit of calculations to better measure the size of tabs.
 *  This is to fix a bug where text would occasionally get cut off.
 *///from   w  ww . java2s  .co m
private void doPreMeasure() {
    TabView tabView = (TabView) mInflater.inflate(R.layout.vpi__tab, null);
    TextView textView = (TextView) tabView.findViewById(android.R.id.text1);
    ImageView imageView = (ImageView) tabView.findViewById(R.id.img);
    mTextPaint = textView.getPaint();
    mTextPadding = textView.getTotalPaddingLeft() + textView.getTotalPaddingRight() + tabView.getPaddingLeft()
            + tabView.getPaddingRight();
    int mImagePadding = imageView.getPaddingLeft() + imageView.getPaddingRight();

    int t = 0;
    int count = getTitleProvider().getCount();
    mAllMinWidths = new int[count];
    String text;
    Drawable d;
    for (int i = 0; i < count; i++) {
        d = getTitleProvider().getIcon(i);
        text = getTitleProvider().getTitle(i);
        if (d != null) {
            mAllMinWidths[i] = d.getIntrinsicWidth() + mImagePadding;
        } else {
            StaticLayout layout = new StaticLayout(text, mTextPaint, MAX_TAB_WIDTH, Alignment.ALIGN_NORMAL,
                    1.0f, 0.0f, false);
            int w = (int) (layout.getLineWidth(0) + 1);
            mAllMinWidths[i] = mTextPadding + w;
        }
        if (getTitleProvider().isVisible(i))
            t += mAllMinWidths[i];
    }
    mTotalMinWidth = t;
}

From source file:com.juick.android.MessageMenu.java

private float convertToLocalHorizontalCoordinate(TextView textView2, float x) {
    x -= textView2.getTotalPaddingLeft();
    // Clamp the position to inside of the view.
    x = Math.max(0.0f, x);/*  w ww .  ja va 2 s.com*/
    x = Math.min(textView2.getWidth() - textView2.getTotalPaddingRight() - 1, x);
    x += textView2.getScrollX();
    return x;
}

From source file:org.openintents.notepad.NoteEditor.java

@Override
protected void onResume() {
    super.onResume();
    if (DEBUG) {//from w  w w . j  ava 2  s.  c o  m
        Log.d(TAG, "onResume");
    }

    if (DEBUG) {
        Log.d(TAG, "mDecrypted: " + mDecryptedText);
    }

    // Set auto-link on or off, based on the current setting.
    int autoLink = PreferenceActivity.getAutoLinkFromPreference(this);

    mText.setAutoLinkMask(autoLink);

    mEncrypted = 0;

    if (mState == STATE_EDIT || (mState == STATE_INSERT) || mState == STATE_EDIT_EXTERNAL_NOTE) {
        getNoteFromContentProvider();
    } else if (mState == STATE_EDIT_NOTE_FROM_SDCARD) {
        getNoteFromFile();
    }

    if (mEncrypted == 0 || mDecryptedText != null) {
        applyInsertText();
    }

    // Make sure that we don't use the link movement method.
    // Instead, we need a blend between the arrow key movement (for regular
    // navigation) and
    // the link movement (so the user can click on links).
    mText.setMovementMethod(new ArrowKeyMovementMethod() {
        public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
            // This block is copied and pasted from LinkMovementMethod's
            // onTouchEvent (without the part that actually changes the
            // selection).
            int action = event.getAction();

            if (action == MotionEvent.ACTION_UP) {
                int x = (int) event.getX();
                int y = (int) event.getY();

                x -= widget.getTotalPaddingLeft();
                y -= widget.getTotalPaddingTop();

                x += widget.getScrollX();
                y += widget.getScrollY();

                Layout layout = widget.getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);

                ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);

                if (link.length != 0) {
                    link[0].onClick(widget);
                    return true;
                }
            }

            return super.onTouchEvent(widget, buffer, event);
        }
    });

    setTheme(loadTheme());

    startupSearch();
}

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;
    }/*from   w w w  . j  av a2 s . c  o 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;
    }
}