Now supporting legacy phone number picker in the Loader/Fragment solution.
Change-Id: Id4e46eb8a4b2b5b2f722a98375d49acbf6cc69da
diff --git a/src/com/android/contacts/list/LegacyContactListAdapter.java b/src/com/android/contacts/list/LegacyContactListAdapter.java
index fdca9b0..753596b 100644
--- a/src/com/android/contacts/list/LegacyContactListAdapter.java
+++ b/src/com/android/contacts/list/LegacyContactListAdapter.java
@@ -69,10 +69,6 @@
return getCursor().getString(PERSON_DISPLAY_NAME_COLUMN_INDEX);
}
- /**
- * Builds the {@link Contacts#CONTENT_LOOKUP_URI} for the given
- * {@link ListView} position.
- */
public Uri getPersonUri() {
Cursor cursor = getCursor();
long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX);
diff --git a/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java b/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java
new file mode 100644
index 0000000..e6c440f
--- /dev/null
+++ b/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+package com.android.contacts.list;
+
+import android.app.patterns.CursorLoader;
+import android.content.ContentUris;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.Contacts.People;
+import android.provider.Contacts.Phones;
+import android.provider.ContactsContract.Data;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * A cursor adapter for the Phones.CONTENT_TYPE content type.
+ */
+@SuppressWarnings("deprecation")
+public class LegacyPhoneNumberListAdapter extends ContactEntryListAdapter {
+
+ protected static final String[] PHONES_PROJECTION = new String[] {
+ Phones._ID, // 0
+ Phones.TYPE, // 1
+ Phones.LABEL, // 2
+ Phones.NUMBER, // 3
+ People.DISPLAY_NAME, // 4
+ People.PHONETIC_NAME, // 5
+ };
+
+ public static final int PHONE_ID_COLUMN_INDEX = 0;
+ public static final int PHONE_TYPE_COLUMN_INDEX = 1;
+ public static final int PHONE_LABEL_COLUMN_INDEX = 2;
+ public static final int PHONE_NUMBER_COLUMN_INDEX = 3;
+ public static final int PHONE_DISPLAY_NAME_COLUMN_INDEX = 4;
+ public static final int PHONE_PHONETIC_NAME_COLUMN_INDEX = 5;
+
+ private CharSequence mUnknownNameText;
+
+ public LegacyPhoneNumberListAdapter(Context context) {
+ super(context);
+ mUnknownNameText = context.getText(android.R.string.unknownName);
+ }
+
+ @Override
+ public void configureLoader(CursorLoader loader) {
+ loader.setUri(Phones.CONTENT_URI);
+ loader.setProjection(PHONES_PROJECTION);
+ loader.setSortOrder(Phones.DISPLAY_NAME);
+ }
+
+ @Override
+ public String getContactDisplayName() {
+ return getCursor().getString(PHONE_DISPLAY_NAME_COLUMN_INDEX);
+ }
+
+ public Uri getPhoneUri() {
+ Cursor cursor = getCursor();
+ long id = cursor.getLong(PHONE_ID_COLUMN_INDEX);
+ return ContentUris.withAppendedId(Phones.CONTENT_URI, id);
+ }
+
+ @Override
+ public View newView(Context context, Cursor cursor, ViewGroup parent) {
+ final ContactListItemView view = new ContactListItemView(context, null);
+ view.setUnknownNameText(mUnknownNameText);
+ return view;
+ }
+
+ @Override
+ public void bindView(View itemView, Context context, Cursor cursor) {
+ ContactListItemView view = (ContactListItemView)itemView;
+ bindName(view, cursor);
+ bindPhoneNumber(view, cursor);
+ }
+
+ protected void bindName(final ContactListItemView view, Cursor cursor) {
+ view.showDisplayName(cursor, PHONE_DISPLAY_NAME_COLUMN_INDEX, false, 0);
+ view.showPhoneticName(cursor, PHONE_PHONETIC_NAME_COLUMN_INDEX);
+ }
+
+ protected void bindPhoneNumber(ContactListItemView view, Cursor cursor) {
+ CharSequence label = null;
+ if (!cursor.isNull(PHONE_TYPE_COLUMN_INDEX)) {
+ final int type = cursor.getInt(PHONE_TYPE_COLUMN_INDEX);
+ final String customLabel = cursor.getString(PHONE_LABEL_COLUMN_INDEX);
+
+ // TODO cache
+ label = Phone.getTypeLabel(getContext().getResources(), type, customLabel);
+ }
+ view.setLabel(label);
+ view.showData(cursor, PHONE_NUMBER_COLUMN_INDEX);
+ }
+}
diff --git a/src/com/android/contacts/list/PhoneNumberPickerFragment.java b/src/com/android/contacts/list/PhoneNumberPickerFragment.java
index 7d00669..d52da50 100644
--- a/src/com/android/contacts/list/PhoneNumberPickerFragment.java
+++ b/src/com/android/contacts/list/PhoneNumberPickerFragment.java
@@ -27,7 +27,7 @@
/**
* Fragment containing a phone number list for picking.
*/
-public class PhoneNumberPickerFragment extends ContactEntryListFragment<PhoneNumberListAdapter>
+public class PhoneNumberPickerFragment extends ContactEntryListFragment<ContactEntryListAdapter>
implements OnShortcutIntentCreatedListener {
private OnPhoneNumberPickerActionListener mListener;
private String mShortcutAction;
@@ -51,21 +51,34 @@
@Override
protected void onItemClick(int position, long id) {
- PhoneNumberListAdapter adapter = getAdapter();
-// if (adapter.isSearchAllContactsItemPosition(position)) {
-// searchAllContacts();
-// } else {
- adapter.moveToPosition(position);
- pickPhoneNumber(adapter.getDataUri());
-// }
+ if (!isLegacyCompatibility()) {
+ PhoneNumberListAdapter adapter = (PhoneNumberListAdapter)getAdapter();
+// if (adapter.isSearchAllContactsItemPosition(position)) {
+// searchAllContacts();
+// } else {
+ adapter.moveToPosition(position);
+ pickPhoneNumber(adapter.getDataUri());
+// }
+ } else {
+ LegacyPhoneNumberListAdapter adapter = (LegacyPhoneNumberListAdapter)getAdapter();
+ adapter.moveToPosition(position);
+ pickPhoneNumber(adapter.getPhoneUri());
+ }
}
@Override
- protected PhoneNumberListAdapter createListAdapter() {
- PhoneNumberListAdapter adapter = new PhoneNumberListAdapter(getActivity());
- adapter.setSectionHeaderDisplayEnabled(true);
- adapter.setDisplayPhotos(true);
- return adapter;
+ protected ContactEntryListAdapter createListAdapter() {
+ if (!isLegacyCompatibility()) {
+ PhoneNumberListAdapter adapter = new PhoneNumberListAdapter(getActivity());
+ adapter.setSectionHeaderDisplayEnabled(true);
+ adapter.setDisplayPhotos(true);
+ return adapter;
+ } else {
+ LegacyPhoneNumberListAdapter adapter = new LegacyPhoneNumberListAdapter(getActivity());
+ adapter.setSectionHeaderDisplayEnabled(true);
+ adapter.setDisplayPhotos(true);
+ return adapter;
+ }
}
@Override
@@ -83,8 +96,11 @@
if (mShortcutAction == null) {
mListener.onPickPhoneNumberAction(uri);
} else {
+ if (isLegacyCompatibility()) {
+ throw new UnsupportedOperationException();
+ }
ShortcutIntentBuilder builder = new ShortcutIntentBuilder(getActivity(), this);
- builder.createPhoneNumberShortcutIntent(getAdapter().getDataUri(), mShortcutAction);
+ builder.createPhoneNumberShortcutIntent(uri, mShortcutAction);
}
}