List of usage examples for android.graphics Paint breakText
public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth)
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;/*from www . j av a2s .com*/ // 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:com.android.screenspeak.contextmenu.RadialMenuView.java
private static String getEllipsizedText(Paint paint, String title, float maxWidth) { final float textWidth = paint.measureText(title); if (textWidth <= maxWidth) { return title; }/*from w ww . jav a 2s. c om*/ // Find the maximum length with an ellipsis. final float ellipsisWidth = paint.measureText(ELLIPSIS); final int length = paint.breakText(title, true, (maxWidth - ellipsisWidth), null); // Try to land on a word break. // TODO(AV): Use breaking iterator for better i18n support. final int space = title.lastIndexOf(' ', length); if (space > 0) { return title.substring(0, space) + ELLIPSIS; } // Otherwise, cut off characters. return title.substring(0, length) + ELLIPSIS; }
From source file:com.android.talkback.contextmenu.RadialMenuView.java
private static String getEllipsizedText(Paint paint, String title, float maxWidth) { final float textWidth = paint.measureText(title); if (textWidth <= maxWidth) { return title; }/*from ww w .j av a2s. c o m*/ // Find the maximum length with an ellipsis. final float ellipsisWidth = paint.measureText(ELLIPSIS); final int length = paint.breakText(title, true, (maxWidth - ellipsisWidth), null); // Try to land on a word break. // TODO: Use breaking iterator for better i18n support. final int space = title.lastIndexOf(' ', length); if (space > 0) { return title.substring(0, space) + ELLIPSIS; } // Otherwise, cut off characters. return title.substring(0, length) + ELLIPSIS; }
From source file:com.googlecode.eyesfree.widget.RadialMenuView.java
private static String getEllipsizedText(Paint paint, String title, float maxWidth) { final float textWidth = paint.measureText(title); if (textWidth <= maxWidth) { return title; }//from w w w.j a v a 2 s. c o m // Find the maximum length with an ellipsis. final float ellipsisWidth = paint.measureText(ELLIPSIS); final int length = paint.breakText(title, true, (maxWidth - ellipsisWidth), null); // Try to land on a word break. // TODO(alanv): Use breaking iterator for better i18n support. final int space = title.lastIndexOf(' ', length); if (space > 0) { return title.substring(0, space) + ELLIPSIS; } // Otherwise, cut off characters. return title.substring(0, length) + ELLIPSIS; }