Amlogic Android N LatinIME 数字键盘移动到无效键导致输入法崩溃

---
 .../keyboard/MainKeyboardView.java            | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 209a50d..815b25d 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -823,6 +823,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
                 Key tmp = sortedKeys.get(i);
                 if (k.getY() >= tmp.getY())
                        continue;
+                if (tmp.getCode() == Constants.CODE_UNSPECIFIED)
+                       continue;
                 if (checkFacing(k, tmp)) {
                     ret =  tmp;
                     lastFocusIndex = i;
@@ -859,6 +861,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
                 Key tmp = sortedKeys.get(i);
                 if (k.getY() <= tmp.getY())
                     continue;
+                if (tmp.getCode() == Constants.CODE_UNSPECIFIED)
+                    continue;
                 if (checkFacing(k, tmp)) {
                     ret =  tmp;
                     lastFocusIndex = i;
@@ -905,6 +909,18 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
         if (lastFocusIndex > 0 && lastFocusIndex < sz) {
             lastFocusIndex--;
             ret = sortedKeys.get(lastFocusIndex);
+            while (ret.getCode() == Constants.CODE_UNSPECIFIED) {
+                    lastFocusIndex--;
+                    if (lastFocusIndex < 0) {
+                            while (ret.getCode() == Constants.CODE_UNSPECIFIED) {
+                                    lastFocusIndex++;
+                                    ret = sortedKeys.get(lastFocusIndex);
+                            }
+
+                    } else {
+                            ret = sortedKeys.get(lastFocusIndex);
+                    }
+            }
             changeFocusState(lastFocusKey, ret);
             KeyEventProcessedFlag = true;
             LatinIME.mIsFocusInKeyboard = true;
@@ -924,6 +940,20 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
         if (lastFocusIndex >= 0 &&  lastFocusIndex < sz -1) {
             lastFocusIndex++;
             ret = sortedKeys.get(lastFocusIndex);
+       //we do not move to undefined keys
+            while (ret.getCode() == Constants.CODE_UNSPECIFIED) {
+                    lastFocusIndex++;
+                    // 最后一位或连续多位为无效按键
+                    if (lastFocusIndex >= sz) {
+                            while (ret.getCode() == Constants.CODE_UNSPECIFIED) {
+                                    lastFocusIndex--;
+                                    ret = sortedKeys.get(lastFocusIndex);
+                            }
+
+                    } else {
+                            ret = sortedKeys.get(lastFocusIndex);
+                    }
+            }
             changeFocusState(lastFocusKey, ret);
         }
         if (ret != null && DEBUG) {
-- 
2.17.1

你可能感兴趣的:(Amlogic Android N LatinIME 数字键盘移动到无效键导致输入法崩溃)