Java Code Examples for android.text.TextUtils#CAP_MODE_WORDS

The following examples show how to use android.text.TextUtils#CAP_MODE_WORDS . 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: CapsModeUtils.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert capitalize mode flags into human readable text.
 *
 * @param capsFlags The modes flags to be converted. It may be any combination of
 * {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
 * {@link TextUtils#CAP_MODE_SENTENCES}.
 * @return the text that describe the <code>capsMode</code>.
 */
public static String flagsToString(final int capsFlags) {
    final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
            | TextUtils.CAP_MODE_SENTENCES;
    if ((capsFlags & ~capsFlagsMask) != 0) {
        return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
    }
    final ArrayList<String> builder = new ArrayList<>();
    if ((capsFlags & android.text.TextUtils.CAP_MODE_CHARACTERS) != 0) {
        builder.add("characters");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_WORDS) != 0) {
        builder.add("words");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_SENTENCES) != 0) {
        builder.add("sentences");
    }
    return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}
 
Example 2
Source File: CapsModeUtils.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
/**
 * Convert capitalize mode flags into human readable text.
 *
 * @param capsFlags The modes flags to be converted. It may be any combination of
 * {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
 * {@link TextUtils#CAP_MODE_SENTENCES}.
 * @return the text that describe the <code>capsMode</code>.
 */
public static String flagsToString(final int capsFlags) {
    final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
            | TextUtils.CAP_MODE_SENTENCES;
    if ((capsFlags & ~capsFlagsMask) != 0) {
        return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
    }
    final ArrayList<String> builder = new ArrayList<>();
    if ((capsFlags & android.text.TextUtils.CAP_MODE_CHARACTERS) != 0) {
        builder.add("characters");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_WORDS) != 0) {
        builder.add("words");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_SENTENCES) != 0) {
        builder.add("sentences");
    }
    return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}
 
Example 3
Source File: CapsModeUtils.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
/**
 * Convert capitalize mode flags into human readable text.
 *
 * @param capsFlags The modes flags to be converted. It may be any combination of
 * {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
 * {@link TextUtils#CAP_MODE_SENTENCES}.
 * @return the text that describe the <code>capsMode</code>.
 */
public static String flagsToString(final int capsFlags) {
    final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
            | TextUtils.CAP_MODE_SENTENCES;
    if ((capsFlags & ~capsFlagsMask) != 0) {
        return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
    }
    final ArrayList<String> builder = new ArrayList<>();
    if ((capsFlags & android.text.TextUtils.CAP_MODE_CHARACTERS) != 0) {
        builder.add("characters");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_WORDS) != 0) {
        builder.add("words");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_SENTENCES) != 0) {
        builder.add("sentences");
    }
    return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}
 
Example 4
Source File: CapsModeUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
/**
 * Convert capitalize mode flags into human readable text.
 *
 * @param capsFlags The modes flags to be converted. It may be any combination of
 * {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
 * {@link TextUtils#CAP_MODE_SENTENCES}.
 * @return the text that describe the <code>capsMode</code>.
 */
public static String flagsToString(final int capsFlags) {
    final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
            | TextUtils.CAP_MODE_SENTENCES;
    if ((capsFlags & ~capsFlagsMask) != 0) {
        return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
    }
    final ArrayList<String> builder = new ArrayList<>();
    if ((capsFlags & TextUtils.CAP_MODE_CHARACTERS) != 0) {
        builder.add("characters");
    }
    if ((capsFlags & TextUtils.CAP_MODE_WORDS) != 0) {
        builder.add("words");
    }
    if ((capsFlags & TextUtils.CAP_MODE_SENTENCES) != 0) {
        builder.add("sentences");
    }
    return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}
 
Example 5
Source File: CapsModeUtils.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
/**
 * Convert capitalize mode flags into human readable text.
 *
 * @param capsFlags The modes flags to be converted. It may be any combination of
 * {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
 * {@link TextUtils#CAP_MODE_SENTENCES}.
 * @return the text that describe the <code>capsMode</code>.
 */
