aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java7
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java27
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestions.java55
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestionsView.java29
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java11
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java4
6 files changed, 103 insertions, 30 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 735caaebb..4ccb27e4c 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -573,6 +573,13 @@ public class Key {
super(res, params, row, parser, keyStyles);
}
+ /**
+ * This constructor is being used only for divider in more keys keyboard.
+ */
+ public Spacer(KeyboardParams params, Drawable icon, int x, int y, int width, int height) {
+ super(params, null, null, icon, Keyboard.CODE_DUMMY, null, x, y, width, height, 0);
+ }
+
@Override
public boolean isSpacer() {
return true;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 08af5c5e3..b467a32a2 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -35,7 +35,6 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.text.InputType;
import android.text.TextUtils;
-import android.util.DisplayMetrics;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
@@ -1011,8 +1010,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
- if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getKeyboardView() != null) {
- if (mKeyboardSwitcher.getKeyboardView().handleBack()) {
+ if (event.getRepeatCount() == 0) {
+ if (mSuggestionsView != null && mSuggestionsView.handleBack()) {
+ return true;
+ }
+ final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
+ if (keyboardView != null && keyboardView.handleBack()) {
return true;
}
}
@@ -1872,14 +1875,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return;
}
- final boolean selectedATypedWordAndItsInUserUnigramDic =
- !selectedANotTypedWord && mUserUnigramDictionary.isValidWord(suggestion);
- final boolean isValidWord = AutoCorrection.isValidWord(
- mSuggest.getUnigramDictionaries(), suggestion, true);
- final boolean needsToAddToUserUnigramDictionary = selectedATypedWordAndItsInUserUnigramDic
- || !isValidWord;
- if (needsToAddToUserUnigramDictionary) {
- mUserUnigramDictionary.addWord(suggestion.toString(), frequencyDelta);
+ if (null != mSuggest && null != mUserUnigramDictionary) {
+ final boolean selectedATypedWordAndItsInUserUnigramDic =
+ !selectedANotTypedWord && mUserUnigramDictionary.isValidWord(suggestion);
+ final boolean isValidWord = AutoCorrection.isValidWord(
+ mSuggest.getUnigramDictionaries(), suggestion, true);
+ final boolean needsToAddToUserUnigramDictionary =
+ selectedATypedWordAndItsInUserUnigramDic || !isValidWord;
+ if (needsToAddToUserUnigramDictionary) {
+ mUserUnigramDictionary.addWord(suggestion.toString(), frequencyDelta);
+ }
}
if (mUserBigramDictionary != null) {
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
index 10d5b5c48..24011c41e 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
@@ -16,7 +16,9 @@
package com.android.inputmethod.latin;
+import android.content.res.Resources;
import android.graphics.Paint;
+import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import com.android.inputmethod.keyboard.Key;
@@ -49,14 +51,21 @@ public class MoreSuggestions extends Keyboard {
private final int[] mNumColumnsInRow = new int[SuggestionsView.MAX_SUGGESTIONS];
private static final int MAX_COLUMNS_IN_ROW = 3;
private int mNumRows;
+ public Drawable mDivider;
+ public int mDividerWidth;
public int layout(SuggestedWords suggestions, int fromPos, int maxWidth, int minWidth,
int maxRow, KeyboardView view) {
clearKeys();
final Paint paint = new Paint();
paint.setAntiAlias(true);
- final int padding = (int) view.getContext().getResources()
- .getDimension(R.dimen.more_suggestions_key_horizontal_padding);
+ final Resources res = view.getContext().getResources();
+ mDivider = res.getDrawable(R.drawable.more_suggestions_divider);
+ // TODO: Drawable itself should has an alpha value.
+ mDivider.setAlpha(128);
+ mDividerWidth = mDivider.getIntrinsicWidth();
+ final int padding = (int) res.getDimension(
+ R.dimen.more_suggestions_key_horizontal_padding);
int row = 0;
int pos = fromPos, rowStartPos = fromPos;
@@ -66,8 +75,10 @@ public class MoreSuggestions extends Keyboard {
// TODO: Should take care of text x-scaling.
mWidths[pos] = (int)view.getDefaultLabelWidth(word, paint) + padding;
final int numColumn = pos - rowStartPos + 1;
+ final int columnWidth =
+ (maxWidth - mDividerWidth * (numColumn - 1)) / numColumn;
if (numColumn > MAX_COLUMNS_IN_ROW
- || !fitInWidth(rowStartPos, pos + 1, maxWidth / numColumn)) {
+ || !fitInWidth(rowStartPos, pos + 1, columnWidth)) {
if ((row + 1) >= maxRow) {
break;
}
@@ -98,13 +109,14 @@ public class MoreSuggestions extends Keyboard {
int maxRowWidth = 0;
int pos = startPos;
for (int row = 0; row < mNumRows; row++) {
- final int numColumn = mNumColumnsInRow[row];
+ final int numColumnInRow = mNumColumnsInRow[row];
int maxKeyWidth = 0;
while (pos < endPos && mRowNumbers[pos] == row) {
maxKeyWidth = Math.max(maxKeyWidth, mWidths[pos]);
pos++;
}
- maxRowWidth = Math.max(maxRowWidth, maxKeyWidth * numColumn);
+ maxRowWidth = Math.max(maxRowWidth,
+ maxKeyWidth * numColumnInRow + mDividerWidth * (numColumnInRow - 1));
}
return maxRowWidth;
}
@@ -115,15 +127,19 @@ public class MoreSuggestions extends Keyboard {
{ 2, 0, 1},
};
- private int getColumnNumber(int pos) {
+ public int getNumColumnInRow(int pos) {
+ return mNumColumnsInRow[mRowNumbers[pos]];
+ }
+
+ public int getColumnNumber(int pos) {
final int columnOrder = mColumnOrders[pos];
- final int numColumn = mNumColumnsInRow[mRowNumbers[pos]];
+ final int numColumn = getNumColumnInRow(pos);
return COLUMN_ORDER_TO_NUMBER[numColumn - 1][columnOrder];
}
public int getX(int pos) {
final int columnNumber = getColumnNumber(pos);
- return columnNumber * getWidth(pos);
+ return columnNumber * (getWidth(pos) + mDividerWidth);
}
public int getY(int pos) {
@@ -132,9 +148,8 @@ public class MoreSuggestions extends Keyboard {
}
public int getWidth(int pos) {
- final int row = mRowNumbers[pos];
- final int numColumn = mNumColumnsInRow[row];
- return mWidth / numColumn;
+ final int numColumnInRow = getNumColumnInRow(pos);
+ return (mWidth - mDividerWidth * (numColumnInRow - 1)) / numColumnInRow;
}
public int getFlags(int pos) {
@@ -146,11 +161,11 @@ public class MoreSuggestions extends Keyboard {
if (row == mNumRows - 1)
rowFlags |= Keyboard.EDGE_TOP;
- final int numColumn = mNumColumnsInRow[row];
+ final int numColumnInRow = mNumColumnsInRow[row];
final int column = getColumnNumber(pos);
if (column == 0)
rowFlags |= Keyboard.EDGE_LEFT;
- if (column == numColumn - 1)
+ if (column == numColumnInRow - 1)
rowFlags |= Keyboard.EDGE_RIGHT;
return rowFlags;
@@ -190,13 +205,23 @@ public class MoreSuggestions extends Keyboard {
public MoreSuggestions build() {
final MoreSuggestionsParam params = mParams;
for (int pos = mFromPos; pos < mToPos; pos++) {
+ final int x = params.getX(pos);
+ final int y = params.getY(pos);
+ final int width = params.getWidth(pos);
final String word = mSuggestions.getWord(pos).toString();
final String info = getDebugInfo(mSuggestions, pos);
final int index = pos + SUGGESTION_CODE_BASE;
final Key key = new Key(
- params, word, info, null, index, null, params.getX(pos), params.getY(pos),
- params.getWidth(pos), params.mDefaultRowHeight, params.getFlags(pos));
+ params, word, info, null, index, null, x, y, width,
+ params.mDefaultRowHeight, params.getFlags(pos));
params.onAddKey(key);
+ final int columnNumber = params.getColumnNumber(pos);
+ final int numColumnInRow = params.getNumColumnInRow(pos);
+ if (columnNumber < numColumnInRow - 1) {
+ final Key.Spacer spacer = new Key.Spacer(params, params.mDivider, x + width, y,
+ params.mDividerWidth, params.mDefaultRowHeight);
+ params.onAddKey(spacer);
+ }
}
return new MoreSuggestions(params);
}
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
index f595510a3..695e60ffd 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
@@ -67,7 +67,10 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
@Override
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
- mListener.onCustomRequest(primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE);
+ final int index = primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE;
+ if (index >= 0 && index < SuggestionsView.MAX_SUGGESTIONS) {
+ mListener.onCustomRequest(index);
+ }
}
@Override
@@ -142,6 +145,13 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
// Nothing to do with.
}
+ private final View.OnTouchListener mMotionEventDelegate = new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent me) {
+ return MoreSuggestionsView.this.dispatchTouchEvent(me);
+ }
+ };
+
@Override
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY,
PopupWindow window, KeyboardActionListener listener) {
@@ -160,6 +170,10 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
- (container.getMeasuredHeight() - container.getPaddingBottom())
+ parentView.getPaddingTop() + mCoordinates[1];
+ container.setOnTouchListener(mMotionEventDelegate);
+ window.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
+ window.setFocusable(true);
+ window.setOutsideTouchable(true);
window.setContentView(container);
window.setWidth(container.getMeasuredWidth());
window.setHeight(container.getMeasuredHeight());
@@ -215,6 +229,19 @@ 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 boolean inside = (x >= 0 && x < getWidth() && y >= 0 && y < getHeight());
+ if (inside) {
+ return super.dispatchTouchEvent(me);
+ } else {
+ dismissMoreKeysPanel();
+ return true;
+ }
+ }
+
+ @Override
public boolean onTouchEvent(MotionEvent me) {
final int action = me.getAction();
final long eventTime = me.getEventTime();
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index f9dda6a40..8a4862094 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -258,7 +258,6 @@ public class SubtypeSwitcher {
triggerVoiceIME();
}
} else {
- Log.w(TAG, "Unknown subtype mode: " + newMode);
if (VOICE_MODE.equals(oldMode) && mVoiceInputWrapper != null) {
// We need to reset the voice input to release the resources and to reset its status
// as it is not the current input mode.
@@ -271,8 +270,14 @@ public class SubtypeSwitcher {
packageName, 0).versionCode;
} catch (NameNotFoundException e) {
}
- throw new RuntimeException("Unknown subtype mode: " + version + ", " + packageName
- + ", " + mVoiceInputWrapper);
+ Log.w(TAG, "Unknown subtype mode: " + newMode + "," + version + ", " + packageName
+ + ", " + mVoiceInputWrapper + ". IME is already changed to other IME.");
+ if (newSubtype != null) {
+ Log.w(TAG, "Subtype mode:" + newSubtype.getMode());
+ Log.w(TAG, "Subtype locale:" + newSubtype.getLocale());
+ Log.w(TAG, "Subtype extra value:" + newSubtype.getExtraValue());
+ Log.w(TAG, "Subtype is auxiliary:" + newSubtype.isAuxiliary());
+ }
}
}
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 6879f7660..380e73bc0 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -728,6 +728,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
return false;
}
+ public boolean handleBack() {
+ return dismissMoreSuggestions();
+ }
+
@Override
public boolean onLongClick(View view) {
final SuggestionsViewParams params = mParams;