Java Code Examples for android.text.TextDirectionHeuristic

The following are top voted examples for showing how to use android.text.TextDirectionHeuristic. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Tada   File: TextView.java   Source Code and License 6 votes vote down vote up
TextDirectionHeuristic getTextDirectionHeuristic() {
    if (hasPasswordTransformationMethod()) {
        // passwords fields should be LTR
        return TextDirectionHeuristics.LTR;
    }

    // Always need to resolve layout direction first
    final boolean defaultIsRtl = (getLayoutDirection() == LAYOUT_DIRECTION_RTL);

    // Now, we can select the heuristic
    switch (getTextDirection()) {
        default:
        case TEXT_DIRECTION_FIRST_STRONG:
            return (defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL :
                    TextDirectionHeuristics.FIRSTSTRONG_LTR);
        case TEXT_DIRECTION_ANY_RTL:
            return TextDirectionHeuristics.ANYRTL_LTR;
        case TEXT_DIRECTION_LTR:
            return TextDirectionHeuristics.LTR;
        case TEXT_DIRECTION_RTL:
            return TextDirectionHeuristics.RTL;
        case TEXT_DIRECTION_LOCALE:
            return TextDirectionHeuristics.LOCALE;
    }
}
 
Example 2
Project: airgram   File: StaticLayoutEx.java   Source Code and License 4 votes vote down vote up
public static void init() {
    if (initialized) {
        return;
    }

    try {
        final Class<?> textDirClass;
        if (Build.VERSION.SDK_INT >= 18) {
            textDirClass = TextDirectionHeuristic.class;
            sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
        } else {
            ClassLoader loader = StaticLayoutEx.class.getClassLoader();
            textDirClass = loader.loadClass(TEXT_DIR_CLASS);
            Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
            sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
        }

        final Class<?>[] signature = new Class[]{
                CharSequence.class,
                int.class,
                int.class,
                TextPaint.class,
                int.class,
                Layout.Alignment.class,
                textDirClass,
                float.class,
                float.class,
                boolean.class,
                TextUtils.TruncateAt.class,
                int.class,
                int.class
        };

        sConstructor = StaticLayout.class.getDeclaredConstructor(signature);
        sConstructor.setAccessible(true);
        sConstructorArgs = new Object[signature.length];
        initialized = true;
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
}
 
Example 3
Project: PlusGram   File: StaticLayoutEx.java   Source Code and License 4 votes vote down vote up
public static void init() {
    if (initialized) {
        return;
    }

    try {
        final Class<?> textDirClass;
        if (Build.VERSION.SDK_INT >= 18) {
            textDirClass = TextDirectionHeuristic.class;
            sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
        } else {
            ClassLoader loader = StaticLayoutEx.class.getClassLoader();
            textDirClass = loader.loadClass(TEXT_DIR_CLASS);
            Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
            sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
        }

        final Class<?>[] signature = new Class[]{
                CharSequence.class,
                int.class,
                int.class,
                TextPaint.class,
                int.class,
                Layout.Alignment.class,
                textDirClass,
                float.class,
                float.class,
                boolean.class,
                TextUtils.TruncateAt.class,
                int.class,
                int.class
        };

        sConstructor = StaticLayout.class.getDeclaredConstructor(signature);
        sConstructor.setAccessible(true);
        sConstructorArgs = new Object[signature.length];
        initialized = true;
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
}
 
Example 4
Project: edx-app-android   File: CustomTypefaceSpan.java   Source Code and License 4 votes vote down vote up
@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());
}
 
Example 5
Project: Telegram   File: StaticLayoutEx.java   Source Code and License 4 votes vote down vote up
public static void init() {
    if (initialized) {
        return;
    }

    try {
        final Class<?> textDirClass;
        if (Build.VERSION.SDK_INT >= 18) {
            textDirClass = TextDirectionHeuristic.class;
            sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
        } else {
            ClassLoader loader = StaticLayoutEx.class.getClassLoader();
            textDirClass = loader.loadClass(TEXT_DIR_CLASS);
            Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
            sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
        }

        final Class<?>[] signature = new Class[]{
                CharSequence.class,
                int.class,
                int.class,
                TextPaint.class,
                int.class,
                Layout.Alignment.class,
                textDirClass,
                float.class,
                float.class,
                boolean.class,
                TextUtils.TruncateAt.class,
                int.class,
                int.class
        };

        sConstructor = StaticLayout.class.getDeclaredConstructor(signature);
        sConstructor.setAccessible(true);
        sConstructorArgs = new Object[signature.length];
        initialized = true;
    } catch (Throwable e) {
        FileLog.e(e);
    }
}