public static String flagsToString(final int capsFlags) {
    final int capsFlagsMask = TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS
            | TextUtils.CAP_MODE_SENTENCES;
    if ((capsFlags & ~capsFlagsMask) != 0) {
        return "unknown<0x" + Integer.toHexString(capsFlags) + ">";
    }
    final ArrayList<String> builder = new ArrayList<>();
    if ((capsFlags & android.text.TextUtils.CAP_MODE_CHARACTERS) != 0) {
        builder.add("characters");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_WORDS) != 0) {
        builder.add("words");
    }
    if ((capsFlags & android.text.TextUtils.CAP_MODE_SENTENCES) != 0) {
        builder.add("sentences");
    }
    return builder.isEmpty() ? "none" : TextUtils.join("|", builder);
}
 
Example 6
Source File: RichInputConnection.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the caps modes we should be in after this specific string.
 *
 * This returns a bit set of TextUtils#CAP_MODE_*, masked by the inputType argument.
 * This method also supports faking an additional space after the string passed in argument,
 * to support cases where a space will be added automatically, like in phantom space
 * state for example.
 * Note that for English, we are using American typography rules (which are not specific to
 * American English, it's just the most common set of rules for English).
 *
 * @param inputType a mask of the caps modes to test for.
 * @param spacingAndPunctuations the values of the settings to use for locale and separators.
 * @param hasSpaceBefore if we should consider there should be a space after the string.
 * @return the caps modes that should be on as a set of bits
 */
public int getCursorCapsMode(final int inputType,
        final SpacingAndPunctuations spacingAndPunctuations, final boolean hasSpaceBefore) {
    mIC = mParent.getCurrentInputConnection();
    if (!isConnected()) {
        return Constants.TextUtils.CAP_MODE_OFF;
    }
    if (!TextUtils.isEmpty(mComposingText)) {
        if (hasSpaceBefore) {
            // If we have some composing text and a space before, then we should have
            // MODE_CHARACTERS and MODE_WORDS on.
            return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & inputType;
        }
        // We have some composing text - we should be in MODE_CHARACTERS only.
        return TextUtils.CAP_MODE_CHARACTERS & inputType;
    }
    // TODO: this will generally work, but there may be cases where the buffer contains SOME
    // information but not enough to determine the caps mode accurately. This may happen after
    // heavy pressing of delete, for example DEFAULT_TEXT_CACHE_SIZE - 5 times or so.
    // getCapsMode should be updated to be able to return a "not enough info" result so that
    // we can get more context only when needed.
    if (TextUtils.isEmpty(mCommittedTextBeforeComposingText) && 0 != mExpectedSelStart) {
        if (!reloadTextCache()) {
            Log.w(TAG, "Unable to connect to the editor. "
                    + "Setting caps mode without knowing text.");
        }
    }
    // This never calls InputConnection#getCapsMode - in fact, it's a static method that
    // never blocks or initiates IPC.
    // TODO: don't call #toString() here. Instead, all accesses to
    // mCommittedTextBeforeComposingText should be done on the main thread.
    return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText.toString(), inputType,
            spacingAndPunctuations, hasSpaceBefore);
}
 
Example 7
Source File: RichInputConnection.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the caps modes we should be in after this specific string.
 *
 * This returns a bit set of TextUtils#CAP_MODE_*, masked by the inputType argument.
 * This method also supports faking an additional space after the string passed in argument,
 * to support cases where a space will be added automatically, like in phantom space
 * state for example.
 * Note that for English, we are using American typography rules (which are not specific to
 * American English, it's just the most common set of rules for English).
 *
 * @param inputType a mask of the caps modes to test for.
 * @param spacingAndPunctuations the values of the settings to use for locale and separators.
 * @param hasSpaceBefore if we should consider there should be a space after the string.
 * @return the caps modes that should be on as a set of bits
 */
public int getCursorCapsMode(final int inputType,
        final SpacingAndPunctuations spacingAndPunctuations, final boolean hasSpaceBefore) {
    mIC = mParent.getCurrentInputConnection();
    if (!isConnected()) {
        return Constants.TextUtils.CAP_MODE_OFF;
    }
    if (!TextUtils.isEmpty(mComposingText)) {
        if (hasSpaceBefore) {
            // If we have some composing text and a space before, then we should have
            // MODE_CHARACTERS and MODE_WORDS on.
            return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & inputType;
        }
        // We have some composing text - we should be in MODE_CHARACTERS only.
        return TextUtils.CAP_MODE_CHARACTERS & inputType;
    }
    // TODO: this will generally work, but there may be cases where the buffer contains SOME
    // information but not enough to determine the caps mode accurately. This may happen after
    // heavy pressing of delete, for example DEFAULT_TEXT_CACHE_SIZE - 5 times or so.
    // getCapsMode should be updated to be able to return a "not enough info" result so that
    // we can get more context only when needed.
    if (TextUtils.isEmpty(mCommittedTextBeforeComposingText) && 0 != mExpectedSelStart) {
        if (!reloadTextCache()) {
            Log.w(TAG, "Unable to connect to the editor. "
                    + "Setting caps mode without knowing text.");
        }
    }
    // This never calls InputConnection#getCapsMode - in fact, it's a static method that
    // never blocks or initiates IPC.
    // TODO: don't call #toString() here. Instead, all accesses to
    // mCommittedTextBeforeComposingText should be done on the main thread.
    return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText.toString(), inputType,
            spacingAndPunctuations, hasSpaceBefore);
}
 
