summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWalter Jang <wjang@google.com>2015-06-01 12:17:06 -0700
committerWalter Jang <wjang@google.com>2015-06-03 13:27:53 -0700
commitac679af994faece43536f1e8b2613f30c50300e1 (patch)
tree829f4126293b2d868742fbef0acc7b4b55334cbb /src
parenta267ba3b0b7a2f8bbcc308bc94b9e92986faa333 (diff)
downloadContacts-ac679af994faece43536f1e8b2613f30c50300e1.tar.gz
Pass the preferred photo ID into the contact editor
Bug 21498424 Change-Id: I35e8fa3cff4d963f8017bdd596132fe749479a17
Diffstat (limited to 'src')
-rw-r--r--src/com/android/contacts/activities/ContactEditorBaseActivity.java5
-rw-r--r--src/com/android/contacts/activities/ContactSelectionActivity.java4
-rw-r--r--src/com/android/contacts/editor/CompactContactEditorFragment.java5
-rw-r--r--src/com/android/contacts/editor/CompactRawContactsEditorView.java27
-rw-r--r--src/com/android/contacts/editor/ContactEditorBaseFragment.java18
-rw-r--r--src/com/android/contacts/editor/EditorIntents.java13
-rw-r--r--src/com/android/contacts/quickcontact/QuickContactActivity.java3
7 files changed, 60 insertions, 15 deletions
diff --git a/src/com/android/contacts/activities/ContactEditorBaseActivity.java b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
index 41b0c6b67..1704ebe57 100644
--- a/src/com/android/contacts/activities/ContactEditorBaseActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
@@ -163,7 +163,7 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
* Invoked after the contact is saved.
*/
void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
- Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed);
+ Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId);
/**
* Invoked after the contact is joined.
@@ -243,7 +243,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
intent.getData(),
(Bundle) intent.getParcelableExtra(ContactSaveService.EXTRA_UPDATED_PHOTOS),
intent.getBooleanExtra(ContactEditorFragment.INTENT_EXTRA_SAVE_BACK_PRESSED,
- false));
+ false),
+ intent.getLongExtra(ContactEditorFragment.INTENT_EXTRA_PHOTO_ID, -1));
} else if (ACTION_JOIN_COMPLETED.equals(action)) {
mFragment.onJoinCompleted(intent.getData());
}
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index e147b764c..0e785616d 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -47,6 +47,7 @@ import com.android.contacts.R;
import com.android.contacts.common.activity.RequestPermissionsActivity;
import com.android.contacts.common.list.ContactEntryListFragment;
import com.android.contacts.common.util.ImplicitIntentsUtil;
+import com.android.contacts.editor.EditorIntents;
import com.android.contacts.list.ContactPickerFragment;
import com.android.contacts.list.ContactsIntentResolver;
import com.android.contacts.list.ContactsRequest;
@@ -425,7 +426,8 @@ public class ContactSelectionActivity extends ContactsActivity
startActivityForResult(intent, SUBACTIVITY_ADD_TO_EXISTING_CONTACT);
} else {
// Otherwise launch the full contact editor.
- startActivityAndForwardResult(new Intent(Intent.ACTION_EDIT, contactLookupUri));
+ startActivityAndForwardResult(EditorIntents.createEditContactIntent(
+ contactLookupUri, /* materialPalette =*/ null, /* photoId =*/ -1));
}
}
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index 10efe1008..64bcf8683 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -201,7 +201,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
// Add input fields for the loaded Contact
final CompactRawContactsEditorView editorView = getContent();
editorView.setListener(this);
- editorView.setState(mState, getMaterialPalette(), mViewIdGenerator);
+ editorView.setState(mState, getMaterialPalette(), mViewIdGenerator, mPhotoId);
// Set up the photo widget
mPhotoHandler = createPhotoHandler();
@@ -357,7 +357,8 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
final Intent intent = isInsert
? EditorIntents.createInsertContactIntent(
mState, getDisplayName(), getPhoneticName(), mUpdatedPhotos)
- : EditorIntents.createEditContactIntent(mLookupUri, getMaterialPalette());
+ : EditorIntents.createEditContactIntent(mLookupUri, getMaterialPalette(),
+ mPhotoId);
ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
getActivity().finish();
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index fdb29ab4a..b841f62a8 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -263,7 +263,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
public void setState(RawContactDeltaList rawContactDeltas,
MaterialColorMapUtils.MaterialPalette materialPalette,
- ViewIdGenerator viewIdGenerator) {
+ ViewIdGenerator viewIdGenerator, long photoId) {
mNames.removeAllViews();
mPhoneticNames.removeAllViews();
mNicknames.removeAllViews();
@@ -281,7 +281,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
mMaterialPalette = materialPalette;
vlog("Setting compact editor state from " + rawContactDeltas);
- addPhotoView(rawContactDeltas, viewIdGenerator);
+ addPhotoView(rawContactDeltas, viewIdGenerator, photoId);
addStructuredNameView(rawContactDeltas);
addEditorViews(rawContactDeltas);
removeExtraEmptyTextFields(mPhoneNumbers);
@@ -289,7 +289,8 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
}
private void addPhotoView(RawContactDeltaList rawContactDeltas,
- ViewIdGenerator viewIdGenerator) {
+ ViewIdGenerator viewIdGenerator, long photoId) {
+ // Look for a match for the photo ID that was passed in
for (RawContactDelta rawContactDelta : rawContactDeltas) {
if (!rawContactDelta.isVisible()) continue;
final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
@@ -301,6 +302,26 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
// Look for a non-empty super primary photo
final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
if (dataKind != null) {
+ for (ValuesDelta valuesDelta
+ : rawContactDelta.getMimeEntries(Photo.CONTENT_ITEM_TYPE)) {
+ if (valuesDelta != null && valuesDelta.getId() != null
+ && valuesDelta.getId().equals(photoId)) {
+ mPhotoRawContactId = rawContactDelta.getRawContactId();
+ mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
+ /* readOnly =*/ !dataKind.editable, mMaterialPalette,
+ viewIdGenerator);
+ return;
+ }
+ }
+ }
+ }
+
+ // Look for a non-empty super primary photo
+ for (RawContactDelta rawContactDelta : rawContactDeltas) {
+ if (!rawContactDelta.isVisible()) continue;
+ final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
+ final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
+ if (dataKind != null) {
final ValuesDelta valuesDelta = getNonEmptySuperPrimaryValuesDeltas(
rawContactDelta, Photo.CONTENT_ITEM_TYPE, dataKind);
if (valuesDelta != null) {
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index d0750e020..5488de575 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -112,6 +112,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
private static final String KEY_DISABLE_DELETE_MENU_OPTION = "disableDeleteMenuOption";
private static final String KEY_NEW_LOCAL_PROFILE = "newLocalProfile";
private static final String KEY_MATERIAL_PALETTE = "materialPalette";
+ private static final String KEY_PHOTO_ID = "photoId";
private static final String KEY_VIEW_ID_GENERATOR = "viewidgenerator";
@@ -173,6 +174,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
public static final String INTENT_EXTRA_UPDATED_PHOTOS = "updated_photos";
/**
+ * Intent key to pass the ID of the photo to display on the editor.
+ */
+ public static final String INTENT_EXTRA_PHOTO_ID = "photo_id";
+
+ /**
* Intent extra to specify a {@link ContactEditor.SaveMode}.
*/
public static final String SAVE_MODE_EXTRA_KEY = "saveMode";
@@ -308,6 +314,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
protected boolean mDisableDeleteMenuOption;
protected boolean mNewLocalProfile;
protected MaterialColorMapUtils.MaterialPalette mMaterialPalette;
+ protected long mPhotoId = -1;
//
// Helpers
@@ -464,6 +471,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
mDisableDeleteMenuOption = savedState.getBoolean(KEY_DISABLE_DELETE_MENU_OPTION);
mNewLocalProfile = savedState.getBoolean(KEY_NEW_LOCAL_PROFILE);
mMaterialPalette = savedState.getParcelable(KEY_MATERIAL_PALETTE);
+ mPhotoId = savedState.getLong(KEY_PHOTO_ID);
mRawContacts = ImmutableList.copyOf(savedState.<RawContact>getParcelableArrayList(
KEY_RAW_CONTACTS));
@@ -584,6 +592,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
if (mMaterialPalette != null) {
outState.putParcelable(KEY_MATERIAL_PALETTE, mMaterialPalette);
}
+ outState.putLong(KEY_PHOTO_ID, mPhotoId);
outState.putParcelable(KEY_VIEW_ID_GENERATOR, mViewIdGenerator);
@@ -915,7 +924,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
}
onSaveCompleted(/* hadChanges =*/ false, saveMode,
/* saveSucceeded =*/ mLookupUri != null, mLookupUri,
- /* updatedPhotos =*/ null, backPressed);
+ /* updatedPhotos =*/ null, backPressed, mPhotoId);
return true;
}
@@ -1312,6 +1321,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
if (mIntentExtras.containsKey(INTENT_EXTRA_UPDATED_PHOTOS)) {
mUpdatedPhotos = mIntentExtras.getParcelable(INTENT_EXTRA_UPDATED_PHOTOS);
}
+ mPhotoId = mIntentExtras.getLong(INTENT_EXTRA_PHOTO_ID);
}
}
@@ -1335,12 +1345,12 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
@Override
public void onJoinCompleted(Uri uri) {
onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri, /* updatedPhotos =*/ null,
- /* backPressed =*/ false);
+ /* backPressed =*/ false, /* photoId =*/ mPhotoId);
}
@Override
public void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
- Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed) {
+ Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId) {
if (hadChanges) {
if (saveSucceeded) {
if (saveMode != SaveMode.JOIN && mShowToastAfterSave) {
@@ -1377,7 +1387,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
? EditorIntents.createCompactInsertContactIntent(
mState, getDisplayName(), getPhoneticName(), updatedPhotos)
: EditorIntents.createCompactEditContactIntent(
- lookupUri, getMaterialPalette(), updatedPhotos);
+ lookupUri, getMaterialPalette(), updatedPhotos, photoId);
resultIntent.putExtra(INTENT_EXTRA_SAVE_BACK_PRESSED, true);
mStatus = Status.CLOSING;
if (mListener != null) mListener.onSaveFinished(resultIntent);
diff --git a/src/com/android/contacts/editor/EditorIntents.java b/src/com/android/contacts/editor/EditorIntents.java
index 5d7edd325..b4e2fcec8 100644
--- a/src/com/android/contacts/editor/EditorIntents.java
+++ b/src/com/android/contacts/editor/EditorIntents.java
@@ -44,10 +44,11 @@ public class EditorIntents {
* existing contact.
*/
public static Intent createCompactEditContactIntent(Uri contactLookupUri,
- MaterialPalette materialPalette, Bundle updatedPhotos) {
+ MaterialPalette materialPalette, Bundle updatedPhotos, long photoId) {
final Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
putMaterialPalette(intent, materialPalette);
putUpdatedPhotos(intent, updatedPhotos);
+ putPhotoId(intent, photoId);
return intent;
}
@@ -96,10 +97,11 @@ public class EditorIntents {
* new contact.
*/
public static Intent createEditContactIntent(Uri contactLookupUri,
- MaterialPalette materialPalette) {
+ MaterialPalette materialPalette, long photoId) {
final Intent intent = new Intent(ContactEditorBaseActivity.ACTION_EDIT, contactLookupUri);
addContactIntentFlags(intent);
putMaterialPalette(intent, materialPalette);
+ putPhotoId(intent, photoId);
return intent;
}
@@ -136,6 +138,13 @@ public class EditorIntents {
}
}
+ private static void putPhotoId(Intent intent, long photoId) {
+ if (photoId >= 0) {
+ intent.putExtra(ContactEditorBaseFragment.INTENT_EXTRA_PHOTO_ID, photoId);
+ }
+ }
+
+
private static void putRawContactDeltaValues(Intent intent,
RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName) {
// Pass on all the data that has been entered so far
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 405d8f0e1..8baf93ef6 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -2210,7 +2210,8 @@ public class QuickContactActivity extends ContactsActivity {
mContactData.getLookupUri(),
mHasComputedThemeColor
? new MaterialPalette(mColorFilterColor, mStatusBarColor) : null,
- /* updatedPhotos =*/ null);
+ /* updatedPhotos =*/ null,
+ mContactData.getPhotoId());
}
private void editContact() {