Java Code Examples for android.text.Layout#Alignment
The following examples show how to use
android.text.Layout#Alignment .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaterialAutoCompleteTextView.java From Social with Apache License 2.0 | 6 votes |
/** * @return True, if adjustments were made that require the view to be invalidated. */ private boolean adjustBottomLines() { // Bail out if we have a zero width; lines will be adjusted during next layout. if (getWidth() == 0) { return false; } int destBottomLines; textPaint.setTextSize(bottomTextSize); if (tempErrorText != null || helperText != null) { Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER; textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true); destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines); } else { destBottomLines = minBottomLines; } if (bottomLines != destBottomLines) { getBottomLinesAnimator(destBottomLines).start(); } bottomLines = destBottomLines; return true; }
Example 2
Source File: MaterialMultiAutoCompleteTextView.java From Social with Apache License 2.0 | 6 votes |
/** * @return True, if adjustments were made that require the view to be invalidated. */ private boolean adjustBottomLines() { // Bail out if we have a zero width; lines will be adjusted during next layout. if (getWidth() == 0) { return false; } int destBottomLines; textPaint.setTextSize(bottomTextSize); if (tempErrorText != null || helperText != null) { Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER; textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true); destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines); } else { destBottomLines = minBottomLines; } if (bottomLines != destBottomLines) { getBottomLinesAnimator(destBottomLines).start(); } bottomLines = destBottomLines; return true; }
Example 3
Source File: Sushi.java From android-slidr with Apache License 2.0 | 6 votes |
private void drawIndicatorsTextAbove(Canvas canvas, String text, TextPaint paintText, float x, float y, Layout.Alignment alignment) { final float textHeight = calculateTextMultilineHeight(text, paintText); y -= textHeight; final int width = (int) paintText.measureText(text); if (x >= getWidth() - settings.paddingCorners) { x = (getWidth() - width - settings.paddingCorners / 2f); } else if (x <= 0) { x = width / 2f; } else { x = (x - width / 2f); } if (x < 0) { x = 0; } if (x + width > getWidth()) { x = getWidth() - width; } drawText(canvas, text, x, y, paintText, alignment); }
Example 4
Source File: MaterialAutoCompleteTextView.java From arcusandroid with Apache License 2.0 | 6 votes |
/** * @return True, if adjustments were made that require the view to be invalidated. */ private boolean adjustBottomLines() { // Bail out if we have a zero width; lines will be adjusted during next layout. if (getWidth() == 0) { return false; } int destBottomLines; textPaint.setTextSize(bottomTextSize); if (tempErrorText != null || helperText != null) { Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER; textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true); destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines); } else { destBottomLines = minBottomLines; } if (bottomLines != destBottomLines) { getBottomLinesAnimator(destBottomLines).start(); } bottomLines = destBottomLines; return true; }
Example 5
Source File: MaterialMultiAutoCompleteTextView.java From arcusandroid with Apache License 2.0 | 6 votes |
/** * @return True, if adjustments were made that require the view to be invalidated. */ private boolean adjustBottomLines() { // Bail out if we have a zero width; lines will be adjusted during next layout. if (getWidth() == 0) { return false; } int destBottomLines; textPaint.setTextSize(bottomTextSize); if (tempErrorText != null || helperText != null) { Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER; textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true); destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines); } else { destBottomLines = minBottomLines; } if (bottomLines != destBottomLines) { getBottomLinesAnimator(destBottomLines).start(); } bottomLines = destBottomLines; return true; }
Example 6
Source File: MaterialEditText.java From arcusandroid with Apache License 2.0 | 6 votes |
/** * @return True, if adjustments were made that require the view to be invalidated. */ private boolean adjustBottomLines() { // Bail out if we have a zero width; lines will be adjusted during next layout. if (getWidth() == 0) { return false; } int destBottomLines; textPaint.setTextSize(bottomTextSize); if (tempErrorText != null || helperText != null) { Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER; textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true); destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines); } else { destBottomLines = minBottomLines; } if (bottomLines != destBottomLines) { getBottomLinesAnimator(destBottomLines).start(); } bottomLines = destBottomLines; return true; }
Example 7
Source File: ConverterHtmlToSpanned.java From memoir with Apache License 2.0 | 6 votes |
private void endDiv() { int end = mResult.length(); Object obj = getLast(mResult, Div.class); int start = mResult.getSpanStart(obj); mResult.removeSpan(obj); if (start != end) { if (!checkDuplicateSpan(mResult, start, AlignmentSpan.class)) { Div divObj = (Div) obj; Layout.Alignment align = divObj.mAlign.equalsIgnoreCase("center") ? Layout.Alignment.ALIGN_CENTER : divObj.mAlign.equalsIgnoreCase("right") ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL; if (align != null) { if (mResult.charAt(end - 1) != '\n') { // yes we need that linefeed, or we will get crashes mResult.append('\n'); } // use SPAN_EXCLUSIVE_EXCLUSIVE here, will be replaced later anyway when the cleanup function is called boolean isRTL = Helper.isRTL(mResult, start, end); mResult.setSpan(new AlignmentSpan(align, isRTL), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } }
Example 8
Source File: TextViewAttrsHelper.java From FastTextView with Apache License 2.0 | 6 votes |
private static Layout.Alignment getAlignmentByGravity(int gravity) { switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.START: return Layout.Alignment.ALIGN_NORMAL; case Gravity.END: return Layout.Alignment.ALIGN_OPPOSITE; case Gravity.LEFT: return Layout.Alignment.ALIGN_LEFT; case Gravity.RIGHT: return Layout.Alignment.ALIGN_RIGHT; case Gravity.CENTER_HORIZONTAL: return Layout.Alignment.ALIGN_CENTER; default: return Layout.Alignment.ALIGN_NORMAL; } }
Example 9
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 5 votes |
private static void encodeTextAlignmentByDiv(StringBuilder out, Spanned text, int option) { int len = text.length(); int next; for (int i = 0; i < len; i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for (int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next, option); if (needDiv) { out.append("</div>"); } } }
Example 10
Source File: Html.java From Nimingban with Apache License 2.0 | 5 votes |
private static void withinHtml(StringBuilder out, Spanned text) { int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, ParagraphStyle.class); ParagraphStyle[] style = text.getSpans(i, next, ParagraphStyle.class); String elements = " "; boolean needDiv = false; for(int j = 0; j < style.length; j++) { if (style[j] instanceof AlignmentSpan) { Layout.Alignment align = ((AlignmentSpan) style[j]).getAlignment(); needDiv = true; if (align == Layout.Alignment.ALIGN_CENTER) { elements = "align=\"center\" " + elements; } else if (align == Layout.Alignment.ALIGN_OPPOSITE) { elements = "align=\"right\" " + elements; } else { elements = "align=\"left\" " + elements; } } } if (needDiv) { out.append("<div ").append(elements).append(">"); } withinDiv(out, text, i, next); if (needDiv) { out.append("</div>"); } } }
Example 11
Source File: Slidr.java From android-slidr with Apache License 2.0 | 5 votes |
private void drawText(Canvas canvas, String text, float x, float y, TextPaint paint, Layout.Alignment aligment) { canvas.save(); { canvas.translate(x, y); final StaticLayout staticLayout = new StaticLayout(text, paint, (int) paint.measureText(text), aligment, 1.0f, 0, false); staticLayout.draw(canvas); } canvas.restore(); }
Example 12
Source File: HorizontalRTToolbar.java From memoir with Apache License 2.0 | 5 votes |
@Override public void setAlignment(Layout.Alignment alignment) { if (mAlignLeft != null) mAlignLeft.setChecked(alignment == Layout.Alignment.ALIGN_NORMAL); if (mAlignCenter != null) mAlignCenter.setChecked(alignment == Layout.Alignment.ALIGN_CENTER); if (mAlignRight != null) mAlignRight.setChecked(alignment == Layout.Alignment.ALIGN_OPPOSITE); }
Example 13
Source File: Sushi.java From android-slidr with Apache License 2.0 | 5 votes |
private void drawText(Canvas canvas, String text, float x, float y, TextPaint paint, Layout.Alignment aligment) { canvas.save(); { canvas.translate(x, y); final StaticLayout staticLayout = new StaticLayout(text, paint, (int) paint.measureText(text), aligment, 1.0f, 0, false); staticLayout.draw(canvas); } canvas.restore(); }
Example 14
Source File: TtmlStyle.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public Layout.Alignment getTextAlign() { return textAlign; }
Example 15
Source File: StaticLayoutEx.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static StaticLayout createStaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) { return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines); }
Example 16
Source File: EditTextSpec.java From litho with Apache License 2.0 | 4 votes |
@OnMount static void onMount( final ComponentContext c, EditTextWithEventHandlers editText, @Prop(optional = true, resType = ResType.STRING) CharSequence text, @Prop(optional = true, resType = ResType.STRING) CharSequence initialText, @Prop(optional = true, resType = ResType.STRING) CharSequence hint, @Prop(optional = true) TextUtils.TruncateAt ellipsize, @Prop(optional = true, resType = ResType.INT) int minLines, @Prop(optional = true, resType = ResType.INT) int maxLines, @Prop(optional = true, resType = ResType.INT) int maxLength, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy, @Prop(optional = true, resType = ResType.COLOR) int shadowColor, @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine, @Prop(optional = true, resType = ResType.COLOR) int textColor, @Prop(optional = true) ColorStateList textColorStateList, @Prop(optional = true, resType = ResType.COLOR) int hintColor, @Prop(optional = true) ColorStateList hintColorStateList, @Prop(optional = true, resType = ResType.COLOR) int linkColor, @Prop(optional = true, resType = ResType.COLOR) int highlightColor, @Prop(optional = true) ColorStateList tintColorStateList, @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float extraSpacing, @Prop(optional = true, resType = ResType.FLOAT) float spacingMultiplier, @Prop(optional = true) int textStyle, @Prop(optional = true) Typeface typeface, @Prop(optional = true) Layout.Alignment textAlignment, @Prop(optional = true) int gravity, @Prop(optional = true) boolean editable, @Prop(optional = true) int selection, @Prop(optional = true) int inputType, @Prop(optional = true) int rawInputType, @Prop(optional = true) int imeOptions, @Prop(optional = true) TextView.OnEditorActionListener editorActionListener, @Prop(optional = true) boolean isSingleLineWrap, @Prop(optional = true) boolean requestFocus, @Prop(optional = true) int cursorDrawableRes, @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters, @State AtomicReference<EditTextWithEventHandlers> mountedView, @State AtomicBoolean configuredInitialText, @State(canUpdateLazily = true) CharSequence input) { mountedView.set(editText); initEditText( editText, input == null ? text : input, // Only set initialText on the EditText during the very first mount. configuredInitialText.getAndSet(true) ? null : initialText, hint, ellipsize, inputFilters, minLines, maxLines, maxLength, shadowRadius, shadowDx, shadowDy, shadowColor, isSingleLine, textColor, textColorStateList, hintColor, hintColorStateList, linkColor, highlightColor, tintColorStateList, textSize, extraSpacing, spacingMultiplier, textStyle, typeface, textAlignment, gravity, editable, selection, inputType, rawInputType, imeOptions, editorActionListener, isSingleLineWrap, requestFocus, cursorDrawableRes); }
Example 17
Source File: StaticLayoutEx.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public static Layout.Alignment ALIGN_LEFT() { return alignments.length >= 5 ? alignments[3] : Layout.Alignment.ALIGN_NORMAL; }
Example 18
Source File: StaticLayoutEx.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public static StaticLayout createStaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) { return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines); }
Example 19
Source File: WebvttCssStyle.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public WebvttCssStyle setTextAlign(Layout.Alignment textAlign) { this.textAlign = textAlign; return this; }
Example 20
Source File: StaticLayoutEx.java From Telegram with GNU General Public License v2.0 | 4 votes |
public static StaticLayout createStaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines, boolean canContainUrl) { return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines, canContainUrl); }