Make WordComposer aware of capitalized word
Change-Id: If6c0edef2334f018f2e04c6034f8ce747206f150
This commit is contained in:
parent
6602b03e80
commit
ea843f2a24
3 changed files with 27 additions and 57 deletions
|
@ -192,7 +192,6 @@ public class Recorrection implements SharedPreferences.OnSharedPreferenceChangeL
|
||||||
new int[] { touching.mWord.charAt(i) }, WordComposer.NOT_A_COORDINATE,
|
new int[] { touching.mWord.charAt(i) }, WordComposer.NOT_A_COORDINATE,
|
||||||
WordComposer.NOT_A_COORDINATE);
|
WordComposer.NOT_A_COORDINATE);
|
||||||
}
|
}
|
||||||
foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.mWord.charAt(0)));
|
|
||||||
}
|
}
|
||||||
// Found a match, show suggestions
|
// Found a match, show suggestions
|
||||||
if (foundWord != null || alternatives != null) {
|
if (foundWord != null || alternatives != null) {
|
||||||
|
|
|
@ -1408,10 +1408,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mHasUncommittedTypedChars) {
|
if (mHasUncommittedTypedChars) {
|
||||||
if (mComposingStringBuilder.length() == 0 && switcher.isAlphabetMode()
|
|
||||||
&& switcher.isShiftedOrShiftLocked()) {
|
|
||||||
mWordComposer.setFirstCharCapitalized(true);
|
|
||||||
}
|
|
||||||
mComposingStringBuilder.append((char) code);
|
mComposingStringBuilder.append((char) code);
|
||||||
mWordComposer.add(code, keyCodes, x, y);
|
mWordComposer.add(code, keyCodes, x, y);
|
||||||
final InputConnection ic = getCurrentInputConnection();
|
final InputConnection ic = getCurrentInputConnection();
|
||||||
|
|
|
@ -33,15 +33,9 @@ public class WordComposer {
|
||||||
*/
|
*/
|
||||||
private ArrayList<int[]> mCodes;
|
private ArrayList<int[]> mCodes;
|
||||||
|
|
||||||
private int mTypedLength;
|
|
||||||
private int[] mXCoordinates;
|
private int[] mXCoordinates;
|
||||||
private int[] mYCoordinates;
|
private int[] mYCoordinates;
|
||||||
|
|
||||||
/**
|
|
||||||
* The word chosen from the candidate list, until it is committed.
|
|
||||||
*/
|
|
||||||
private String mPreferredWord;
|
|
||||||
|
|
||||||
private StringBuilder mTypedWord;
|
private StringBuilder mTypedWord;
|
||||||
|
|
||||||
private int mCapsCount;
|
private int mCapsCount;
|
||||||
|
@ -57,7 +51,6 @@ public class WordComposer {
|
||||||
final int N = BinaryDictionary.MAX_WORD_LENGTH;
|
final int N = BinaryDictionary.MAX_WORD_LENGTH;
|
||||||
mCodes = new ArrayList<int[]>(N);
|
mCodes = new ArrayList<int[]>(N);
|
||||||
mTypedWord = new StringBuilder(N);
|
mTypedWord = new StringBuilder(N);
|
||||||
mTypedLength = 0;
|
|
||||||
mXCoordinates = new int[N];
|
mXCoordinates = new int[N];
|
||||||
mYCoordinates = new int[N];
|
mYCoordinates = new int[N];
|
||||||
}
|
}
|
||||||
|
@ -68,14 +61,12 @@ public class WordComposer {
|
||||||
|
|
||||||
public void init(WordComposer source) {
|
public void init(WordComposer source) {
|
||||||
mCodes = new ArrayList<int[]>(source.mCodes);
|
mCodes = new ArrayList<int[]>(source.mCodes);
|
||||||
mPreferredWord = source.mPreferredWord;
|
|
||||||
mTypedWord = new StringBuilder(source.mTypedWord);
|
mTypedWord = new StringBuilder(source.mTypedWord);
|
||||||
mCapsCount = source.mCapsCount;
|
|
||||||
mAutoCapitalized = source.mAutoCapitalized;
|
|
||||||
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
|
||||||
mTypedLength = source.mTypedLength;
|
|
||||||
mXCoordinates = source.mXCoordinates;
|
mXCoordinates = source.mXCoordinates;
|
||||||
mYCoordinates = source.mYCoordinates;
|
mYCoordinates = source.mYCoordinates;
|
||||||
|
mCapsCount = source.mCapsCount;
|
||||||
|
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
||||||
|
mAutoCapitalized = source.mAutoCapitalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,19 +74,17 @@ public class WordComposer {
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public void reset() {
|
||||||
mCodes.clear();
|
mCodes.clear();
|
||||||
mTypedLength = 0;
|
|
||||||
mIsFirstCharCapitalized = false;
|
|
||||||
mPreferredWord = null;
|
|
||||||
mTypedWord.setLength(0);
|
mTypedWord.setLength(0);
|
||||||
mCapsCount = 0;
|
mCapsCount = 0;
|
||||||
|
mIsFirstCharCapitalized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of keystrokes in the composing word.
|
* Number of keystrokes in the composing word.
|
||||||
* @return the number of keystrokes
|
* @return the number of keystrokes
|
||||||
*/
|
*/
|
||||||
public int size() {
|
public final int size() {
|
||||||
return mCodes.size();
|
return mTypedWord.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,21 +104,28 @@ public class WordComposer {
|
||||||
return mYCoordinates;
|
return mYCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isFirstCharCapitalized(int index, int codePoint, boolean previous) {
|
||||||
|
if (index == 0) return Character.isUpperCase(codePoint);
|
||||||
|
return previous && Character.isLowerCase(codePoint);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of
|
* Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of
|
||||||
* the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
|
* the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
|
||||||
* @param codes the array of unicode values
|
* @param codes the array of unicode values
|
||||||
*/
|
*/
|
||||||
public void add(int primaryCode, int[] codes, int x, int y) {
|
public void add(int primaryCode, int[] codes, int x, int y) {
|
||||||
|
final int newIndex = size();
|
||||||
mTypedWord.append((char) primaryCode);
|
mTypedWord.append((char) primaryCode);
|
||||||
correctPrimaryJuxtapos(primaryCode, codes);
|
correctPrimaryJuxtapos(primaryCode, codes);
|
||||||
mCodes.add(codes);
|
mCodes.add(codes);
|
||||||
if (mTypedLength < BinaryDictionary.MAX_WORD_LENGTH) {
|
if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
|
||||||
mXCoordinates[mTypedLength] = x;
|
mXCoordinates[newIndex] = x;
|
||||||
mYCoordinates[mTypedLength] = y;
|
mYCoordinates[newIndex] = y;
|
||||||
}
|
}
|
||||||
++mTypedLength;
|
mIsFirstCharCapitalized = isFirstCharCapitalized(
|
||||||
if (Character.isUpperCase((char) primaryCode)) mCapsCount++;
|
newIndex, primaryCode, mIsFirstCharCapitalized);
|
||||||
|
if (Character.isUpperCase(primaryCode)) mCapsCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,16 +147,16 @@ public class WordComposer {
|
||||||
* Delete the last keystroke as a result of hitting backspace.
|
* Delete the last keystroke as a result of hitting backspace.
|
||||||
*/
|
*/
|
||||||
public void deleteLast() {
|
public void deleteLast() {
|
||||||
final int codesSize = mCodes.size();
|
final int size = size();
|
||||||
if (codesSize > 0) {
|
if (size > 0) {
|
||||||
mCodes.remove(codesSize - 1);
|
final int lastPos = size - 1;
|
||||||
final int lastPos = mTypedWord.length() - 1;
|
char lastChar = mTypedWord.charAt(lastPos);
|
||||||
char last = mTypedWord.charAt(lastPos);
|
mCodes.remove(lastPos);
|
||||||
mTypedWord.deleteCharAt(lastPos);
|
mTypedWord.deleteCharAt(lastPos);
|
||||||
if (Character.isUpperCase(last)) mCapsCount--;
|
if (Character.isUpperCase(lastChar)) mCapsCount--;
|
||||||
}
|
}
|
||||||
if (mTypedLength > 0) {
|
if (size() == 0) {
|
||||||
--mTypedLength;
|
mIsFirstCharCapitalized = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,17 +165,12 @@ public class WordComposer {
|
||||||
* @return the word that was typed so far
|
* @return the word that was typed so far
|
||||||
*/
|
*/
|
||||||
public CharSequence getTypedWord() {
|
public CharSequence getTypedWord() {
|
||||||
int wordSize = mCodes.size();
|
if (size() == 0) {
|
||||||
if (wordSize == 0) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return mTypedWord;
|
return mTypedWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstCharCapitalized(boolean capitalized) {
|
|
||||||
mIsFirstCharCapitalized = capitalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the user typed a capital letter as the first letter in the word
|
* Whether or not the user typed a capital letter as the first letter in the word
|
||||||
* @return capitalization preference
|
* @return capitalization preference
|
||||||
|
@ -196,22 +187,6 @@ public class WordComposer {
|
||||||
return (mCapsCount > 0) && (mCapsCount == size());
|
return (mCapsCount > 0) && (mCapsCount == size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores the user's selected word, before it is actually committed to the text field.
|
|
||||||
* @param preferred
|
|
||||||
*/
|
|
||||||
public void setPreferredWord(String preferred) {
|
|
||||||
mPreferredWord = preferred;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the word chosen by the user, or the typed word if no other word was chosen.
|
|
||||||
* @return the preferred word
|
|
||||||
*/
|
|
||||||
public CharSequence getPreferredWord() {
|
|
||||||
return mPreferredWord != null ? mPreferredWord : getTypedWord();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if more than one character is upper case, otherwise returns false.
|
* Returns true if more than one character is upper case, otherwise returns false.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue