Java Code Examples for android.text.TextUtils.CAP_MODE_CHARACTERS

The following are Jave code examples for showing how to use CAP_MODE_CHARACTERS of the android.text.TextUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: simple-keyboard   File: CapsModeUtils.java   View Source Code Vote up 6 votes
/**
 * 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
Project: AOSP-Kayboard-7.1.2   File: CapsModeUtils.java   View Source Code Vote up 6 votes
/**
 * 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 3
Project: simple-keyboard   File: InputLogic.java   View Source Code Vote up 5 votes
/**
 * Factor in auto-caps and manual caps and compute the current caps mode.
 * @param settingsValues the current settings values.
 * @param keyboardShiftMode the current shift mode of the keyboard. See
 *   KeyboardSwitcher#getKeyboardShiftMode() for possible values.
 * @return the actual caps mode the keyboard is in right now.
 */
private int getActualCapsMode(final SettingsValues settingsValues,
        final int keyboardShiftMode) {
    if (keyboardShiftMode != CAPS_MODE_AUTO_SHIFTED) {
        return keyboardShiftMode;
    }
    final int auto = getCurrentAutoCapsState(settingsValues);
    if (0 != (auto & TextUtils.CAP_MODE_CHARACTERS)) {
        return CAPS_MODE_AUTO_SHIFT_LOCKED;
    }
    if (0 != auto) {
        return CAPS_MODE_AUTO_SHIFTED;
    }
    return CAPS_MODE_OFF;
}
 
Example 4
Project: simple-keyboard   File: RichInputConnection.java   View Source Code Vote up 5 votes
/**
 * 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.
 * @return the caps modes that should be on as a set of bits
 */
public int getCursorCapsMode(final int inputType, final SpacingAndPunctuations spacingAndPunctuations) {
    mIC = mParent.getCurrentInputConnection();
    if (!isConnected()) {
        return Constants.TextUtils.CAP_MODE_OFF;
    }
    if (!TextUtils.isEmpty(mComposingText)) {
        // 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);
}
 
Example 5
Project: simple-keyboard   File: KeyboardState.java   View Source Code Vote up 5 votes
public void onPressKey(final int code, final boolean isSinglePointer, final int autoCapsFlags,
        final int recapitalizeMode) {
    if (DEBUG_EVENT) {
        Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code)
                + " single=" + isSinglePointer
                + " " + stateToString(autoCapsFlags, recapitalizeMode));
    }
    if (code != Constants.CODE_SHIFT) {
        // Because the double tap shift key timer is to detect two consecutive shift key press,
        // it should be canceled when a non-shift key is pressed.
        mSwitchActions.cancelDoubleTapShiftKeyTimer();
    }
    if (code == Constants.CODE_SHIFT) {
        onPressShift();
    } else if (code == Constants.CODE_CAPSLOCK) {
        // Nothing to do here. See {@link #onReleaseKey(int,boolean)}.
    } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
        onPressSymbol(autoCapsFlags, recapitalizeMode);
    } else {
        mShiftKeyState.onOtherKeyPressed();
        mSymbolKeyState.onOtherKeyPressed();
        // It is required to reset the auto caps state when all of the following conditions
        // are met:
        // 1) two or more fingers are in action
        // 2) in alphabet layout
        // 3) not in all characters caps mode
        // As for #3, please note that it's required to check even when the auto caps mode is
        // off because, for example, we may be in the #1 state within the manual temporary
        // shifted mode.
        if (!isSinglePointer && mIsAlphabetMode
                && autoCapsFlags != TextUtils.CAP_MODE_CHARACTERS) {
            final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted()
                    || (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing());
            if (needsToResetAutoCaps) {
                mSwitchActions.setAlphabetKeyboard();
            }
        }
    }
}
 
Example 6
Project: AOSP-Kayboard-7.1.2   File: InputLogic.java   View Source Code Vote up 5 votes
/**
 * Factor in auto-caps and manual caps and compute the current caps mode.
 * @param settingsValues the current settings values.
 * @param keyboardShiftMode the current shift mode of the keyboard. See
 *   KeyboardSwitcher#getKeyboardShiftMode() for possible values.
 * @return the actual caps mode the keyboard is in right now.
 */
private int getActualCapsMode(final SettingsValues settingsValues,
        final int keyboardShiftMode) {
    if (keyboardShiftMode != WordComposer.CAPS_MODE_AUTO_SHIFTED) {
        return keyboardShiftMode;
    }
    final int auto = getCurrentAutoCapsState(settingsValues);
    if (0 != (auto & TextUtils.CAP_MODE_CHARACTERS)) {
        return WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED;
    }
    if (0 != auto) {
        return WordComposer.CAPS_MODE_AUTO_SHIFTED;
    }
    return WordComposer.CAPS_MODE_OFF;
}
 
Example 7
Project: AOSP-Kayboard-7.1.2   File: RichInputConnection.java   View Source Code Vote up 5 votes
/**
 * 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
Project: AOSP-Kayboard-7.1.2   File: KeyboardState.java   View Source Code Vote up 5 votes
public void onPressKey(final int code, final boolean isSinglePointer, final int autoCapsFlags,
        final int recapitalizeMode) {
    if (DEBUG_EVENT) {
        Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code)
                + " single=" + isSinglePointer
                + " " + stateToString(autoCapsFlags, recapitalizeMode));
    }
    if (code != Constants.CODE_SHIFT) {
        // Because the double tap shift key timer is to detect two consecutive shift key press,
        // it should be canceled when a non-shift key is pressed.
        mSwitchActions.cancelDoubleTapShiftKeyTimer();
    }
    if (code == Constants.CODE_SHIFT) {
        onPressShift();
    } else if (code == Constants.CODE_CAPSLOCK) {
        // Nothing to do here. See {@link #onReleaseKey(int,boolean)}.
    } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
        onPressSymbol(autoCapsFlags, recapitalizeMode);
    } else {
        mShiftKeyState.onOtherKeyPressed();
        mSymbolKeyState.onOtherKeyPressed();
        // It is required to reset the auto caps state when all of the following conditions
        // are met:
        // 1) two or more fingers are in action
        // 2) in alphabet layout
        // 3) not in all characters caps mode
        // As for #3, please note that it's required to check even when the auto caps mode is
        // off because, for example, we may be in the #1 state within the manual temporary
        // shifted mode.
        if (!isSinglePointer && mIsAlphabetMode
                && autoCapsFlags != TextUtils.CAP_MODE_CHARACTERS) {
            final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted()
                    || (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing());
            if (needsToResetAutoCaps) {
                mSwitchActions.setAlphabetKeyboard();
            }
        }
    }
}