diff options
author | Danny Baumann <dannybaumann@web.de> | 2014-09-07 14:24:56 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2014-09-18 14:31:24 +0200 |
commit | e1cf0d6b5b0d099a578345d70640327cd1643fee (patch) | |
tree | 6af68d5f0c4ff1ab9dfa098567e4b86cdfc4ab7e | |
parent | ad1c461c13ff6657bd310d2b19620e8c5f0b729d (diff) | |
download | packages_apps_Contacts-e1cf0d6b5b0d099a578345d70640327cd1643fee.tar.gz packages_apps_Contacts-e1cf0d6b5b0d099a578345d70640327cd1643fee.tar.bz2 packages_apps_Contacts-e1cf0d6b5b0d099a578345d70640327cd1643fee.zip |
Clean up multi picker activity.
Change-Id: Id8d66cf3ff5f806a053f40bd4d8db453ab292219
23 files changed, 492 insertions, 772 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5ffc13787..bdefaff97 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -467,10 +467,10 @@ </activity> <activity - android:name=".editor.MultiPickContactActivity" + android:name=".activities.MultiPickContactActivity" android:windowSoftInputMode="stateHidden|adjustResize" android:screenOrientation="nosensor" - android:theme="@android:style/Theme.Holo.Light" + android:theme="@style/ContactPickerTheme" android:configChanges="orientation|keyboardHidden|layoutDirection"> <intent-filter> <action android:name="com.android.contacts.action.MULTI_PICK" /> diff --git a/res/drawable-hdpi/ic_call_incoming_holo_dark.png b/res/drawable-hdpi/ic_call_incoming_holo_dark.png Binary files differnew file mode 100644 index 000000000..8351f4805 --- /dev/null +++ b/res/drawable-hdpi/ic_call_incoming_holo_dark.png diff --git a/res/drawable-hdpi/ic_call_log_list_incoming_call.png b/res/drawable-hdpi/ic_call_log_list_incoming_call.png Binary files differdeleted file mode 100644 index 15b5e4436..000000000 --- a/res/drawable-hdpi/ic_call_log_list_incoming_call.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_call_log_list_missed_call.png b/res/drawable-hdpi/ic_call_log_list_missed_call.png Binary files differdeleted file mode 100644 index 8dcb2796c..000000000 --- a/res/drawable-hdpi/ic_call_log_list_missed_call.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_call_log_list_outgoing_call.png b/res/drawable-hdpi/ic_call_log_list_outgoing_call.png Binary files differdeleted file mode 100644 index 160c70736..000000000 --- a/res/drawable-hdpi/ic_call_log_list_outgoing_call.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_call_missed_holo_dark.png b/res/drawable-hdpi/ic_call_missed_holo_dark.png Binary files differnew file mode 100644 index 000000000..7c17c3010 --- /dev/null +++ b/res/drawable-hdpi/ic_call_missed_holo_dark.png diff --git a/res/drawable-hdpi/ic_call_outgoing_holo_dark.png b/res/drawable-hdpi/ic_call_outgoing_holo_dark.png Binary files differnew file mode 100644 index 000000000..3b9e0f8a9 --- /dev/null +++ b/res/drawable-hdpi/ic_call_outgoing_holo_dark.png diff --git a/res/drawable-mdpi/ic_call_incoming_holo_dark.png b/res/drawable-mdpi/ic_call_incoming_holo_dark.png Binary files differnew file mode 100644 index 000000000..8dcb350bc --- /dev/null +++ b/res/drawable-mdpi/ic_call_incoming_holo_dark.png diff --git a/res/drawable-mdpi/ic_call_missed_holo_dark.png b/res/drawable-mdpi/ic_call_missed_holo_dark.png Binary files differnew file mode 100644 index 000000000..af030cf13 --- /dev/null +++ b/res/drawable-mdpi/ic_call_missed_holo_dark.png diff --git a/res/drawable-mdpi/ic_call_outgoing_holo_dark.png b/res/drawable-mdpi/ic_call_outgoing_holo_dark.png Binary files differnew file mode 100644 index 000000000..38a01b7a6 --- /dev/null +++ b/res/drawable-mdpi/ic_call_outgoing_holo_dark.png diff --git a/res/drawable-xhdpi/ic_call_incoming_holo_dark.png b/res/drawable-xhdpi/ic_call_incoming_holo_dark.png Binary files differnew file mode 100644 index 000000000..8eb5f3d8b --- /dev/null +++ b/res/drawable-xhdpi/ic_call_incoming_holo_dark.png diff --git a/res/drawable-xhdpi/ic_call_missed_holo_dark.png b/res/drawable-xhdpi/ic_call_missed_holo_dark.png Binary files differnew file mode 100644 index 000000000..6d09a4e95 --- /dev/null +++ b/res/drawable-xhdpi/ic_call_missed_holo_dark.png diff --git a/res/drawable-xhdpi/ic_call_outgoing_holo_dark.png b/res/drawable-xhdpi/ic_call_outgoing_holo_dark.png Binary files differnew file mode 100644 index 000000000..636050403 --- /dev/null +++ b/res/drawable-xhdpi/ic_call_outgoing_holo_dark.png diff --git a/res/drawable-xxhdpi/ic_call_incoming_holo_dark.png b/res/drawable-xxhdpi/ic_call_incoming_holo_dark.png Binary files differnew file mode 100644 index 000000000..12769173b --- /dev/null +++ b/res/drawable-xxhdpi/ic_call_incoming_holo_dark.png diff --git a/res/drawable-xxhdpi/ic_call_missed_holo_dark.png b/res/drawable-xxhdpi/ic_call_missed_holo_dark.png Binary files differnew file mode 100644 index 000000000..8919fd3c9 --- /dev/null +++ b/res/drawable-xxhdpi/ic_call_missed_holo_dark.png diff --git a/res/drawable-xxhdpi/ic_call_outgoing_holo_dark.png b/res/drawable-xxhdpi/ic_call_outgoing_holo_dark.png Binary files differnew file mode 100644 index 000000000..192bbf6a3 --- /dev/null +++ b/res/drawable-xxhdpi/ic_call_outgoing_holo_dark.png diff --git a/res/layout/pick_calls_item.xml b/res/layout/pick_calls_item.xml index 61787cc91..16fd33093 100644 --- a/res/layout/pick_calls_item.xml +++ b/res/layout/pick_calls_item.xml @@ -28,118 +28,93 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:minHeight="?android:attr/listPreferredItemHeight" - android:paddingTop="3dip" - android:paddingBottom="3dip" - > - <LinearLayout - android:layout_width="60dip" - android:layout_weight="0" - android:layout_height="match_parent" - android:orientation="vertical" - android:gravity="center_horizontal"> - - <ImageView android:id="@+id/call_type_icon" - android:layout_width="wrap_content" - android:layout_weight="1" - android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_alignParentLeft="true" - android:layout_marginLeft="4dip"/> + android:descendantFocusability="blocksDescendants"> - <TextView android:id="@+id/label" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:singleLine="true" - android:textAppearance="?android:attr/textAppearanceSmall" - android:textStyle="bold"/> - </LinearLayout> + <CheckBox + android:id="@+id/pick_contact_check" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dip" + android:layout_marginEnd="8dip" + android:layout_gravity="center_vertical" + android:clickable="false" /> <LinearLayout - android:layout_width="wrap_content" + android:layout_width="0dp" + android:layout_height="wrap_content" android:layout_weight="1" - android:layout_height="match_parent" + android:layout_gravity="center_vertical" android:orientation="vertical"> + <TextView + android:id="@+id/name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textSize="16sp" + android:singleLine="true" /> + <LinearLayout - android:layout_width="match_parent" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" android:orientation="horizontal"> - <TextView android:id="@+id/number" + <TextView + android:id="@+id/subscription" android:layout_width="wrap_content" - android:layout_weight="1" android:layout_height="wrap_content" + android:layout_marginEnd="4dip" + android:textSize="12sp" android:singleLine="true" - android:textAppearance="?android:attr/textAppearanceSmall" - /> + android:ellipsize="marquee" /> - <TextView android:id="@+id/line1" + <TextView + android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" - android:textAppearance="?android:attr/textAppearanceSmall" + android:textSize="12sp" android:singleLine="true" - /> + android:ellipsize="marquee" /> - <TextView android:id="@+id/subscription" - android:layout_width="wrap_content" - android:layout_weight="0" - android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceSmall" - android:singleLine="true" - /> </LinearLayout> + <LinearLayout - android:layout_width="match_parent" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" android:orientation="horizontal"> - <TextView android:id="@+id/duration" + <ImageView + android:id="@+id/call_type_icon" android:layout_width="wrap_content" - android:layout_weight="1" android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceSmall" - android:singleLine="true" - /> + android:layout_marginEnd="4dip" + android:layout_gravity="center_vertical" /> - <TextView android:id="@+id/date" - android:layout_weight="0" + + <TextView + android:id="@+id/call_date" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceSmall" - android:singleLine="true" - /> + android:layout_gravity="center_vertical" + android:textSize="12sp" + android:singleLine="true" /> </LinearLayout> + </LinearLayout> - <View android:id="@+id/divider" - android:layout_weight="0" - android:layout_width="1px" - android:layout_height="match_parent" - android:layout_marginTop="5dip" - android:layout_marginBottom="5dip" - android:layout_marginLeft="11dip" - android:background="@drawable/divider_vertical_dark" - /> + <TextView android:id="@+id/duration" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_marginStart="4dip" + android:layout_marginEnd="8dip" + android:textAppearance="?android:attr/textAppearanceSmall" + android:singleLine="true" /> - <CheckBox - android:layout_weight="0" - android:id="@+id/pick_contact_check" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginRight="10dip" - android:layout_centerVertical="true" - android:focusable="false" - android:clickable="false"> - </CheckBox> -</LinearLayout>
\ No newline at end of file +</LinearLayout> diff --git a/res/layout/pick_contact.xml b/res/layout/pick_contact.xml deleted file mode 100644 index af50d3522..000000000 --- a/res/layout/pick_contact.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - * Copyright (c) 2013, The Linux Foundation. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - > - - <ListView android:layout_width="match_parent" - android:layout_height="0dip" - android:layout_weight="1.0" - android:fastScrollEnabled="true" - android:id="@android:id/list"> - </ListView> -</LinearLayout>
\ No newline at end of file diff --git a/res/layout/pick_contact_item.xml b/res/layout/pick_contact_item.xml index 2e2e54086..8e03e7a5c 100644 --- a/res/layout/pick_contact_item.xml +++ b/res/layout/pick_contact_item.xml @@ -27,49 +27,28 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> -<RelativeLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:minHeight="?android:attr/listPreferredItemHeight" - android:paddingTop="3dip" - android:paddingBottom="3dip" - > - <ImageView android:layout_width="@dimen/contact_browser_list_item_photo_size" - android:layout_height="@dimen/contact_browser_list_item_photo_size" - android:layout_marginLeft="10dip" - android:layout_marginRight="5dip" - android:layout_marginTop="5dip" - android:visibility="gone" - android:id="@+id/pick_contact_photo"/> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_toRightOf="@id/pick_contact_photo" - android:layout_marginLeft="10dip" - android:layout_marginRight="50dip" - android:layout_marginTop="5dip" - android:textAppearance="?android:attr/textAppearanceLarge" - android:id="@+id/pick_contact_name"> - </TextView> - <TextView - android:layout_height="wrap_content" - android:layout_width="wrap_content" - android:layout_below="@id/pick_contact_name" - android:layout_marginLeft="10dip" - android:layout_marginBottom="5dip" - android:textAppearance="?android:attr/textAppearanceSmall" - android:id="@+id/pick_contact_number" - android:singleLine="true"> - </TextView> - <CheckBox - android:id="@+id/pick_contact_check" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginRight="10dip" - android:layout_centerVertical="true" - android:layout_alignParentRight="true" - android:focusable="false" - android:clickable="false"> - </CheckBox> -</RelativeLayout>
\ No newline at end of file +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:minHeight="?android:attr/listPreferredItemHeight" + android:descendantFocusability="blocksDescendants"> + + <CheckBox + android:id="@+id/pick_contact_check" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dip" + android:layout_marginEnd="8dip" + android:layout_gravity="center_vertical" + android:clickable="false" /> + + <com.android.contacts.common.list.ContactListItemView + android:id="@+id/contact" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginEnd="8dip" + android:layout_gravity="center_vertical" + android:layout_weight="1" /> + +</LinearLayout> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 89fde52d2..9069e4186 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -97,7 +97,11 @@ <string name="contactsLocalGroupsLabel">Local groups</string> <string name="select_all">All</string> <string name="action_done">Done</string> - <string name="contacts_selected">selected</string> + + <plurals name="contacts_selected"> + <item quantity="one">%d selected</item> + <item quantity="other">%d selected</item> + </plurals> <string name="delete_call_title">Delete call logs</string> <string name="delete_call_message">Deleting call logs\u2026</string> diff --git a/src/com/android/contacts/editor/MultiPickContactActivity.java b/src/com/android/contacts/activities/MultiPickContactActivity.java index a5af391dd..0d4a57292 100644 --- a/src/com/android/contacts/editor/MultiPickContactActivity.java +++ b/src/com/android/contacts/activities/MultiPickContactActivity.java @@ -28,7 +28,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.android.contacts.editor; +package com.android.contacts.activities; import android.app.ActionBar; import android.app.AlertDialog; @@ -40,31 +40,27 @@ import android.accounts.AccountManager; import android.content.AsyncQueryHandler; import android.content.BroadcastReceiver; import android.content.ContentResolver; +import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; -import android.content.ContentProviderOperation; import android.content.DialogInterface; -import android.content.IntentFilter; -import android.content.DialogInterface.OnCancelListener; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; +import android.content.IntentFilter; import android.content.OperationApplicationException; import android.database.Cursor; -import android.graphics.drawable.Drawable; import android.net.Uri; -import android.net.Uri.Builder; import android.os.Bundle; import android.os.RemoteException; import android.provider.CallLog; +import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.provider.ContactsContract.ContactCounts; -import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.Data; -import android.provider.ContactsContract.CommonDataKinds.StructuredName; +import android.provider.ContactsContract.RawContacts; import android.telephony.MSimTelephonyManager; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; @@ -77,7 +73,6 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; -import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.CheckBox; @@ -89,25 +84,26 @@ import android.widget.SectionIndexer; import android.widget.TextView; import android.widget.Toast; -import com.android.contacts.activities.PeopleActivity; import com.android.contacts.R; +import com.android.contacts.activities.PeopleActivity; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.SimContactsConstants; import com.android.contacts.common.SimContactsOperation; import com.android.contacts.common.list.AccountFilterActivity; import com.android.contacts.common.list.ContactListFilter; +import com.android.contacts.common.list.ContactListItemView; import com.android.contacts.common.list.ContactsSectionIndexer; import com.android.contacts.common.list.DefaultContactListAdapter; import com.android.contacts.common.MoreContactUtils; import com.android.contacts.common.model.account.SimAccountType; import com.android.internal.telephony.MSimConstants; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Iterator; import java.util.Set; -public class MultiPickContactActivity extends ListActivity implements OnTouchListener { +public class MultiPickContactActivity extends ListActivity implements + View.OnTouchListener, DialogInterface.OnClickListener, DialogInterface.OnKeyListener { private final static String TAG = "MultiPickContactActivity"; private final static boolean DEBUG = true; @@ -116,18 +112,28 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, // 0 Contacts.DISPLAY_NAME_PRIMARY, // 1 - Contacts.DISPLAY_NAME_ALTERNATIVE, // 2 - Contacts.SORT_KEY_PRIMARY, // 3 - Contacts.STARRED, // 4 - Contacts.TIMES_CONTACTED, // 5 - Contacts.CONTACT_PRESENCE, // 6 - Contacts.PHOTO_ID, // 7 - Contacts.LOOKUP_KEY, // 8 - Contacts.PHONETIC_NAME, // 9 - Contacts.HAS_PHONE_NUMBER, // 10 - RawContacts.ACCOUNT_TYPE, // 11 - RawContacts.ACCOUNT_NAME, // 12 - Contacts.IN_VISIBLE_GROUP, + Contacts.PHOTO_ID, // 2 + Contacts.LOOKUP_KEY, // 3 + }; + + static final String[] PHONES_PROJECTION = new String[] { + Data.CONTACT_ID, // 0 + Data.DISPLAY_NAME, // 1 + Data.PHOTO_ID, // 2 + Data.LOOKUP_KEY, // 3 + Phone._ID, // 4 + Phone.TYPE, // 5 + Phone.LABEL, // 6 + Phone.NUMBER, // 7 + }; + + static final String[] EMAILS_PROJECTION = new String[] { + Data.CONTACT_ID, // 0 + Data.DISPLAY_NAME, // 1 + Data.PHOTO_ID, // 2 + Data.LOOKUP_KEY, // 3 + Email._ID, // 4 + Email.ADDRESS // 5 }; static final String[] CALL_LOG_PROJECTION = new String[] { @@ -139,78 +145,41 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis Calls.CACHED_NAME, Calls.CACHED_NUMBER_TYPE, Calls.CACHED_NUMBER_LABEL, + Calls.GEOCODED_LOCATION, Calls.SUBSCRIPTION }; static final String CONTACTS_SELECTION = Contacts.IN_VISIBLE_GROUP + "=1"; - static final String[] PHONES_PROJECTION = new String[] { - Phone._ID, // 0 - Phone.TYPE, // 1 - Phone.LABEL, // 2 - Phone.NUMBER, // 3 - Phone.DISPLAY_NAME, // 4 - Phone.CONTACT_ID, // 5 - Phone.PRESENCE, // 6 - Phone.PHOTO_ID, // 7 - Phone.LOOKUP_KEY, // 8 - RawContacts.ACCOUNT_TYPE, - RawContacts.ACCOUNT_NAME - }; - static final String PHONES_SELECTION = RawContacts.ACCOUNT_TYPE + "<>?"; static final String[] PHONES_SELECTION_ARGS = { SimContactsConstants.ACCOUNT_TYPE_SIM }; - static final String[] EMAILS_PROJECTION = new String[] { - Email._ID, - Phone.DISPLAY_NAME, - Email.ADDRESS, - }; - - public static final int SUMMARY_ID_COLUMN_INDEX = 0; - public static final int SUMMARY_DISPLAY_NAME_PRIMARY_COLUMN_INDEX = 1; - public static final int SUMMARY_DISPLAY_NAME_ALTERNATIVE_COLUMN_INDEX = 2; - public static final int SUMMARY_SORT_KEY_PRIMARY_COLUMN_INDEX = 3; - public static final int SUMMARY_STARRED_COLUMN_INDEX = 4; - public static final int SUMMARY_TIMES_CONTACTED_COLUMN_INDEX = 5; - public static final int SUMMARY_PRESENCE_STATUS_COLUMN_INDEX = 6; - public static final int SUMMARY_PHOTO_ID_COLUMN_INDEX = 7; - public static final int SUMMARY_LOOKUP_KEY_COLUMN_INDEX = 8; - public static final int SUMMARY_PHONETIC_NAME_COLUMN_INDEX = 9; - public static final int SUMMARY_HAS_PHONE_COLUMN_INDEX = 10; - public static final int SUMMARY_ACCOUNT_TYPE = 11; - public static final int SUMMARY_ACCOUNT_NAME = 12; - - public static final int ID_COLUMN_INDEX = 0; - public static final int NUMBER_COLUMN_INDEX = 1; - public static final int DATE_COLUMN_INDEX = 2; - public static final int DURATION_COLUMN_INDEX = 3; - public static final int CALL_TYPE_COLUMN_INDEX = 4; - public static final int CALLER_NAME_COLUMN_INDEX = 5; - public static final int CALLER_NUMBERTYPE_COLUMN_INDEX = 6; - public static final int CALLER_NUMBERLABEL_COLUMN_INDEX = 7; - public static final int PHONE_SUBSCRIPTION_COLUMN_INDEX = 8; - - public static final int PHONE_COLUMN_ID = 0; - public static final int PHONE_COLUMN_TYPE = 1; - public static final int PHONE_COLUMN_LABEL = 2; - public static final int PHONE_COLUMN_NUMBER = 3; - public static final int PHONE_COLUMN_DISPLAY_NAME = 4; - public static final int PHONE_COLUMN_CONTACT_ID = 5; - public static final int PHONE_COLUMN_PRESENCE = 6; - public static final int PHONE_COLUMN_PHOTO_ID = 7; - public static final int PHONE_COLUMN_LOOKUP_KEY = 8; - - public static final int EMAIL_COLUMN_ID = 0; - public static final int EMAIL_COLUMN_DISPLAY_NAME = 1; - public static final int EMAIL_COLUMN_ADDRESS = 2; - - public static final int ACCOUNT_COLUMN_ID = 0; - public static final int ACCOUNT_COLUMN_NAME = 1; - public static final int ACCOUNT_COLUMN_TYPE = 2; + public static final int CONTACT_COLUMN_ID = 0; + public static final int CONTACT_COLUMN_DISPLAY_NAME = 1; + public static final int CONTACT_COLUMN_PHOTO_ID = 2; + public static final int CONTACT_COLUMN_LOOKUP_KEY = 3; + // phone query specific columns + public static final int PHONE_COLUMN_ID = 4; + public static final int PHONE_COLUMN_TYPE = 5; + public static final int PHONE_COLUMN_LABEL = 6; + public static final int PHONE_COLUMN_NUMBER = 7; + // email query specific columns + public static final int EMAIL_COLUMN_ID = 4; + public static final int EMAIL_COLUMN_ADDRESS = 5; + + public static final int CALLLOG_COLUMN_ID = 0; + public static final int CALLLOG_COLUMN_NUMBER = 1; + public static final int CALLLOG_COLUMN_DATE = 2; + public static final int CALLLOG_COLUMN_DURATION = 3; + public static final int CALLLOG_COLUMN_CALL_TYPE = 4; + public static final int CALLLOG_COLUMN_CALLER_NAME = 5; + public static final int CALLLOG_COLUMN_CALLER_NUMBERTYPE = 6; + public static final int CALLLOG_COLUMN_CALLER_NUMBERLABEL = 7; + public static final int CALLLOG_COLUMN_CALLER_LOCATION = 8; + public static final int CALLLOG_COLUMN_SUBSCRIPTION = 9; private static final int QUERY_TOKEN = 42; private static final int MODE_MASK_SEARCH = 0x80000000; @@ -231,42 +200,36 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis static final String ACTION_MULTI_PICK_CALL = "com.android.contacts.action.MULTI_PICK_CALL"; static final String ACTION_MULTI_PICK_SIM = "com.android.contacts.action.MULTI_PICK_SIM"; - public static final String IS_CONTACT ="is_contact"; - public static final String IS_SELECT_ALL_DISALLOWED = "is_select_all_disallowed"; + public static final String EXTRA_IS_CONTACT = "is_contact"; + public static final String EXTRA_IS_SELECT_ALL_DISALLOWED = "is_select_all_disallowed"; + public static final String EXTRA_SELECT_CALLLOG = "selectcalllog"; + public static final String EXTRA_NOT_SHOW_SIM_FLAG = "not_sim_show"; private static final int DIALOG_DEL_CALL = 1; - static final String SUBSCRIPTION = "Subscription"; private ContactItemListAdapter mAdapter; private QueryHandler mQueryHandler; private Bundle mChoiceSet; - private Bundle mBackupChoiceSet; + private ActionBar mActionBar; private SearchView mSearchView; - private MenuItem mSelectAllCheck; + private MenuItem mSelectAllItem; + private MenuItem mDoneItem; private int mMode; private boolean mSelectCallLog; private boolean mAllowSelectAll = true; - public static final String KEY_SELECT_CALLLOG = "selectcalllog"; private ProgressDialog mProgressDialog; - private Drawable mDrawableIncoming; - private Drawable mDrawableOutgoing; - private Drawable mDrawableMissed; private CharSequence[] mLabelArray; private SimContactsOperation mSimContactsOperation; protected static final int SUB1 = 0; protected static final int SUB2 = 1; - private ActionBar mBar; - private MenuItem mDone; - private Context mContext; - private Intent mIntent; - private AccountManager accountManager; + private AccountManager mAccountManager; private int mSubscription = -1; - private static final String[] COLUMN_NAMES = new String[] { + private static final String[] SIM_COLUMN_NAMES = new String[] { "name", "number", "emails", @@ -280,61 +243,46 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis public static final int SIM_COLUMN_ANRS = 3; public static final int SIM_COLUMN_ID = 4; - /** - * control of whether show the contacts in SIM card, if intent has this - * flag,not show. - */ - public static final String EXT_NOT_SHOW_SIM_FLAG = "not_sim_show"; - private int MAX_CONTACTS_NUM_TO_SELECT_ONCE = 500; //registerReceiver to update content when airplane mode change. private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - // TODO Auto-generated method stub if (intent.getAction().equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) { updateContent(); // If now is airplane mode, should cancel import sim contacts - if (isPickSim() && MoreContactUtils.isAPMOnAndSIMPowerDown(mContext)) { + if (isPickSim() && MoreContactUtils.isAPMOnAndSIMPowerDown(context)) { cancelSimContactsImporting(); } } } }; - /** Called when the activity is first created. */ + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String action = intent.getAction(); - boolean isContact = intent.getBooleanExtra(IS_CONTACT,false); - mAllowSelectAll = !intent.getBooleanExtra(IS_SELECT_ALL_DISALLOWED, false); + boolean isContact = intent.getBooleanExtra(EXTRA_IS_CONTACT,false); + mAllowSelectAll = !intent.getBooleanExtra(EXTRA_IS_SELECT_ALL_DISALLOWED, false); + if (Intent.ACTION_DELETE.equals(action)) { mMode = MODE_DEFAULT_CONTACT; setTitle(R.string.menu_deleteContact); } else if (Intent.ACTION_GET_CONTENT.equals(action)) { mMode = MODE_DEFAULT_CONTACT; } else if (ACTION_MULTI_PICK.equals(action)) { - if (!isContact) { - mMode = MODE_DEFAULT_PHONE; - } else { - mMode = MODE_DEFAULT_CONTACT; - } + mMode = isContact ? MODE_DEFAULT_CONTACT : MODE_DEFAULT_PHONE; } else if (ACTION_MULTI_PICK_EMAIL.equals(action)) { mMode = MODE_DEFAULT_EMAIL; } else if (ACTION_MULTI_PICK_CALL.equals(action)) { mMode = MODE_DEFAULT_CALL; setTitle(R.string.delete_call_title); - mDrawableIncoming = getResources().getDrawable( - R.drawable.ic_call_log_list_incoming_call); - mDrawableOutgoing = getResources().getDrawable( - R.drawable.ic_call_log_list_outgoing_call); - mDrawableMissed = getResources().getDrawable( - R.drawable.ic_call_log_list_missed_call); - mSubscription = intent.getIntExtra(SUBSCRIPTION, MSimConstants.INVALID_SUBSCRIPTION); - if (intent.getBooleanExtra(KEY_SELECT_CALLLOG, false)) { + mSubscription = intent.getIntExtra(MSimConstants.SUBSCRIPTION_KEY, + MSimConstants.INVALID_SUBSCRIPTION); + if (intent.getBooleanExtra(EXTRA_SELECT_CALLLOG, false)) { mSelectCallLog = true; setTitle(R.string.select_call_title); } @@ -342,17 +290,18 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis mMode = MODE_DEFAULT_SIM; } - setContentView(R.layout.pick_contact); mChoiceSet = new Bundle(); mAdapter = new ContactItemListAdapter(this); getListView().setAdapter(mAdapter); mQueryHandler = new QueryHandler(this); mSimContactsOperation = new SimContactsOperation(this); - mContext = getApplicationContext(); - accountManager = AccountManager.get(mContext); - mBar = getActionBar(); - mBar.setHomeButtonEnabled(true); - mBar.setDisplayHomeAsUpEnabled(true); + mAccountManager = AccountManager.get(this); + + mActionBar = getActionBar(); + mActionBar.setHomeButtonEnabled(true); + mActionBar.setDisplayHomeAsUpEnabled(true); + mActionBar.setDisplayShowTitleEnabled(true); + startQuery(); //register receiver. IntentFilter filter = new IntentFilter(); @@ -365,37 +314,32 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.multi_contact_picker_options, menu); - mDone = menu.findItem(R.id.done); - mDone.setVisible(false); - mSelectAllCheck = menu.findItem(R.id.select_all_check); - mSelectAllCheck.setVisible(mAllowSelectAll); - mSearchView = (SearchView) menu.findItem(R.id.search) - .getActionView(); + mDoneItem = menu.findItem(R.id.done); + mDoneItem.setVisible(false); + mSelectAllItem = menu.findItem(R.id.select_all_check); + mSelectAllItem.setVisible(mAllowSelectAll); + + mSearchView = (SearchView) menu.findItem(R.id.search).getActionView(); mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { - if (!TextUtils.isEmpty(query)) { - if (!isSearchMode()) { - enterSearchMode(); - } - } else if (isSearchMode()) { - exitSearchMode(true); - } - doFilter(query); + updateState(query); return true; } - @Override public boolean onQueryTextChange(String newText) { - if (!TextUtils.isEmpty(newText)) { + updateState(newText); + return true; + } + private void updateState(String query) { + if (!TextUtils.isEmpty(query)) { if (!isSearchMode()) { enterSearchMode(); } } else if (isSearchMode()) { exitSearchMode(true); } - doFilter(newText); - return true; + doFilter(query); } }); return super.onCreateOptionsMenu(menu); @@ -405,12 +349,7 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.select_all_check: - mSelectAllCheck.setChecked(!mSelectAllCheck.isChecked()); - if (mSelectAllCheck.isChecked()) { - selectAll(true); - } else { - selectAll(false); - } + selectAll(!mSelectAllItem.isChecked()); return true; case R.id.done: if (isSearchMode()) { @@ -419,49 +358,27 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis if (mMode == MODE_DEFAULT_CONTACT) { if (ACTION_MULTI_PICK.equals(getIntent().getAction())) { if (mChoiceSet.size() > MAX_CONTACTS_NUM_TO_SELECT_ONCE) { - Toast.makeText( - mContext, - mContext.getString(R.string.too_many_contacts_add_to_group, - MAX_CONTACTS_NUM_TO_SELECT_ONCE), Toast.LENGTH_SHORT) - .show(); + String text = getString(R.string.too_many_contacts_add_to_group, + MAX_CONTACTS_NUM_TO_SELECT_ONCE); + Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); } else { - Intent intent = new Intent(); - Bundle bundle = new Bundle(); - bundle.putBundle(PeopleActivity.RESULT_KEY, mChoiceSet); - intent.putExtras(bundle); - this.setResult(RESULT_OK, intent); - finish(); + setResultAndFinish(); } } else if (mChoiceSet.size() > 0) { showDialog(R.id.dialog_delete_contact_confirmation); } } else if (mMode == MODE_DEFAULT_PHONE) { - Intent intent = new Intent(); - Bundle bundle = new Bundle(); - bundle.putBundle(PeopleActivity.RESULT_KEY, mChoiceSet); - intent.putExtras(bundle); - this.setResult(RESULT_OK, intent); - finish(); + setResultAndFinish(); } else if (mMode == MODE_DEFAULT_SIM) { if (mChoiceSet.size() > 0) { showDialog(R.id.dialog_import_sim_contact_confirmation); } } else if (mMode == MODE_DEFAULT_EMAIL) { - Intent intent = new Intent(); - Bundle bundle = new Bundle(); - bundle.putBundle(PeopleActivity.RESULT_KEY, mChoiceSet); - intent.putExtras(bundle); - this.setResult(RESULT_OK, intent); - finish(); + setResultAndFinish(); } else if (mMode == MODE_DEFAULT_CALL) { if (mChoiceSet.size() > 0) { if (mSelectCallLog) { - Intent intent = new Intent(); - Bundle bundle = new Bundle(); - bundle.putBundle(PeopleActivity.RESULT_KEY, mChoiceSet); - intent.putExtras(bundle); - this.setResult(RESULT_OK, intent); - finish(); + setResultAndFinish(); } else { showDialog(DIALOG_DEL_CALL); } @@ -475,6 +392,15 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis return super.onOptionsItemSelected(item); } + private void setResultAndFinish() { + Intent intent = new Intent(); + Bundle bundle = new Bundle(); + bundle.putBundle(PeopleActivity.RESULT_KEY, mChoiceSet); + intent.putExtras(bundle); + setResult(RESULT_OK, intent); + finish(); + } + private boolean isSearchMode() { return (mMode & MODE_MASK_SEARCH) == MODE_MASK_SEARCH; } @@ -482,47 +408,41 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis @Override protected void onListItemClick(ListView l, View v, int position, long id) { hideSoftKeyboard(); - CheckBox checkBox = (CheckBox) v.findViewById(R.id.pick_contact_check); - boolean isChecked = !checkBox.isChecked(); - checkBox.setChecked(isChecked); - if (isChecked) { + + ContactItemCache cache = (ContactItemCache) v.getTag(); + String key = String.valueOf(cache.id); + + if (!mChoiceSet.containsKey(key)) { String[] value = null; - ContactItemCache cache = (ContactItemCache) v.getTag(); if (isPickContact()) { value = new String[] { - cache.lookupKey, String.valueOf(cache.id) + cache.lookupKey, String.valueOf(cache.id) }; } else if (isPickPhone()) { value = new String[] { - cache.name, cache.number, cache.type, - cache.label, cache.contact_id + cache.name, cache.number, cache.type, + cache.label, cache.contact_id }; } else if (isPickEmail()) { value = new String[] { - cache.name, cache.email + cache.name, cache.email }; } else if (isPickSim()) { value = new String[] { - cache.name, cache.number, cache.email, cache.anrs + cache.name, cache.number, cache.email, cache.anrs + }; + } else if (isPickCall() && mSelectCallLog) { + value = new String[] { + cache.name, cache.number }; - } else if (isPickCall()) { - if (mSelectCallLog) { - value = new String[] { - cache.name, cache.number - }; - } - } - mChoiceSet.putStringArray(String.valueOf(id), value); - if (!isSearchMode()) { - if (mChoiceSet.size() == mAdapter.getCount()) { - mSelectAllCheck.setChecked(true); - } } + mChoiceSet.putStringArray(key, value); } else { - mChoiceSet.remove(String.valueOf(id)); - mSelectAllCheck.setChecked(false); + mChoiceSet.remove(key); } - mBar.setSubtitle(updateCount()); + + updateActionBar(); + mAdapter.notifyDataSetChanged(); } @Override @@ -538,82 +458,72 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis return super.onKeyDown(keyCode, event); } - private String updateCount() { - if (0 == mChoiceSet.size()) { - mDone.setVisible(false); - return null; - } else { - mDone.setVisible(true); - return mChoiceSet.size() + " " + getString(R.string.contacts_selected); + private void updateActionBar() { + String countTitle = null; + if (!mChoiceSet.isEmpty()) { + countTitle = getResources().getQuantityString(R.plurals.contacts_selected, + mChoiceSet.size(), mChoiceSet.size()); + } + mActionBar.setSubtitle(countTitle); + if (mDoneItem != null) { + mDoneItem.setVisible(!mChoiceSet.isEmpty()); + } + if (mSelectAllItem != null) { + mSelectAllItem.setChecked(mChoiceSet.size() == mAdapter.getCount()); } - } - - private void backupChoiceSet() { - mBackupChoiceSet = (Bundle) mChoiceSet.clone(); - } - - private void restoreChoiceSet() { - mChoiceSet = mBackupChoiceSet; } private void enterSearchMode() { + mSelectAllItem.setVisible(false); mMode |= MODE_MASK_SEARCH; - backupChoiceSet(); } private void exitSearchMode(boolean isConfirmed) { mMode &= ~MODE_MASK_SEARCH; hideSoftKeyboard(); - if (!isConfirmed) { - restoreChoiceSet(); - } - mBar.setSubtitle(updateCount()); + mSelectAllItem.setVisible(true); + updateActionBar(); } + @Override protected Dialog onCreateDialog(int id, Bundle bundle) { switch (id) { - case R.id.dialog_delete_contact_confirmation: { + case R.id.dialog_delete_contact_confirmation: return new AlertDialog.Builder(this) .setTitle(R.string.deleteConfirmation_title) - .setIcon(android.R.drawable.ic_dialog_alert) .setMessage(getResources().getQuantityString( R.plurals.ContactMultiDeleteConfirmation, mChoiceSet.size(), mChoiceSet.size())) .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, - new DeleteClickListener()).create(); - } - case DIALOG_DEL_CALL: { - return new AlertDialog.Builder(this).setTitle(R.string.title_del_call) - .setIcon(android.R.drawable.ic_dialog_alert).setMessage( - R.string.delete_call_alert).setNegativeButton( - android.R.string.cancel, null).setPositiveButton( - android.R.string.ok, new DeleteClickListener()).create(); - } - case R.id.dialog_import_sim_contact_confirmation: { + .setPositiveButton(android.R.string.ok, this) + .create(); + case DIALOG_DEL_CALL: + return new AlertDialog.Builder(this) + .setTitle(R.string.title_del_call) + .setMessage(R.string.delete_call_alert) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(android.R.string.ok, this) + .create(); + case R.id.dialog_import_sim_contact_confirmation: return new AlertDialog.Builder(this) .setTitle(R.string.importConfirmation_title) - .setIcon(android.R.drawable.ic_dialog_alert) .setMessage(getResources().getQuantityString( R.plurals.ContactMultiImportConfirmation, mChoiceSet.size(), mChoiceSet.size())) .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(android.R.string.ok, - new DeleteClickListener()).create(); - } - + .setPositiveButton(android.R.string.ok, this) + .create(); } return super.onCreateDialog(id, bundle); } - private class DeleteContactsThread extends Thread - implements OnCancelListener, DialogInterface.OnClickListener { - + private class DeleteContactsThread extends Thread implements + DialogInterface.OnCancelListener, DialogInterface.OnClickListener { boolean mCanceled = false; private String name = null; private String number = null; - final String[] PROJECTION = new String[] { + private final String[] PROJECTION = new String[] { Phone.CONTACT_ID, Phone.NUMBER, Phone.DISPLAY_NAME @@ -622,7 +532,6 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis private final int COLUMN_NAME = 2; private ArrayList<ContentProviderOperation> mOpsCalls = null; - private ArrayList<ContentProviderOperation> mOpsContacts = null; public DeleteContactsThread() { @@ -630,6 +539,7 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis @Override public void run() { + final Context context = MultiPickContactActivity.this; final ContentResolver resolver = getContentResolver(); // The mChoiceSet object will change when activity restart, but @@ -639,8 +549,7 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis Set<String> keySet = choiceSet.keySet(); Iterator<String> it = keySet.iterator(); - android.content.ContentProviderOperation.Builder builder = null; - + ContentProviderOperation.Builder builder = null; ContentProviderOperation cpo = null; // Current contact count we can delete. @@ -663,18 +572,16 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis } else { uri = Uri.withAppendedPath(Contacts.CONTENT_URI, id); long longId = Long.parseLong(id); - int subscription = - mSimContactsOperation.getSimSubscription(longId); + int subscription = mSimContactsOperation.getSimSubscription(longId); if (subscription == MSimConstants.SUB1 || subscription == MSimConstants.SUB2) { - if (MoreContactUtils.isAPMOnAndSIMPowerDown(mContext)) { + if (MoreContactUtils.isAPMOnAndSIMPowerDown(context)) { break; } ContentValues values = mSimContactsOperation.getSimAccountValues(longId); log("values is : " + values + "; sub is " + subscription); - int result = mSimContactsOperation.delete(values, subscription); - if (result == 0) { + if (mSimContactsOperation.delete(values, subscription) == 0) { mProgressDialog.incrementProgressBy(1); continue; } @@ -690,7 +597,7 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis if (count % BATCH_DELETE_CONTACT_NUMBER == 0) { batchDelete(); } - count ++; + count++; } batchDelete(); @@ -706,8 +613,8 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis */ private void batchDelete() { try { - mContext.getContentResolver().applyBatch(CallLog.AUTHORITY, mOpsCalls); - mContext.getContentResolver().applyBatch(ContactsContract.AUTHORITY, mOpsContacts); + getContentResolver().applyBatch(CallLog.AUTHORITY, mOpsCalls); + getContentResolver().applyBatch(ContactsContract.AUTHORITY, mOpsContacts); mOpsCalls.clear(); mOpsContacts.clear(); } catch (RemoteException e) { @@ -717,74 +624,68 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis } } + @Override public void onCancel(DialogInterface dialog) { mCanceled = true; Log.d(TAG, "DeleteContactsThread onCancel, progress:" + mProgressDialog.getProgress()); // Give a toast show to tell user delete termination } + @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_NEGATIVE) { mCanceled = true; mProgressDialog.dismiss(); } } - } - private class DeleteClickListener implements DialogInterface.OnClickListener { - public void onClick(DialogInterface dialog, int which) { - CharSequence title = null; - CharSequence message = null; - - if (isPickCall()) { - title = getString(R.string.delete_call_title); - message = getString(R.string.delete_call_message); - } else if (isPickSim()) { - title = getString(R.string.import_sim_contacts_title); - message = getString(R.string.import_sim_contacts_message); - } else { - title = getString(R.string.delete_contacts_title); - message = getString(R.string.delete_contacts_message); - } - - Thread thread; - if (isPickSim()) { - thread = new ImportAllSimContactsThread(); - } else { - thread = new DeleteContactsThread(); - } + @Override + public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { + switch (keyCode) { + case KeyEvent.KEYCODE_SEARCH: + case KeyEvent.KEYCODE_CALL: + return true; + default: + return false; + } + } - DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() { - public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { - switch (keyCode) { - case KeyEvent.KEYCODE_SEARCH: - case KeyEvent.KEYCODE_CALL: - return true; - default: - return false; - } - } - }; - - mProgressDialog = new ProgressDialog(MultiPickContactActivity.this); - mProgressDialog.setTitle(title); - mProgressDialog.setMessage(message); - mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, - getString(android.R.string.cancel), (OnClickListener) thread); - mProgressDialog.setOnCancelListener((OnCancelListener) thread); - mProgressDialog.setOnKeyListener(keyListener); - mProgressDialog.setProgress(0); - mProgressDialog.setMax(mChoiceSet.size()); - - // set dialog can not be canceled by touching outside area of - // dialog. - mProgressDialog.setCanceledOnTouchOutside(false); - mProgressDialog.show(); - - thread.start(); + @Override + public void onClick(DialogInterface dialog, int which) { + CharSequence title = null; + CharSequence message = null; + + if (isPickCall()) { + title = getString(R.string.delete_call_title); + message = getString(R.string.delete_call_message); + } else if (isPickSim()) { + title = getString(R.string.import_sim_contacts_title); + message = getString(R.string.import_sim_contacts_message); + } else { + title = getString(R.string.delete_contacts_title); + message = getString(R.string.delete_contacts_message); } + + Thread thread = isPickSim() + ? new ImportAllSimContactsThread() : new DeleteContactsThread(); + + mProgressDialog = new ProgressDialog(MultiPickContactActivity.this); + mProgressDialog.setTitle(title); + mProgressDialog.setMessage(message); + mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, + getString(android.R.string.cancel), (DialogInterface.OnClickListener) thread); + mProgressDialog.setOnCancelListener((DialogInterface.OnCancelListener) thread); + mProgressDialog.setOnKeyListener(this); + mProgressDialog.setProgress(0); + mProgressDialog.setMax(mChoiceSet.size()); + + // set dialog can not be canceled by touching outside area of dialog + mProgressDialog.setCanceledOnTouchOutside(false); + mProgressDialog.show(); + + thread.start(); } @Override @@ -798,7 +699,7 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis mProgressDialog.cancel(); } - //unregister receiver. + // unregister receiver. if (mBroadcastReceiver != null) { unregisterReceiver(mBroadcastReceiver); } @@ -806,39 +707,6 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis super.onDestroy(); } - private Uri getUriToQuery() { - Uri uri; - switch (mMode) { - case MODE_DEFAULT_CONTACT: - case MODE_SEARCH_CONTACT: - uri = Contacts.CONTENT_URI; - break; - case MODE_DEFAULT_EMAIL: - case MODE_SEARCH_EMAIL: - uri = Email.CONTENT_URI; - break; - case MODE_DEFAULT_PHONE: - case MODE_SEARCH_PHONE: - uri = Phone.CONTENT_URI; - break; - case MODE_DEFAULT_CALL: - case MODE_SEARCH_CALL: - uri = Calls.CONTENT_URI_WITH_VOICEMAIL; - break; - case MODE_DEFAULT_SIM: - case MODE_SEARCH_SIM: { - mIntent = getIntent(); - int subscription = mIntent.getIntExtra(MSimConstants.SUBSCRIPTION_KEY, 0); - uri = querySimContacts(subscription); - break; - } - default: - throw new IllegalArgumentException("getUriToQuery: Incorrect mode: " + mMode); - } - return uri.buildUpon() - .appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true").build(); - } - /** * Just get the uri we need to query contacts. * @@ -855,24 +723,59 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis if (filter != null && filter.filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) { - // Need consider account info limitation, construct the uri with // account info query parameter. - Builder builder = filterUri.buildUpon(); + Uri.Builder builder = filterUri.buildUpon(); filter.addAccountQueryParameterToUrl(builder); return builder.build(); } if (!isShowSIM()) { - filterUri = filterUri.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_TYPE, - SimAccountType.ACCOUNT_TYPE) - .appendQueryParameter(DefaultContactListAdapter.WITHOUT_SIM_FLAG, - "true").build(); + filterUri = filterUri.buildUpon() + .appendQueryParameter(RawContacts.ACCOUNT_TYPE, SimAccountType.ACCOUNT_TYPE) + .appendQueryParameter(DefaultContactListAdapter.WITHOUT_SIM_FLAG, "true") + .build(); } // No need to consider account info limitation, just return a uri // with "filter" path. return filterUri; } + + private Uri getUriToQuery() { + Uri uri; + switch (mMode) { + case MODE_DEFAULT_CONTACT: + case MODE_SEARCH_CONTACT: + uri = Contacts.CONTENT_URI; + break; + case MODE_DEFAULT_EMAIL: + case MODE_SEARCH_EMAIL: + uri = Email.CONTENT_URI; + break; + case MODE_DEFAULT_PHONE: + case MODE_SEARCH_PHONE: + uri = Phone.CONTENT_URI; + break; + case MODE_DEFAULT_CALL: + case MODE_SEARCH_CALL: + uri = Calls.CONTENT_URI_WITH_VOICEMAIL; + break; + case MODE_DEFAULT_SIM: + case MODE_SEARCH_SIM: + if (isMultiSimEnabled() && + getIntent().getIntExtra(MSimConstants.SUBSCRIPTION_KEY, 0) == SUB2) { + uri = Uri.parse("content://iccmsim/adn_sub2"); + } else { + uri = Uri.parse("content://iccmsim/adn"); + } + break; + default: + throw new IllegalArgumentException("getUriToQuery: Incorrect mode: " + mMode); + } + return uri.buildUpon() + .appendQueryParameter(ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS, "true").build(); + } + private Uri getFilterUri() { switch (mMode) { case MODE_SEARCH_CONTACT: @@ -903,7 +806,7 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis return CALL_LOG_PROJECTION; case MODE_DEFAULT_SIM: case MODE_SEARCH_SIM: - return COLUMN_NAMES; + return SIM_COLUMN_NAMES; default: log("getProjectionForQuery: Incorrect mode: " + mMode); } @@ -927,9 +830,8 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis case MODE_SEARCH_PHONE: if (isShowSIM()) { return null; - } else { - return PHONES_SELECTION; } + return PHONES_SELECTION; case MODE_DEFAULT_CONTACT: return getSelectionForAccount(); case MODE_DEFAULT_SIM: @@ -974,9 +876,8 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis case MODE_SEARCH_PHONE: if (isShowSIM()) { return null; - } else { - return PHONES_SELECTION_ARGS; } + return PHONES_SELECTION_ARGS; case MODE_DEFAULT_SIM: case MODE_SEARCH_SIM: return null; @@ -987,8 +888,8 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis private boolean isShowSIM() { // if airplane mode on, do not show SIM. - return !getIntent().hasExtra(EXT_NOT_SHOW_SIM_FLAG) - && !MoreContactUtils.isAPMOnAndSIMPowerDown(mContext); + return !getIntent().hasExtra(EXTRA_NOT_SHOW_SIM_FLAG) + && !MoreContactUtils.isAPMOnAndSIMPowerDown(this); } public void startQuery() { @@ -998,26 +899,26 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis if (filter != null) { if (filter.filterType == ContactListFilter.FILTER_TYPE_ACCOUNT) { // We should exclude the invisiable contacts. - uri = uri.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, - filter.accountName).appendQueryParameter(RawContacts.ACCOUNT_TYPE, - filter.accountType) + uri = uri.buildUpon() + .appendQueryParameter(RawContacts.ACCOUNT_NAME, filter.accountName) + .appendQueryParameter(RawContacts.ACCOUNT_TYPE, filter.accountType) .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY, - ContactsContract.Directory.DEFAULT+"").build(); + String.valueOf(ContactsContract.Directory.DEFAULT)) + .build(); } else if (filter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS) { // Do not query sim contacts in airplane mode. if (!isShowSIM()) { - uri = uri.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_TYPE, - SimAccountType.ACCOUNT_TYPE) - .appendQueryParameter(DefaultContactListAdapter.WITHOUT_SIM_FLAG, - "true").build(); + uri = uri.buildUpon() + .appendQueryParameter(RawContacts.ACCOUNT_TYPE, + SimAccountType.ACCOUNT_TYPE) + .appendQueryParameter(DefaultContactListAdapter.WITHOUT_SIM_FLAG, "true") + .build(); } } } String[] projection = getProjectionForQuery(); - String selection = getSelectionForQuery(); - String[] selectionArgs = getSelectionArgsForQuery(); - mQueryHandler.startQuery(QUERY_TOKEN, null, uri, projection, selection, - selectionArgs, getSortOrder(projection)); + mQueryHandler.startQuery(QUERY_TOKEN, null, uri, projection, + getSelectionForQuery(), getSelectionArgsForQuery(), getSortOrder(projection)); } public void doFilter(String s) { @@ -1028,10 +929,8 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis Uri uri = Uri.withAppendedPath(getFilterUri(), Uri.encode(s)); String[] projection = getProjectionForQuery(); - String selection = getSelectionForQuery(); - String[] selectionArgs = getSelectionArgsForQuery(); - mQueryHandler.startQuery(QUERY_TOKEN, null, uri, projection, selection, - selectionArgs, getSortOrder(projection)); + mQueryHandler.startQuery(QUERY_TOKEN, null, uri, projection, + getSelectionForQuery(), getSelectionArgsForQuery(), getSortOrder(projection)); } public void updateContent() { @@ -1086,49 +985,45 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis String id = null; String[] value = null; if (isPickContact()) { - id = String.valueOf(cursor.getLong(SUMMARY_ID_COLUMN_INDEX)); + id = String.valueOf(cursor.getLong(CONTACT_COLUMN_ID)); value = new String[] { - cursor.getString(SUMMARY_LOOKUP_KEY_COLUMN_INDEX), id + cursor.getString(CONTACT_COLUMN_LOOKUP_KEY), id }; } else if (isPickPhone()) { id = String.valueOf(cursor.getLong(PHONE_COLUMN_ID)); - String name = cursor.getString(PHONE_COLUMN_DISPLAY_NAME); - String number = cursor.getString(PHONE_COLUMN_NUMBER); - String type = String.valueOf(cursor.getInt(PHONE_COLUMN_TYPE)); - String label = cursor.getString(PHONE_COLUMN_LABEL); - String contact_id = String.valueOf(cursor.getLong(PHONE_COLUMN_CONTACT_ID)); value = new String[] { - name, number, type, label, contact_id + cursor.getString(CONTACT_COLUMN_DISPLAY_NAME), + cursor.getString(PHONE_COLUMN_NUMBER), + String.valueOf(cursor.getInt(PHONE_COLUMN_TYPE)), + cursor.getString(PHONE_COLUMN_LABEL), + String.valueOf(cursor.getLong(CONTACT_COLUMN_ID)) }; } else if (isPickEmail()) { id = String.valueOf(cursor.getLong(EMAIL_COLUMN_ID)); - String name = cursor.getString(EMAIL_COLUMN_DISPLAY_NAME); - String email = cursor.getString(EMAIL_COLUMN_ADDRESS); value = new String[] { - name, email, id + cursor.getString(CONTACT_COLUMN_DISPLAY_NAME), + cursor.getString(EMAIL_COLUMN_ADDRESS), + id }; } else if (isPickCall()) { + id = String.valueOf(cursor.getLong(CALLLOG_COLUMN_ID)); if (mSelectCallLog) { - id = String.valueOf(cursor.getLong(ID_COLUMN_INDEX)); - String number = cursor.getString(NUMBER_COLUMN_INDEX); - String name = cursor.getString(CALLER_NAME_COLUMN_INDEX); value = new String[] { - name, number + cursor.getString(CALLLOG_COLUMN_NUMBER), + cursor.getString(CALLLOG_COLUMN_CALLER_NAME) }; } else { - id = String.valueOf(cursor.getLong(ID_COLUMN_INDEX)); value = new String[] { - id + id }; } } else if (isPickSim()) { id = String.valueOf(cursor.getLong(SIM_COLUMN_ID)); - String name = cursor.getString(SIM_COLUMN_DISPLAY_NAME); - String number = cursor.getString(SIM_COLUMN_NUMBER); - String email = cursor.getString(SIM_COLUMN_EMAILS); - String anrs = cursor.getString(SIM_COLUMN_ANRS); value = new String[] { - name, number, email, anrs + cursor.getString(SIM_COLUMN_DISPLAY_NAME), + cursor.getString(SIM_COLUMN_NUMBER), + cursor.getString(SIM_COLUMN_EMAILS), + cursor.getString(SIM_COLUMN_ANRS) }; } if (isSelected) { @@ -1138,44 +1033,24 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis } } - // update UI items. - mBar.setSubtitle(updateCount()); - - int count = mList.getChildCount(); - for (int i = 0; i < count; i++) { - View v = mList.getChildAt(i); - CheckBox checkBox = (CheckBox) v.findViewById(R.id.pick_contact_check); - checkBox.setChecked(isSelected); - } + updateActionBar(); + mAdapter.notifyDataSetChanged(); } private class QueryHandler extends AsyncQueryHandler { - protected WeakReference<MultiPickContactActivity> mActivity; - public QueryHandler(Context context) { super(context.getContentResolver()); - mActivity = new WeakReference<MultiPickContactActivity>( - (MultiPickContactActivity) context); } @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { - // In the case of low memory, the WeakReference object may be - // recycled. - if (mActivity == null || mActivity.get() == null) { - mActivity = new WeakReference<MultiPickContactActivity>( - MultiPickContactActivity.this); - } - final MultiPickContactActivity activity = mActivity.get(); - activity.mAdapter.changeCursor(cursor); + mAdapter.changeCursor(cursor); if (cursor == null || cursor.getCount() == 0) { if (isPickCall()) { log("no call found"); - } else if (!activity.mAdapter.mIsContentChanged) { - Toast.makeText(mContext, R.string.listFoundAllContactsZero, Toast.LENGTH_SHORT) - .show(); } else { - activity.mAdapter.mIsContentChanged = false; + Toast.makeText(MultiPickContactActivity.this, + R.string.listFoundAllContactsZero, Toast.LENGTH_SHORT).show(); } } } @@ -1197,92 +1072,92 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis Context mContext; protected LayoutInflater mInflater; private ContactsSectionIndexer mIndexer; - public boolean mIsContentChanged = false; private ContactPhotoManager mContactPhotoManager; public ContactItemListAdapter(Context context) { super(context, null, false); mContext = context; - mInflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mContactPhotoManager = ContactPhotoManager.getInstance(mContext); } + private void assignContactAndFillCache(ContactListItemView cliv, Cursor cursor, + ContactItemCache cache) { + cache.lookupKey = cursor.getString(CONTACT_COLUMN_LOOKUP_KEY); + cache.name = cursor.getString(CONTACT_COLUMN_DISPLAY_NAME); + cliv.setDisplayName(cache.name); + + long photoId = cursor.getLong(CONTACT_COLUMN_PHOTO_ID); + mContactPhotoManager.loadThumbnail(cliv.getPhotoView(), photoId, false, null); + + CharSequence query = mSearchView != null ? mSearchView.getQuery() : null; + cliv.setHighlightedPrefix(query != null ? query.toString().toUpperCase() : null); + } + @Override public void bindView(View view, Context context, Cursor cursor) { ContactItemCache cache = (ContactItemCache) view.getTag(); + ContactListItemView cliv = (ContactListItemView) view.findViewById(R.id.contact); + if (isPickContact()) { - cache.id = cursor.getLong(SUMMARY_ID_COLUMN_INDEX); - cache.lookupKey = cursor.getString(SUMMARY_LOOKUP_KEY_COLUMN_INDEX); - cache.name = cursor.getString(SUMMARY_DISPLAY_NAME_PRIMARY_COLUMN_INDEX); - ((TextView) view.findViewById(R.id.pick_contact_name)) - .setText(cache.name == null ? getString(R.string.unknown) : cache.name); - view.findViewById(R.id.pick_contact_number).setVisibility(View.GONE); - - long photoId = 0; - if (!cursor.isNull(SUMMARY_PHOTO_ID_COLUMN_INDEX)) { - photoId = cursor.getLong(SUMMARY_PHOTO_ID_COLUMN_INDEX); - } - Account account = null; - if (!cursor.isNull(SUMMARY_ACCOUNT_TYPE) && !cursor.isNull(SUMMARY_ACCOUNT_NAME)) { - final String accountType = cursor.getString(SUMMARY_ACCOUNT_TYPE); - final String accountName = cursor.getString(SUMMARY_ACCOUNT_NAME); - account = new Account(accountName, accountType); - } - ImageView photo = ((ImageView) view.findViewById(R.id.pick_contact_photo)); - photo.setVisibility(View.VISIBLE); - mContactPhotoManager.loadThumbnail(photo, photoId, false, null); + cache.id = cursor.getLong(CONTACT_COLUMN_ID); + assignContactAndFillCache(cliv, cursor, cache); + cliv.setPhoneNumber(null); } else if (isPickPhone()) { cache.id = cursor.getLong(PHONE_COLUMN_ID); - cache.name = cursor.getString(PHONE_COLUMN_DISPLAY_NAME); cache.number = cursor.getString(PHONE_COLUMN_NUMBER); cache.label = cursor.getString(PHONE_COLUMN_LABEL); cache.type = String.valueOf(cursor.getInt(PHONE_COLUMN_TYPE)); - ((TextView) view.findViewById(R.id.pick_contact_name)).setText(cache.name); - ((TextView) view.findViewById(R.id.pick_contact_number)).setText(cache.number); + + assignContactAndFillCache(cliv, cursor, cache); + cliv.setPhoneNumber(cache.number); } else if (isPickSim()) { cache.id = cursor.getLong(SIM_COLUMN_ID); cache.name = cursor.getString(SIM_COLUMN_DISPLAY_NAME); cache.number = cursor.getString(SIM_COLUMN_NUMBER); cache.email = cursor.getString(SIM_COLUMN_EMAILS); cache.anrs = cursor.getString(SIM_COLUMN_ANRS); - ((TextView) view.findViewById(R.id.pick_contact_name)).setText(cache.name); + + cliv.setDisplayName(cache.name); + cliv.removePhotoView(); if (!TextUtils.isEmpty(cache.number)) { - ((TextView) view.findViewById(R.id.pick_contact_number)).setText(cache.number); + cliv.setPhoneNumber(cache.number); } else if (!TextUtils.isEmpty(cache.email)) { String[] emailArray = (cache.email).split(","); - ((TextView) view.findViewById(R.id.pick_contact_number)).setText(emailArray[0]); + cliv.setPhoneNumber(emailArray[0]); + } else { + cliv.setPhoneNumber(null); } } else if (isPickEmail()) { cache.id = cursor.getLong(EMAIL_COLUMN_ID); - cache.name = cursor.getString(EMAIL_COLUMN_DISPLAY_NAME); cache.email = cursor.getString(EMAIL_COLUMN_ADDRESS); - ((TextView) view.findViewById(R.id.pick_contact_name)).setText(cache.name); - ((TextView) view.findViewById(R.id.pick_contact_number)).setText(cache.email); + + assignContactAndFillCache(cliv, cursor, cache); + cliv.setPhoneNumber(cache.email); } else if (isPickCall()) { - cache.id = cursor.getLong(ID_COLUMN_INDEX); - cache.name = cursor.getString(CALLER_NAME_COLUMN_INDEX); - cache.number = cursor.getString(NUMBER_COLUMN_INDEX); - String number = cursor.getString(NUMBER_COLUMN_INDEX); - String callerName = cursor.getString(CALLER_NAME_COLUMN_INDEX); - int callerNumberType = cursor.getInt(CALLER_NUMBERTYPE_COLUMN_INDEX); - String callerNumberLabel = cursor.getString(CALLER_NUMBERLABEL_COLUMN_INDEX); - int subscription = cursor.getInt(PHONE_SUBSCRIPTION_COLUMN_INDEX); - long date = cursor.getLong(DATE_COLUMN_INDEX); - long duration = cursor.getLong(DURATION_COLUMN_INDEX); - int type = cursor.getInt(CALL_TYPE_COLUMN_INDEX); + cache.id = cursor.getLong(CALLLOG_COLUMN_ID); + cache.name = cursor.getString(CALLLOG_COLUMN_CALLER_NAME); + cache.number = cursor.getString(CALLLOG_COLUMN_NUMBER); + + String callerName = cursor.getString(CALLLOG_COLUMN_CALLER_NAME); + int callerNumberType = cursor.getInt(CALLLOG_COLUMN_CALLER_NUMBERTYPE); + String callerNumberLabel = cursor.getString(CALLLOG_COLUMN_CALLER_NUMBERLABEL); + String geocodedLocation = cursor.getString(CALLLOG_COLUMN_CALLER_LOCATION); + int subscription = cursor.getInt(CALLLOG_COLUMN_SUBSCRIPTION); + long date = cursor.getLong(CALLLOG_COLUMN_DATE); + long duration = cursor.getLong(CALLLOG_COLUMN_DURATION); + int type = cursor.getInt(CALLLOG_COLUMN_CALL_TYPE); ImageView callType = (ImageView) view.findViewById(R.id.call_type_icon); - TextView dateText = (TextView) view.findViewById(R.id.date); + TextView dateText = (TextView) view.findViewById(R.id.call_date); TextView durationText = (TextView) view.findViewById(R.id.duration); TextView subSlotText = (TextView) view.findViewById(R.id.subscription); - TextView numberLableText = (TextView) view.findViewById(R.id.label); - TextView numberText = (TextView) view.findViewById(R.id.number); - TextView callerNameText = (TextView) view.findViewById(R.id.line1); + TextView numberLabelText = (TextView) view.findViewById(R.id.label); + TextView nameText = (TextView) view.findViewById(R.id.name); // only for monkey test, callType can not be null in normal behaviour - if(callType == null){ + if (callType == null) { return; } @@ -1290,16 +1165,13 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis // Set the icon switch (type) { case Calls.INCOMING_TYPE: - callType.setImageDrawable(mDrawableIncoming); + callType.setImageResource(R.drawable.ic_call_incoming_holo_dark); break; - case Calls.OUTGOING_TYPE: - callType.setImageDrawable(mDrawableOutgoing); + callType.setImageResource(R.drawable.ic_call_outgoing_holo_dark); break; - - case Calls.MISSED_TYPE: - callType.setImageDrawable(mDrawableMissed); + callType.setImageResource(R.drawable.ic_call_missed_holo_dark); break; default: callType.setVisibility(View.INVISIBLE); @@ -1308,31 +1180,21 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis // set the number if (!TextUtils.isEmpty(callerName)) { - callerNameText.setText(callerName); - callerNameText.setVisibility(View.VISIBLE); - - numberText.setVisibility(View.GONE); - numberText.setText(null); + nameText.setText(callerName); } else { - callerNameText.setVisibility(View.GONE); - callerNameText.setText(null); - - numberText.setVisibility(View.VISIBLE); - numberText.setText(getDisplayNumber(number)); + nameText.setText(getDisplayNumber(cache.number)); } CharSequence numberLabel = null; - if (!PhoneNumberUtils.isUriNumber(number)) { + if (callerNumberType != 0 && !PhoneNumberUtils.isUriNumber(cache.number)) { numberLabel = Phone.getDisplayLabel(context, callerNumberType, callerNumberLabel); - } - if (!TextUtils.isEmpty(numberLabel)) { - numberLableText.setText(numberLabel); - numberLableText.setVisibility(View.VISIBLE); } else { - numberLableText.setText(null); - numberLableText.setVisibility(View.INVISIBLE); + numberLabel = geocodedLocation; } + numberLabelText.setText(numberLabel); + numberLabelText.setVisibility(TextUtils.isEmpty(numberLabel) + ? View.GONE : View.VISIBLE); // set date dateText.setText(DateUtils.getRelativeTimeSpanString(date, @@ -1343,48 +1205,36 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis durationText.setText(DateUtils.formatElapsedTime(duration)); // set slot - subSlotText.setText(MoreContactUtils.getMultiSimAliasesName( - MultiPickContactActivity.this, subscription)); + if (isMultiSimEnabled()) { + subSlotText.setText(MoreContactUtils.getMultiSimAliasesName( + MultiPickContactActivity.this, subscription)); + } else { + subSlotText.setVisibility(View.GONE); + } } CheckBox checkBox = (CheckBox) view.findViewById(R.id.pick_contact_check); - if (mChoiceSet.containsKey(String.valueOf(cache.id))) { - checkBox.setChecked(true); - } else { - checkBox.setChecked(false); - } + checkBox.setChecked(mChoiceSet.containsKey(String.valueOf(cache.id))); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - View v = null; - if (isPickCall()) { - v = mInflater.inflate(R.layout.pick_calls_item, parent, false); - } else { - v = mInflater - .inflate(R.layout.pick_contact_item, parent, false); + int layoutResId = isPickCall() ? R.layout.pick_calls_item : R.layout.pick_contact_item; + View v = mInflater.inflate(layoutResId, parent, false); + ContactListItemView cliv = (ContactListItemView) v.findViewById(R.id.contact); + if (cliv != null) { + ContactListItemView.PhotoPosition pp = cliv.getPhotoPosition(); + cliv.setPhotoPosition(pp == ContactListItemView.PhotoPosition.LEFT + ? ContactListItemView.PhotoPosition.RIGHT + : ContactListItemView.PhotoPosition.LEFT); + cliv.setUnknownNameText(getString(R.string.unknown)); + cliv.setDividerVisible(false); } ContactItemCache cache = new ContactItemCache(); v.setTag(cache); return v; } - public View getView(int position, View convertView, ViewGroup parent) { - View v; - - if (!mCursor.moveToPosition(position)) { - throw new IllegalStateException( - "couldn't move cursor to position " + position); - } - if (convertView != null && convertView.getTag() != null) { - v = convertView; - } else { - v = newView(mContext, mCursor, parent); - } - bindView(v, mContext, mCursor); - return v; - } - @Override protected void onContentChanged() { updateContent(); @@ -1393,36 +1243,19 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis @Override public void changeCursor(Cursor cursor) { super.changeCursor(cursor); - if (!isSearchMode()) { - if (cursor == null || cursor.getCount() == 0) { - if (mSelectAllCheck != null) { - mSelectAllCheck.setChecked(false); - } - } else if (cursor.getCount() > mChoiceSet.size()) { - if (mSelectAllCheck != null) { - mSelectAllCheck.setChecked(false); - } - } else { - if (mSelectAllCheck != null) { - mSelectAllCheck.setChecked(true); - } - } - } String[] sections = null; int[] counts = null; - if (cursor != null - && cursor.getExtras() != null - && cursor.getExtras() - .containsKey(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES)) { - sections = cursor.getExtras().getStringArray( - ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES); - counts = cursor.getExtras().getIntArray( - ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS); + Bundle extras = cursor != null ? cursor.getExtras() : null; + if (extras != null && + extras.containsKey(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES)) { + sections = extras.getStringArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES); + counts = extras.getIntArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS); } else { sections = new String[0]; counts = new int[0]; } mIndexer = new ContactsSectionIndexer(sections, counts); + updateActionBar(); } @Override @@ -1447,36 +1280,30 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis @Override public int getSectionForPosition(int position) { - return 0; + if (mIndexer != null) { + return mIndexer.getSectionForPosition(position); + } + return -1; } public int getSortIndex() { - int index = -1; switch (mMode) { case MODE_DEFAULT_CONTACT: case MODE_SEARCH_CONTACT: - index = SUMMARY_DISPLAY_NAME_PRIMARY_COLUMN_INDEX; - break; case MODE_DEFAULT_PHONE: case MODE_SEARCH_PHONE: - index = PHONE_COLUMN_DISPLAY_NAME; - break; case MODE_DEFAULT_EMAIL: case MODE_SEARCH_EMAIL: - index = EMAIL_COLUMN_DISPLAY_NAME; - break; + return CONTACT_COLUMN_DISPLAY_NAME; case MODE_DEFAULT_CALL: case MODE_SEARCH_CALL: - index = CALLER_NAME_COLUMN_INDEX; - break; + return CALLLOG_COLUMN_CALLER_NAME; case MODE_DEFAULT_SIM: case MODE_SEARCH_SIM: - index = SIM_COLUMN_DISPLAY_NAME; - break; + return SIM_COLUMN_DISPLAY_NAME; default: throw new IllegalArgumentException("Incorrect mode for multi pick"); } - return index; } } @@ -1492,48 +1319,25 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis private void hideSoftKeyboard() { // Hide soft keyboard, if visible - InputMethodManager inputMethodManager = (InputMethodManager) - getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager inputMethodManager = + (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); } protected static void log(String msg) { - if (DEBUG) - Log.d(TAG, msg); + if (DEBUG) Log.d(TAG, msg); } private boolean isMultiSimEnabled() { return MSimTelephonyManager.getDefault().isMultiSimEnabled(); } - private Uri querySimContacts(int subscription) { - Intent intent = new Intent(); - if (subscription != SUB1 && subscription != SUB2) { - return null; - } - - if (isMultiSimEnabled()) { - if (subscription == SUB1) { - intent.setData(Uri.parse("content://iccmsim/adn")); - } else if (subscription == SUB2) { - intent.setData(Uri.parse("content://iccmsim/adn_sub2")); - } - } - else { - intent.setData(Uri.parse("content://icc/adn")); - } - - Uri uri = intent.getData(); - return uri; - } - protected Account[] getSimAccounts() { - return accountManager - .getAccountsByType(SimContactsConstants.ACCOUNT_TYPE_SIM); + return mAccountManager.getAccountsByType(SimContactsConstants.ACCOUNT_TYPE_SIM); } private class ImportAllSimContactsThread extends Thread - implements OnCancelListener, DialogInterface.OnClickListener { + implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener { private int mSubscription = 0; boolean mCanceled = false; // The total count how many to import. @@ -1553,20 +1357,19 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis @Override public void run() { final ContentValues emptyContentValues = new ContentValues(); - final ContentResolver resolver = mContext.getContentResolver(); + final ContentResolver resolver = getContentResolver(); String type = getIntent().getStringExtra(SimContactsConstants.ACCOUNT_TYPE); String name = getIntent().getStringExtra(SimContactsConstants.ACCOUNT_NAME); mAccount = new Account(name != null ? name : SimContactsConstants.PHONE_NAME, - type != null ? type - : SimContactsConstants.ACCOUNT_TYPE_PHONE); + type != null ? type : SimContactsConstants.ACCOUNT_TYPE_PHONE); log("import sim contact to account: " + mAccount); - Set<String> keySet = mChoiceSet.keySet(); - mTotalCount = keySet.size(); - Iterator<String> it = keySet.iterator(); - while (!mCanceled && it.hasNext()) { + mTotalCount = mChoiceSet.size(); - String key = it.next(); + for (String key : mChoiceSet.keySet()) { + if (mCanceled) { + break; + } String[] values = mChoiceSet.getStringArray(key); actuallyImportOneSimContact(values, resolver, mAccount); mActualCount++; @@ -1575,15 +1378,17 @@ public class MultiPickContactActivity extends ListActivity implements OnTouchLis finish(); } + @Override public void onCancel(DialogInterface dialog) { + final Context context = MultiPickContactActivity.this; mCanceled = true; // Give a toast show to tell user import termination. if (mActualCount < mTotalCount) { String text = getResources().getQuantityString(R.plurals.import_stop, mActualCount, mActualCount); - Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show(); + Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); } else { - Toast.makeText(mContext, R.string.import_finish, Toast.LENGTH_SHORT).show(); + Toast.makeText(context, R.string.import_finish, Toast.LENGTH_SHORT).show(); } } diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java index 70463c222..efabf3259 100644 --- a/src/com/android/contacts/activities/PeopleActivity.java +++ b/src/com/android/contacts/activities/PeopleActivity.java @@ -72,7 +72,6 @@ import com.android.contacts.detail.ContactDetailLayoutController; import com.android.contacts.detail.ContactDetailUpdatesFragment; import com.android.contacts.detail.ContactLoaderFragment; import com.android.contacts.detail.ContactLoaderFragment.ContactLoaderFragmentListener; -import com.android.contacts.editor.MultiPickContactActivity; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.dialog.ClearFrequentsDialog; import com.android.contacts.common.editor.SelectAccountDialogFragment; diff --git a/src/com/android/contacts/group/local/MemberListActivity.java b/src/com/android/contacts/group/local/MemberListActivity.java index 2bb5b1903..723bb60f9 100644 --- a/src/com/android/contacts/group/local/MemberListActivity.java +++ b/src/com/android/contacts/group/local/MemberListActivity.java @@ -84,13 +84,13 @@ import android.widget.TextView; import android.widget.Toast; import com.android.contacts.R; +import com.android.contacts.activities.MultiPickContactActivity; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.SimContactsConstants; import com.android.contacts.common.list.AccountFilterActivity; import com.android.contacts.common.list.ContactListFilter; import com.android.contacts.common.model.account.PhoneAccountType; -import com.android.contacts.editor.MultiPickContactActivity; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -659,7 +659,7 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl private void pickMembers() { Intent intent = new Intent(MultiPickContactActivity.ACTION_MULTI_PICK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); - intent.putExtra(MultiPickContactActivity.IS_CONTACT,true); + intent.putExtra(MultiPickContactActivity.EXTRA_IS_CONTACT, true); intent.setClass(this, MultiPickContactActivity.class); ContactListFilter filter = new ContactListFilter(ContactListFilter.FILTER_TYPE_ACCOUNT, PhoneAccountType.ACCOUNT_TYPE, SimContactsConstants.PHONE_NAME, null, null); |