diff options
author | Scott Kennedy <skennedy@google.com> | 2013-08-06 09:31:55 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-08-06 09:31:55 -0700 |
commit | db7eabe04254528c048737a0b92966473ea2f319 (patch) | |
tree | cdbacd12b00d9d541b3690bb1b3ec5f0719964e2 | |
parent | 4f8b198aeac24fbbc73fcb1fe644d520a7902939 (diff) | |
parent | bc742af5bb568ed39dc37764587120928d068330 (diff) | |
download | android_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+
-rw-r--r-- | chips/Android.mk | 3 | ||||
-rw-r--r-- | chips/AndroidManifest.xml | 7 | ||||
-rw-r--r-- | chips/src/com/android/ex/chips/BaseRecipientAdapter.java | 2 | ||||
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientEditTextView.java | 51 |
4 files changed, 58 insertions, 5 deletions
diff --git a/chips/Android.mk b/chips/Android.mk index 6aa8a01..ef4b8ab 100644 --- a/chips/Android.mk +++ b/chips/Android.mk @@ -16,6 +16,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := android-common-chips +LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4 LOCAL_SDK_VERSION := 14 LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ @@ -26,4 +27,4 @@ include $(BUILD_STATIC_JAVA_LIBRARY) ################################################## # Build all sub-directories -include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/chips/AndroidManifest.xml b/chips/AndroidManifest.xml index fd7775d..7487c18 100644 --- a/chips/AndroidManifest.xml +++ b/chips/AndroidManifest.xml @@ -16,4 +16,9 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.ex.chips" android:versionCode="1"> -</manifest> + + <uses-sdk + android:minSdkVersion="11" + android:targetSdkVersion="18" /> + +</manifest>
\ No newline at end of file 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. */ |