Merge "Make Keyboard aware of theme"
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index 5b02de3..5d89669 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
@@ -23,8 +23,10 @@
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.Spanned;
+import android.text.TextUtils;
 
 import java.lang.reflect.Constructor;
+import java.util.ArrayList;
 import java.util.Locale;
 
 public class SuggestionSpanUtils {
@@ -33,6 +35,7 @@
     public static final String SUGGESTION_SPAN_PICKED_AFTER = "after";
     public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before";
     public static final String SUGGESTION_SPAN_PICKED_HASHCODE = "hashcode";
+    public static final int SUGGESTION_MAX_SIZE = 5;
 
     private static final Class<?> CLASS_SuggestionSpan = CompatUtils
             .getClass("android.text.style.SuggestionSpan");
@@ -48,8 +51,8 @@
 
     public static CharSequence getTextWithSuggestionSpan(Context context,
             CharSequence suggestion, SuggestedWords suggestedWords) {
-        if (CONSTRUCTOR_SuggestionSpan == null || suggestedWords == null
-                || suggestedWords.size() == 0) {
+        if (TextUtils.isEmpty(suggestion) || CONSTRUCTOR_SuggestionSpan == null
+                || suggestedWords == null || suggestedWords.size() == 0) {
             return suggestion;
         }
 
@@ -59,14 +62,19 @@
         } else {
             spannable = new SpannableString(suggestion);
         }
-        // TODO: Use SUGGESTIONS_MAX_SIZE instead of 5.
-        final int N = Math.min(5, suggestedWords.size());
-        final String[] suggestionsArray = new String[N];
-        for (int i = 0; i < N; ++i) {
-            suggestionsArray[i] = suggestedWords.getWord(i).toString();
+        final ArrayList<String> suggestionsList = new ArrayList<String>();
+        for (int i = 0; i < suggestedWords.size(); ++i) {
+            if (suggestionsList.size() >= SUGGESTION_MAX_SIZE) {
+                break;
+            }
+            final CharSequence word = suggestedWords.getWord(i);
+            if (!TextUtils.equals(suggestion, word)) {
+                suggestionsList.add(word.toString());
+            }
         }
+
         final Object[] args =
-                { context, null, suggestionsArray, 0,
+                { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), 0,
                         (Class<?>) SuggestionSpanPickedNotificationReceiver.class };
         final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args);
         if (ss == null) {
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 6b4e946..cf84589 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -22,6 +22,7 @@
 import com.android.inputmethod.latin.SubtypeSwitcher;
 
 import android.content.res.Resources;
+import android.os.SystemClock;
 import android.util.Log;
 import android.view.MotionEvent;
 
@@ -540,8 +541,11 @@
 
     public void onLongPressed(PointerTrackerQueue queue) {
         mKeyAlreadyProcessed = true;
-        if (queue != null)
+        if (queue != null) {
+            // TODO: Support chording + long-press input.
+            queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
             queue.remove(this);
+        }
     }
 
     public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
index 60d87f7..ff64c73 100644
--- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java
@@ -37,7 +37,6 @@
 
     private int mOriginX;
     private int mOriginY;
-    private int mTrackerId;
     private long mDownTime;
 
     public PopupMiniKeyboardView(Context context, AttributeSet attrs) {
@@ -98,30 +97,19 @@
 
         mOriginX = x + container.getPaddingLeft() - mCoordinates[0];
         mOriginY = y + container.getPaddingTop() - mCoordinates[1];
-        mTrackerId = tracker.mPointerId;
         mDownTime = SystemClock.uptimeMillis();
 
         // Inject down event on the key to mini keyboard.
-        final MotionEvent downEvent = translateMotionEvent(MotionEvent.ACTION_DOWN, pointX,
-                pointY + parentKey.mHeight / 2, mDownTime);
+        final MotionEvent downEvent = MotionEvent.obtain(mDownTime, mDownTime,
+                MotionEvent.ACTION_DOWN, pointX - mOriginX,
+                pointY + parentKey.mHeight / 2 - mOriginY, 0);
         onTouchEvent(downEvent);
         downEvent.recycle();
     }
 
-    private MotionEvent translateMotionEvent(int action, float x, float y, long eventTime) {
-        return MotionEvent.obtain(mDownTime, eventTime, action, x - mOriginX, y - mOriginY, 0);
-    }
-
     @Override
     public boolean onTouchEvent(MotionEvent me) {
-        final int index = me.getActionIndex();
-        final int id = me.getPointerId(index);
-        if (id == mTrackerId) {
-            final MotionEvent translated = translateMotionEvent(me.getAction(), me.getX(index),
-                    me.getY(index), me.getEventTime());
-            super.onTouchEvent(translated);
-            translated.recycle();
-        }
-        return true;
+        me.offsetLocation(-mOriginX, -mOriginY);
+        return super.onTouchEvent(me);
     }
 }