Merge "Hide FAB if the account is read-only"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 27c9f96..6a0338a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -508,5 +508,11 @@
</provider>
<meta-data android:name="android.nfc.disable_beam_default" android:value="true" />
+
+ <receiver android:name="com.android.contacts.editor.AccountsChangedBroadcastReceiver">
+ <intent-filter>
+ <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED"/>
+ </intent-filter>
+ </receiver>
</application>
</manifest>
diff --git a/res/layout/group_member_suggestion.xml b/res/layout/group_member_suggestion.xml
deleted file mode 100644
index 4fe8d20..0000000
--- a/res/layout/group_member_suggestion.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 2011, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="48dip"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- android:background="?android:attr/selectableItemBackground">
-
- <LinearLayout
- android:layout_width="0dip"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:gravity="center_vertical"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/text1"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingLeft="8dip"
- android:paddingStart="8dip"
- android:singleLine="true"
- android:ellipsize="end"/>
-
- <TextView android:id="@+id/text2"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?android:attr/textColorSecondary"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingLeft="8dip"
- android:paddingStart="8dip"
- android:singleLine="true"
- android:ellipsize="end" />
-
- </LinearLayout>
-
- <ImageView
- android:id="@+id/icon"
- android:layout_width="48dip"
- android:layout_height="48dip"
- android:cropToPadding="true"
- android:scaleType="centerCrop" />
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/menu/view_group.xml b/res/menu/view_group.xml
index 2fc36be..cf945fd 100644
--- a/res/menu/view_group.xml
+++ b/res/menu/view_group.xml
@@ -24,11 +24,6 @@
contacts:showAsAction="ifRoom" />
<item
- android:id="@+id/menu_search"
- android:icon="@drawable/ic_ab_search"
- android:title="@string/menu_search" />
-
- <item
android:id="@+id/menu_rename_group"
android:title="@string/menu_renameGroup"/>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 880460b..995ed06 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -134,8 +134,8 @@
<item name="colorPrimary">@color/primary_color</item>
<item name="android:colorAccent">@color/primary_color</item>
<item name="colorAccent">@color/primary_color</item>
- <item name="android:alertDialogTheme">@style/ContactsAlertDialogTheme</item>
- <item name="alertDialogTheme">@style/ContactsAlertDialogTheme</item>
+ <item name="android:alertDialogTheme">@style/ContactsAlertDialogThemeAppCompat</item>
+ <item name="alertDialogTheme">@style/ContactsAlertDialogThemeAppCompat</item>
<item name="list_item_height">?android:attr/listPreferredItemHeight</item>
<item name="activated_background">@drawable/list_item_activated_background</item>
<item name="section_header_background">@drawable/list_title_holo</item>
@@ -376,7 +376,13 @@
<item name="android:fontFamily">sans-serif</item>
</style>
- <style name="ContactsAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.MinWidth">
+ <!-- Inherit from Theme.Material.Light.Dialog instead of Theme.Material.Light.Dialog.Alert
+ since the Alert dialog is private. They are identical anyway. -->
+ <style name="ContactsAlertDialogTheme" parent="@android:style/Theme.Material.Light.Dialog">
+ <item name="android:colorAccent">@color/primary_color</item>
+ </style>
+
+ <style name="ContactsAlertDialogThemeAppCompat" parent="Theme.AppCompat.Light.Dialog.MinWidth">
<item name="android:colorAccent">@color/primary_color</item>
<item name="colorAccent">@color/primary_color</item>
</style>
diff --git a/src/com/android/contacts/GroupMemberLoader.java b/src/com/android/contacts/GroupMemberLoader.java
index 9f55848..8bc7d04 100644
--- a/src/com/android/contacts/GroupMemberLoader.java
+++ b/src/com/android/contacts/GroupMemberLoader.java
@@ -52,34 +52,8 @@
public static final int CONTACT_PHOTO_ID = 5;
}
- public static class GroupDetailQuery {
- private static final String[] PROJECTION = new String[] {
- Data.CONTACT_ID, // 0
- Data.PHOTO_URI, // 1
- Data.LOOKUP_KEY, // 2
- Data.DISPLAY_NAME_PRIMARY, // 3
- Data.CONTACT_PRESENCE, // 4
- Data.CONTACT_STATUS, // 5
- };
-
- public static final int CONTACT_ID = 0;
- public static final int CONTACT_PHOTO_URI = 1;
- public static final int CONTACT_LOOKUP_KEY = 2;
- public static final int CONTACT_DISPLAY_NAME_PRIMARY = 3;
- public static final int CONTACT_PRESENCE_STATUS = 4;
- public static final int CONTACT_STATUS = 5;
- }
-
private final long mGroupId;
- /**
- * @return GroupMemberLoader object which can be used in group editor.
- */
- public static GroupMemberLoader constructLoaderForGroupEditorQuery(
- Context context, long groupId) {
- return new GroupMemberLoader(context, groupId, GroupEditorQuery.PROJECTION);
- }
-
private GroupMemberLoader(Context context, long groupId, String[] projection) {
super(context);
mGroupId = groupId;
diff --git a/src/com/android/contacts/activities/ContactEditorBaseActivity.java b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
index ffbeb49..97095f0 100644
--- a/src/com/android/contacts/activities/ContactEditorBaseActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
@@ -16,6 +16,18 @@
package com.android.contacts.activities;
+import android.app.ActionBar;
+import android.app.Dialog;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.RawContacts;
+import android.util.Log;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+
import com.android.contacts.ContactSaveService;
import com.android.contacts.ContactsActivity;
import com.android.contacts.R;
@@ -29,18 +41,6 @@
import com.android.contacts.interactions.ContactDeletionInteraction;
import com.android.contacts.util.DialogManager;
-import android.app.ActionBar;
-import android.app.Dialog;
-import android.content.ContentValues;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.RawContacts;
-import android.util.Log;
-import android.view.View;
-import android.view.inputmethod.InputMethodManager;
-
import java.util.ArrayList;
/**
@@ -68,6 +68,8 @@
public static final String ACTION_SAVE_COMPLETED = "saveCompleted";
public static final int RESULT_CODE_SPLIT = 2;
+ // 3 used for ContactDeletionInteraction.RESULT_CODE_DELETED
+ public static final int RESULT_CODE_EDITED = 4;
protected int mActionBarTitleResId;
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index 80a4acb..6e2746d 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -139,10 +139,9 @@
.inflate(R.layout.custom_action_bar, null);
mSearchView = (SearchView) mSearchViewContainer.findViewById(R.id.search_view);
- // Postal address group member,and legacy pickers don't support search, so just show
+ // Postal address pickers (and legacy pickers) don't support search, so just show
// "HomeAsUp" button and title.
if (mRequest.getActionCode() == ContactsRequest.ACTION_PICK_POSTAL ||
- mRequest.getActionCode() == ContactsRequest.ACTION_PICK_GROUP_MEMBERS ||
mRequest.isLegacyCompatibilityMode()) {
mSearchView.setVisibility(View.GONE);
if (actionBar != null) {
@@ -359,9 +358,9 @@
case ContactsRequest.ACTION_PICK_GROUP_MEMBERS: {
final AccountWithDataSet account = getIntent().getParcelableExtra(
UiIntentActions.GROUP_ACCOUNT_WITH_DATA_SET);
- final ArrayList<String> rawContactIds = getIntent().getStringArrayListExtra(
- UiIntentActions.GROUP_RAW_CONTACT_IDS);
- mListFragment = GroupMemberPickerFragment.newInstance(account, rawContactIds);
+ final ArrayList<String> contactIds = getIntent().getStringArrayListExtra(
+ UiIntentActions.GROUP_CONTACT_IDS);
+ mListFragment = GroupMemberPickerFragment.newInstance(account, contactIds);
break;
}
@@ -483,8 +482,10 @@
private final class GroupMemberPickerListener implements GroupMemberPickerFragment.Listener {
@Override
- public void onGroupMemberClicked(Uri uri) {
- returnPickerResult(uri);
+ public void onGroupMemberClicked(long contactId) {
+ final Intent intent = new Intent();
+ intent.putExtra(UiIntentActions.TARGET_CONTACT_ID_EXTRA_KEY, contactId);
+ returnPickerResult(intent);
}
}
diff --git a/src/com/android/contacts/activities/GroupMembersActivity.java b/src/com/android/contacts/activities/GroupMembersActivity.java
index f41972e..f1242d6 100644
--- a/src/com/android/contacts/activities/GroupMembersActivity.java
+++ b/src/com/android/contacts/activities/GroupMembersActivity.java
@@ -17,29 +17,23 @@
import android.accounts.Account;
import android.app.FragmentManager;
-import android.app.LoaderManager.LoaderCallbacks;
-import android.content.CursorLoader;
+import android.content.Context;
import android.content.Intent;
-import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Intents;
+import android.provider.ContactsContract.RawContacts;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AutoCompleteTextView;
import android.widget.Toast;
import com.android.contacts.AppCompatContactsActivity;
import com.android.contacts.ContactSaveService;
-import com.android.contacts.GroupMemberLoader;
-import com.android.contacts.GroupMemberLoader.GroupEditorQuery;
import com.android.contacts.R;
import com.android.contacts.common.editor.SelectAccountDialogFragment;
import com.android.contacts.common.logging.ListEvent;
@@ -53,9 +47,6 @@
import com.android.contacts.group.GroupMembersListFragment;
import com.android.contacts.group.GroupMetadata;
import com.android.contacts.group.GroupNameEditDialogFragment;
-import com.android.contacts.group.Member;
-import com.android.contacts.group.SuggestedMemberListAdapter;
-import com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember;
import com.android.contacts.interactions.GroupDeletionDialogFragment;
import com.android.contacts.list.ContactsRequest;
import com.android.contacts.list.MultiSelectContactsListFragment;
@@ -85,8 +76,6 @@
private static final String TAG_SELECT_ACCOUNT_DIALOG = "selectAccountDialog";
private static final String TAG_GROUP_NAME_EDIT_DIALOG = "groupNameEditDialog";
- private static final int LOADER_GROUP_MEMBERS = 0;
-
private static final String ACTION_DELETE_GROUP = "deleteGroup";
private static final String ACTION_CREATE_GROUP = "createGroup";
private static final String ACTION_UPDATE_GROUP = "updateGroup";
@@ -95,35 +84,74 @@
private static final int RESULT_GROUP_ADD_MEMBER = 100;
- /** Loader callbacks for existing group members for the autocomplete text view. */
- private final LoaderCallbacks<Cursor> mGroupMemberCallbacks = new LoaderCallbacks<Cursor>() {
+ /**
+ * Starts an Intent to add the raw contacts for a given contact ID to a group.
+ * Only the raw contacts that belong to the specified account are added.
+ */
+ private static class AddGroupMembersAsyncTask extends AsyncTask<Void, Void, Intent> {
- @Override
- public CursorLoader onCreateLoader(int id, Bundle args) {
- return GroupMemberLoader.constructLoaderForGroupEditorQuery(
- GroupMembersActivity.this, mGroupMetadata.groupId);
+ private final Context mContext;
+ private final long mContactId;
+ private final long mGroupId;
+ private final String mAccountName;
+ private final String mAccountType;
+
+ AddGroupMembersAsyncTask(Context context, long contactId, long groupId, String accountName,
+ String accountType) {
+ mContext = context;
+ mContactId = contactId;
+ mGroupId = groupId;
+ mAccountName = accountName;
+ mAccountType = accountType;
}
@Override
- public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
- final List<Member> members = new ArrayList<>();
- data.moveToPosition(-1);
- while (data.moveToNext()) {
- members.add(new Member(
- data.getLong(GroupEditorQuery.RAW_CONTACT_ID),
- data.getString(GroupEditorQuery.CONTACT_LOOKUP_KEY),
- data.getLong(GroupEditorQuery.CONTACT_ID),
- data.getString(GroupEditorQuery.CONTACT_DISPLAY_NAME_PRIMARY),
- data.getString(GroupEditorQuery.CONTACT_PHOTO_URI),
- data.getLong(GroupEditorQuery.CONTACT_PHOTO_ID)));
+ protected Intent doInBackground(Void... params) {
+ final long[] rawContactIdsToAdd = getRawContactIdsToAdd();
+ if (rawContactIdsToAdd.length == 0) {
+ return null;
}
+ return ContactSaveService.createGroupUpdateIntent(
+ mContext, mGroupId, /* newLabel */ null,
+ rawContactIdsToAdd, /* rawContactIdsToRemove */ null,
+ GroupMembersActivity.class, GroupMembersActivity.ACTION_ADD_TO_GROUP);
+ }
- bindAutocompleteGroupMembers(members);
+ // TODO(wjang): prune raw contacts that are already in the group; ContactSaveService will
+ // log a warning if the raw contact is already a member and keep going but it is not ideal.
+ private long[] getRawContactIdsToAdd() {
+ final Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
+ .appendQueryParameter(RawContacts.ACCOUNT_NAME, mAccountName)
+ .appendQueryParameter(RawContacts.ACCOUNT_TYPE, mAccountType)
+ .build();
+ final String[] projection = new String[]{RawContacts._ID};
+ final String selection = RawContacts.CONTACT_ID + "=?";
+ final String[] selectionArgs = new String[1];
+ selectionArgs[0] = Long.toString(mContactId);
+ final Cursor cursor = mContext.getContentResolver().query(
+ rawContactUri, projection, selection, selectionArgs, null, null);
+ final long[] rawContactIds = new long[cursor.getCount()];
+ try {
+ int i = 0;
+ while (cursor.moveToNext()) {
+ rawContactIds[i] = cursor.getLong(0);
+ i++;
+ }
+ } finally {
+ cursor.close();
+ }
+ return rawContactIds;
}
@Override
- public void onLoaderReset(Loader<Cursor> loader) {}
- };
+ protected void onPostExecute(Intent intent) {
+ if (intent == null) {
+ Toast.makeText(mContext, R.string.groupSavedErrorToast, Toast.LENGTH_SHORT).show();
+ } else {
+ mContext.startService(intent);
+ }
+ }
+ }
private ActionBarAdapter mActionBarAdapter;
@@ -131,8 +159,6 @@
private GroupMembersListFragment mMembersListFragment;
- private SuggestedMemberListAdapter mAutoCompleteAdapter;
-
private Uri mGroupUri;
private boolean mIsInsertAction;
@@ -198,8 +224,6 @@
fragmentManager.beginTransaction()
.replace(R.id.fragment_container, mMembersListFragment, TAG_GROUP_MEMBERS)
.commit();
- } else {
- getLoaderManager().initLoader(LOADER_GROUP_MEMBERS, null, mGroupMemberCallbacks);
}
mMembersListFragment.setListener(this);
if (mGroupMetadata != null && mGroupMetadata.editable) {
@@ -311,25 +335,13 @@
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
final boolean isSelectionMode = mActionBarAdapter.isSelectionMode();
- final boolean isSearchMode = mActionBarAdapter.isSearchMode();
-
final boolean isGroupEditable = mGroupMetadata != null && mGroupMetadata.editable;
final boolean isGroupReadOnly = mGroupMetadata != null && mGroupMetadata.readOnly;
- setVisible(menu, R.id.menu_add,
- isGroupEditable && !isSelectionMode && !isSearchMode);
-
- setVisible(menu, R.id.menu_search,
- isGroupEditable && !isSelectionMode && !isSearchMode);
-
- setVisible(menu, R.id.menu_rename_group,
- isGroupEditable && !isSelectionMode && !isSearchMode);
-
- setVisible(menu, R.id.menu_delete_group,
- !isGroupReadOnly && !isSelectionMode && !isSearchMode);
-
- setVisible(menu, R.id.menu_remove_from_group,
- isGroupEditable && isSelectionMode);
+ setVisible(menu, R.id.menu_add, isGroupEditable && !isSelectionMode);
+ setVisible(menu, R.id.menu_rename_group, isGroupEditable && !isSelectionMode);
+ setVisible(menu, R.id.menu_delete_group, !isGroupReadOnly && !isSelectionMode);
+ setVisible(menu, R.id.menu_remove_from_group, isGroupEditable && isSelectionMode);
return true;
}
@@ -353,17 +365,11 @@
intent.setType(ContactsContract.Groups.CONTENT_ITEM_TYPE);
intent.putExtra(UiIntentActions.GROUP_ACCOUNT_WITH_DATA_SET,
mGroupMetadata.createAccountWithDataSet());
- intent.putExtra(UiIntentActions.GROUP_RAW_CONTACT_IDS,
- getExistingGroupMemberRawContactIds());
+ intent.putExtra(UiIntentActions.GROUP_CONTACT_IDS,
+ getExistingGroupMemberContactIds());
startActivityForResult(intent, RESULT_GROUP_ADD_MEMBER);
return true;
}
- case R.id.menu_search: {
- if (mActionBarAdapter != null) {
- mActionBarAdapter.setSearchMode(true);
- }
- return true;
- }
case R.id.menu_rename_group: {
GroupNameEditDialogFragment.showUpdateDialog(
getFragmentManager(), TAG_GROUP_NAME_EDIT_DIALOG, mGroupMetadata.groupName);
@@ -385,15 +391,15 @@
return super.onOptionsItemSelected(item);
}
- private ArrayList<String> getExistingGroupMemberRawContactIds() {
- final ArrayList<String> rawContactIds = new ArrayList<>();
+ private ArrayList<String> getExistingGroupMemberContactIds() {
+ final ArrayList<String> contactIds = new ArrayList<>();
final Cursor cursor = mMembersListFragment.getAdapter().getCursor(/* partition */ 0);
if (cursor != null && cursor.moveToFirst()) {
do {
- rawContactIds.add(cursor.getString(GroupMembersQuery.RAW_CONTACT_ID));
+ contactIds.add(cursor.getString(GroupMembersQuery.CONTACT_ID));
} while (cursor.moveToNext());
}
- return rawContactIds;
+ return contactIds;
}
private void deleteGroup() {
@@ -408,7 +414,6 @@
}
}
- // TODO(wjang): replace this with group events
private void logListEvent() {
Logger.logListEvent(
ListEvent.ActionType.REMOVE_LABEL,
@@ -446,30 +451,14 @@
}
}
-
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_GROUP_ADD_MEMBER && resultCode == RESULT_OK && data != null) {
- final Uri rawContactUri = data.getData();
- if (rawContactUri != null) {
- long rawContactId = -1;
- try {
- rawContactId = Long.parseLong(rawContactUri.getLastPathSegment());
- } catch (NumberFormatException ignored) {}
- if (rawContactId < 0) {
- Toast.makeText(this, R.string.groupSavedErrorToast, Toast.LENGTH_SHORT).show();
- Log.w(TAG, "Failed to parse ID from pick group member result uri " +
- rawContactUri);
- return;
- }
- final long[] rawContactIdsToAdd = new long[1];
- rawContactIdsToAdd[0] = rawContactId;
- final Intent intent = ContactSaveService.createGroupUpdateIntent(
- GroupMembersActivity.this, mGroupMetadata.groupId, /* newLabel */ null,
- rawContactIdsToAdd, /* rawContactIdsToRemove */ null,
- GroupMembersActivity.class, GroupMembersActivity.ACTION_ADD_TO_GROUP);
- startService(intent);
- }
+ final long contactId = data.getLongExtra(
+ UiIntentActions.TARGET_CONTACT_ID_EXTRA_KEY, -1);
+ new AddGroupMembersAsyncTask(this, contactId, mGroupMetadata.groupId,
+ mGroupMetadata.accountName, mGroupMetadata.accountType)
+ .execute();
}
}
@@ -512,11 +501,6 @@
@Override
public void onAction(int action) {
switch (action) {
- case ActionBarAdapter.Listener.Action.START_SEARCH_MODE:
- mActionBarAdapter.setSearchMode(true);
- invalidateOptionsMenu();
- showFabWithAnimation(/* showFabWithAnimation = */ false);
- break;
case ActionBarAdapter.Listener.Action.START_SELECTION_MODE:
if (mMembersListFragment != null) {
mMembersListFragment.displayCheckBoxes(true);
@@ -539,7 +523,7 @@
}
private void showFabWithAnimation(boolean showFab) {
- // TODO(wjang): b/28497108
+ // TODO: b/28497108
}
@Override
@@ -598,63 +582,12 @@
@Override
public void onGroupMetadataLoaded(GroupMetadata groupMetadata) {
mGroupMetadata = groupMetadata;
-
if (!mIsInsertAction) {
getSupportActionBar().setTitle(mGroupMetadata.groupName);
}
-
- bindAutocompleteTextView();
- getLoaderManager().initLoader(LOADER_GROUP_MEMBERS, null, mGroupMemberCallbacks);
-
invalidateOptionsMenu();
}
- private void bindAutocompleteTextView() {
- final AutoCompleteTextView autoCompleteTextView =
- (AutoCompleteTextView) mActionBarAdapter.getSearchView();
- if (autoCompleteTextView == null) return;
- mAutoCompleteAdapter = createAutocompleteAdapter();
- autoCompleteTextView.setAdapter(mAutoCompleteAdapter);
- autoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- final SuggestedMember member = (SuggestedMember) view.getTag();
- if (member == null) {
- return;
- }
- final long[] rawContactIdsToAdd = new long[1];
- rawContactIdsToAdd[0] = member.getRawContactId();
- final Intent intent = ContactSaveService.createGroupUpdateIntent(
- GroupMembersActivity.this, mGroupMetadata.groupId, /* newLabel */ null,
- rawContactIdsToAdd, /* rawContactIdsToRemove */ null,
- GroupMembersActivity.class, ACTION_ADD_TO_GROUP);
- startService(intent);
-
- // Update the autocomplete adapter so the contact doesn't get suggested again
- mAutoCompleteAdapter.addNewMember(member.getContactId());
-
- // Clear out the text field
- autoCompleteTextView.setText("");
- }
- });
- }
-
- private SuggestedMemberListAdapter createAutocompleteAdapter() {
- final SuggestedMemberListAdapter adapter = new SuggestedMemberListAdapter(
- this, android.R.layout.simple_dropdown_item_1line);
- adapter.setContentResolver(this.getContentResolver());
- adapter.setAccountType(mGroupMetadata.accountType);
- adapter.setAccountName(mGroupMetadata.accountName);
- adapter.setDataSet(mGroupMetadata.dataSet);
- return adapter;
- }
-
- private void bindAutocompleteGroupMembers(List<Member> members) {
- if (mAutoCompleteAdapter != null) {
- mAutoCompleteAdapter.updateExistingMembersList(members);
- }
- }
-
@Override
public void onGroupMetadataLoadFailed() {
setResultCanceledAndFinish(R.string.groupLoadErrorToast);
diff --git a/src/com/android/contacts/editor/AccountsChangedBroadcastReceiver.java b/src/com/android/contacts/editor/AccountsChangedBroadcastReceiver.java
new file mode 100644
index 0000000..55300d5
--- /dev/null
+++ b/src/com/android/contacts/editor/AccountsChangedBroadcastReceiver.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2016 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.editor;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.contacts.R;
+import com.android.contacts.common.model.AccountTypeManager;
+import com.android.contacts.common.model.account.AccountWithDataSet;
+
+import java.util.List;
+
+/**
+ * This class is to fix the bug that no prompt is seen for multiple accounts while creating new
+ * contacts. By registering a BroadcastReceiver statically, we detect the changes of accounts by
+ * receiving the message "android.accounts.LOGIN_ACCOUNTS_CHANGED". If the BroadcastReceiver gets
+ * this message, it will get the default account from the SharedPreference and compare current
+ * accounts with the default account. At last, it will renew the default account in the
+ * SharedPreference if necessary.
+ */
+public class AccountsChangedBroadcastReceiver extends BroadcastReceiver {
+ final String TAG = "AccountsChanged";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Context appContext = context.getApplicationContext();
+ final ContactEditorUtils contactEditorUtils = ContactEditorUtils.getInstance(appContext);
+ final String defaultAccountKey = appContext.getResources().getString(
+ R.string.contact_editor_default_account_key);
+ final SharedPreferences pref = appContext.getSharedPreferences(
+ appContext.getPackageName(), Context.MODE_PRIVATE);
+ final String defaultAccountString = pref.getString(defaultAccountKey, null);
+
+ if (!TextUtils.isEmpty(defaultAccountString)) {
+ AccountWithDataSet defaultAccount;
+ try {
+ defaultAccount = AccountWithDataSet.unstringify(defaultAccountString);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Invalid string in SharedPreference", e);
+ contactEditorUtils.saveDefaultAndAllAccounts(null);
+ return;
+ }
+
+ final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(
+ appContext);
+ final List<AccountWithDataSet> accounts = accountTypeManager.getAccounts(true);
+ // Delete default account pref if it has been deleted.
+ if (accounts == null || accounts.size() < 1 || !accounts.contains(defaultAccount)) {
+ contactEditorUtils.saveDefaultAndAllAccounts(null);
+ }
+ }
+ }
+}
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 4182e1f..c1e5af8 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -16,35 +16,6 @@
package com.android.contacts.editor;
-import com.android.contacts.common.logging.ScreenEvent.ScreenType;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-
-import com.android.contacts.ContactSaveService;
-import com.android.contacts.GroupMetaDataLoader;
-import com.android.contacts.R;
-import com.android.contacts.activities.ContactEditorAccountsChangedActivity;
-import com.android.contacts.activities.ContactEditorBaseActivity;
-import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
-import com.android.contacts.common.model.AccountTypeManager;
-import com.android.contacts.common.model.Contact;
-import com.android.contacts.common.model.ContactLoader;
-import com.android.contacts.common.model.RawContact;
-import com.android.contacts.common.model.RawContactDelta;
-import com.android.contacts.common.model.RawContactDeltaList;
-import com.android.contacts.common.model.RawContactModifier;
-import com.android.contacts.common.model.ValuesDelta;
-import com.android.contacts.common.model.account.AccountType;
-import com.android.contacts.common.model.account.AccountWithDataSet;
-import com.android.contacts.common.util.ImplicitIntentsUtil;
-import com.android.contacts.common.util.MaterialColorMapUtils;
-import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion;
-import com.android.contacts.list.UiIntentActions;
-import com.android.contacts.quickcontact.QuickContactActivity;
-import com.android.contacts.util.HelpUtils;
-import com.android.contacts.util.PhoneCapabilityTester;
-import com.android.contacts.util.UiClosables;
-
import android.accounts.Account;
import android.app.Activity;
import android.app.Fragment;
@@ -84,6 +55,34 @@
import android.widget.ListPopupWindow;
import android.widget.Toast;
+import com.android.contacts.ContactSaveService;
+import com.android.contacts.GroupMetaDataLoader;
+import com.android.contacts.R;
+import com.android.contacts.activities.ContactEditorAccountsChangedActivity;
+import com.android.contacts.activities.ContactEditorBaseActivity;
+import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
+import com.android.contacts.common.logging.ScreenEvent.ScreenType;
+import com.android.contacts.common.model.AccountTypeManager;
+import com.android.contacts.common.model.Contact;
+import com.android.contacts.common.model.ContactLoader;
+import com.android.contacts.common.model.RawContact;
+import com.android.contacts.common.model.RawContactDelta;
+import com.android.contacts.common.model.RawContactDeltaList;
+import com.android.contacts.common.model.RawContactModifier;
+import com.android.contacts.common.model.ValuesDelta;
+import com.android.contacts.common.model.account.AccountType;
+import com.android.contacts.common.model.account.AccountWithDataSet;
+import com.android.contacts.common.util.ImplicitIntentsUtil;
+import com.android.contacts.common.util.MaterialColorMapUtils;
+import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion;
+import com.android.contacts.list.UiIntentActions;
+import com.android.contacts.quickcontact.QuickContactActivity;
+import com.android.contacts.util.HelpUtils;
+import com.android.contacts.util.PhoneCapabilityTester;
+import com.android.contacts.util.UiClosables;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -1472,6 +1471,7 @@
QuickContactActivity.MODE_FULLY_EXPANDED);
resultIntent.putExtra(QuickContactActivity.EXTRA_PREVIOUS_SCREEN_TYPE,
ScreenType.EDITOR);
+ resultIntent.putExtra(QuickContactActivity.EXTRA_CONTACT_EDITED, true);
} else {
resultIntent = null;
}
diff --git a/src/com/android/contacts/group/GroupMembersListAdapter.java b/src/com/android/contacts/group/GroupMembersListAdapter.java
index 86e75b1..0f3ae8a 100644
--- a/src/com/android/contacts/group/GroupMembersListAdapter.java
+++ b/src/com/android/contacts/group/GroupMembersListAdapter.java
@@ -28,6 +28,7 @@
import android.view.ViewGroup;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
+import com.android.contacts.common.R;
import com.android.contacts.common.list.ContactListItemView;
import com.android.contacts.common.list.MultiSelectEntryContactListAdapter;
import com.android.contacts.common.preference.ContactsPreferences;
@@ -71,7 +72,7 @@
public GroupMembersListAdapter(Context context) {
super(context, GroupMembersQuery.RAW_CONTACT_ID);
- mUnknownNameText = context.getText(android.R.string.unknownName);
+ mUnknownNameText = context.getText(R.string.missing_name);
}
/** Sets the ID of the group whose members will be displayed. */
diff --git a/src/com/android/contacts/group/Member.java b/src/com/android/contacts/group/Member.java
deleted file mode 100644
index ad6f9b2..0000000
--- a/src/com/android/contacts/group/Member.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.contacts.group;
-
-import android.net.Uri;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.provider.ContactsContract.Contacts;
-
-import com.google.common.base.Objects;
-
-/** A member of the group currently being displayed to the user. */
-public class Member implements Parcelable {
-
- public static final Parcelable.Creator<Member> CREATOR = new Parcelable.Creator<Member>() {
- @Override
- public Member createFromParcel(Parcel in) {
- return new Member(in);
- }
-
- @Override
- public Member[] newArray(int size) {
- return new Member[size];
- }
- };
-
- private final long mRawContactId;
- private final long mContactId;
- private final Uri mLookupUri;
- private final String mDisplayName;
- private final Uri mPhotoUri;
- private final String mLookupKey;
- private final long mPhotoId;
-
- public Member(long rawContactId, String lookupKey, long contactId, String displayName,
- String photoUri, long photoId) {
- mRawContactId = rawContactId;
- mContactId = contactId;
- mLookupKey = lookupKey;
- mLookupUri = Contacts.getLookupUri(contactId, lookupKey);
- mDisplayName = displayName;
- mPhotoUri = (photoUri != null) ? Uri.parse(photoUri) : null;
- mPhotoId = photoId;
- }
-
- public long getRawContactId() {
- return mRawContactId;
- }
-
- public long getContactId() {
- return mContactId;
- }
-
- public Uri getLookupUri() {
- return mLookupUri;
- }
-
- public String getLookupKey() {
- return mLookupKey;
- }
-
- public String getDisplayName() {
- return mDisplayName;
- }
-
- public Uri getPhotoUri() {
- return mPhotoUri;
- }
-
- public long getPhotoId() {
- return mPhotoId;
- }
-
- @Override
- public boolean equals(Object object) {
- if (object instanceof Member) {
- Member otherMember = (Member) object;
- return Objects.equal(mLookupUri, otherMember.getLookupUri());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return mLookupUri == null ? 0 : mLookupUri.hashCode();
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeLong(mRawContactId);
- dest.writeLong(mContactId);
- dest.writeParcelable(mLookupUri, flags);
- dest.writeString(mLookupKey);
- dest.writeString(mDisplayName);
- dest.writeParcelable(mPhotoUri, flags);
- dest.writeLong(mPhotoId);
- }
-
- private Member(Parcel in) {
- mRawContactId = in.readLong();
- mContactId = in.readLong();
- mLookupUri = in.readParcelable(getClass().getClassLoader());
- mLookupKey = in.readString();
- mDisplayName = in.readString();
- mPhotoUri = in.readParcelable(getClass().getClassLoader());
- mPhotoId = in.readLong();
- }
-}
\ No newline at end of file
diff --git a/src/com/android/contacts/group/SuggestedMemberListAdapter.java b/src/com/android/contacts/group/SuggestedMemberListAdapter.java
deleted file mode 100644
index e2756c6..0000000
--- a/src/com/android/contacts/group/SuggestedMemberListAdapter.java
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.contacts.group;
-
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.Context;
-import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
-import android.net.Uri;
-import android.provider.ContactsContract.CommonDataKinds.Email;
-import android.provider.ContactsContract.CommonDataKinds.Phone;
-import android.provider.ContactsContract.CommonDataKinds.Photo;
-import android.provider.ContactsContract.Contacts.Data;
-import android.provider.ContactsContract.RawContacts;
-import android.provider.ContactsContract.RawContactsEntity;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.AutoCompleteTextView;
-import android.widget.Filter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import com.android.contacts.R;
-import com.android.contacts.common.ContactPhotoManager;
-import com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * This adapter provides suggested contacts that can be added to a group for an
- * {@link AutoCompleteTextView} within the group editor.
- */
-public class SuggestedMemberListAdapter extends ArrayAdapter<SuggestedMember> {
-
- private static final String[] PROJECTION_FILTERED_MEMBERS = new String[] {
- RawContacts._ID, // 0
- RawContacts.CONTACT_ID, // 1
- RawContacts.DISPLAY_NAME_PRIMARY // 2
- };
-
- private static final int RAW_CONTACT_ID_COLUMN_INDEX = 0;
- private static final int CONTACT_ID_COLUMN_INDEX = 1;
- private static final int DISPLAY_NAME_PRIMARY_COLUMN_INDEX = 2;
-
- private static final String[] PROJECTION_MEMBER_DATA = new String[] {
- RawContacts._ID, // 0
- RawContacts.CONTACT_ID, // 1
- Data.MIMETYPE, // 2
- Data.DATA1, // 3
- Photo.PHOTO, // 4
- };
-
- private static final int ID_INDEX = 0;
- private static final int MIMETYPE_COLUMN_INDEX = 2;
- private static final int DATA_COLUMN_INDEX = 3;
- private static final int PHOTO_COLUMN_INDEX = 4;
-
- private Filter mFilter;
- private ContentResolver mContentResolver;
- private LayoutInflater mInflater;
- private ContactPhotoManager mPhotoManager;
-
- private String mAccountType;
- private String mAccountName;
- private String mDataSet;
-
- // TODO: Make this a Map for better performance when we check if a new contact is in the list
- // or not
- private final List<Long> mExistingMemberContactIds = new ArrayList<Long>();
-
- private static final int SUGGESTIONS_LIMIT = 5;
-
- public SuggestedMemberListAdapter(Context context, int textViewResourceId) {
- super(context, textViewResourceId);
- mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mPhotoManager = ContactPhotoManager.getInstance(context);
- }
-
- public void setAccountType(String accountType) {
- mAccountType = accountType;
- }
-
- public void setAccountName(String accountName) {
- mAccountName = accountName;
- }
-
- public void setDataSet(String dataSet) {
- mDataSet = dataSet;
- }
-
- public void setContentResolver(ContentResolver resolver) {
- mContentResolver = resolver;
- }
-
- public void updateExistingMembersList(List<Member> list) {
- mExistingMemberContactIds.clear();
- for (Member member : list) {
- mExistingMemberContactIds.add(member.getContactId());
- }
- }
-
- public void addNewMember(long contactId) {
- mExistingMemberContactIds.add(contactId);
- }
-
- public void removeMember(long contactId) {
- if (mExistingMemberContactIds.contains(contactId)) {
- mExistingMemberContactIds.remove(contactId);
- }
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View result = convertView;
- if (result == null) {
- result = mInflater.inflate(R.layout.group_member_suggestion, parent, false);
- }
- // TODO: Use a viewholder
- SuggestedMember member = getItem(position);
- TextView text1 = (TextView) result.findViewById(R.id.text1);
- TextView text2 = (TextView) result.findViewById(R.id.text2);
- ImageView icon = (ImageView) result.findViewById(R.id.icon);
- text1.setText(member.getDisplayName());
- if (member.hasExtraInfo()) {
- text2.setText(member.getExtraInfo());
- } else {
- text2.setVisibility(View.GONE);
- }
- byte[] byteArray = member.getPhotoByteArray();
- if (byteArray == null) {
- final Uri contactLookupUri = RawContacts.getContactLookupUri(mContentResolver,
- ContentUris.withAppendedId(RawContacts.CONTENT_URI, member.getContactId()));
- final String imageRequestIdentifier = contactLookupUri == null
- ? null : contactLookupUri.toString();
- GroupUtil.bindPhoto(mPhotoManager, icon, member.getPhotoId(),
- /* photoUri */ null, member.getDisplayName(), imageRequestIdentifier);
- } else {
- Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
- icon.setImageBitmap(frameBitmapInCircle(bitmap));
- }
- result.setTag(member);
- return result;
- }
-
- private static Bitmap frameBitmapInCircle(Bitmap input) {
- // Crop the image if not squared.
- final int targetDiameter = input.getWidth();
- final Bitmap scaled = Bitmap.createScaledBitmap(
- input, targetDiameter, targetDiameter, /* filter */ false);
- int inputWidth = scaled.getWidth();
- int inputHeight = scaled.getHeight();
- int targetX, targetY, targetSize;
- if (inputWidth >= inputHeight) {
- targetX = inputWidth / 2 - inputHeight / 2;
- targetY = 0;
- targetSize = inputHeight;
- } else {
- targetX = 0;
- targetY = inputHeight / 2 - inputWidth / 2;
- targetSize = inputWidth;
- }
-
- // Create an output bitmap and a canvas to draw on it.
- final Bitmap output = Bitmap.createBitmap(targetSize, targetSize, Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(output);
-
- // Create a black paint to draw the mask.
- final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
- paint.setColor(Color.BLACK);
-
- // Draw a circle.
- canvas.drawCircle(targetDiameter / 2, targetDiameter / 2, targetDiameter / 2, paint);
-
- // Replace the black parts of the mask with the input image.
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- canvas.drawBitmap(scaled, targetX /* left */, targetY /* top */, paint);
-
- return output;
- }
-
- @Override
- public Filter getFilter() {
- if (mFilter == null) {
- mFilter = new SuggestedMemberFilter();
- }
- return mFilter;
- }
-
- /**
- * This filter queries for raw contacts that match the given account name and account type,
- * as well as the search query.
- */
- public class SuggestedMemberFilter extends Filter {
-
- @Override
- protected FilterResults performFiltering(CharSequence prefix) {
- FilterResults results = new FilterResults();
- if (mContentResolver == null || TextUtils.isEmpty(prefix)) {
- return results;
- }
-
- // Create a list to store the suggested contacts (which will be alphabetically ordered),
- // but also keep a map of raw contact IDs to {@link SuggestedMember}s to make it easier
- // to add supplementary data to the contact (photo, phone, email) to the members based
- // on raw contact IDs after the second query is completed.
- List<SuggestedMember> suggestionsList = new ArrayList<SuggestedMember>();
- HashMap<Long, SuggestedMember> suggestionsMap = new HashMap<Long, SuggestedMember>();
-
- // First query for all the raw contacts that match the given search query
- // and have the same account name and type as specified in this adapter
- String searchQuery = prefix.toString() + "%";
- String accountClause = RawContacts.ACCOUNT_NAME + "=? AND " +
- RawContacts.ACCOUNT_TYPE + "=?";
- String[] args;
- if (mDataSet == null) {
- accountClause += " AND " + RawContacts.DATA_SET + " IS NULL";
- args = new String[] {mAccountName, mAccountType, searchQuery, searchQuery};
- } else {
- accountClause += " AND " + RawContacts.DATA_SET + "=?";
- args = new String[] {
- mAccountName, mAccountType, mDataSet, searchQuery, searchQuery
- };
- }
-
- Cursor cursor = mContentResolver.query(
- RawContacts.CONTENT_URI, PROJECTION_FILTERED_MEMBERS,
- accountClause + " AND (" +
- RawContacts.DISPLAY_NAME_PRIMARY + " LIKE ? OR " +
- RawContacts.DISPLAY_NAME_ALTERNATIVE + " LIKE ? )",
- args, RawContacts.DISPLAY_NAME_PRIMARY + " COLLATE LOCALIZED ASC");
-
- if (cursor == null) {
- return results;
- }
-
- // Read back the results from the cursor and filter out existing group members.
- // For valid suggestions, add them to the hash map of suggested members.
- try {
- cursor.moveToPosition(-1);
- while (cursor.moveToNext() && suggestionsMap.keySet().size() < SUGGESTIONS_LIMIT) {
- long rawContactId = cursor.getLong(RAW_CONTACT_ID_COLUMN_INDEX);
- long contactId = cursor.getLong(CONTACT_ID_COLUMN_INDEX);
- // Filter out contacts that have already been added to this group
- if (mExistingMemberContactIds.contains(contactId)) {
- continue;
- }
- // Otherwise, add the contact as a suggested new group member
- String displayName = cursor.getString(DISPLAY_NAME_PRIMARY_COLUMN_INDEX);
- SuggestedMember member = new SuggestedMember(rawContactId, displayName,
- contactId);
- // Store the member in the list of suggestions and add it to the hash map too.
- suggestionsList.add(member);
- suggestionsMap.put(rawContactId, member);
- }
- } finally {
- cursor.close();
- }
-
- int numSuggestions = suggestionsMap.keySet().size();
- if (numSuggestions == 0) {
- return results;
- }
-
- // Create a part of the selection string for the next query with the pattern (?, ?, ?)
- // where the number of comma-separated question marks represent the number of raw
- // contact IDs found in the previous query (while respective the SUGGESTION_LIMIT)
- final StringBuilder rawContactIdSelectionBuilder = new StringBuilder();
- final String[] questionMarks = new String[numSuggestions];
- Arrays.fill(questionMarks, "?");
- rawContactIdSelectionBuilder.append(RawContacts._ID + " IN (")
- .append(TextUtils.join(",", questionMarks))
- .append(")");
-
- // Construct the selection args based on the raw contact IDs we're interested in
- // (as well as the photo, email, and phone mimetypes)
- List<String> selectionArgs = new ArrayList<String>();
- selectionArgs.add(Photo.CONTENT_ITEM_TYPE);
- selectionArgs.add(Email.CONTENT_ITEM_TYPE);
- selectionArgs.add(Phone.CONTENT_ITEM_TYPE);
- for (Long rawContactId : suggestionsMap.keySet()) {
- selectionArgs.add(String.valueOf(rawContactId));
- }
-
- // Perform a second query to retrieve a photo and possibly a phone number or email
- // address for the suggested contact
- Cursor memberDataCursor = mContentResolver.query(
- RawContactsEntity.CONTENT_URI, PROJECTION_MEMBER_DATA,
- "(" + Data.MIMETYPE + "=? OR " + Data.MIMETYPE + "=? OR " + Data.MIMETYPE +
- "=?) AND " + rawContactIdSelectionBuilder.toString(),
- selectionArgs.toArray(new String[0]), null);
-
- if (memberDataCursor != null) {
- try {
- memberDataCursor.moveToPosition(-1);
- while (memberDataCursor.moveToNext()) {
- long rawContactId = memberDataCursor.getLong(RAW_CONTACT_ID_COLUMN_INDEX);
- SuggestedMember member = suggestionsMap.get(rawContactId);
- if (member == null) {
- continue;
- }
- String mimetype = memberDataCursor.getString(MIMETYPE_COLUMN_INDEX);
- if (Photo.CONTENT_ITEM_TYPE.equals(mimetype)) {
- // Set photo
- member.setPhotoId(memberDataCursor.getLong(ID_INDEX));
- byte[] bitmapArray = memberDataCursor.getBlob(PHOTO_COLUMN_INDEX);
- member.setPhotoByteArray(bitmapArray);
- } else if (Email.CONTENT_ITEM_TYPE.equals(mimetype) ||
- Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {
- // Set at most 1 extra piece of contact info that can be a phone number or
- // email
- if (!member.hasExtraInfo()) {
- String info = memberDataCursor.getString(DATA_COLUMN_INDEX);
- member.setExtraInfo(info);
- }
- }
- }
- } finally {
- memberDataCursor.close();
- }
- }
- results.values = suggestionsList;
- return results;
- }
-
- @Override
- protected void publishResults(CharSequence constraint, FilterResults results) {
- @SuppressWarnings("unchecked")
- List<SuggestedMember> suggestionsList = (List<SuggestedMember>) results.values;
- if (suggestionsList == null) {
- return;
- }
-
- // Clear out the existing suggestions in this adapter
- clear();
-
- // Add all the suggested members to this adapter
- for (SuggestedMember member : suggestionsList) {
- add(member);
- }
-
- notifyDataSetChanged();
- }
- }
-
- /**
- * This represents a single contact that is a suggestion for the user to add to a group.
- */
- // TODO: Merge this with the {@link GroupEditorFragment} Member class once we can find the
- // lookup URI for this contact using the autocomplete filter queries
- public class SuggestedMember {
-
- private long mRawContactId;
- private long mContactId;
- private String mDisplayName;
-
- private String mExtraInfo;
- private byte[] mPhoto;
- private long mPhotoId;
-
- public SuggestedMember(long rawContactId, String displayName, long contactId) {
- mRawContactId = rawContactId;
- mDisplayName = displayName;
- mContactId = contactId;
- }
-
- public String getDisplayName() {
- return mDisplayName;
- }
-
- public String getExtraInfo() {
- return mExtraInfo;
- }
-
- public long getRawContactId() {
- return mRawContactId;
- }
-
- public long getContactId() {
- return mContactId;
- }
-
- public byte[] getPhotoByteArray() {
- return mPhoto;
- }
-
- public long getPhotoId() {
- return mPhotoId;
- }
-
- public boolean hasExtraInfo() {
- return mExtraInfo != null;
- }
-
- /**
- * Set a phone number or email to distinguish this contact
- */
- public void setExtraInfo(String info) {
- mExtraInfo = info;
- }
-
- public void setPhotoByteArray(byte[] photo) {
- mPhoto = photo;
- }
-
- public void setPhotoId(long photoId) {
- mPhotoId = photoId;
- }
-
- @Override
- public String toString() {
- return getDisplayName();
- }
- }
-}
diff --git a/src/com/android/contacts/list/ContactsIntentResolver.java b/src/com/android/contacts/list/ContactsIntentResolver.java
index ded72c2..4bd131e 100644
--- a/src/com/android/contacts/list/ContactsIntentResolver.java
+++ b/src/com/android/contacts/list/ContactsIntentResolver.java
@@ -97,7 +97,7 @@
request.setAccountWithDataSet(intent.<AccountWithDataSet> getParcelableExtra(
UiIntentActions.GROUP_ACCOUNT_WITH_DATA_SET));
request.setRawContactIds(intent.getStringArrayListExtra(
- UiIntentActions.GROUP_RAW_CONTACT_IDS));
+ UiIntentActions.GROUP_CONTACT_IDS));
}
} else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
String component = intent.getComponent().getClassName();
diff --git a/src/com/android/contacts/list/GroupMemberPickListAdapter.java b/src/com/android/contacts/list/GroupMemberPickListAdapter.java
deleted file mode 100644
index d25aafd..0000000
--- a/src/com/android/contacts/list/GroupMemberPickListAdapter.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2016 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.content.Context;
-import android.content.CursorLoader;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
-import android.provider.ContactsContract.Data;
-import android.provider.ContactsContract.RawContacts;
-import android.text.TextUtils;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
-import com.android.contacts.common.list.ContactEntryListAdapter;
-import com.android.contacts.common.list.ContactListItemView;
-import com.android.contacts.common.model.account.AccountWithDataSet;
-import com.android.contacts.common.preference.ContactsPreferences;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Adapter for raw contacts owned by an account that are not already members of a given group.
- */
-public class GroupMemberPickListAdapter extends ContactEntryListAdapter {
-
- static class GroupMembersQuery {
-
- private static final String[] PROJECTION_PRIMARY = new String[] {
- Data.RAW_CONTACT_ID, // 0
- Data.CONTACT_ID, // 1
- Data.DISPLAY_NAME_PRIMARY, // 2
- // Dummy columns overwritten by the cursor wrapper
- Data.PHOTO_ID, // 3
- Data.LOOKUP_KEY // 4
- };
-
- private static final String[] PROJECTION_ALTERNATIVE = new String[] {
- Data.RAW_CONTACT_ID, // 0
- Data.CONTACT_ID, // 1
- Data.DISPLAY_NAME_ALTERNATIVE, // 2
- // Dummy columns overwritten by the cursor wrapper
- Data.PHOTO_ID, // 3
- Data.LOOKUP_KEY // 4
- };
-
- static final int RAW_CONTACT_ID = 0;
- static final int CONTACT_ID = 1;
- static final int CONTACT_DISPLAY_NAME = 2;
- // Provided by the cursor wrapper.
- static final int CONTACT_PHOTO_ID = 3;
- // Provided by the cursor wrapper.
- static final int CONTACT_LOOKUP_KEY = 4;
-
- private GroupMembersQuery() {
- }
- }
-
- private AccountWithDataSet mAccount;
- private final Set<String> mRawContactIds = new HashSet<>();
-
- private final CharSequence mUnknownNameText;
-
- public GroupMemberPickListAdapter(Context context) {
- super(context);
- mUnknownNameText = context.getText(android.R.string.unknownName);
- }
-
- public GroupMemberPickListAdapter setAccount(AccountWithDataSet account) {
- mAccount = account;
- return this;
- }
-
- public GroupMemberPickListAdapter setRawContactIds(ArrayList<String> rawContactIds) {
- mRawContactIds.clear();
- mRawContactIds.addAll(rawContactIds);
- return this;
- }
-
- @Override
- public String getContactDisplayName(int position) {
- final Cursor cursor = (Cursor) getItem(position);
- return cursor.getString(GroupMembersQuery.CONTACT_DISPLAY_NAME);
- }
-
- @Override
- public void configureLoader(CursorLoader loader, long directoryId) {
- final Uri uri = Data.CONTENT_URI.buildUpon()
- .appendQueryParameter(Data.VISIBLE_CONTACTS_ONLY, "true")
- .build();
- loader.setUri(uri);
- loader.setProjection(
- getContactNameDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY
- ? GroupMembersQuery.PROJECTION_PRIMARY
- : GroupMembersQuery.PROJECTION_ALTERNATIVE);
- loader.setSelection(getSelection());
- loader.setSelectionArgs(getSelectionArgs());
- loader.setSortOrder(getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY
- ? Data.SORT_KEY_PRIMARY : Data.SORT_KEY_ALTERNATIVE
- + " COLLATE LOCALIZED ASC");
- }
-
- private String getSelection() {
- // Select raw contacts by account
- String result = RawContacts.ACCOUNT_NAME + "=? AND " + RawContacts.ACCOUNT_TYPE + "=? AND "
- + Data.MIMETYPE + "=? AND ";
- if (TextUtils.isEmpty(mAccount.dataSet)) {
- result += Data.DATA_SET + " IS NULL";
- } else {
- result += Data.DATA_SET + "=?";
- }
- return result;
- }
-
- private String[] getSelectionArgs() {
- final ArrayList<String> result = new ArrayList<>();
- result.add(mAccount.name);
- result.add(mAccount.type);
- result.add(GroupMembership.CONTENT_ITEM_TYPE);
- if (!TextUtils.isEmpty(mAccount.dataSet)) result.add(mAccount.dataSet);
- return result.toArray(new String[0]);
- }
-
- public Uri getRawContactUri(int position) {
- final Cursor cursor = (Cursor) getItem(position);
- final long rawContactId = cursor.getLong(GroupMembersQuery.RAW_CONTACT_ID);
- return Data.CONTENT_URI.buildUpon()
- .appendPath(Long.toString(rawContactId))
- .build();
- }
-
- @Override
- protected ContactListItemView newView(Context context, int partition, Cursor cursor,
- int position, ViewGroup parent) {
- final ContactListItemView view =
- super.newView(context, partition, cursor, position, parent);
- view.setUnknownNameText(mUnknownNameText);
- return view;
- }
-
- @Override
- protected void bindView(View v, int partition, Cursor cursor, int position) {
- super.bindView(v, partition, cursor, position);
- final ContactListItemView view = (ContactListItemView) v;
- bindName(view, cursor);
- bindViewId(view, cursor, GroupMembersQuery.RAW_CONTACT_ID);
- bindPhoto(view, cursor);
- }
-
- private void bindName(ContactListItemView view, Cursor cursor) {
- view.showDisplayName(cursor, GroupMembersQuery.CONTACT_DISPLAY_NAME,
- getContactNameDisplayOrder());
- }
-
- private void bindPhoto(final ContactListItemView view, Cursor cursor) {
- final long photoId = cursor.isNull(GroupMembersQuery.CONTACT_PHOTO_ID)
- ? 0 : cursor.getLong(GroupMembersQuery.CONTACT_PHOTO_ID);
- final DefaultImageRequest imageRequest = photoId == 0
- ? getDefaultImageRequestFromCursor(cursor, GroupMembersQuery.CONTACT_DISPLAY_NAME,
- GroupMembersQuery.CONTACT_LOOKUP_KEY)
- : null;
- getPhotoLoader().loadThumbnail(view.getPhotoView(), photoId, false, getCircularPhotos(),
- imageRequest);
- }
-}
diff --git a/src/com/android/contacts/list/GroupMemberPickerFragment.java b/src/com/android/contacts/list/GroupMemberPickerFragment.java
index edd5739..fb378e6 100644
--- a/src/com/android/contacts/list/GroupMemberPickerFragment.java
+++ b/src/com/android/contacts/list/GroupMemberPickerFragment.java
@@ -15,38 +15,29 @@
*/
package com.android.contacts.list;
-import android.app.LoaderManager.LoaderCallbacks;
-import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.database.CursorWrapper;
-import android.net.Uri;
import android.os.Bundle;
-import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.Data;
import android.util.Log;
-import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.contacts.common.R;
import com.android.contacts.common.list.ContactEntryListFragment;
+import com.android.contacts.common.list.ContactListAdapter.ContactQuery;
+import com.android.contacts.common.list.ContactListFilter;
+import com.android.contacts.common.list.DefaultContactListAdapter;
import com.android.contacts.common.model.account.AccountWithDataSet;
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.list.GroupMemberPickListAdapter.GroupMembersQuery;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
/**
* Fragment containing raw contacts for a specified account that are not already in a group.
*/
public class GroupMemberPickerFragment extends
- ContactEntryListFragment<GroupMemberPickListAdapter> {
+ ContactEntryListFragment<DefaultContactListAdapter> {
public static final String TAG = "GroupMemberPicker";
@@ -56,13 +47,11 @@
private static final String ARG_ACCOUNT = "account";
private static final String ARG_RAW_CONTACT_IDS = "rawContactIds";
- private static final int LOADER_CONTACT_ENTITY = 0;
-
/** Callbacks for host of {@link GroupMemberPickerFragment}. */
public interface Listener {
/** Invoked when a potential group member is selected. */
- void onGroupMemberClicked(Uri uri);
+ void onGroupMemberClicked(long contactId);
}
/**
@@ -82,23 +71,14 @@
mIndex = new int[mCount];
if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "FilterCursorWrapper starting size cursor=" + mCount + " photosMap="
- + (mContactPhotosMap == null ? 0 : mContactPhotosMap.size()));
+ Log.v(TAG, "FilterCursorWrapper starting cursor size is " + mCount);
}
- final Set<String> uniqueRawContactIds = new HashSet<String>();
-
for (int i = 0; i < mCount; i++) {
super.moveToPosition(i);
- final String rawContactId = getString(GroupMembersQuery.RAW_CONTACT_ID);
- if (!mRawContactIds.contains(rawContactId)
- && !uniqueRawContactIds.contains(rawContactId)) {
+ final String contactId = getString(ContactQuery.CONTACT_ID);
+ if (!mRawContactIds.contains(contactId)) {
mIndex[mPos++] = i;
- uniqueRawContactIds.add(rawContactId);
- }
- if (mRawContactIds.contains(rawContactId) && mContactPhotosMap != null) {
- final long contactId = getLong(GroupMembersQuery.CONTACT_ID);
- mContactPhotosMap.remove(contactId);
}
}
mCount = mPos;
@@ -106,82 +86,11 @@
super.moveToFirst();
if (Log.isLoggable(TAG, Log.VERBOSE)) {
- Log.v(TAG, "FilterCursorWrapper ending size cursor=" + mCount + " photosMap="
- + (mContactPhotosMap == null ? 0 : mContactPhotosMap.size()));
+ Log.v(TAG, "FilterCursorWrapper ending cursor size is" + mCount);
}
}
@Override
- public int getColumnIndex(String columnName) {
- final int index = getColumnIndexForContactColumn(columnName);
- return index < 0 ? super.getColumnIndex(columnName) : index;
- }
-
- @Override
- public int getColumnIndexOrThrow(String columnName) {
- final int index = getColumnIndexForContactColumn(columnName);
- return index < 0 ? super.getColumnIndexOrThrow(columnName) : index;
- }
-
- private int getColumnIndexForContactColumn(String columnName) {
- if (Data.PHOTO_ID.equals(columnName)) {
- return GroupMembersQuery.CONTACT_PHOTO_ID;
- }
- if (Data.LOOKUP_KEY.equals(columnName)) {
- return GroupMembersQuery.CONTACT_LOOKUP_KEY;
- }
- return -1;
- }
-
- @Override
- public String[] getColumnNames() {
- final String displayNameColumnName =
- getContactNameDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY
- ? Data.DISPLAY_NAME_PRIMARY
- : Data.DISPLAY_NAME_ALTERNATIVE;
- return new String[] {
- Data._ID,
- Data.CONTACT_ID,
- displayNameColumnName,
- Data.PHOTO_ID,
- Data.LOOKUP_KEY,
- };
- }
-
- @Override
- public String getString(int columnIndex) {
- if (columnIndex == GroupMembersQuery.CONTACT_LOOKUP_KEY) {
- if (columnIndex == GroupMembersQuery.CONTACT_PHOTO_ID) {
- final long contactId = getLong(GroupMembersQuery.CONTACT_ID);
- final Pair<Long,String> pair = getContactPhotoPair(contactId);
- if (pair != null) {
- return pair.second;
- }
- }
- return null;
- }
- return super.getString(columnIndex);
- }
-
- @Override
- public long getLong(int columnIndex) {
- if (columnIndex == GroupMembersQuery.CONTACT_PHOTO_ID) {
- final long contactId = getLong(GroupMembersQuery.CONTACT_ID);
- final Pair<Long,String> pair = getContactPhotoPair(contactId);
- if (pair != null) {
- return pair.first;
- }
- return 0;
- }
- return super.getLong(columnIndex);
- }
-
- private Pair<Long,String> getContactPhotoPair(long contactId) {
- return mContactPhotosMap != null && mContactPhotosMap.containsKey(contactId)
- ? mContactPhotosMap.get(contactId) : null;
- }
-
- @Override
public boolean move(int offset) {
return moveToPosition(mPos + offset);
}
@@ -223,49 +132,15 @@
}
}
- private final LoaderCallbacks<Cursor> mContactsEntityCallbacks = new LoaderCallbacks<Cursor>() {
-
- private final String[] PROJECTION = new String[] {
- Data.CONTACT_ID,
- Data.PHOTO_ID,
- Data.LOOKUP_KEY
- };
-
- @Override
- public CursorLoader onCreateLoader(int id, Bundle args) {
- final CursorLoader loader = new CursorLoader(getActivity());
- loader.setUri(Data.CONTENT_URI);
- loader.setProjection(PROJECTION);
- return loader;
- }
- @Override
- public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
- mContactPhotosMap = new HashMap<>();
- while (cursor.moveToNext()) {
- final long contactId = cursor.getLong(0);
- final Pair<Long, String> pair =
- new Pair(cursor.getLong(1), cursor.getString(2));
- mContactPhotosMap.put(contactId, pair);
- }
- GroupMemberPickerFragment.super.startLoading();
- }
-
- @Override
- public void onLoaderReset(Loader<Cursor> loader) {}
- };
-
private AccountWithDataSet mAccount;
private ArrayList<String> mRawContactIds;
- // Contact ID longs to Pairs of photo ID and contact lookup keys
- private Map<Long, Pair<Long,String>> mContactPhotosMap;
-
private Listener mListener;
public static GroupMemberPickerFragment newInstance(AccountWithDataSet account,
- ArrayList<String> rawContactids) {
+ ArrayList<String> rawContactIds) {
final Bundle args = new Bundle();
args.putParcelable(ARG_ACCOUNT, account);
- args.putStringArrayList(ARG_RAW_CONTACT_IDS, rawContactids);
+ args.putStringArrayList(ARG_RAW_CONTACT_IDS, rawContactIds);
final GroupMemberPickerFragment fragment = new GroupMemberPickerFragment();
fragment.setArguments(args);
@@ -273,15 +148,15 @@
}
public GroupMemberPickerFragment() {
- setQuickContactEnabled(false);
setPhotoLoaderEnabled(true);
+ setSectionHeaderDisplayEnabled(false);
setVisibleScrollbarEnabled(true);
+
setHasOptionsMenu(true);
}
@Override
public void onCreate(Bundle savedState) {
- super.onCreate(savedState);
if (savedState == null) {
mAccount = getArguments().getParcelable(ARG_ACCOUNT);
mRawContactIds = getArguments().getStringArrayList(ARG_RAW_CONTACT_IDS);
@@ -289,6 +164,7 @@
mAccount = savedState.getParcelable(KEY_ACCOUNT);
mRawContactIds = savedState.getStringArrayList(KEY_RAW_CONTACT_IDS);
}
+ super.onCreate(savedState);
}
@Override
@@ -298,15 +174,6 @@
outState.putStringArrayList(KEY_RAW_CONTACT_IDS, mRawContactIds);
}
- @Override
- protected void startLoading() {
- if (mContactPhotosMap == null) {
- getLoaderManager().restartLoader(LOADER_CONTACT_ENTITY, null, mContactsEntityCallbacks);
- } else {
- super.startLoading();
- }
- }
-
public void setListener(Listener listener) {
mListener = listener;
}
@@ -324,24 +191,22 @@
}
@Override
- protected GroupMemberPickListAdapter createListAdapter() {
- final GroupMemberPickListAdapter adapter = new GroupMemberPickListAdapter(getActivity());
+ protected DefaultContactListAdapter createListAdapter() {
+ final DefaultContactListAdapter adapter = new DefaultContactListAdapter(getActivity());
+ adapter.setFilter(ContactListFilter.createGroupMembersFilter(
+ mAccount.type, mAccount.name, mAccount.dataSet));
+ adapter.setSectionHeaderDisplayEnabled(true);
adapter.setDisplayPhotos(true);
return adapter;
}
@Override
- protected void configureAdapter() {
- super.configureAdapter();
- getAdapter().setAccount(mAccount);
- getAdapter().setRawContactIds(mRawContactIds);
- getAdapter().setEmptyListEnabled(true);
- }
-
- @Override
protected void onItemClick(int position, long id) {
if (mListener != null) {
- mListener.onGroupMemberClicked(getAdapter().getRawContactUri(position));
+ final long contactId = getAdapter().getContactId(position);
+ if (contactId > 0) {
+ mListener.onGroupMemberClicked(contactId);
+ }
}
}
}
diff --git a/src/com/android/contacts/list/GroupMemberTileAdapter.java b/src/com/android/contacts/list/GroupMemberTileAdapter.java
deleted file mode 100644
index 15e67f1..0000000
--- a/src/com/android/contacts/list/GroupMemberTileAdapter.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2012 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.content.Context;
-import android.database.Cursor;
-
-import com.android.contacts.GroupMemberLoader;
-import com.android.contacts.common.list.ContactEntry;
-import com.android.contacts.common.list.ContactTileAdapter;
-import com.android.contacts.common.list.ContactTileView;
-import com.google.common.collect.Lists;
-
-import java.util.ArrayList;
-
-/**
- * Tile adapter for groups.
- */
-public class GroupMemberTileAdapter extends ContactTileAdapter {
-
- public GroupMemberTileAdapter(Context context, ContactTileView.Listener listener, int numCols) {
- super(context, listener, numCols, DisplayType.GROUP_MEMBERS);
- }
-
- @Override
- protected void bindColumnIndices() {
- mIdIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_ID;
- mLookupIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_LOOKUP_KEY;
- mPhotoUriIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_PHOTO_URI;
- mNameIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_DISPLAY_NAME_PRIMARY;
- mPresenceIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_PRESENCE_STATUS;
- mStatusIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_STATUS;
- }
-
- @Override
- protected void saveNumFrequentsFromCursor(Cursor cursor) {
- mNumFrequents = 0;
- }
-
- @Override
- public int getItemViewType(int position) {
- return ViewTypes.STARRED;
- }
-
- @Override
- protected int getDividerPosition(Cursor cursor) {
- // No divider
- return -1;
- }
-
- @Override
- public int getCount() {
- if (mContactCursor == null || mContactCursor.isClosed()) {
- return 0;
- }
-
- return getRowCount(mContactCursor.getCount());
- }
-
- @Override
- public ArrayList<ContactEntry> getItem(int position) {
- final ArrayList<ContactEntry> resultList = Lists.newArrayListWithCapacity(mColumnCount);
- int contactIndex = position * mColumnCount;
-
- for (int columnCounter = 0; columnCounter < mColumnCount; columnCounter++) {
- resultList.add(createContactEntryFromCursor(mContactCursor, contactIndex));
- contactIndex++;
- }
- return resultList;
- }
-}
diff --git a/src/com/android/contacts/list/UiIntentActions.java b/src/com/android/contacts/list/UiIntentActions.java
index 31e5ade..571d56f 100644
--- a/src/com/android/contacts/list/UiIntentActions.java
+++ b/src/com/android/contacts/list/UiIntentActions.java
@@ -40,16 +40,16 @@
public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
/**
- * The account used to filter potential raw contact groups members.
+ * The account used to filter potential new group members.
*/
public static final String GROUP_ACCOUNT_WITH_DATA_SET =
"com.android.contacts.extra.GROUP_ACCOUNT_WITH_DATA_SET";
/**
- * The raw contact IDs for existing group members.
+ * The contact IDs for existing group members.
*/
- public static final String GROUP_RAW_CONTACT_IDS =
- "com.android.contacts.extra.GROUP_RAW_CONTACT_IDS";
+ public static final String GROUP_CONTACT_IDS =
+ "com.android.contacts.extra.GROUP_CONTACT_IDS";
/**
* The action for the all contacts list tab.
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 76e8605..64db298 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -209,6 +209,9 @@
/** Used to pass the screen where the user came before launching this Activity. */
public static final String EXTRA_PREVIOUS_SCREEN_TYPE = "previous_screen_type";
+ /** Used to tell the QuickContact that the previous contact was edited, so it can return an
+ * activity result back to the original Activity that launched it. */
+ public static final String EXTRA_CONTACT_EDITED = "contact_edited";
private static final String TAG = "QuickContact";
@@ -1209,6 +1212,9 @@
return;
}
Uri lookupUri = intent.getData();
+ if (intent.getBooleanExtra(EXTRA_CONTACT_EDITED, false)) {
+ setResult(ContactEditorBaseActivity.RESULT_CODE_EDITED);
+ }
// Check to see whether it comes from the old version.
if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) {