am 324cc1db: Merge "Tell the shift mode to the word composer." into jb-mr1-dev
* commit '324cc1dbe60a39b65989356067a03f2ff9fb1a86': Tell the shift mode to the word composer.main
commit
4034699a0b
|
@ -39,6 +39,7 @@ import com.android.inputmethod.latin.R;
|
|||
import com.android.inputmethod.latin.SettingsValues;
|
||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||
import com.android.inputmethod.latin.Utils;
|
||||
import com.android.inputmethod.latin.WordComposer;
|
||||
|
||||
public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
||||
|
@ -402,4 +403,16 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getManualCapsMode() {
|
||||
switch (getKeyboard().mId.mElementId) {
|
||||
case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
|
||||
case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
|
||||
return WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED;
|
||||
case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
|
||||
return WordComposer.CAPS_MODE_MANUAL_SHIFTED;
|
||||
default:
|
||||
return WordComposer.CAPS_MODE_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1093,6 +1093,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
return mConnection.getCursorCapsMode(inputType);
|
||||
}
|
||||
|
||||
// Factor in auto-caps and manual caps and compute the current caps mode.
|
||||
private int getActualCapsMode() {
|
||||
final int manual = mKeyboardSwitcher.getManualCapsMode();
|
||||
if (manual != WordComposer.CAPS_MODE_OFF) return manual;
|
||||
final int auto = getCurrentAutoCapsState();
|
||||
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;
|
||||
}
|
||||
|
||||
private void swapSwapperAndSpace() {
|
||||
CharSequence lastTwo = mConnection.getTextBeforeCursor(2, 0);
|
||||
// It is guaranteed lastTwo.charAt(1) is a swapper - else this method is not called.
|
||||
|
@ -1377,8 +1389,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
}
|
||||
mConnection.endBatchEdit();
|
||||
// TODO: Should handle TextUtils.CAP_MODE_CHARACTER.
|
||||
mWordComposer.setAutoCapitalized(
|
||||
getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
|
||||
mWordComposer.setCapitalizedModeAtStartComposingTime(getActualCapsMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1613,8 +1624,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mWordComposer.add(primaryCode, keyX, keyY);
|
||||
// If it's the first letter, make note of auto-caps state
|
||||
if (mWordComposer.size() == 1) {
|
||||
mWordComposer.setAutoCapitalized(
|
||||
getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
|
||||
mWordComposer.setCapitalizedModeAtStartComposingTime(getActualCapsMode());
|
||||
}
|
||||
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
||||
} else {
|
||||
|
@ -2012,7 +2022,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
final CharSequence prevWord
|
||||
= mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 2);
|
||||
final String secondWord;
|
||||
if (mWordComposer.isAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
||||
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
||||
secondWord = suggestion.toString().toLowerCase(
|
||||
mSubtypeSwitcher.getCurrentSubtypeLocale());
|
||||
} else {
|
||||
|
|
|
@ -309,7 +309,7 @@ public class Suggest {
|
|||
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
||||
new ArrayList<SuggestedWordInfo>(suggestionsSet);
|
||||
final int suggestionsCount = suggestionsContainer.size();
|
||||
final boolean isFirstCharCapitalized = wordComposer.isAutoCapitalized();
|
||||
final boolean isFirstCharCapitalized = wordComposer.wasAutoCapitalized();
|
||||
// TODO: Handle the manual temporary shifted mode.
|
||||
// TODO: Should handle TextUtils.CAP_MODE_CHARACTER.
|
||||
final boolean isAllUpperCase = false;
|
||||
|
|
|
@ -27,6 +27,14 @@ import java.util.Arrays;
|
|||
public class WordComposer {
|
||||
private static final int N = BinaryDictionary.MAX_WORD_LENGTH;
|
||||
|
||||
public static final int CAPS_MODE_OFF = 0;
|
||||
// 1 is shift bit, 2 is caps bit, 4 is auto bit but this is just a convention as these bits
|
||||
// aren't used anywhere in the code
|
||||
public static final int CAPS_MODE_MANUAL_SHIFTED = 0x1;
|
||||
public static final int CAPS_MODE_MANUAL_SHIFT_LOCKED = 0x3;
|
||||
public static final int CAPS_MODE_AUTO_SHIFTED = 0x5;
|
||||
public static final int CAPS_MODE_AUTO_SHIFT_LOCKED = 0x7;
|
||||
|
||||
private int[] mPrimaryKeyCodes;
|
||||
private final InputPointers mInputPointers = new InputPointers(N);
|
||||
private final StringBuilder mTypedWord;
|
||||
|
@ -37,7 +45,7 @@ public class WordComposer {
|
|||
// Cache these values for performance
|
||||
private int mCapsCount;
|
||||
private int mDigitsCount;
|
||||
private boolean mAutoCapitalized;
|
||||
private int mCapitalizedMode;
|
||||
private int mTrailingSingleQuotesCount;
|
||||
private int mCodePointSize;
|
||||
|
||||
|
@ -63,7 +71,7 @@ public class WordComposer {
|
|||
mCapsCount = source.mCapsCount;
|
||||
mDigitsCount = source.mDigitsCount;
|
||||
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
||||
mAutoCapitalized = source.mAutoCapitalized;
|
||||
mCapitalizedMode = source.mCapitalizedMode;
|
||||
mTrailingSingleQuotesCount = source.mTrailingSingleQuotesCount;
|
||||
mIsResumed = source.mIsResumed;
|
||||
mIsBatchMode = source.mIsBatchMode;
|
||||
|
@ -275,20 +283,27 @@ public class WordComposer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Saves the reason why the word is capitalized - whether it was automatic or
|
||||
* due to the user hitting shift in the middle of a sentence.
|
||||
* @param auto whether it was an automatic capitalization due to start of sentence
|
||||
* Saves the caps mode at the start of composing.
|
||||
*
|
||||
* WordComposer needs to know about this for several reasons. The first is, we need to know
|
||||
* after the fact what the reason was, to register the correct form into the user history
|
||||
* dictionary: if the word was automatically capitalized, we should insert it in all-lower
|
||||
* case but if it's a manual pressing of shift, then it should be inserted as is.
|
||||
* Also, batch input needs to know about the current caps mode to display correctly
|
||||
* capitalized suggestions.
|
||||
* @param mode the mode at the time of start
|
||||
*/
|
||||
public void setAutoCapitalized(boolean auto) {
|
||||
mAutoCapitalized = auto;
|
||||
public void setCapitalizedModeAtStartComposingTime(final int mode) {
|
||||
mCapitalizedMode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the word was automatically capitalized.
|
||||
* @return whether the word was automatically capitalized
|
||||
*/
|
||||
public boolean isAutoCapitalized() {
|
||||
return mAutoCapitalized;
|
||||
public boolean wasAutoCapitalized() {
|
||||
return mCapitalizedMode == CAPS_MODE_AUTO_SHIFT_LOCKED
|
||||
|| mCapitalizedMode == CAPS_MODE_AUTO_SHIFTED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue