Merge "When Accessibility is on, intercept touch events during dispatch." into jb-mr1-dev
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 03c2164..cb120a3 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -52,7 +52,7 @@
 /**
  * Class for describing the position and characteristics of a single key in the keyboard.
  */
-public class Key {
+public class Key implements Comparable<Key> {
     private static final String TAG = Key.class.getSimpleName();
 
     /**
@@ -410,7 +410,7 @@
         });
     }
 
-    private boolean equals(final Key o) {
+    private boolean equalsInternal(final Key o) {
         if (this == o) return true;
         return o.mX == mX
                 && o.mY == mY
@@ -428,13 +428,20 @@
     }
 
     @Override
+    public int compareTo(Key o) {
+        if (equalsInternal(o)) return 0;
+        if (mHashCode > o.mHashCode) return 1;
+        return -1;
+    }
+
+    @Override
     public int hashCode() {
         return mHashCode;
     }
 
     @Override
     public boolean equals(final Object o) {
-        return o instanceof Key && equals((Key)o);
+        return o instanceof Key && equalsInternal((Key)o);
     }
 
     @Override
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index ab5d31d..e6fe50e 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -24,7 +24,7 @@
 import com.android.inputmethod.latin.CollectionUtils;
 
 import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.TreeSet;
 
 public class KeyboardParams {
     public KeyboardId mId;
@@ -58,7 +58,7 @@
     public int GRID_WIDTH;
     public int GRID_HEIGHT;
 
-    public final HashSet<Key> mKeys = CollectionUtils.newHashSet();
+    public final TreeSet<Key> mKeys = CollectionUtils.newTreeSet(); // ordered set
     public final ArrayList<Key> mShiftKeys = CollectionUtils.newArrayList();
     public final ArrayList<Key> mAltCodeKeysWhileTyping = CollectionUtils.newArrayList();
     public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index 01ba300..f425e36 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -73,11 +73,11 @@
         return maxFreq;
     }
 
-    // Returns true if this isn't in any dictionary.
-    public static boolean isNotAWord(
+    // Returns true if this is in any of the dictionaries.
+    public static boolean isInTheDictionary(
             final ConcurrentHashMap<String, Dictionary> dictionaries,
             final CharSequence word, final boolean ignoreCase) {
-        return !isValidWord(dictionaries, word, ignoreCase);
+        return isValidWord(dictionaries, word, ignoreCase);
     }
 
     public static boolean suggestionExceedsAutoCorrectionThreshold(SuggestedWordInfo suggestion,
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 51ed096..f922bc9 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -214,10 +214,12 @@
             whitelistedWord = suggestionsSet.first().mWord;
         }
 
+        // The word can be auto-corrected if it has a whitelist entry that is not itself,
+        // or if it's a 2+ characters non-word (i.e. it's not in the dictionary).
         final boolean allowsToBeAutoCorrected = (null != whitelistedWord
                 && !whitelistedWord.equals(consideredWord))
-                || AutoCorrection.isNotAWord(mDictionaries, consideredWord,
-                        wordComposer.isFirstCharCapitalized());
+                || (consideredWord.length() > 1 && !AutoCorrection.isInTheDictionary(mDictionaries,
+                        consideredWord, wordComposer.isFirstCharCapitalized()));
 
         final boolean hasAutoCorrection;
         // TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
diff --git a/native/jni/src/debug.h b/native/jni/src/debug.h
deleted file mode 100644
index 8f6b69d..0000000
--- a/native/jni/src/debug.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2011, 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.
- */
-
-#ifndef LATINIME_DEBUG_H
-#define LATINIME_DEBUG_H
-
-#include "defines.h"
-
-static inline unsigned char *convertToUnibyteString(unsigned short *input, unsigned char *output,
-        const unsigned int length) {
-    unsigned int i = 0;
-    for (; i < length && input[i] != 0; ++i)
-        output[i] = input[i] & 0xFF;
-    output[i] = 0;
-    return output;
-}
-
-static inline unsigned char *convertToUnibyteStringAndReplaceLastChar(unsigned short *input,
-        unsigned char *output, const unsigned int length, unsigned char c) {
-    unsigned int i = 0;
-    for (; i < length && input[i] != 0; ++i)
-        output[i] = input[i] & 0xFF;
-    if (i > 0) output[i-1] = c;
-    output[i] = 0;
-    return output;
-}
-
-static inline void LOGI_S16(unsigned short *string, const unsigned int length) {
-    unsigned char tmp_buffer[length];
-    convertToUnibyteString(string, tmp_buffer, length);
-    AKLOGI(">> %s", tmp_buffer);
-    // The log facility is throwing out log that comes too fast. The following
-    // is a dirty way of slowing down processing so that we can see all log.
-    // TODO : refactor this in a blocking log or something.
-    // usleep(10);
-}
-
-static inline void LOGI_S16_PLUS(unsigned short *string, const unsigned int length,
-        unsigned char c) {
-    unsigned char tmp_buffer[length+1];
-    convertToUnibyteStringAndReplaceLastChar(string, tmp_buffer, length, c);
-    AKLOGI(">> %s", tmp_buffer);
-    // Likewise
-    // usleep(10);
-}
-
-static inline void printDebug(const char *tag, int *codes, int codesSize, int MAX_PROXIMITY_CHARS) {
-    unsigned char *buf = static_cast<unsigned char *>(malloc((1 + codesSize) * sizeof(*buf)));
-
-    buf[codesSize] = 0;
-    while (--codesSize >= 0) {
-        buf[codesSize] = static_cast<unsigned char>(codes[codesSize * MAX_PROXIMITY_CHARS]);
-    }
-    AKLOGI("%s, WORD = %s", tag, buf);
-
-    free(buf);
-}
-#endif // LATINIME_DEBUG_H
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 95a9027..ad526fb 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -220,7 +220,11 @@
 #define DEBUG_CORRECTION_FREQ false
 #define DEBUG_WORDS_PRIORITY_QUEUE false
 
+#ifdef FLAG_FULL_DBG
+#define DEBUG_GEO_FULL true
+#else
 #define DEBUG_GEO_FULL false
+#endif
 
 #else // FLAG_DBG
 
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index a4eb7e3..f21d00b 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -124,8 +124,8 @@
                 const int x = proximityOnly ? NOT_A_COORDINATE : xCoordinates[i];
                 const int y = proximityOnly ? NOT_A_COORDINATE : yCoordinates[i];
                 const int time = times ? times[i] : -1;
-                if (pushTouchPoint(i, c, x, y, time, isGeometric, i == lastInputIndex,
-                        currentNearKeysDistances, prevNearKeysDistances,
+                if (pushTouchPoint(i, c, x, y, time, isGeometric /* do sampling */,
+                        i == lastInputIndex, currentNearKeysDistances, prevNearKeysDistances,
                         prevPrevNearKeysDistances)) {
                     // Previous point information was popped.
                     NearKeysDistanceMap *tmp = prevNearKeysDistances;
@@ -218,6 +218,10 @@
             }
         }
     }
+
+    if (DEBUG_GEO_FULL) {
+        AKLOGI("ProximityState init finished: %d points out of %d", mInputSize, inputSize);
+    }
 }
 
 bool ProximityInfoState::checkAndReturnIsContinuationPossible(const int inputSize,
@@ -402,6 +406,10 @@
     mInputYs.push_back(y);
     mTimes.push_back(time);
     mInputIndice.push_back(inputIndex);
+    if (DEBUG_GEO_FULL) {
+        AKLOGI("pushTouchPoint: x = %03d, y = %03d, time = %d, index = %d, popped ? %01d",
+                x, y, time, inputIndex, popped);
+    }
     return popped;
 }