diff options
Diffstat (limited to 'java/src')
8 files changed, 185 insertions, 31 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 1b0e488bc..2623dcc03 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -113,7 +113,7 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat { case MotionEvent.ACTION_HOVER_EXIT: // Make sure we're not getting an EXIT event because the user slid // off the keyboard area, then force a key press. - if (pointInView(x, y)) { + if (pointInView(x, y) && (key != null)) { getAccessibilityNodeProvider().simulateKeyPress(key); } //$FALL-THROUGH$ diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index c3f5e7da2..45ed34ed2 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -66,11 +66,14 @@ public class Key { private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08; private static final int LABEL_FLAGS_FONT_NORMAL = 0x10; private static final int LABEL_FLAGS_FONT_MONO_SPACE = 0x20; - private static final int LABEL_FLAGS_FOLLOW_KEY_RATIO_MASK = 0x1C0; + // Start of key text ratio enum values + private static final int LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK = 0x1C0; private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO = 0x40; private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80; private static final int LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO = 0xC0; - private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x100; + private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO = 0x100; + private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x140; + // End of key text ratio mask enum values private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200; private static final int LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT = 0x400; private static final int LABEL_FLAGS_HAS_HINT_LABEL = 0x800; @@ -490,18 +493,21 @@ public class Key { } } - public int selectTextSize(int letter, int largeLetter, int label, int hintLabel) { - switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_RATIO_MASK) { - case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO: - return largeLetter; + public int selectTextSize(int letterSize, int largeLetterSize, int labelSize, + int largeLabelSize, int hintLabelSize) { + switch (mLabelFlags & LABEL_FLAGS_FOLLOW_KEY_TEXT_RATIO_MASK) { case LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO: - return letter; + return letterSize; + case LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO: + return largeLetterSize; case LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO: - return label; + return labelSize; + case LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO: + return largeLabelSize; case LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO: - return hintLabel; + return hintLabelSize; default: // No follow key ratio flag specified. - return StringUtils.codePointCount(mLabel) == 1 ? letter : label; + return StringUtils.codePointCount(mLabel) == 1 ? letterSize : labelSize; } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index cc0a1fb10..2045b0c82 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -191,6 +191,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { /* package */ final float mKeyLetterRatio; private final float mKeyLargeLetterRatio; private final float mKeyLabelRatio; + private final float mKeyLargeLabelRatio; private final float mKeyHintLetterRatio; private final float mKeyShiftedLetterHintRatio; private final float mKeyHintLabelRatio; @@ -200,6 +201,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public int mKeyLetterSize; public int mKeyLargeLetterSize; public int mKeyLabelSize; + public int mKeyLargeLabelSize; public int mKeyHintLetterSize; public int mKeyShiftedLetterHintSize; public int mKeyHintLabelSize; @@ -219,6 +221,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } else { mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio); } + mKeyLargeLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLabelRatio); mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio); mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio); mKeyShiftedLetterHintRatio = getRatio(a, @@ -254,6 +257,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio); if (mKeyLabelRatio >= 0.0f) mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio); + mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio); mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio); mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio); mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio); @@ -570,7 +574,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // For characters, use large font. For labels like "Done", use smaller font. paint.setTypeface(key.selectTypeface(params.mKeyTextStyle)); final int labelSize = key.selectTextSize(params.mKeyLetterSize, - params.mKeyLargeLetterSize, params.mKeyLabelSize, params.mKeyHintLabelSize); + params.mKeyLargeLetterSize, params.mKeyLabelSize, params.mKeyLargeLabelSize, + params.mKeyHintLabelSize); paint.setTextSize(labelSize); final float labelCharHeight = getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint); final float labelCharWidth = getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 2d80a798d..e3661a9f8 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -20,6 +20,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.ResearchLogger; import com.android.inputmethod.latin.define.ProductionFlag; @@ -30,8 +31,8 @@ import com.android.inputmethod.latin.define.ProductionFlag; * * The input events are {@link #onLoadKeyboard(String)}, {@link #onSaveKeyboardState()}, * {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)}, - * {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)}, - * {@link #onUpdateShiftState(boolean)}, {@link #onLongPressTimeout(int)}. + * {@link #onCodeInput(int, boolean, int)}, {@link #onCancelInput(boolean)}, + * {@link #onUpdateShiftState(int)}, {@link #onLongPressTimeout(int)}. * * The actions are {@link SwitchActions}'s methods. */ @@ -50,7 +51,7 @@ public class KeyboardState { public void setSymbolsShiftedKeyboard(); /** - * Request to call back {@link KeyboardState#onUpdateShiftState(boolean)}. + * Request to call back {@link KeyboardState#onUpdateShiftState(int)}. */ public void requestUpdatingShiftState(); @@ -371,14 +372,14 @@ public class KeyboardState { } } - public void onUpdateShiftState(boolean autoCaps) { + public void onUpdateShiftState(int autoCaps) { if (DEBUG_EVENT) { Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this); } updateAlphabetShiftState(autoCaps); } - private void updateAlphabetShiftState(boolean autoCaps) { + private void updateAlphabetShiftState(int autoCaps) { if (!mIsAlphabetMode) return; if (!mShiftKeyState.isReleasing()) { // Ignore update shift state event while the shift key is being pressed (including @@ -386,7 +387,7 @@ public class KeyboardState { return; } if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) { - if (mShiftKeyState.isReleasing() && autoCaps) { + if (mShiftKeyState.isReleasing() && autoCaps != Constants.TextUtils.CAP_MODE_OFF) { // Only when shift key is releasing, automatic temporary upper case will be set. setShifted(AUTOMATIC_SHIFT); } else { @@ -521,7 +522,7 @@ public class KeyboardState { return false; } - public void onCodeInput(int code, boolean isSinglePointer, boolean autoCaps) { + public void onCodeInput(int code, boolean isSinglePointer, int autoCaps) { if (DEBUG_EVENT) { Log.d(TAG, "onCodeInput: code=" + Keyboard.printableCode(code) + " single=" + isSinglePointer diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java index 7c2284569..e79db367c 100644 --- a/java/src/com/android/inputmethod/latin/Constants.java +++ b/java/src/com/android/inputmethod/latin/Constants.java @@ -106,6 +106,21 @@ public final class Constants { } } + public static class TextUtils { + /** + * Capitalization mode for {@link android.text.TextUtils#getCapsMode}: don't capitalize + * characters. This value may be used with + * {@link android.text.TextUtils#CAP_MODE_CHARACTERS}, + * {@link android.text.TextUtils#CAP_MODE_WORDS}, and + * {@link android.text.TextUtils#CAP_MODE_SENTENCES}. + */ + public static final int CAP_MODE_OFF = 0; + + private TextUtils() { + // This utility class is not publicly instantiable. + } + } + private Constants() { // This utility class is not publicly instantiable. } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a9ef91f1b..113941de3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1041,26 +1041,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen updateSuggestions(); } - public boolean getCurrentAutoCapsState() { - if (!mSettingsValues.mAutoCap) return false; + public int getCurrentAutoCapsState() { + if (!mSettingsValues.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF; final EditorInfo ei = getCurrentInputEditorInfo(); - if (ei == null) return false; + if (ei == null) return Constants.TextUtils.CAP_MODE_OFF; final int inputType = ei.inputType; - if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) return true; + if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) { + return TextUtils.CAP_MODE_CHARACTERS; + } final boolean noNeedToCheckCapsMode = (inputType & (InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_CAP_WORDS)) == 0; - if (noNeedToCheckCapsMode) return false; + if (noNeedToCheckCapsMode) return Constants.TextUtils.CAP_MODE_OFF; final InputConnection ic = getCurrentInputConnection(); - if (ic == null) return false; + if (ic == null) return Constants.TextUtils.CAP_MODE_OFF; // TODO: This blocking IPC call is heavy. Consider doing this without using IPC calls. // Note: getCursorCapsMode() returns the current capitalization mode that is any // combination of CAP_MODE_CHARACTERS, CAP_MODE_WORDS, and CAP_MODE_SENTENCES. 0 means none // of them. - return ic.getCursorCapsMode(inputType) != 0; + return ic.getCursorCapsMode(inputType); } // "ic" may be null @@ -1535,7 +1537,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ic != null) { // If it's the first letter, make note of auto-caps state if (mWordComposer.size() == 1) { - mWordComposer.setAutoCapitalized(getCurrentAutoCapsState()); + mWordComposer.setAutoCapitalized( + getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF); } ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); } @@ -1847,10 +1850,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void pickSuggestionManually(final int index, final CharSequence suggestion, int x, int y) { - final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); final InputConnection ic = getCurrentInputConnection(); - if (ic != null) ic.beginBatchEdit(); + if (null != ic) ic.beginBatchEdit(); + pickSuggestionManuallyWhileInBatchEdit(index, suggestion, x, y, ic); + if (null != ic) ic.endBatchEdit(); + } + public void pickSuggestionManuallyWhileInBatchEdit(final int index, + final CharSequence suggestion, final int x, final int y, final InputConnection ic) { + final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); // If this is a punctuation picked from the suggestion strip, pass it to onCodeInput if (suggestion.length() == 1 && isShowingPunctuationList()) { // Word separators are suggested before the user inputs something. @@ -1946,7 +1954,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.postUpdateSuggestions(); } } - if (null != ic) ic.endBatchEdit(); } /** diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index 566af7061..aa979a66f 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -444,7 +444,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } public static void keyboardState_onCodeInput( - final int code, final boolean isSinglePointer, final boolean autoCaps, + final int code, final boolean isSinglePointer, final int autoCaps, final KeyboardState keyboardState) { if (UnsLogGroup.KEYBOARDSTATE_ONCODEINPUT_ENABLED) { final String s = "onCodeInput: code=" + Keyboard.printableCode(code) diff --git a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java new file mode 100644 index 000000000..eb3881726 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin; + +public class UserHistoryForgettingCurveUtils { + private static final int FC_FREQ_MAX = 127; + /* package */ static final int COUNT_MAX = 3; + private static final int FC_LEVEL_MAX = 3; + /* package */ static final int ELAPSED_TIME_MAX = 15; + private static final int ELAPSED_TIME_INTERVAL_HOURS = 6; + private static final int HALF_LIFE_HOURS = 48; + + /* package */ static int fcToElapsedTime(byte fc) { + return fc & 0x0F; + } + + /* package */ static int fcToCount(byte fc) { + return (fc >> 4) & 0x03; + } + + /* package */ static int fcToLevel(byte fc) { + return (fc >> 6) & 0x03; + } + + private static int calcFreq(int elapsedTime, int count, int level) { + if (level <= 0) { + // Reserved words, just return 0 + return 0; + } + if (count == COUNT_MAX) { + // Temporary promote because it's frequently typed recently + ++level; + } + final int et = Math.min(FC_FREQ_MAX, Math.max(0, elapsedTime)); + final int l = Math.min(FC_LEVEL_MAX, Math.max(0, level)); + return MathUtils.SCORE_TABLE[l - 1][et]; + } + + /* pakcage */ static byte calcFc(int elapsedTime, int count, int level) { + final int et = Math.min(FC_FREQ_MAX, Math.max(0, elapsedTime)); + final int c = Math.min(COUNT_MAX, Math.max(0, count)); + final int l = Math.min(FC_LEVEL_MAX, Math.max(0, level)); + return (byte)(et | (c << 4) | (l << 6)); + } + + public static int fcToFreq(byte fc) { + final int elapsedTime = fcToElapsedTime(fc); + final int count = fcToCount(fc); + final int level = fcToLevel(fc); + return calcFreq(elapsedTime, count, level); + } + + public static byte pushElapsedTime(byte fc) { + int elapsedTime = fcToElapsedTime(fc); + int count = fcToCount(fc); + int level = fcToLevel(fc); + if (elapsedTime >= ELAPSED_TIME_MAX) { + // Downgrade level + elapsedTime = 0; + count = COUNT_MAX; + --level; + } else { + ++elapsedTime; + } + return calcFc(elapsedTime, count, level); + } + + public static byte pushCount(byte fc, boolean isValid) { + final int elapsedTime = fcToElapsedTime(fc); + int count = fcToCount(fc); + int level = fcToLevel(fc); + if ((elapsedTime == 0 && count >= COUNT_MAX) || (isValid && level == 0)) { + // Upgrade level + ++level; + count = 0; + } else { + ++count; + } + return calcFc(0, count, level); + } + + private static class MathUtils { + public static final int[][] SCORE_TABLE = new int[FC_LEVEL_MAX][ELAPSED_TIME_MAX + 1]; + static { + for (int i = 0; i < FC_LEVEL_MAX; ++i) { + final double initialFreq; + if (i >= 2) { + initialFreq = (double)FC_FREQ_MAX; + } else if (i == 1) { + initialFreq = (double)FC_FREQ_MAX / 2; + } else if (i == 0) { + initialFreq = (double)FC_FREQ_MAX / 4; + } else { + continue; + } + for (int j = 0; j < ELAPSED_TIME_MAX; ++j) { + final double elapsedHour = j * ELAPSED_TIME_INTERVAL_HOURS; + final double freq = + initialFreq * Math.pow(initialFreq, elapsedHour / HALF_LIFE_HOURS); + final int intFreq = Math.min(FC_FREQ_MAX, Math.max(0, (int)freq)); + SCORE_TABLE[i][j] = intFreq; + } + } + } + } +} |