summaryrefslogtreecommitdiffstats
path: root/chips/src/com/android
diff options
context:
space:
mode:
authorScott Kennedy <skennedy@google.com>2013-08-06 09:31:55 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-08-06 09:31:55 -0700
commitdb7eabe04254528c048737a0b92966473ea2f319 (patch)
treecdbacd12b00d9d541b3690bb1b3ec5f0719964e2 /chips/src/com/android
parent4f8b198aeac24fbbc73fcb1fe644d520a7902939 (diff)
parentbc742af5bb568ed39dc37764587120928d068330 (diff)
downloadandroid_frameworks_ex-db7eabe04254528c048737a0b92966473ea2f319.tar.gz
android_frameworks_ex-db7eabe04254528c048737a0b92966473ea2f319.tar.bz2
android_frameworks_ex-db7eabe04254528c048737a0b92966473ea2f319.zip
am bc742af5: Make Chips work on API 11+
* commit 'bc742af5bb568ed39dc37764587120928d068330': Make Chips work on API 11+
Diffstat (limited to 'chips/src/com/android')
-rw-r--r--chips/src/com/android/ex/chips/BaseRecipientAdapter.java2
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java51
2 files changed, 50 insertions, 3 deletions
diff --git a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
index dd74f30..8b4317b 100644
--- a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
+++ b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
@@ -32,10 +32,10 @@ import android.os.Message;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.Directory;
+import android.support.v4.util.LruCache;
import android.text.TextUtils;
import android.text.util.Rfc822Token;
import android.util.Log;
-import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index 9fe4ab1..e300354 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -36,6 +36,7 @@ import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
+import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -1419,7 +1420,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (mCopyAddress == null && action == MotionEvent.ACTION_UP) {
float x = event.getX();
float y = event.getY();
- int offset = putOffsetInRange(getOffsetForPosition(x, y));
+ int offset = putOffsetInRange(x, y);
DrawableRecipientChip currentChip = findChip(offset);
if (currentChip != null) {
if (action == MotionEvent.ACTION_UP) {
@@ -1513,6 +1514,18 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
mCheckedItem = position;
}
+ private int putOffsetInRange(final float x, final float y) {
+ final int offset;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ offset = getOffsetForPosition(x, y);
+ } else {
+ offset = supportGetOffsetForPosition(x, y);
+ }
+
+ return putOffsetInRange(offset);
+ }
+
// TODO: This algorithm will need a lot of tweaking after more people have used
// the chips ui. This attempts to be "forgiving" to fat finger touches by favoring
// what comes before the finger.
@@ -2685,7 +2698,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
float x = event.getX();
float y = event.getY();
- int offset = putOffsetInRange(getOffsetForPosition(x, y));
+ final int offset = putOffsetInRange(x, y);
DrawableRecipientChip currentChip = findChip(offset);
if (currentChip != null) {
if (mDragEnabled) {
@@ -2698,6 +2711,40 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
}
+ // The following methods are used to provide some functionality on older versions of Android
+ // These methods were copied out of JB MR2's TextView
+ /////////////////////////////////////////////////
+ private int supportGetOffsetForPosition(float x, float y) {
+ if (getLayout() == null) return -1;
+ final int line = supportGetLineAtCoordinate(y);
+ final int offset = supportGetOffsetAtCoordinate(line, x);
+ return offset;
+ }
+
+ private float supportConvertToLocalHorizontalCoordinate(float x) {
+ x -= getTotalPaddingLeft();
+ // Clamp the position to inside of the view.
+ x = Math.max(0.0f, x);
+ x = Math.min(getWidth() - getTotalPaddingRight() - 1, x);
+ x += getScrollX();
+ return x;
+ }
+
+ private int supportGetLineAtCoordinate(float y) {
+ y -= getTotalPaddingLeft();
+ // Clamp the position to inside of the view.
+ y = Math.max(0.0f, y);
+ y = Math.min(getHeight() - getTotalPaddingBottom() - 1, y);
+ y += getScrollY();
+ return getLayout().getLineForVertical((int) y);
+ }
+
+ private int supportGetOffsetAtCoordinate(int line, float x) {
+ x = supportConvertToLocalHorizontalCoordinate(x);
+ return getLayout().getOffsetForHorizontal(line, x);
+ }
+ /////////////////////////////////////////////////
+
/**
* Enables drag-and-drop for chips.
*/