List of usage examples for android.widget TextView getLayout
public final Layout getLayout()
From source file:Main.java
/** * Returns true if the textview is ellipsized * @param textView/*from ww w . j ava 2 s .c o m*/ * @return */ public static boolean isTextEllipsized(TextView textView) { Layout textViewLayout = textView.getLayout(); if (textViewLayout != null) { int lines = textViewLayout.getLineCount(); if (lines > 0) { if (textViewLayout.getEllipsisCount(lines - 1) > 0) return true; } } return false; }
From source file:Main.java
public static int getFistLine(TextView tv) { // int height = tv.getHeight(); int scrollY = tv.getScrollY(); Layout layout = tv.getLayout(); int firstVisibleLineNumber = layout.getLineForVertical(scrollY); // int lastVisibleLineNumber = // layout.getLineForVertical(scrollY+height); return firstVisibleLineNumber; }
From source file:Main.java
public static int getLastLine(TextView tv) { int height = tv.getHeight(); int scrollY = tv.getScrollY(); Layout layout = tv.getLayout(); if (layout == null) { return 0; }//www . j a v a 2 s. c o m // int firstVisibleLineNumber = layout.getLineForVertical(scrollY); int lastVisibleLineNumber = layout.getLineForVertical(scrollY + height); return lastVisibleLineNumber; }
From source file:Main.java
public static void setTextWithLinks(TextView textView, String htmlText) { setHtmlText(textView, htmlText);/* w w w . ja va 2 s . c o 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:com.findme.views.ExpandableTextView.java
private static int getRealTextViewHeight(TextView textView) { int textHeight = textView.getLayout().getLineTop(textView.getLineCount()); int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom(); return textHeight + padding; }
From source file:com.rashwan.reactive_popular_movies.common.utilities.ExpandableTextView.java
private static int getRealTextViewHeight(@NonNull TextView textView, int parentPadding) { int textHeight = textView.getLayout().getLineTop(textView.getLineCount()); int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom(); return textHeight + padding + parentPadding; }
From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java
/** * ?tv?padding//from w w w. j a va2s . c o m * @param textView * @return */ private static int getRealTextViewHeight(TextView textView) { int textHeight = textView.getLayout().getLineTop(textView.getLineCount()); int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom(); return textHeight + padding; }
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 2s. c om*/ // 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:free.yhc.feeder.model.Utils.java
/** * Text in given TextView is ellipsed?/* ww w.j av a2s. c om*/ * @param tv * @return */ public static boolean isEllipsed(TextView tv) { Layout l = tv.getLayout(); if (null != l) { int lines = l.getLineCount(); if (lines > 0) if (l.getEllipsisCount(lines - 1) > 0) return true; } return false; }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public void statusUpdate(String msg) { TextView tv = (TextView) MyApp.context.findViewById(R.id.textview); tv.append(msg);// w w w . j a v a 2s .c om try { int lineTop = 0; try { lineTop = tv.getLayout().getLineTop(tv.getLineCount()); } catch (Throwable e) { lineTop = 0; } final int scrollAmount = lineTop - tv.getHeight(); if (scrollAmount > 0) { tv.scrollTo(0, scrollAmount); } else { tv.scrollTo(0, 0); } } catch (Throwable e) { Log.i(MyApp.TAG, e.getMessage().toString()); } }