Forward intent extras to editor activity from springboard
Apply the extras once we have selected a raw contact to edit.
Test:
Selected an existing contact to add to and saw passed in
data was correctly applied.
Tested cases where editor auto loads, and picker dialog shows up.
In the case of the picker made sure that selecting any of them
would have the data passed through.
Bug: 32345528
Change-Id: I9a4088b3358ab532362c878394c657781965fb03
diff --git a/src/com/android/contacts/activities/ContactEditorActivity.java b/src/com/android/contacts/activities/ContactEditorActivity.java
index 1845a52..3052a24 100644
--- a/src/com/android/contacts/activities/ContactEditorActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorActivity.java
@@ -164,7 +164,7 @@
void load(String action, Uri lookupUri, Bundle intentExtras);
/**
- * Applies extras from the hosting Activity to the first writable raw contact.
+ * Applies extras from the hosting Activity to the writable raw contact.
*/
void setIntentExtras(Bundle extras);
diff --git a/src/com/android/contacts/activities/ContactEditorSpringBoardActivity.java b/src/com/android/contacts/activities/ContactEditorSpringBoardActivity.java
index 5b71c48..69dccb5 100644
--- a/src/com/android/contacts/activities/ContactEditorSpringBoardActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorSpringBoardActivity.java
@@ -30,7 +30,8 @@
* This activity has noHistory set to true, and all intents coming out from it have
* {@code FLAG_ACTIVITY_FORWARD_RESULT} set.
*/
-public class ContactEditorSpringBoardActivity extends AppCompatContactsActivity {
+public class ContactEditorSpringBoardActivity extends AppCompatContactsActivity implements
+ PickRawContactDialogFragment.PickRawContactListener {
private static final String TAG = "EditorSpringBoard";
private static final String TAG_RAW_CONTACTS_DIALOG = "rawContactsDialog";
private static final int LOADER_RAW_CONTACTS = 1;
@@ -109,13 +110,17 @@
if (ContactsContract.AUTHORITY.equals(authority) &&
RawContacts.CONTENT_ITEM_TYPE.equals(type)) {
final long rawContactId = ContentUris.parseId(mUri);
- final Intent editorIntent = getIntentForRawContact(rawContactId);
- ImplicitIntentsUtil.startActivityInApp(this, editorIntent);
+ startEditorAndForwardExtras(getIntentForRawContact(rawContactId));
} else {
getLoaderManager().initLoader(LOADER_RAW_CONTACTS, null, mRawContactLoaderListener);
}
}
+ @Override
+ public void onPickRawContact(long rawContactId) {
+ startEditorAndForwardExtras(getIntentForRawContact(rawContactId));
+ }
+
/**
* Start the dialog to pick the raw contact to edit.
*/
@@ -134,7 +139,7 @@
ft.remove(oldFragment);
}
final PickRawContactDialogFragment newFragment = PickRawContactDialogFragment.getInstance(
- mUri, mCursor, mMaterialPalette, mIsUserProfile);
+ mCursor, mIsUserProfile);
ft.add(newFragment, TAG_RAW_CONTACTS_DIALOG);
// commitAllowingStateLoss is safe in this activity because the fragment entirely depends
// on the result of the loader. Even if we lose the fragment because the activity was
@@ -163,7 +168,7 @@
// Destroy the loader to prevent multiple onLoadFinished calls in case CP2 is updating in
// the background.
getLoaderManager().destroyLoader(LOADER_RAW_CONTACTS);
- ImplicitIntentsUtil.startActivityInApp(this, intent);
+ startEditorAndForwardExtras(intent);
}
/**
@@ -195,4 +200,15 @@
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
return intent;
}
+
+ /**
+ * Starts the given intent within the app, attaching any extras to it that were passed to us.
+ */
+ private void startEditorAndForwardExtras(Intent intent) {
+ final Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ intent.putExtras(extras);
+ }
+ ImplicitIntentsUtil.startActivityInApp(this, intent);
+ }
}
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 9f55551..0f1ff8e 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -1366,19 +1366,7 @@
@Override
public void setIntentExtras(Bundle extras) {
- if (extras == null || extras.size() == 0) {
- return;
- }
-
- final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
- for (RawContactDelta state : mState) {
- final AccountType type = state.getAccountType(accountTypes);
- if (type.areContactsWritable()) {
- // Apply extras to the first writable raw contact only
- RawContactModifier.parseExtras(mContext, type, state, extras);
- break;
- }
- }
+ getContent().setIntentExtras(extras);
}
@Override
diff --git a/src/com/android/contacts/editor/PickRawContactDialogFragment.java b/src/com/android/contacts/editor/PickRawContactDialogFragment.java
index 623d038..dd079a2 100644
--- a/src/com/android/contacts/editor/PickRawContactDialogFragment.java
+++ b/src/com/android/contacts/editor/PickRawContactDialogFragment.java
@@ -6,7 +6,6 @@
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@@ -28,18 +27,19 @@
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.model.account.GoogleAccountType;
import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.common.util.ImplicitIntentsUtil;
-import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette;
/**
+ * Should only be started from an activity that implements {@link PickRawContactListener}.
* Dialog containing the raw contacts that make up a contact. On selection the editor is loaded
* for the chosen raw contact.
*/
public class PickRawContactDialogFragment extends DialogFragment {
- private static final String ARGS_URI = "uri";
- private static final String ARGS_MATERIAL_PALETTE = "materialPalette";
private static final String ARGS_IS_USER_PROFILE = "isUserProfile";
+ public interface PickRawContactListener {
+ void onPickRawContact(long rawContactId);
+ }
+
/**
* Used to list the account info for the given raw contacts list.
*/
@@ -142,18 +142,12 @@
// Cursor holding all raw contact rows for the given Contact.
private Cursor mCursor;
- // Uri for the whole Contact.
- private Uri mUri;
private CursorAdapter mAdapter;
- private MaterialPalette mMaterialPalette;
private boolean mIsUserProfile;
- public static PickRawContactDialogFragment getInstance(Uri uri, Cursor cursor,
- MaterialPalette materialPalette, boolean isUserProfile) {
+ public static PickRawContactDialogFragment getInstance(Cursor cursor, boolean isUserProfile) {
final PickRawContactDialogFragment fragment = new PickRawContactDialogFragment();
final Bundle args = new Bundle();
- args.putParcelable(ARGS_URI, uri);
- args.putParcelable(ARGS_MATERIAL_PALETTE, materialPalette);
args.putBoolean(ARGS_IS_USER_PROFILE, isUserProfile);
fragment.setArguments(args);
fragment.setCursor(cursor);
@@ -162,6 +156,10 @@
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
+ if (!(getActivity() instanceof PickRawContactListener)) {
+ throw new IllegalArgumentException(
+ "Host activity doesn't implement PickRawContactListener");
+ }
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
mAdapter = new RawContactAccountListAdapter(getContext(), mCursor);
builder.setTitle(R.string.contact_editor_pick_raw_contact_dialog_title);
@@ -169,10 +167,7 @@
@Override
public void onClick(DialogInterface dialog, int which) {
final long rawContactId = mAdapter.getItemId(which);
- final Intent intent = EditorIntents.createEditContactIntentForRawContact(
- getActivity(), mUri, rawContactId, mMaterialPalette);
- intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
- ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
+ ((PickRawContactListener) getActivity()).onPickRawContact(rawContactId);
}
});
builder.setCancelable(true);
@@ -192,8 +187,6 @@
final Bundle args = getArguments();
if (args != null) {
- mUri = args.getParcelable(ARGS_URI);
- mMaterialPalette = args.getParcelable(ARGS_MATERIAL_PALETTE);
mIsUserProfile = args.getBoolean(ARGS_IS_USER_PROFILE);
}
}
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index 1b37dab..fe7894a 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -21,6 +21,7 @@
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.ContactsContract.CommonDataKinds.Email;
@@ -223,6 +224,8 @@
private boolean mIsExpanded;
+ private Bundle mIntentExtras;
+
private ValuesDelta mPhotoValuesDelta;
public RawContactEditorView(Context context) {
@@ -425,6 +428,10 @@
}
}
+ public void setIntentExtras(Bundle extras) {
+ mIntentExtras = extras;
+ }
+
public void setState(RawContactDeltaList rawContactDeltas,
MaterialColorMapUtils.MaterialPalette materialPalette, ViewIdGenerator viewIdGenerator,
boolean hasNewContact, boolean isUserProfile, AccountWithDataSet primaryAccount,
@@ -455,6 +462,8 @@
return;
}
pickRawContactDelta();
+ // Apply any intent extras now that we have selected a raw contact delta.
+ applyIntentExtras();
parseRawContactDelta();
if (mKindSectionDataMap.isEmpty()) {
elog("No kind section data parsed from RawContactDelta(s)");
@@ -531,6 +540,17 @@
}
+ private void applyIntentExtras() {
+ if (mIntentExtras == null || mIntentExtras.size() == 0) {
+ return;
+ }
+ final AccountTypeManager accountTypes = AccountTypeManager.getInstance(getContext());
+ final AccountType type = mCurrentRawContactDelta.getAccountType(accountTypes);
+
+ RawContactModifier.parseExtras(getContext(), type, mCurrentRawContactDelta, mIntentExtras);
+ mIntentExtras = null;
+ }
+
private void parseRawContactDelta() {
mKindSectionDataMap.clear();
mSortedMimetypes.clear();