aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java1
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java4
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestionsView.java9
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java39
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java79
5 files changed, 60 insertions, 72 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java b/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java
index 75efa52f2..94615a71f 100644
--- a/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java
+++ b/java/src/com/android/inputmethod/deprecated/recorrection/Recorrection.java
@@ -192,7 +192,6 @@ public class Recorrection implements SharedPreferences.OnSharedPreferenceChangeL
new int[] { touching.mWord.charAt(i) }, WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE);
}
- foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.mWord.charAt(0)));
}
// Found a match, show suggestions
if (foundWord != null || alternatives != null) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b467a32a2..fdf58f6ef 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1408,10 +1408,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
if (mHasUncommittedTypedChars) {
- if (mComposingStringBuilder.length() == 0 && switcher.isAlphabetMode()
- && switcher.isShiftedOrShiftLocked()) {
- mWordComposer.setFirstCharCapitalized(true);
- }
mComposingStringBuilder.append((char) code);
mWordComposer.add(code, keyCodes, x, y);
final InputConnection ic = getCurrentInputConnection();
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
index 695e60ffd..15a0cec2e 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
@@ -230,10 +230,13 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
@Override
public boolean dispatchTouchEvent(MotionEvent me) {
- final int x = (int)me.getX();
- final int y = (int)me.getY();
+ final int index = me.getActionIndex();
+ final int id = me.getPointerId(index);
+ final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
+ final int x = (int)me.getX(index);
+ final int y = (int)me.getY(index);
final boolean inside = (x >= 0 && x < getWidth() && y >= 0 && y < getHeight());
- if (inside) {
+ if (inside || tracker.isInSlidingKeyInput()) {
return super.dispatchTouchEvent(me);
} else {
dismissMoreKeysPanel();
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 380e73bc0..13beb4479 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -163,6 +163,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final int mColorTypedWord;
private final int mColorAutoCorrect;
private final int mColorSuggested;
+ private final float mAlphaObsoleted;
private final float mCenterSuggestionWeight;
private final int mCenterSuggestionIndex;
private final Drawable mMoreSuggestionsHint;
@@ -205,15 +206,26 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SuggestionsView, defStyle, R.style.SuggestionsViewStyle);
mSuggestionStripOption = a.getInt(R.styleable.SuggestionsView_suggestionStripOption, 0);
- mColorTypedWord = a.getColor(R.styleable.SuggestionsView_colorTypedWord, 0);
- mColorAutoCorrect = a.getColor(R.styleable.SuggestionsView_colorAutoCorrect, 0);
- mColorSuggested = a.getColor(R.styleable.SuggestionsView_colorSuggested, 0);
+ final float alphaTypedWord = getPercent(a,
+ R.styleable.SuggestionsView_alphaTypedWord, 100);
+ final float alphaAutoCorrect = getPercent(a,
+ R.styleable.SuggestionsView_alphaAutoCorrect, 100);
+ final float alphaSuggested = getPercent(a,
+ R.styleable.SuggestionsView_alphaSuggested, 100);
+ mAlphaObsoleted = getPercent(a, R.styleable.SuggestionsView_alphaSuggested, 100);
+ mColorTypedWord = applyAlpha(
+ a.getColor(R.styleable.SuggestionsView_colorTypedWord, 0), alphaTypedWord);
+ mColorAutoCorrect = applyAlpha(
+ a.getColor(R.styleable.SuggestionsView_colorAutoCorrect, 0), alphaAutoCorrect);
+ mColorSuggested = applyAlpha(
+ a.getColor(R.styleable.SuggestionsView_colorSuggested, 0), alphaSuggested);
mSuggestionsCountInStrip = a.getInt(
R.styleable.SuggestionsView_suggestionsCountInStrip,
DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
- mCenterSuggestionWeight = a.getInt(
+ mCenterSuggestionWeight = getPercent(a,
R.styleable.SuggestionsView_centerSuggestionPercentile,
- DEFAULT_CENTER_SUGGESTION_PERCENTILE) / 100.0f;
+ DEFAULT_CENTER_SUGGESTION_PERCENTILE);
+ mMoreSuggestionsHint = a.getDrawable(R.styleable.SuggestionsView_moreSuggestionsHint);
mMaxMoreSuggestionsRow = a.getInt(
R.styleable.SuggestionsView_maxMoreSuggestionsRow,
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
@@ -222,7 +234,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
a.recycle();
mCenterSuggestionIndex = mSuggestionsCountInStrip / 2;
- mMoreSuggestionsHint = res.getDrawable(R.drawable.more_suggestions_hint);
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
R.dimen.more_suggestions_bottom_gap);
@@ -235,6 +246,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
}
+ // Read integer value in TypedArray as percent.
+ private static float getPercent(TypedArray a, int index, int defValue) {
+ return a.getInt(index, defValue) / 100.0f;
+ }
+
// Read fraction value in TypedArray as float.
private static float getRatio(TypedArray a, int index) {
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
@@ -293,7 +309,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final SuggestedWordInfo info = (pos < suggestions.size())
? suggestions.getInfo(pos) : null;
if (info != null && info.isObsoleteSuggestedWord()) {
- return applyAlpha(color, 0.5f);
+ return applyAlpha(color, mAlphaObsoleted);
} else {
return color;
}
@@ -792,11 +808,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final int translatedY = moreKeysPanel.translateY(y);
if (mCheckingIfModalOrSlidingMode) {
- final int deltaX = Math.abs(x - mOriginX);
- final int deltaY = Math.abs(y - mOriginY);
- if (deltaX >= mMoreSuggestionsModalTolerance
- || deltaY >= mMoreSuggestionsModalTolerance) {
- // Decided to be in the sliding input mode
+ if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance
+ || mOriginY - y >= mMoreSuggestionsModalTolerance) {
+ // Decided to be in the sliding input mode only when the touch point has been moved
+ // upward.
mCheckingIfModalOrSlidingMode = false;
tracker.onShowMoreKeysPanel(
translatedX, translatedY, SystemClock.uptimeMillis(), moreKeysPanel);
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index af5e4b179..24519ad92 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -33,15 +33,9 @@ public class WordComposer {
*/
private ArrayList<int[]> mCodes;
- private int mTypedLength;
private int[] mXCoordinates;
private int[] mYCoordinates;
- /**
- * The word chosen from the candidate list, until it is committed.
- */
- private String mPreferredWord;
-
private StringBuilder mTypedWord;
private int mCapsCount;
@@ -57,7 +51,6 @@ public class WordComposer {
final int N = BinaryDictionary.MAX_WORD_LENGTH;
mCodes = new ArrayList<int[]>(N);
mTypedWord = new StringBuilder(N);
- mTypedLength = 0;
mXCoordinates = new int[N];
mYCoordinates = new int[N];
}
@@ -68,14 +61,12 @@ public class WordComposer {
public void init(WordComposer source) {
mCodes = new ArrayList<int[]>(source.mCodes);
- mPreferredWord = source.mPreferredWord;
mTypedWord = new StringBuilder(source.mTypedWord);
- mCapsCount = source.mCapsCount;
- mAutoCapitalized = source.mAutoCapitalized;
- mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
- mTypedLength = source.mTypedLength;
mXCoordinates = source.mXCoordinates;
mYCoordinates = source.mYCoordinates;
+ mCapsCount = source.mCapsCount;
+ mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
+ mAutoCapitalized = source.mAutoCapitalized;
}
/**
@@ -83,19 +74,17 @@ public class WordComposer {
*/
public void reset() {
mCodes.clear();
- mTypedLength = 0;
- mIsFirstCharCapitalized = false;
- mPreferredWord = null;
mTypedWord.setLength(0);
mCapsCount = 0;
+ mIsFirstCharCapitalized = false;
}
/**
* Number of keystrokes in the composing word.
* @return the number of keystrokes
*/
- public int size() {
- return mCodes.size();
+ public final int size() {
+ return mTypedWord.length();
}
/**
@@ -115,21 +104,28 @@ public class WordComposer {
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
* the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
* @param codes the array of unicode values
*/
public void add(int primaryCode, int[] codes, int x, int y) {
+ final int newIndex = size();
mTypedWord.append((char) primaryCode);
correctPrimaryJuxtapos(primaryCode, codes);
mCodes.add(codes);
- if (mTypedLength < BinaryDictionary.MAX_WORD_LENGTH) {
- mXCoordinates[mTypedLength] = x;
- mYCoordinates[mTypedLength] = y;
+ if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) {
+ mXCoordinates[newIndex] = x;
+ mYCoordinates[newIndex] = y;
}
- ++mTypedLength;
- if (Character.isUpperCase((char) primaryCode)) mCapsCount++;
+ mIsFirstCharCapitalized = isFirstCharCapitalized(
+ 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.
*/
public void deleteLast() {
- final int codesSize = mCodes.size();
- if (codesSize > 0) {
- mCodes.remove(codesSize - 1);
- final int lastPos = mTypedWord.length() - 1;
- char last = mTypedWord.charAt(lastPos);
+ final int size = size();
+ if (size > 0) {
+ final int lastPos = size - 1;
+ char lastChar = mTypedWord.charAt(lastPos);
+ mCodes.remove(lastPos);
mTypedWord.deleteCharAt(lastPos);
- if (Character.isUpperCase(last)) mCapsCount--;
+ if (Character.isUpperCase(lastChar)) mCapsCount--;
}
- if (mTypedLength > 0) {
- --mTypedLength;
+ if (size() == 0) {
+ mIsFirstCharCapitalized = false;
}
}
@@ -169,17 +165,12 @@ public class WordComposer {
* @return the word that was typed so far
*/
public CharSequence getTypedWord() {
- int wordSize = mCodes.size();
- if (wordSize == 0) {
+ if (size() == 0) {
return null;
}
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
* @return capitalization preference
@@ -197,22 +188,6 @@ public class WordComposer {
}
/**
- * 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.
*/
public boolean isMostlyCaps() {