Java Code Examples for android.text.TextDirectionHeuristics#LTR
The following examples show how to use
android.text.TextDirectionHeuristics#LTR .
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: StaticLayoutProxy.java From TextLayoutBuilder with Apache License 2.0 | 6 votes |
public static TextDirectionHeuristic fromTextDirectionHeuristicCompat( TextDirectionHeuristicCompat textDirection) { if (textDirection == TextDirectionHeuristicsCompat.LTR) { return TextDirectionHeuristics.LTR; } else if (textDirection == TextDirectionHeuristicsCompat.RTL) { return TextDirectionHeuristics.RTL; } else if (textDirection == TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR) { return TextDirectionHeuristics.FIRSTSTRONG_LTR; } else if (textDirection == TextDirectionHeuristicsCompat.FIRSTSTRONG_RTL) { return TextDirectionHeuristics.FIRSTSTRONG_RTL; } else if (textDirection == TextDirectionHeuristicsCompat.ANYRTL_LTR) { return TextDirectionHeuristics.ANYRTL_LTR; } else if (textDirection == TextDirectionHeuristicsCompat.LOCALE) { return TextDirectionHeuristics.LOCALE; } else { return TextDirectionHeuristics.FIRSTSTRONG_LTR; } }
Example 2
Source File: StaticLayoutManager.java From FastTextView with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public void initLayout(Context context, CharSequence source, CharSequence longString) { textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); textPaint.density = context.getResources().getDisplayMetrics().density; textPaint.setTextSize(Util.fromDPtoPix(context, Util.TEXT_SIZE_DP)); textDir = TextDirectionHeuristics.LTR; alignment = Layout.Alignment.ALIGN_NORMAL; hardCodeWidth = Util.getScreenWidth(context); longStringLayout = new StaticLayout(longString, textPaint, hardCodeWidth, alignment, 1.0f, 0f, true); dummyCanvas = new Canvas(); longStringLayout.draw(dummyCanvas); for (int i = 0; i < layout.length; i++) { layout[i] = new StaticLayout(TestSpan.getSpanString(i), textPaint, hardCodeWidth, alignment, 1.0f, 0f, true); layout[i].draw(dummyCanvas); } }
Example 3
Source File: StaticLayoutBuilderCompat.java From material-components-android with Apache License 2.0 | 4 votes |
/** A method that allows to create a StaticLayout with maxLines on all supported API levels. */ public StaticLayout build() throws StaticLayoutBuilderCompatException { if (source == null) { source = ""; } int availableWidth = Math.max(0, width); CharSequence textToDraw = source; if (maxLines == 1) { textToDraw = TextUtils.ellipsize(source, paint, availableWidth, ellipsize); } end = Math.min(textToDraw.length(), end); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (isRtl) { alignment = Alignment.ALIGN_OPPOSITE; } // Marshmallow introduced StaticLayout.Builder which allows us not to use // the hidden constructor. StaticLayout.Builder builder = StaticLayout.Builder.obtain( textToDraw, start, end, paint, availableWidth); builder.setAlignment(alignment); builder.setIncludePad(includePad); TextDirectionHeuristic textDirectionHeuristic = isRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR; builder.setTextDirection(textDirectionHeuristic); if (ellipsize != null) { builder.setEllipsize(ellipsize); } builder.setMaxLines(maxLines); return builder.build(); } createConstructorWithReflection(); // Use the hidden constructor on older API levels. try { return checkNotNull(constructor) .newInstance( textToDraw, start, end, paint, availableWidth, alignment, checkNotNull(textDirection), 1.0f, 0.0f, includePad, null, availableWidth, maxLines); } catch (Exception cause) { throw new StaticLayoutBuilderCompatException(cause); } }
Example 4
Source File: StaticLayoutBuilderCompat.java From material-components-android with Apache License 2.0 | 4 votes |
/** * set constructor to this hidden {@link StaticLayout constructor.} * * <pre>{@code * StaticLayout( * CharSequence source, * int bufstart, * int bufend, * TextPaint paint, * int outerwidth, * Alignment align, * TextDirectionHeuristic textDir, * float spacingmult, * float spacingadd, * boolean includepad, * TextUtils.TruncateAt ellipsize, * int ellipsizedWidth, * int maxLines) * }</pre> */ private void createConstructorWithReflection() throws StaticLayoutBuilderCompatException { if (initialized) { return; } try { final Class<?> textDirClass; boolean useRtl = isRtl && Build.VERSION.SDK_INT >= VERSION_CODES.M; if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) { textDirClass = TextDirectionHeuristic.class; textDirection = useRtl ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR; } else { ClassLoader loader = StaticLayoutBuilderCompat.class.getClassLoader(); String textDirClassName = isRtl ? TEXT_DIR_CLASS_RTL : TEXT_DIR_CLASS_LTR; textDirClass = loader.loadClass(TEXT_DIR_CLASS); Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS); textDirection = textDirsClass.getField(textDirClassName).get(textDirsClass); } final Class<?>[] signature = new Class<?>[] { CharSequence.class, int.class, int.class, TextPaint.class, int.class, Alignment.class, textDirClass, float.class, float.class, boolean.class, TextUtils.TruncateAt.class, int.class, int.class }; constructor = StaticLayout.class.getDeclaredConstructor(signature); constructor.setAccessible(true); initialized = true; } catch (Exception cause) { throw new StaticLayoutBuilderCompatException(cause); } }
Example 5
Source File: CustomTypefaceSpan.java From edx-app-android with Apache License 2.0 | 4 votes |
@TargetApi(JELLY_BEAN_MR1) @CheckResult private boolean needMirroring() { if (!mirrorable) return false; // Passwords fields should be LTR if (view.getTransformationMethod() instanceof PasswordTransformationMethod) { return false; } // Always need to resolve layout direction first final boolean defaultIsRtl = view.getLayoutDirection() == LAYOUT_DIRECTION_RTL; if (SDK_INT < JELLY_BEAN_MR2) { return defaultIsRtl; } // Select the text direction heuristic according to the // package-private getTextDirectionHeuristic() method in TextView TextDirectionHeuristic textDirectionHeuristic; switch (view.getTextDirection()) { default: case TEXT_DIRECTION_FIRST_STRONG: textDirectionHeuristic = defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL : TextDirectionHeuristics.FIRSTSTRONG_LTR; break; case TEXT_DIRECTION_ANY_RTL: textDirectionHeuristic = TextDirectionHeuristics.ANYRTL_LTR; break; case TEXT_DIRECTION_LTR: textDirectionHeuristic = TextDirectionHeuristics.LTR; break; case TEXT_DIRECTION_RTL: textDirectionHeuristic = TextDirectionHeuristics.RTL; break; case TEXT_DIRECTION_LOCALE: textDirectionHeuristic = TextDirectionHeuristics.LOCALE; break; case TEXT_DIRECTION_FIRST_STRONG_LTR: textDirectionHeuristic = TextDirectionHeuristics.FIRSTSTRONG_LTR; break; case TEXT_DIRECTION_FIRST_STRONG_RTL: textDirectionHeuristic = TextDirectionHeuristics.FIRSTSTRONG_RTL; break; } CharSequence text = view.getText(); return textDirectionHeuristic.isRtl(text, 0, text.length()); }