aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/MoreKeysKeyboardAccessibilityDelegate.java11
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java12
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java13
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java1
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java1
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java14
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java10
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java17
-rw-r--r--java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java6
10 files changed, 54 insertions, 34 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/MoreKeysKeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/MoreKeysKeyboardAccessibilityDelegate.java
index 3a56c5d2a..6fe8bc3b9 100644
--- a/java/src/com/android/inputmethod/accessibility/MoreKeysKeyboardAccessibilityDelegate.java
+++ b/java/src/com/android/inputmethod/accessibility/MoreKeysKeyboardAccessibilityDelegate.java
@@ -23,7 +23,7 @@ import android.view.MotionEvent;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.MoreKeysKeyboardView;
-import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.keyboard.PointerTracker;
/**
* This class represents a delegate that can be registered in {@link MoreKeysKeyboardView} to
@@ -103,12 +103,15 @@ public class MoreKeysKeyboardAccessibilityDelegate
// Invoke {@link MoreKeysKeyboardView#onUpEvent(int,int,int,long)} as if this hover
// exit event selects a key.
mKeyboardView.onUpEvent(x, y, pointerId, eventTime);
- mKeyboardView.dismissMoreKeysPanel();
+ // TODO: Should fix this reference. This is a hack to clear the state of
+ // {@link PointerTracker}.
+ PointerTracker.dismissAllMoreKeysPanels();
return;
}
// Close the more keys keyboard.
- mKeyboardView.onMoveEvent(
- Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, pointerId, eventTime);
+ // TODO: Should fix this reference. This is a hack to clear the state of
+ // {@link PointerTracker}.
+ PointerTracker.dismissAllMoreKeysPanels();
sendWindowStateChanged(mCloseAnnounceResId);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 89a60cc1d..88cde1111 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -195,7 +195,8 @@ public class Key implements Comparable<Key> {
mHintLabel = hintLabel;
mLabelFlags = labelFlags;
mBackgroundType = backgroundType;
- mActionFlags = 0;
+ // TODO: Pass keyActionFlags as an argument.
+ mActionFlags = ACTION_FLAGS_NO_KEY_PREVIEW;
mMoreKeys = null;
mMoreKeysColumnAndFlags = 0;
mLabel = label;
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index bcd0cd848..9a859bfdb 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -446,15 +446,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void showKeyPreview(final Key key) {
- // If key is invalid or IME is already closed, we must not show key preview.
- // Trying to show key preview while root window is closed causes
- // WindowManager.BadTokenException.
- if (key == null) {
+ // If the key is invalid or has no key preview, we must not show key preview.
+ if (key == null || key.noKeyPreview()) {
return;
}
-
- final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
final Keyboard keyboard = getKeyboard();
+ if (keyboard == null) {
+ return;
+ }
+ final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
if (!previewParams.isPopupEnabled()) {
previewParams.setVisibleOffset(-keyboard.mVerticalGap);
return;
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index 0f575d30c..68a11398c 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -35,7 +35,7 @@ import com.android.inputmethod.latin.utils.CoordinateUtils;
public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
private final int[] mCoordinates = CoordinateUtils.newInstance();
- protected KeyDetector mKeyDetector;
+ protected final KeyDetector mKeyDetector;
private Controller mController = EMPTY_CONTROLLER;
protected KeyboardActionListener mListener;
private int mOriginX;
@@ -72,13 +72,10 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
@Override
public void setKeyboard(final Keyboard keyboard) {
super.setKeyboard(keyboard);
+ mKeyDetector.setKeyboard(
+ keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
- // With accessibility mode on, any hover event outside {@link MoreKeysKeyboardView} is
- // discarded at {@link InputView#dispatchHoverEvent(MotionEvent)}. Because only a hover
- // event that is on this view is dispatched by the platform, we should use a
- // {@link KeyDetector} that has no sliding allowance and no hysteresis.
if (mAccessibilityDelegate == null) {
- mKeyDetector = new KeyDetector();
mAccessibilityDelegate = new MoreKeysKeyboardAccessibilityDelegate(
this, mKeyDetector);
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_keys_keyboard);
@@ -86,12 +83,8 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
}
mAccessibilityDelegate.setKeyboard(keyboard);
} else {
- mKeyDetector = new MoreKeysDetector(getResources().getDimension(
- R.dimen.config_more_keys_keyboard_slide_allowance));
mAccessibilityDelegate = null;
}
- mKeyDetector.setKeyboard(
- keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
}
@Override
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index e69499829..8bff27574 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -444,6 +444,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
continue;
}
final int labelFlags = row.getDefaultKeyLabelFlags();
+ // TODO: Should be able to assign default keyActionFlags as well.
final int backgroundType = row.getDefaultBackgroundType();
final int x = (int)row.getKeyX(null);
final int y = row.getKeyY();
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java
index 6db1d02c9..92daf0742 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardRow.java
@@ -45,6 +45,7 @@ public final class KeyboardRow {
private final ArrayDeque<RowAttributes> mRowAttributesStack = new ArrayDeque<>();
+ // TODO: Add keyActionFlags.
private static class RowAttributes {
/** Default width of a key in this row. */
public final float mDefaultKeyWidth;
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 4dbfb44d6..543f74fc4 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -207,6 +207,7 @@ public final class BinaryDictionary extends Dictionary {
private static native boolean addUnigramWordNative(long dict, int[] word, int probability,
int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence,
boolean isNotAWord, boolean isBlacklisted, int timestamp);
+ private static native boolean removeUnigramWordNative(long dict, int[] word);
private static native boolean addBigramWordsNative(long dict, int[] word0,
boolean isBeginningOfSentence, int[] word1, int probability, int timestamp);
private static native boolean removeBigramWordsNative(long dict, int[] word0,
@@ -436,6 +437,19 @@ public final class BinaryDictionary extends Dictionary {
return true;
}
+ // Remove a unigram entry from the binary dictionary in native code.
+ public boolean removeUnigramEntry(final String word) {
+ if (TextUtils.isEmpty(word)) {
+ return false;
+ }
+ final int[] codePoints = StringUtils.toCodePointArray(word);
+ if (!removeUnigramWordNative(mNativeDict, codePoints)) {
+ return false;
+ }
+ mHasUpdated = true;
+ return true;
+ }
+
// Add an n-gram entry to the binary dictionary with timestamp in native code.
public boolean addNgramEntry(final PrevWordsInfo prevWordsInfo, final String word,
final int probability, final int timestamp) {
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 4dbfa0bac..b1966bffc 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -122,6 +122,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
return mBinaryDictionary.isValidDictionary();
}
+ // TODO: Remove and always enable beginning of sentence prediction. Currently, this is enabled
+ // only for ContextualDictionary.
+ protected boolean enableBeginningOfSentencePrediction() {
+ return false;
+ }
+
/**
* Creates a new expandable binary dictionary.
*
@@ -398,6 +404,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
if (mBinaryDictionary == null) {
return null;
}
+ if (composer.size() == 0 && prevWordsInfo.mIsBeginningOfSentence
+ && !enableBeginningOfSentencePrediction()) {
+ return null;
+ }
final ArrayList<SuggestedWordInfo> suggestions =
mBinaryDictionary.getSuggestions(composer, prevWordsInfo, proximityInfo,
blockOffensiveWords, additionalFeaturesOptions, sessionId,
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index cbdc4b9eb..7758ac78e 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -409,21 +409,12 @@ public final class RichInputMethodManager {
public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder,
boolean defaultValue) {
- // Use the default value instead on Jelly Bean MR2 and previous, where
- // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available.
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ // Use the default value instead on Jelly Bean MR2 and previous where
+ // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available
+ // and on KitKat where the API is still just a stub to return true always.
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
return defaultValue;
}
- // Use the default value instead on KitKat as well, where
- // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is still just a stub to
- // return true always.
- if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
- // Make sure this is actually KitKat.
- // TODO: Consider to remove this check once the *next* version becomes available.
- if (Build.VERSION.CODENAME.equals("REL")) {
- return defaultValue;
- }
- }
return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder);
}
}
diff --git a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java
index 536554d98..a96018fe9 100644
--- a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java
+++ b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java
@@ -35,6 +35,7 @@ public class ContextualDictionary extends ExpandableBinaryDictionary {
// Always reset the contents.
clear();
}
+
@UsedForTesting
public static ContextualDictionary getDictionary(final Context context, final Locale locale,
final File dictFile, final String dictNamePrefix) {
@@ -42,6 +43,11 @@ public class ContextualDictionary extends ExpandableBinaryDictionary {
}
@Override
+ protected boolean enableBeginningOfSentencePrediction() {
+ return true;
+ }
+
+ @Override
public boolean isValidWord(final String word) {
// Strings out of this dictionary should not be considered existing words.
return false;