summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chips/list_selector_pressed_holo_dark.9.pngbin0 -> 191 bytes
-rw-r--r--chips/res/drawable-hdpi/alternate_list_background.pngbin0 -> 1336 bytes
-rw-r--r--chips/res/drawable-hdpi/chip_checkmark.pngbin1133 -> 1199 bytes
-rw-r--r--chips/res/drawable-mdpi/alternate_list_background.pngbin0 -> 1336 bytes
-rw-r--r--chips/res/drawable/list_item_background.xml21
-rw-r--r--chips/res/layout/chips_alternate_item.xml3
-rw-r--r--chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java27
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java33
8 files changed, 67 insertions, 17 deletions
diff --git a/chips/list_selector_pressed_holo_dark.9.png b/chips/list_selector_pressed_holo_dark.9.png
new file mode 100644
index 0000000..0ed5ba3
--- /dev/null
+++ b/chips/list_selector_pressed_holo_dark.9.png
Binary files differ
diff --git a/chips/res/drawable-hdpi/alternate_list_background.png b/chips/res/drawable-hdpi/alternate_list_background.png
new file mode 100644
index 0000000..ad79a76
--- /dev/null
+++ b/chips/res/drawable-hdpi/alternate_list_background.png
Binary files differ
diff --git a/chips/res/drawable-hdpi/chip_checkmark.png b/chips/res/drawable-hdpi/chip_checkmark.png
index cac823b..cc0b617 100644
--- a/chips/res/drawable-hdpi/chip_checkmark.png
+++ b/chips/res/drawable-hdpi/chip_checkmark.png
Binary files differ
diff --git a/chips/res/drawable-mdpi/alternate_list_background.png b/chips/res/drawable-mdpi/alternate_list_background.png
new file mode 100644
index 0000000..ad79a76
--- /dev/null
+++ b/chips/res/drawable-mdpi/alternate_list_background.png
Binary files differ
diff --git a/chips/res/drawable/list_item_background.xml b/chips/res/drawable/list_item_background.xml
new file mode 100644
index 0000000..18033af
--- /dev/null
+++ b/chips/res/drawable/list_item_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_activated="true" android:drawable="@drawable/alternate_list_background" />
+ <item android:state_checked="true" android:drawable="@drawable/alternate_list_background" />
+ <item android:state_selected="true" android:drawable="@drawable/alternate_list_background" />
+</selector> \ No newline at end of file
diff --git a/chips/res/layout/chips_alternate_item.xml b/chips/res/layout/chips_alternate_item.xml
index b5c4e9d..0d69659 100644
--- a/chips/res/layout/chips_alternate_item.xml
+++ b/chips/res/layout/chips_alternate_item.xml
@@ -20,7 +20,8 @@
android:layout_height="wrap_content"
android:minHeight="30dip"
android:orientation="horizontal"
- android:gravity="left|center_vertical">
+ android:gravity="left|center_vertical"
+ android:background="@drawable/list_item_background">
<FrameLayout
android:layout_width="50dip"
android:layout_height="wrap_content">
diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
index 335ba1d..3d2c87b 100644
--- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
+++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java
@@ -33,19 +33,17 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
private final int mLayoutId;
- private final int mSelectedLayoutId;
-
private final long mCurrentId;
- public RecipientAlternatesAdapter(Context context, long contactId, long currentId, int viewId,
- int selectedViewId) {
+ private int mCheckedItemPosition = -1;
+
+ public RecipientAlternatesAdapter(Context context, long contactId, long currentId, int viewId) {
super(context, context.getContentResolver().query(Email.CONTENT_URI, EmailQuery.PROJECTION,
Email.CONTACT_ID + " =?", new String[] {
String.valueOf(contactId)
}, null), 0);
mLayoutInflater = LayoutInflater.from(context);
mLayoutId = viewId;
- mSelectedLayoutId = selectedViewId;
mCurrentId = currentId;
}
@@ -69,7 +67,10 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
Cursor cursor = getCursor();
cursor.moveToPosition(position);
if (convertView == null) {
- convertView = newView(cursor.getLong(EmailQuery.DATA_ID) == mCurrentId);
+ convertView = newView();
+ }
+ if (cursor.getLong(EmailQuery.DATA_ID) == mCurrentId) {
+ mCheckedItemPosition = position;
}
bindView(convertView, convertView.getContext(), cursor);
return convertView;
@@ -101,11 +102,17 @@ public class RecipientAlternatesAdapter extends CursorAdapter {
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- return newView(false);
+ return newView();
+ }
+
+ private View newView() {
+ return mLayoutInflater.inflate(mLayoutId, null);
}
- private View newView(boolean isSelected) {
- return isSelected ? mLayoutInflater.inflate(mSelectedLayoutId, null) : mLayoutInflater
- .inflate(mLayoutId, null);
+ /**
+ * Get the position of the item that should be checked.
+ */
+ public int getCheckedItemPosition() {
+ return mCheckedItemPosition;
}
}
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index e5b1f7f..8e00919 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -26,6 +26,8 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.os.Handler;
+import android.os.Message;
import android.text.Editable;
import android.text.Layout;
import android.text.Spannable;
@@ -47,8 +49,8 @@ import android.view.View;
import android.view.ActionMode.Callback;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AutoCompleteTextView.Validator;
import android.widget.ListPopupWindow;
+import android.widget.ListView;
import android.widget.MultiAutoCompleteTextView;
import java.util.Collection;
@@ -108,6 +110,12 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView
private Drawable mInvalidChipBackground;
+ private Handler mHandler;
+
+ private static int DISMISS = "dismiss".hashCode();
+
+ private static final long DISMISS_DELAY = 300;
+
public RecipientEditTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setSuggestionsEnabled(false);
@@ -129,6 +137,16 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView
// TODO: find a better way to unfocus a chip when a user starts typing.
}
});
+ mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == DISMISS) {
+ ((ListPopupWindow)msg.obj).dismiss();
+ return;
+ }
+ super.handleMessage(msg);
+ }
+ };
}
@Override
@@ -1051,10 +1069,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView
mAlternatesPopup = new ListPopupWindow(getContext());
if (!mAlternatesPopup.isShowing()) {
- mAlternatesAdapter = new RecipientAlternatesAdapter(
- getContext(),
- mEntry.getContactId(), mEntry.getDataId(),
- mAlternatesLayout, mAlternatesSelectedLayout);
+ mAlternatesAdapter = new RecipientAlternatesAdapter(getContext(),
+ mEntry.getContactId(), mEntry.getDataId(), mAlternatesLayout);
mAnchorView.setLeft(mLeft);
mAnchorView.setRight(mLeft);
mAlternatesPopup.setAnchorView(mAnchorView);
@@ -1062,6 +1078,9 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView
mAlternatesPopup.setWidth(getWidth());
mAlternatesPopup.setOnItemClickListener(this);
mAlternatesPopup.show();
+ ListView listView = mAlternatesPopup.getListView();
+ listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ listView.setItemChecked(mAlternatesAdapter.getCheckedItemPosition(), true);
}
}
@@ -1138,7 +1157,9 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView
*/
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowId) {
- mAlternatesPopup.dismiss();
+ Message delayed = Message.obtain(mHandler, DISMISS);
+ delayed.obj = mAlternatesPopup;
+ mHandler.sendMessageDelayed(delayed, DISMISS_DELAY);
clearComposingText();
replaceChip(mAlternatesAdapter.getRecipientEntry(position));
}