Example 8
Source File: RichInputConnection.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the caps modes we should be in after this specific string.
 *
 * This returns a bit set of TextUtils#CAP_MODE_*, masked by the inputType argument.
 * This method also supports faking an additional space after the string passed in argument,
 * to support cases where a space will be added automatically, like in phantom space
 * state for example.
 * Note that for English, we are using American typography rules (which are not specific to
 * American English, it's just the most common set of rules for English).
 *
 * @param inputType a mask of the caps modes to test for.
 * @param spacingAndPunctuations the values of the settings to use for locale and separators.
 * @param hasSpaceBefore if we should consider there should be a space after the string.
 * @return the caps modes that should be on as a set of bits
 */
public int getCursorCapsMode(final int inputType,
        final SpacingAndPunctuations spacingAndPunctuations, final boolean hasSpaceBefore) {
    mIC = mParent.getCurrentInputConnection();
    if (!isConnected()) {
        return Constants.TextUtils.CAP_MODE_OFF;
    }
    if (!TextUtils.isEmpty(mComposingText)) {
        if (hasSpaceBefore) {
            // If we have some composing text and a space before, then we should have
            // MODE_CHARACTERS and MODE_WORDS on.
            return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & inputType;
        }
        // We have some composing text - we should be in MODE_CHARACTERS only.
        return TextUtils.CAP_MODE_CHARACTERS & inputType;
    }
    // TODO: this will generally work, but there may be cases where the buffer contains SOME
    // information but not enough to determine the caps mode accurately. This may happen after
    // heavy pressing of delete, for example DEFAULT_TEXT_CACHE_SIZE - 5 times or so.
    // getCapsMode should be updated to be able to return a "not enough info" result so that
    // we can get more context only when needed.
    if (TextUtils.isEmpty(mCommittedTextBeforeComposingText) && 0 != mExpectedSelStart) {
        if (!reloadTextCache()) {
            Log.w(TAG, "Unable to connect to the editor. "
                    + "Setting caps mode without knowing text.");
        }
    }
    // This never calls InputConnection#getCapsMode - in fact, it's a static method that
    // never blocks or initiates IPC.
    // TODO: don't call #toString() here. Instead, all accesses to
    // mCommittedTextBeforeComposingText should be done on the main thread.
    return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText.toString(), inputType,
            spacingAndPunctuations, hasSpaceBefore);
}
 
Example 9
Source File: CapsModeUtilsTests.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private static void allPathsForCaps(final CharSequence cs, final int expectedResult,
        final SpacingAndPunctuations sp, final boolean hasSpaceBefore) {
    final int c = TextUtils.CAP_MODE_CHARACTERS;
    final int w = TextUtils.CAP_MODE_WORDS;
    final int s = TextUtils.CAP_MODE_SENTENCES;
    onePathForCaps(cs, expectedResult, c | w | s, sp, hasSpaceBefore);
    onePathForCaps(cs, expectedResult, w | s, sp, hasSpaceBefore);
    onePathForCaps(cs, expectedResult, c | s, sp, hasSpaceBefore);
    onePathForCaps(cs, expectedResult, c | w, sp, hasSpaceBefore);
    onePathForCaps(cs, expectedResult, c, sp, hasSpaceBefore);
    onePathForCaps(cs, expectedResult, w, sp, hasSpaceBefore);
    onePathForCaps(cs, expectedResult, s, sp, hasSpaceBefore);
}