Now supporting legacy postal address picker in the Loader/Fragment solution.
Change-Id: I7cbb9dc455966b0f5d5e3537596410f6216c9fe0
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 17c466d..2eb54ca 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -687,7 +687,7 @@
case MODE_LEGACY_PICK_POSTAL:
case MODE_PICK_POSTAL: {
PostalAddressPickerFragment fragment = new PostalAddressPickerFragment();
- if (mMode == MODE_LEGACY_PICK_PHONE) {
+ if (mMode == MODE_LEGACY_PICK_POSTAL) {
fragment.setLegacyCompatibility(true);
}
fragment.setSectionHeaderDisplayEnabled(false);
diff --git a/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java b/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java
index e6c440f..a98ed07 100644
--- a/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java
+++ b/src/com/android/contacts/list/LegacyPhoneNumberListAdapter.java
@@ -22,7 +22,6 @@
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;
@@ -33,7 +32,7 @@
@SuppressWarnings("deprecation")
public class LegacyPhoneNumberListAdapter extends ContactEntryListAdapter {
- protected static final String[] PHONES_PROJECTION = new String[] {
+ private static final String[] PHONES_PROJECTION = new String[] {
Phones._ID, // 0
Phones.TYPE, // 1
Phones.LABEL, // 2
@@ -42,12 +41,12 @@
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 static final int PHONE_ID_COLUMN_INDEX = 0;
+ private static final int PHONE_TYPE_COLUMN_INDEX = 1;
+ private static final int PHONE_LABEL_COLUMN_INDEX = 2;
+ private static final int PHONE_NUMBER_COLUMN_INDEX = 3;
+ private static final int PHONE_DISPLAY_NAME_COLUMN_INDEX = 4;
+ private static final int PHONE_PHONETIC_NAME_COLUMN_INDEX = 5;
private CharSequence mUnknownNameText;
diff --git a/src/com/android/contacts/list/LegacyPostalAddressListAdapter.java b/src/com/android/contacts/list/LegacyPostalAddressListAdapter.java
new file mode 100644
index 0000000..1eff102
--- /dev/null
+++ b/src/com/android/contacts/list/LegacyPostalAddressListAdapter.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.ContactMethods;
+import android.provider.Contacts.People;
+import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * A cursor adapter for the ContactMethods.CONTENT_TYPE content type.
+ */
+@SuppressWarnings("deprecation")
+public class LegacyPostalAddressListAdapter extends ContactEntryListAdapter {
+
+ static final String[] POSTALS_PROJECTION = new String[] {
+ ContactMethods._ID, // 0
+ ContactMethods.TYPE, // 1
+ ContactMethods.LABEL, // 2
+ ContactMethods.DATA, // 3
+ People.DISPLAY_NAME, // 4
+ People.PHONETIC_NAME, // 5
+ };
+
+ public static final int POSTAL_ID_COLUMN_INDEX = 0;
+ public static final int POSTAL_TYPE_COLUMN_INDEX = 1;
+ public static final int POSTAL_LABEL_COLUMN_INDEX = 2;
+ public static final int POSTAL_NUMBER_COLUMN_INDEX = 3;
+ public static final int POSTAL_DISPLAY_NAME_COLUMN_INDEX = 4;
+ public static final int POSTAL_PHONETIC_NAME_COLUMN_INDEX = 5;
+
+ private CharSequence mUnknownNameText;
+
+ public LegacyPostalAddressListAdapter(Context context) {
+ super(context);
+ mUnknownNameText = context.getText(android.R.string.unknownName);
+ }
+
+ @Override
+ public void configureLoader(CursorLoader loader) {
+ loader.setUri(ContactMethods.CONTENT_URI);
+ loader.setProjection(POSTALS_PROJECTION);
+ loader.setSortOrder(People.DISPLAY_NAME);
+ loader.setSelection(ContactMethods.KIND + "=" + android.provider.Contacts.KIND_POSTAL);
+ }
+
+ @Override
+ public String getContactDisplayName() {
+ return getCursor().getString(POSTAL_DISPLAY_NAME_COLUMN_INDEX);
+ }
+
+ public Uri getContactMethodUri() {
+ Cursor cursor = getCursor();
+ long id = cursor.getLong(POSTAL_ID_COLUMN_INDEX);
+ return ContentUris.withAppendedId(ContactMethods.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);
+ bindPostalAddress(view, cursor);
+ }
+
+ protected void bindName(final ContactListItemView view, Cursor cursor) {
+ view.showDisplayName(cursor, POSTAL_DISPLAY_NAME_COLUMN_INDEX, false, 0);
+ view.showPhoneticName(cursor, POSTAL_PHONETIC_NAME_COLUMN_INDEX);
+ }
+
+ protected void bindPostalAddress(ContactListItemView view, Cursor cursor) {
+ CharSequence label = null;
+ if (!cursor.isNull(POSTAL_TYPE_COLUMN_INDEX)) {
+ final int type = cursor.getInt(POSTAL_TYPE_COLUMN_INDEX);
+ final String customLabel = cursor.getString(POSTAL_LABEL_COLUMN_INDEX);
+
+ // TODO cache
+ label = StructuredPostal.getTypeLabel(getContext().getResources(), type, customLabel);
+ }
+ view.setLabel(label);
+ view.showData(cursor, POSTAL_NUMBER_COLUMN_INDEX);
+ }
+}
diff --git a/src/com/android/contacts/list/PostalAddressPickerFragment.java b/src/com/android/contacts/list/PostalAddressPickerFragment.java
index e886a76..a012768 100644
--- a/src/com/android/contacts/list/PostalAddressPickerFragment.java
+++ b/src/com/android/contacts/list/PostalAddressPickerFragment.java
@@ -26,7 +26,7 @@
* Fragment containing a postal address list for picking.
*/
public class PostalAddressPickerFragment
- extends ContactEntryListFragment<PostalAddressListAdapter> {
+ extends ContactEntryListFragment<ContactEntryListAdapter> {
private OnPostalAddressPickerActionListener mListener;
public PostalAddressPickerFragment() {
@@ -41,23 +41,35 @@
@Override
protected void onItemClick(int position, long id) {
- PostalAddressListAdapter adapter = getAdapter();
-// if (adapter.isSearchAllContactsItemPosition(position)) {
-// searchAllContacts();
-// } else {
- adapter.moveToPosition(position);
- pickPostalAddress(adapter.getDataUri());
-// }
+ if (!isLegacyCompatibility()) {
+ PostalAddressListAdapter adapter = (PostalAddressListAdapter)getAdapter();
+// if (adapter.isSearchAllContactsItemPosition(position)) {
+// searchAllContacts();
+// } else {
+ adapter.moveToPosition(position);
+ pickPostalAddress(adapter.getDataUri());
+// }
+ } else {
+ LegacyPostalAddressListAdapter adapter = (LegacyPostalAddressListAdapter)getAdapter();
+ adapter.moveToPosition(position);
+ pickPostalAddress(adapter.getContactMethodUri());
+ }
}
@Override
- protected PostalAddressListAdapter createListAdapter() {
- PostalAddressListAdapter adapter = new PostalAddressListAdapter(getActivity());
-
- adapter.setSectionHeaderDisplayEnabled(true);
- adapter.setDisplayPhotos(true);
-
- return adapter;
+ protected ContactEntryListAdapter createListAdapter() {
+ if (!isLegacyCompatibility()) {
+ PostalAddressListAdapter adapter = new PostalAddressListAdapter(getActivity());
+ adapter.setSectionHeaderDisplayEnabled(true);
+ adapter.setDisplayPhotos(true);
+ return adapter;
+ } else {
+ LegacyPostalAddressListAdapter adapter =
+ new LegacyPostalAddressListAdapter(getActivity());
+ adapter.setSectionHeaderDisplayEnabled(false);
+ adapter.setDisplayPhotos(false);
+ return adapter;
+ }
}
@Override