List of usage examples for android.widget TextView getText
@ViewDebug.CapturedViewProperty
public CharSequence getText()
From source file:Main.java
public static int getTextLen(TextView textView) { TextPaint paint = textView.getPaint(); return (int) Layout.getDesiredWidth(textView.getText().toString(), 0, textView.getText().length(), paint); }
From source file:Main.java
public static String getValue(TextView v) { String err_msg_which = ""; String value = ""; if (v != null) { value = v.getText().toString(); } else {/*from w w w . j av a 2s . c o m*/ err_msg_which = "TextView"; String err_msg_format = "%s is null"; // LogU.eLog(String.format(err_msg_format, err_msg_which)); } return value; }
From source file:Main.java
public static String getViewText(TextView view) { if (view == null) { return "0"; }//from www.j ava 2 s . co m boolean empty = android.text.TextUtils.isEmpty(view.getText().toString()); return empty ? "0" : view.getText().toString(); }
From source file:Main.java
public static int getStationFromUI(TextView textView) { int station = 0; float frequency = 0; String frequencyStr = textView.getText().toString(); try {/*from w ww . j ava 2 s .co m*/ frequency = Float.parseFloat(frequencyStr); } catch (NumberFormatException e) { e.printStackTrace(); } station = (int) (frequency * CONVERT_RATE); return station; }
From source file:Main.java
public static String getEllipsisedText(TextView textView) { try {/*from w w w .j av a2 s .c o m*/ String text = textView.getText().toString(); int lines = textView.getLineCount(); int width = textView.getWidth(); int len = text.length(); Log.d("Test", "text-->" + text + "; lines-->" + lines + "; width-->" + width + ";len-->" + len); TextUtils.TruncateAt where = TextUtils.TruncateAt.END; TextPaint paint = textView.getPaint(); StringBuffer result = new StringBuffer(); int spos = 0, cnt, tmp, hasLines = 0; while (hasLines < lines - 1) { cnt = paint.breakText(text, spos, len, true, width, null); if (cnt >= len - spos) { result.append(text.substring(spos)); break; } tmp = text.lastIndexOf('\n', spos + cnt - 1); if (tmp >= 0 && tmp < spos + cnt) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { tmp = text.lastIndexOf(' ', spos + cnt - 1); if (tmp >= spos) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { result.append(text.substring(spos, cnt)); spos += cnt; } } hasLines++; } if (spos < len) { result.append(TextUtils.ellipsize(text.subSequence(spos, len), paint, (float) width, where)); } return result.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int applyNewLineCharacter(TextView textView) { Paint paint = textView.getPaint(); String text = (String) textView.getText(); int frameWidth = getPixelFromDp(textView, 120f); int startIndex = 0; int endIndex = paint.breakText(text, true, frameWidth, null); String save = text.substring(startIndex, endIndex); // Count line of TextView int lines = 1; while (true) { // Set new start index startIndex = endIndex;//w w w. j a v a2 s. c om // Get substring the remaining of text text = text.substring(startIndex); if (text.length() == 0) { break; } else { lines++; } // Calculate end of index that fits endIndex = paint.breakText(text, true, frameWidth, null); // Append substring that fits into the frame save += "\n" + text.substring(0, endIndex); } // Set text to TextView textView.setText(save); return lines; }
From source file:Main.java
public static void setClickable(final TextView textView) { textView.setMovementMethod(LinkMovementMethod.getInstance()); Spannable sp = (Spannable) textView.getText(); ImageSpan[] images = sp.getSpans(0, textView.getText().length(), ImageSpan.class); for (ImageSpan span : images) { final String image_src = span.getSource(); final int start = sp.getSpanStart(span); final int end = sp.getSpanEnd(span); ClickableSpan click_span = new ClickableSpan() { @Override//from w w w .j av a 2s . c o m public void onClick(View widget) { String[] strs = image_src.split("/"); String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LilyClient/" + strs[strs.length - 2] + "-" + strs[strs.length - 1]; Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setType("image/*"); intent.setDataAndType(Uri.fromFile(new File(filePath)), "image/*"); textView.getContext().startActivity(intent); } }; ClickableSpan[] click_spans = sp.getSpans(start, end, ClickableSpan.class); if (click_spans.length != 0) { for (ClickableSpan c_span : click_spans) { sp.removeSpan(c_span); } } sp.setSpan(click_span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:Main.java
public static Callable<Boolean> notBlank(final TextView view) { return new Callable<Boolean>() { @Override//from ww w . j a va 2s.c o m public Boolean call() throws Exception { if (view == null || view.getText() == null) { throw new IllegalArgumentException("TextView should not be null!"); } return view.getText().length() > 0; } }; }
From source file:Main.java
public static void buildLink(TextView view, String url) { Log.d(TAG, "buildLink(view = " + view + ", url = " + url + ")"); StringBuilder sb = new StringBuilder(); sb.append("<a href='").append(url).append("'>").append(view.getText()).append("</a>"); view.setText(Html.fromHtml(sb.toString())); view.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:codepath.watsiapp.utils.Util.java
/** * Sets a hyperlink style to the textview. *///from w w w . j a v a 2 s .c o m public static void makeTextViewHyperlink(TextView tv) { SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(tv.getText()); ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(ssb, TextView.BufferType.SPANNABLE); }