Java Code Examples for android.text.TextUtils#CAP_MODE_CHARACTERS

The following examples show how to use android.text.TextUtils#CAP_MODE_CHARACTERS . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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
/**
 * 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 Project: simple-keyboard   File: CapsModeUtils.java    License: 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
/**
 * 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 Project: Indic-Keyboard   File: CapsModeUtils.java    License: 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
/**
 * 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
/**
 * 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
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 9
/**
 * 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 10
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 11
/**
 * 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 12
Source Project: simple-keyboard   File: KeyboardState.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: AOSP-Kayboard-7.1.2   File: InputLogic.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 14
/**
 * 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 15
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 16
Source Project: Indic-Keyboard   File: InputLogic.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 17
/**
 * 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 18
Source Project: Indic-Keyboard   File: KeyboardState.java    License: Apache License 2.0 5 votes vote down vote up
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 19
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);
}