Fixes for returning to the compact editor from the expanded one
* Don't abort the save even if there are no unsaved changed
when returning the compact from the full editor
* No need to pass the material palette on insert intents.
It does, however, need to be passed back to the compact
editor when editing an existing contact w/o a picture.
* Fix returning to the compact editor repeatedly by
removing the Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
on compact editor intents.
* Updated StructuredNameEditorView#getDisplayName to fall
back to the display name directly from the ValuesDelta.
This is required when the name is passed to the
contact editor, and the user does not change it, in which
case it will not be written to the underlying data
structure, and thus not passed subsequent expantions.
Bug 19624360
Change-Id: Ife285f3e411a869a76fbbff4d42939c866db617c
diff --git a/src/com/android/contacts/activities/ContactEditorBaseActivity.java b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
index 3e05513..25846bc 100644
--- a/src/com/android/contacts/activities/ContactEditorBaseActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
@@ -177,12 +177,6 @@
public static final String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED =
"finishActivityOnSaveCompleted";
- /**
- * Intent key to pass the calculated photo palette calculated by
- * {@link com.android.contacts.quickcontact.QuickContactActivity} to the compact editor.
- */
- public static final String INTENT_KEY_MATERIAL_PALETTE = "materialPalette";
-
protected ContactEditor mFragment;
private boolean mFinishActivityOnSaveCompleted;
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index 570f09a..9a96262 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -19,14 +19,12 @@
import com.android.contacts.ContactSaveService;
import com.android.contacts.R;
import com.android.contacts.activities.CompactContactEditorActivity;
-import com.android.contacts.activities.ContactEditorBaseActivity;
import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.ValuesDelta;
import com.android.contacts.common.model.account.AccountType;
import com.android.contacts.common.util.ImplicitIntentsUtil;
-import com.android.contacts.common.util.MaterialColorMapUtils;
import com.android.contacts.detail.PhotoSelectionHandler;
import com.android.contacts.util.ContactPhotoUtils;
@@ -55,7 +53,6 @@
private static final String KEY_PHOTO_URI = "photo_uri";
private static final String KEY_PHOTO_RAW_CONTACT_ID = "photo_raw_contact_id";
private static final String KEY_UPDATED_PHOTOS = "updated_photos";
- private static final String KEY_MATERIAL_PALETTE = "material_palette";
/**
* Displays a PopupWindow with photo edit options.
@@ -133,7 +130,6 @@
private Uri mPhotoUri;
private long mPhotoRawContactId;
private Bundle mUpdatedPhotos = new Bundle();
- private MaterialColorMapUtils.MaterialPalette mMaterialPalette;
private boolean mShowToastAfterSave = true;
@Override
@@ -144,10 +140,6 @@
mPhotoUri = savedState.getParcelable(KEY_PHOTO_URI);
mPhotoRawContactId = savedState.getLong(KEY_PHOTO_RAW_CONTACT_ID);
mUpdatedPhotos = savedState.getParcelable(KEY_UPDATED_PHOTOS);
- mMaterialPalette = savedState.getParcelable(KEY_MATERIAL_PALETTE);
- } else {
- mMaterialPalette = getActivity().getIntent().getParcelableExtra(
- ContactEditorBaseActivity.INTENT_KEY_MATERIAL_PALETTE);
}
}
@@ -166,9 +158,6 @@
outState.putParcelable(KEY_PHOTO_URI, mPhotoUri);
outState.putLong(KEY_PHOTO_RAW_CONTACT_ID, mPhotoRawContactId);
outState.putParcelable(KEY_UPDATED_PHOTOS, mUpdatedPhotos);
- if (mMaterialPalette != null) {
- outState.putParcelable(KEY_MATERIAL_PALETTE, mMaterialPalette);
- }
super.onSaveInstanceState(outState);
}
@@ -223,7 +212,7 @@
// Add input fields for the loaded Contact
final CompactRawContactsEditorView editorView = getContent();
editorView.setListener(this);
- editorView.setState(mState, mMaterialPalette, mViewIdGenerator);
+ editorView.setState(mState, getMaterialPalette(), mViewIdGenerator);
// Set up the photo widget
mPhotoHandler = createPhotoHandler();
@@ -310,12 +299,11 @@
@Override
protected boolean doSaveAction(int saveMode) {
- // Save contact
+ // Save contact. No need to pass the palette since we are finished editing after the save.
final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
((Activity) mContext).getClass(),
- CompactContactEditorActivity.ACTION_SAVE_COMPLETED,
- mUpdatedPhotos);
+ CompactContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos);
mContext.startService(intent);
return true;
@@ -369,13 +357,10 @@
// Prepare an Intent to start the expanded editor
final Intent intent = isInsert
? EditorIntents.createInsertContactIntent(mState, getDisplayName())
- : EditorIntents.createEditContactIntent(mLookupUri);
+ : EditorIntents.createEditContactIntent(mLookupUri, getMaterialPalette());
ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
- final Activity activity = getActivity();
- if (activity != null) {
- activity.finish();
- }
+ getActivity().finish();
}
@Override
@@ -390,11 +375,6 @@
}
@Override
- public MaterialColorMapUtils.MaterialPalette getMaterialPalette() {
- return mMaterialPalette;
- }
-
- @Override
public String getDisplayName() {
final StructuredNameEditorView structuredNameEditorView =
getContent().getStructuredNameEditorView();
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 584ef6f..258747d 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -111,6 +111,7 @@
private static final String KEY_AUTO_ADD_TO_DEFAULT_GROUP = "autoAddToDefaultGroup";
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_VIEW_ID_GENERATOR = "viewidgenerator";
@@ -157,6 +158,13 @@
"disableDeleteMenuOption";
/**
+ * Intent key to pass the photo palette calculated by
+ * {@link com.android.contacts.quickcontact.QuickContactActivity} to and between the compact
+ * editor and fully expanded editor.
+ */
+ public static final String INTENT_EXTRA_MATERIAL_PALETTE = "material_palette";
+
+ /**
* Intent extra to specify a {@link ContactEditor.SaveMode}.
*/
public static final String SAVE_MODE_EXTRA_KEY = "saveMode";
@@ -285,6 +293,7 @@
protected boolean mAutoAddToDefaultGroup;
protected boolean mDisableDeleteMenuOption;
protected boolean mNewLocalProfile;
+ protected MaterialColorMapUtils.MaterialPalette mMaterialPalette;
//
// Helpers
@@ -434,6 +443,7 @@
mAutoAddToDefaultGroup = savedState.getBoolean(KEY_AUTO_ADD_TO_DEFAULT_GROUP);
mDisableDeleteMenuOption = savedState.getBoolean(KEY_DISABLE_DELETE_MENU_OPTION);
mNewLocalProfile = savedState.getBoolean(KEY_NEW_LOCAL_PROFILE);
+ mMaterialPalette = savedState.getParcelable(KEY_MATERIAL_PALETTE);
mRawContacts = ImmutableList.copyOf(savedState.<RawContact>getParcelableArrayList(
KEY_RAW_CONTACTS));
@@ -548,6 +558,9 @@
outState.putBoolean(KEY_AUTO_ADD_TO_DEFAULT_GROUP, mAutoAddToDefaultGroup);
outState.putBoolean(KEY_DISABLE_DELETE_MENU_OPTION, mDisableDeleteMenuOption);
outState.putBoolean(KEY_NEW_LOCAL_PROFILE, mNewLocalProfile);
+ if (mMaterialPalette != null) {
+ outState.putParcelable(KEY_MATERIAL_PALETTE, mMaterialPalette);
+ }
outState.putParcelable(KEY_VIEW_ID_GENERATOR, mViewIdGenerator);
@@ -866,7 +879,9 @@
mStatus = Status.SAVING;
- if (!hasPendingChanges()) {
+ // Don't abort if there are no changes and we are returning to the compact editor --
+ // the user may have simply expanded the editor then hit back
+ if (!hasPendingChanges() && saveMode != SaveMode.COMPACT) {
if (mLookupUri == null && saveMode == SaveMode.RELOAD) {
// We don't have anything to save and there isn't even an existing contact yet.
// Nothing to do, simply go back to editing mode
@@ -887,11 +902,11 @@
// If we're coming back from the fully expanded editor and this is an insert, just
// pass any values entered by the user back to the compact editor without doing a save
final Intent resultIntent = EditorIntents.createCompactInsertContactIntent(
- getMaterialPalette(), mState, getDisplayName());
+ mState, getDisplayName());
mListener.onSaveFinished(resultIntent);
return true;
}
- // Otherwise this is an edit or a back press on the compact editor so do an actual save
+ // Otherwise this is an edit or a back press so do an actual save
return doSaveAction(saveMode);
}
@@ -935,7 +950,9 @@
/**
* Returns the palette extra that was passed in.
*/
- abstract protected MaterialColorMapUtils.MaterialPalette getMaterialPalette();
+ protected MaterialColorMapUtils.MaterialPalette getMaterialPalette() {
+ return mMaterialPalette;
+ }
/**
* Returns the currently displayed displayName;
@@ -1094,9 +1111,9 @@
RawContactDelta oldState, AccountType oldAccountType) {
mStatus = Status.EDITING;
mState.add(createNewRawContactDelta(account, accountType, oldState, oldAccountType));
- // We bind field values that may be present on inserts (as well as edits) since
- // the caller may want certain fields pre-populated or we may be returning to
- // the compact editor from the fully expanded one.
+ // We bind field values that may be present on inserts since the caller may want certain
+ // fields pre-populated or we may be returning to the compact editor from the fully
+ // expanded one.
setIntentExtras(mIntentExtras);
mRequestFocus = true;
mNewContactDataReady = true;
@@ -1260,6 +1277,8 @@
mIntentExtras.getBoolean(INTENT_EXTRA_NEW_LOCAL_PROFILE);
mDisableDeleteMenuOption =
mIntentExtras.getBoolean(INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION);
+ mMaterialPalette =
+ mIntentExtras.getParcelable(INTENT_EXTRA_MATERIAL_PALETTE);
}
}
@@ -1310,7 +1329,7 @@
} else if (saveMode == SaveMode.COMPACT) {
if (isInsert(getActivity().getIntent())) {
resultIntent = EditorIntents.createCompactInsertContactIntent(
- getMaterialPalette(), mState, getDisplayName());
+ mState, getDisplayName());
} else {
resultIntent = EditorIntents.createCompactEditContactIntent(
lookupUri, getMaterialPalette());
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 89b4bf8..791e20d 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -417,12 +417,6 @@
return null;
}
- @Override
- public MaterialColorMapUtils.MaterialPalette getMaterialPalette() {
- // There is no color for default photos on the fully expanded editor
- return null;
- }
-
/**
* Adjust how dark the hint text should be on all the names' text fields.
*
@@ -537,10 +531,10 @@
@Override
protected boolean doSaveAction(int saveMode) {
- // Save contact
+ // Save contact and reload the compact editor after saving.
Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
- ((Activity)mContext).getClass(), ContactEditorActivity.ACTION_SAVE_COMPLETED,
+ ((Activity) mContext).getClass(), ContactEditorActivity.ACTION_SAVE_COMPLETED,
mUpdatedPhotos);
mContext.startService(intent);
diff --git a/src/com/android/contacts/editor/EditorIntents.java b/src/com/android/contacts/editor/EditorIntents.java
index 121b8c8..39c14e5 100644
--- a/src/com/android/contacts/editor/EditorIntents.java
+++ b/src/com/android/contacts/editor/EditorIntents.java
@@ -45,11 +45,7 @@
public static Intent createCompactEditContactIntent(Uri contactLookupUri,
MaterialPalette materialPalette) {
final Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- if (materialPalette != null) {
- intent.putExtra(ContactEditorBaseActivity.INTENT_KEY_MATERIAL_PALETTE,
- materialPalette);
- }
+ putMaterialPalette(intent, materialPalette);
return intent;
}
@@ -57,22 +53,17 @@
* Returns an Intent to start the {@link CompactContactEditorActivity} for a new contact.
*/
public static Intent createCompactInsertContactIntent() {
- return createCompactInsertContactIntent(/* materialPalette =*/ null,
- /* rawContactDeltaList =*/ null, /* displayName =*/ null);
+ return createCompactInsertContactIntent(/* rawContactDeltaList =*/ null,
+ /* displayName =*/ null);
}
/**
* Returns an Intent to start the {@link CompactContactEditorActivity} for a new contact with
* the field values specified by rawContactDeltaList pre-populate in the form.
*/
- public static Intent createCompactInsertContactIntent(MaterialPalette materialPalette,
- RawContactDeltaList rawContactDeltaList, String displayName) {
+ public static Intent createCompactInsertContactIntent(RawContactDeltaList rawContactDeltaList,
+ String displayName) {
final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
- if (materialPalette != null) {
- intent.putExtra(ContactEditorBaseActivity.INTENT_KEY_MATERIAL_PALETTE,
- materialPalette);
- }
if (rawContactDeltaList != null || displayName != null) {
putRawContactDeltaValues(intent, rawContactDeltaList, displayName);
}
@@ -101,9 +92,11 @@
* Returns an Intent to start the fully expanded {@link ContactEditorActivity} for a
* new contact.
*/
- public static Intent createEditContactIntent(Uri contactLookupUri) {
+ public static Intent createEditContactIntent(Uri contactLookupUri,
+ MaterialPalette materialPalette) {
final Intent intent = new Intent(ContactEditorBaseActivity.ACTION_EDIT, contactLookupUri);
addContactIntentFlags(intent);
+ putMaterialPalette(intent, materialPalette);
return intent;
}
@@ -114,7 +107,7 @@
public static Intent createInsertContactIntent(RawContactDeltaList rawContactDeltaList,
String displayName) {
final Intent intent = new Intent(ContactEditorBaseActivity.ACTION_INSERT,
- ContactsContract.Contacts.CONTENT_URI);
+ Contacts.CONTENT_URI);
addContactIntentFlags(intent);
putRawContactDeltaValues(intent, rawContactDeltaList, displayName);
return intent;
@@ -126,13 +119,22 @@
| Intent.FLAG_ACTIVITY_FORWARD_RESULT);
}
+ private static void putMaterialPalette(Intent intent, MaterialPalette materialPalette) {
+ if (materialPalette != null) {
+ intent.putExtra(ContactEditorBaseFragment.INTENT_EXTRA_MATERIAL_PALETTE,
+ materialPalette);
+ }
+ }
+
private static void putRawContactDeltaValues(Intent intent,
RawContactDeltaList rawContactDeltaList, String displayName) {
// Pass on all the data that has been entered so far
- ArrayList<ContentValues> contentValues = rawContactDeltaList.get(0).getContentValues();
- if (contentValues != null && contentValues.size() != 0) {
- intent.putParcelableArrayListExtra(
- ContactsContract.Intents.Insert.DATA, contentValues);
+ if (rawContactDeltaList != null && !rawContactDeltaList.isEmpty()) {
+ ArrayList<ContentValues> contentValues = rawContactDeltaList.get(0).getContentValues();
+ if (contentValues != null && contentValues.size() != 0) {
+ intent.putParcelableArrayListExtra(
+ ContactsContract.Intents.Insert.DATA, contentValues);
+ }
}
// Name must be passed separately since it is skipped in RawContactModifier.parseValues
if (!TextUtils.isEmpty(displayName)) {
diff --git a/src/com/android/contacts/editor/StructuredNameEditorView.java b/src/com/android/contacts/editor/StructuredNameEditorView.java
index adeb8ad..f9dd0c9 100644
--- a/src/com/android/contacts/editor/StructuredNameEditorView.java
+++ b/src/com/android/contacts/editor/StructuredNameEditorView.java
@@ -217,7 +217,14 @@
return valuesDelta.getDisplayName();
}
final Map<String, String> structuredNameMap = valuesToStructuredNameMap(valuesDelta);
- return NameConverter.structuredNameToDisplayName(getContext(), structuredNameMap);
+ final String displayName = NameConverter.structuredNameToDisplayName(
+ getContext(), structuredNameMap);
+ if (!TextUtils.isEmpty(displayName)) {
+ return displayName;
+ }
+ // The name may have been passed to the compact editor and not written to the underlying
+ // data structure.
+ return valuesDelta.getDisplayName();
}
@Override