summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorWalter Jang <wjang@google.com>2015-01-27 17:38:30 +0000
committerWalter Jang <wjang@google.com>2015-01-28 20:13:31 +0000
commit3f990ba4e35a99078d831c041290e574a320caa5 (patch)
treea0a7d5204d365c9a65cf8274510edea58b5334cf /src/com
parentfb5dc6f857104c38ff49993d7498e8aa5fbc462e (diff)
downloadpackages_apps_Contacts-3f990ba4e35a99078d831c041290e574a320caa5.tar.gz
packages_apps_Contacts-3f990ba4e35a99078d831c041290e574a320caa5.tar.bz2
packages_apps_Contacts-3f990ba4e35a99078d831c041290e574a320caa5.zip
Move some contact editor functionality into new base classes
To make room for a new "compact" contact editor. The Status and SaveMode interfaces in ContactEditorFragment were moved to ContactEditorBaseActivity but the Listener interface was moved to the ContactEditorBaseFragment. The logic in ContactEditorFragment to construct the result Intent after successful saves was alos moved to the ContactEditorBaseFragment. This reverts commit 02375f1e45ade453c56810f32d63dfe8eebe4f44. Change-Id: Ib0129d9ba4e4351677b6979c5f720df2094bf48d
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/contacts/activities/CompactContactEditorActivity.java45
-rw-r--r--src/com/android/contacts/activities/ContactEditorActivity.java226
-rw-r--r--src/com/android/contacts/activities/ContactEditorBaseActivity.java353
-rw-r--r--src/com/android/contacts/editor/CompactContactEditorFragment.java111
-rw-r--r--src/com/android/contacts/editor/ContactEditorBaseFragment.java137
-rw-r--r--src/com/android/contacts/editor/ContactEditorFragment.java162
6 files changed, 670 insertions, 364 deletions
diff --git a/src/com/android/contacts/activities/CompactContactEditorActivity.java b/src/com/android/contacts/activities/CompactContactEditorActivity.java
new file mode 100644
index 000000000..875586334
--- /dev/null
+++ b/src/com/android/contacts/activities/CompactContactEditorActivity.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2015 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.activities;
+
+import com.android.contacts.R;
+import com.android.contacts.editor.CompactContactEditorFragment;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+
+/**
+ * Contact editor with only the most important fields displayed initially.
+ */
+public class CompactContactEditorActivity extends ContactEditorBaseActivity {
+
+ @Override
+ public void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ setContentView(R.layout.compact_contact_editor_activity);
+
+ mFragment = (CompactContactEditorFragment) getFragmentManager().findFragmentById(
+ R.id.compact_contact_editor_fragment);
+ mFragment.setListener(mFragmentListener);
+
+ final String action = getIntent().getAction();
+ final Uri uri = Intent.ACTION_EDIT.equals(action) ? getIntent().getData() : null;
+ mFragment.load(action, uri, getIntent().getExtras());
+ }
+}
diff --git a/src/com/android/contacts/activities/ContactEditorActivity.java b/src/com/android/contacts/activities/ContactEditorActivity.java
index 09097fd32..d04578e6b 100644
--- a/src/com/android/contacts/activities/ContactEditorActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorActivity.java
@@ -16,238 +16,32 @@
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;
-import android.provider.ContactsContract.Contacts;
-import android.provider.ContactsContract.RawContacts;
-import android.util.Log;
-
-import com.android.contacts.ContactSaveService;
-import com.android.contacts.ContactsActivity;
import com.android.contacts.R;
import com.android.contacts.editor.ContactEditorFragment;
-import com.android.contacts.editor.ContactEditorFragment.SaveMode;
-import com.android.contacts.common.model.AccountTypeManager;
-import com.android.contacts.common.model.account.AccountType;
-import com.android.contacts.common.model.account.AccountWithDataSet;
-import com.android.contacts.interactions.ContactDeletionInteraction;
import com.android.contacts.util.DialogManager;
-import java.util.ArrayList;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
-public class ContactEditorActivity extends ContactsActivity
+/**
+ * Contact editor with all fields displayed.
+ */
+public class ContactEditorActivity extends ContactEditorBaseActivity
implements DialogManager.DialogShowingViewActivity {
- private static final String TAG = "ContactEditorActivity";
-
- public static final String ACTION_JOIN_COMPLETED = "joinCompleted";
- public static final String ACTION_SAVE_COMPLETED = "saveCompleted";
-
- /**
- * Boolean intent key that specifies that this activity should finish itself
- * (instead of launching a new view intent) after the editor changes have been
- * saved.
- */
- public static final String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED =
- "finishActivityOnSaveCompleted";
-
- private ContactEditorFragment mFragment;
- private boolean mFinishActivityOnSaveCompleted;
-
- private DialogManager mDialogManager = new DialogManager(this);
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
- final Intent intent = getIntent();
- final String action = intent.getAction();
-
- // Determine whether or not this activity should be finished after the user is done
- // editing the contact or if this activity should launch another activity to view the
- // contact's details.
- mFinishActivityOnSaveCompleted = intent.getBooleanExtra(
- INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, false);
-
- // The only situation where action could be ACTION_JOIN_COMPLETED is if the
- // user joined the contact with another and closed the activity before
- // the save operation was completed. The activity should remain closed then.
- if (ACTION_JOIN_COMPLETED.equals(action)) {
- finish();
- return;
- }
-
- if (ACTION_SAVE_COMPLETED.equals(action)) {
- finish();
- return;
- }
-
setContentView(R.layout.contact_editor_activity);
- ActionBar actionBar = getActionBar();
- if (actionBar != null) {
- if (Intent.ACTION_EDIT.equals(action)) {
- actionBar.setTitle(getResources().getString(
- R.string.contact_editor_title_existing_contact));
- } else {
- actionBar.setTitle(getResources().getString(
- R.string.contact_editor_title_new_contact));
- }
- actionBar.setDisplayShowHomeEnabled(true);
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
-
mFragment = (ContactEditorFragment) getFragmentManager().findFragmentById(
R.id.contact_editor_fragment);
mFragment.setListener(mFragmentListener);
- Uri uri = Intent.ACTION_EDIT.equals(action) ? getIntent().getData() : null;
- mFragment.load(action, uri, getIntent().getExtras());
- }
-
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
-
- if (mFragment == null) {
- return;
- }
-
- String action = intent.getAction();
- if (Intent.ACTION_EDIT.equals(action)) {
- mFragment.setIntentExtras(intent.getExtras());
- } else if (ACTION_SAVE_COMPLETED.equals(action)) {
- mFragment.onSaveCompleted(true,
- intent.getIntExtra(ContactEditorFragment.SAVE_MODE_EXTRA_KEY, SaveMode.CLOSE),
- intent.getBooleanExtra(ContactSaveService.EXTRA_SAVE_SUCCEEDED, false),
- intent.getData());
- } else if (ACTION_JOIN_COMPLETED.equals(action)) {
- mFragment.onJoinCompleted(intent.getData());
- }
- }
- @Override
- protected Dialog onCreateDialog(int id, Bundle args) {
- if (DialogManager.isManagedId(id)) return mDialogManager.onCreateDialog(id, args);
-
- // Nobody knows about the Dialog
- Log.w(TAG, "Unknown dialog requested, id: " + id + ", args: " + args);
- return null;
- }
-
- @Override
- public void onBackPressed() {
- mFragment.save(SaveMode.CLOSE);
- }
-
- private final ContactEditorFragment.Listener mFragmentListener =
- new ContactEditorFragment.Listener() {
-
- @Override
- public void onDeleteRequested(Uri contactUri) {
- ContactDeletionInteraction.start(ContactEditorActivity.this, contactUri, true);
- }
-
- @Override
- public void onReverted() {
- finish();
- }
-
- @Override
- public void onSaveFinished(Intent resultIntent) {
- if (mFinishActivityOnSaveCompleted) {
- setResult(resultIntent == null ? RESULT_CANCELED : RESULT_OK, resultIntent);
- } else if (resultIntent != null) {
- startActivity(resultIntent);
- }
- finish();
- }
-
- @Override
- public void onContactSplit(Uri newLookupUri) {
- finish();
- }
-
- @Override
- public void onContactNotFound() {
- finish();
- }
-
- @Override
- public void onEditOtherContactRequested(
- Uri contactLookupUri, ArrayList<ContentValues> values) {
- Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
- intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
- intent.putExtra(ContactEditorFragment.INTENT_EXTRA_ADD_TO_DEFAULT_DIRECTORY, "");
-
- // Pass on all the data that has been entered so far
- if (values != null && values.size() != 0) {
- intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, values);
- }
-
- startActivity(intent);
- finish();
- }
-
- @Override
- public void onCustomCreateContactActivityRequested(AccountWithDataSet account,
- Bundle intentExtras) {
- final AccountTypeManager accountTypes =
- AccountTypeManager.getInstance(ContactEditorActivity.this);
- final AccountType accountType = accountTypes.getAccountType(
- account.type, account.dataSet);
-
- Intent intent = new Intent();
- intent.setClassName(accountType.syncAdapterPackageName,
- accountType.getCreateContactActivityClassName());
- intent.setAction(Intent.ACTION_INSERT);
- intent.setType(Contacts.CONTENT_ITEM_TYPE);
- if (intentExtras != null) {
- intent.putExtras(intentExtras);
- }
- intent.putExtra(RawContacts.ACCOUNT_NAME, account.name);
- intent.putExtra(RawContacts.ACCOUNT_TYPE, account.type);
- intent.putExtra(RawContacts.DATA_SET, account.dataSet);
- intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
- startActivity(intent);
- finish();
- }
-
- @Override
- public void onCustomEditContactActivityRequested(AccountWithDataSet account,
- Uri rawContactUri, Bundle intentExtras, boolean redirect) {
- final AccountTypeManager accountTypes =
- AccountTypeManager.getInstance(ContactEditorActivity.this);
- final AccountType accountType = accountTypes.getAccountType(
- account.type, account.dataSet);
-
- Intent intent = new Intent();
- intent.setClassName(accountType.syncAdapterPackageName,
- accountType.getEditContactActivityClassName());
- intent.setAction(Intent.ACTION_EDIT);
- intent.setData(rawContactUri);
- if (intentExtras != null) {
- intent.putExtras(intentExtras);
- }
-
- if (redirect) {
- intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
- startActivity(intent);
- finish();
- } else {
- startActivity(intent);
- }
- }
- };
-
- @Override
- public DialogManager getDialogManager() {
- return mDialogManager;
+ final String action = getIntent().getAction();
+ final Uri uri = Intent.ACTION_EDIT.equals(action) ? getIntent().getData() : null;
+ mFragment.load(action, uri, getIntent().getExtras());
}
}
diff --git a/src/com/android/contacts/activities/ContactEditorBaseActivity.java b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
new file mode 100644
index 000000000..94f694ecd
--- /dev/null
+++ b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
@@ -0,0 +1,353 @@
+/*
+ * Copyright (C) 2015 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.activities;
+
+import com.android.contacts.ContactSaveService;
+import com.android.contacts.ContactsActivity;
+import com.android.contacts.R;
+import com.android.contacts.common.model.AccountTypeManager;
+import com.android.contacts.common.model.account.AccountType;
+import com.android.contacts.common.model.account.AccountWithDataSet;
+import com.android.contacts.editor.ContactEditorBaseFragment;
+import com.android.contacts.editor.ContactEditorFragment;
+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;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.RawContacts;
+import android.util.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Base Activity for contact editors.
+ */
+abstract public class ContactEditorBaseActivity extends ContactsActivity
+ implements DialogManager.DialogShowingViewActivity {
+ protected static final String TAG = "ContactEditorActivity";
+
+ public static final String ACTION_JOIN_COMPLETED = "joinCompleted";
+ public static final String ACTION_SAVE_COMPLETED = "saveCompleted";
+
+ /**
+ * Contract for contact editors Fragments that are managed by this Activity.
+ */
+ public interface ContactEditor {
+
+ /**
+ * Modes that specify what the AsyncTask has to perform after saving
+ */
+ public interface SaveMode {
+ /**
+ * Close the editor after saving
+ */
+ public static final int CLOSE = 0;
+
+ /**
+ * Reload the data so that the user can continue editing
+ */
+ public static final int RELOAD = 1;
+
+ /**
+ * Split the contact after saving
+ */
+ public static final int SPLIT = 2;
+
+ /**
+ * Join another contact after saving
+ */
+ public static final int JOIN = 3;
+
+ /**
+ * Navigate to Contacts Home activity after saving.
+ */
+ public static final int HOME = 4;
+ }
+
+ /**
+ * The status of the contact editor.
+ */
+ public interface Status {
+ /**
+ * The loader is fetching data
+ */
+ public static final int LOADING = 0;
+
+ /**
+ * Not currently busy. We are waiting for the user to enter data
+ */
+ public static final int EDITING = 1;
+
+ /**
+ * The data is currently being saved. This is used to prevent more
+ * auto-saves (they shouldn't overlap)
+ */
+ public static final int SAVING = 2;
+
+ /**
+ * Prevents any more saves. This is used if in the following cases:
+ * - After Save/Close
+ * - After Revert
+ * - After the user has accepted an edit suggestion
+ */
+ public static final int CLOSING = 3;
+
+ /**
+ * Prevents saving while running a child activity.
+ */
+ public static final int SUB_ACTIVITY = 4;
+ }
+
+ /**
+ * Sets the hosting Activity that will receive callbacks from the contact editor.
+ */
+ void setListener(ContactEditorBaseFragment.Listener listener);
+
+ /**
+ * Initialize the contact editor.
+ */
+ void load(String action, Uri lookupUri, Bundle intentExtras);
+
+ /**
+ * Merges extras from the intent.
+ */
+ void setIntentExtras(Bundle extras);
+
+ /**
+ * Saves or creates the contact based on the mode, and if successful
+ * finishes the activity.
+ */
+ boolean save(int saveMode);
+
+ /**
+ * Invoked after the contact is saved.
+ */
+ void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
+ Uri contactLookupUri);
+
+ /**
+ * Invoked after the contact is joined.
+ */
+ void onJoinCompleted(Uri uri);
+ }
+
+ /**
+ * Boolean intent key that specifies that this activity should finish itself
+ * (instead of launching a new view intent) after the editor changes have been
+ * saved.
+ */
+ public static final String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED =
+ "finishActivityOnSaveCompleted";
+
+ protected ContactEditor mFragment;
+ private boolean mFinishActivityOnSaveCompleted;
+
+ private DialogManager mDialogManager = new DialogManager(this);
+
+ @Override
+ public void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ final Intent intent = getIntent();
+ final String action = intent.getAction();
+
+ // Determine whether or not this activity should be finished after the user is done
+ // editing the contact or if this activity should launch another activity to view the
+ // contact's details.
+ mFinishActivityOnSaveCompleted = intent.getBooleanExtra(
+ INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, false);
+
+ // The only situation where action could be ACTION_JOIN_COMPLETED is if the
+ // user joined the contact with another and closed the activity before
+ // the save operation was completed. The activity should remain closed then.
+ if (ACTION_JOIN_COMPLETED.equals(action)) {
+ finish();
+ return;
+ }
+
+ if (ACTION_SAVE_COMPLETED.equals(action)) {
+ finish();
+ return;
+ }
+
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ if (Intent.ACTION_EDIT.equals(action)) {
+ actionBar.setTitle(getResources().getString(
+ R.string.contact_editor_title_existing_contact));
+ } else {
+ actionBar.setTitle(getResources().getString(
+ R.string.contact_editor_title_new_contact));
+ }
+ actionBar.setDisplayShowHomeEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+
+ if (mFragment == null) {
+ return;
+ }
+
+ String action = intent.getAction();
+ if (Intent.ACTION_EDIT.equals(action)) {
+ mFragment.setIntentExtras(intent.getExtras());
+ } else if (ACTION_SAVE_COMPLETED.equals(action)) {
+ mFragment.onSaveCompleted(true,
+ intent.getIntExtra(ContactEditorFragment.SAVE_MODE_EXTRA_KEY,
+ ContactEditor.SaveMode.CLOSE),
+ intent.getBooleanExtra(ContactSaveService.EXTRA_SAVE_SUCCEEDED, false),
+ intent.getData());
+ } else if (ACTION_JOIN_COMPLETED.equals(action)) {
+ mFragment.onJoinCompleted(intent.getData());
+ }
+ }
+
+ @Override
+ protected Dialog onCreateDialog(int id, Bundle args) {
+ if (DialogManager.isManagedId(id)) return mDialogManager.onCreateDialog(id, args);
+
+ // Nobody knows about the Dialog
+ Log.w(TAG, "Unknown dialog requested, id: " + id + ", args: " + args);
+ return null;
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (mFragment != null) {
+ mFragment.save(ContactEditor.SaveMode.CLOSE);
+ }
+ }
+
+ protected final ContactEditorBaseFragment.Listener mFragmentListener =
+ new ContactEditorBaseFragment.Listener() {
+
+ @Override
+ public void onDeleteRequested(Uri contactUri) {
+ ContactDeletionInteraction.start(ContactEditorBaseActivity.this, contactUri, true);
+ }
+
+ @Override
+ public void onReverted() {
+ finish();
+ }
+
+ @Override
+ public void onSaveFinished(Intent resultIntent) {
+ if (mFinishActivityOnSaveCompleted) {
+ setResult(resultIntent == null ? RESULT_CANCELED : RESULT_OK, resultIntent);
+ } else if (resultIntent != null) {
+ startActivity(resultIntent);
+ }
+ finish();
+ }
+
+ @Override
+ public void onContactSplit(Uri newLookupUri) {
+ finish();
+ }
+
+ @Override
+ public void onContactNotFound() {
+ finish();
+ }
+
+ @Override
+ public void onEditOtherContactRequested(
+ Uri contactLookupUri, ArrayList<ContentValues> values) {
+ Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
+ intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
+ | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ intent.putExtra(ContactEditorFragment.INTENT_EXTRA_ADD_TO_DEFAULT_DIRECTORY, "");
+
+ // Pass on all the data that has been entered so far
+ if (values != null && values.size() != 0) {
+ intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, values);
+ }
+
+ startActivity(intent);
+ finish();
+ }
+
+ @Override
+ public void onCustomCreateContactActivityRequested(AccountWithDataSet account,
+ Bundle intentExtras) {
+ final AccountTypeManager accountTypes =
+ AccountTypeManager.getInstance(ContactEditorBaseActivity.this);
+ final AccountType accountType = accountTypes.getAccountType(
+ account.type, account.dataSet);
+
+ Intent intent = new Intent();
+ intent.setClassName(accountType.syncAdapterPackageName,
+ accountType.getCreateContactActivityClassName());
+ intent.setAction(Intent.ACTION_INSERT);
+ intent.setType(Contacts.CONTENT_ITEM_TYPE);
+ if (intentExtras != null) {
+ intent.putExtras(intentExtras);
+ }
+ intent.putExtra(RawContacts.ACCOUNT_NAME, account.name);
+ intent.putExtra(RawContacts.ACCOUNT_TYPE, account.type);
+ intent.putExtra(RawContacts.DATA_SET, account.dataSet);
+ intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
+ | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ startActivity(intent);
+ finish();
+ }
+
+ @Override
+ public void onCustomEditContactActivityRequested(AccountWithDataSet account,
+ Uri rawContactUri, Bundle intentExtras, boolean redirect) {
+ final AccountTypeManager accountTypes =
+ AccountTypeManager.getInstance(ContactEditorBaseActivity.this);
+ final AccountType accountType = accountTypes.getAccountType(
+ account.type, account.dataSet);
+
+ Intent intent = new Intent();
+ intent.setClassName(accountType.syncAdapterPackageName,
+ accountType.getEditContactActivityClassName());
+ intent.setAction(Intent.ACTION_EDIT);
+ intent.setData(rawContactUri);
+ if (intentExtras != null) {
+ intent.putExtras(intentExtras);
+ }
+
+ if (redirect) {
+ intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
+ | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ startActivity(intent);
+ finish();
+ } else {
+ startActivity(intent);
+ }
+ }
+ };
+
+ @Override
+ public DialogManager getDialogManager() {
+ return mDialogManager;
+ }
+}
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
new file mode 100644
index 000000000..536115511
--- /dev/null
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2015 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 com.android.contacts.R;
+import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
+import com.android.contacts.editor.ContactEditorBaseFragment.Listener;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+/**
+ * Contact editor with only the most important fields displayed initially.
+ */
+public class CompactContactEditorFragment extends ContactEditorBaseFragment
+ implements ContactEditor {
+
+ private Context mContext;
+ private Listener mListener;
+
+ private String mAction;
+ private Uri mLookupUri;
+ private Bundle mIntentExtras;
+
+ private LinearLayout mContent;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ mContext = activity;
+ }
+
+ @Override
+ public void setListener(Listener listener) {
+ mListener = listener;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
+ final View view = inflater.inflate(
+ R.layout.compact_contact_editor_fragment, container, false);
+ mContent = (LinearLayout) view.findViewById(R.id.editors);
+ return view;
+ }
+
+ @Override
+ public void load(String action, Uri lookupUri, Bundle intentExtras) {
+ mAction = action;
+ mLookupUri = lookupUri;
+ mIntentExtras = intentExtras;
+ }
+
+ @Override
+ public void setIntentExtras(Bundle extras) {
+ }
+
+ @Override
+ public boolean save(int saveMode) {
+ onSaveCompleted(/* hadChanges =*/ false, saveMode,
+ /* saveSucceeded =*/ mLookupUri != null, mLookupUri);
+ return true;
+ }
+
+ @Override
+ public void onJoinCompleted(Uri uri) {
+ onSaveCompleted(/* hadChanges =*/ false, SaveMode.RELOAD,
+ /* saveSucceeded =*/ uri != null, uri);
+ }
+
+ @Override
+ public void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
+ Uri contactLookupUri) {
+ switch (saveMode) {
+ case SaveMode.CLOSE:
+ case SaveMode.HOME:
+ if (mListener != null) {
+ final Intent resultIntent;
+ if (saveSucceeded && contactLookupUri != null) {
+ final Uri lookupUri = maybeConvertToLegacyLookupUri(
+ mContext, contactLookupUri, mLookupUri);
+ resultIntent = composeQuickContactsIntent(mContext, lookupUri);
+ } else {
+ resultIntent = null;
+ }
+ mListener.onSaveFinished(resultIntent);
+ }
+ break;
+ }
+ }
+}
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
new file mode 100644
index 000000000..240a42f1e
--- /dev/null
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 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 com.android.contacts.common.model.account.AccountWithDataSet;
+import com.android.contacts.quickcontact.QuickContactActivity;
+
+import android.app.Fragment;
+import android.content.ContentUris;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Rect;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.QuickContact;
+
+import java.util.ArrayList;
+
+/**
+ * Base Fragment for contact editors.
+ */
+abstract public class ContactEditorBaseFragment extends Fragment {
+
+ protected static final String TAG = "ContactCompactEditor";
+
+ /**
+ * Callbacks for Activities that host contact editors Fragments.
+ */
+ public interface Listener {
+
+ /**
+ * Contact was not found, so somehow close this fragment. This is raised after a contact
+ * is removed via Menu/Delete
+ */
+ void onContactNotFound();
+
+ /**
+ * Contact was split, so we can close now.
+ *
+ * @param newLookupUri The lookup uri of the new contact that should be shown to the user.
+ * The editor tries best to chose the most natural contact here.
+ */
+ void onContactSplit(Uri newLookupUri);
+
+ /**
+ * User has tapped Revert, close the fragment now.
+ */
+ void onReverted();
+
+ /**
+ * Contact was saved and the Fragment can now be closed safely.
+ */
+ void onSaveFinished(Intent resultIntent);
+
+ /**
+ * User switched to editing a different contact (a suggestion from the
+ * aggregation engine).
+ */
+ void onEditOtherContactRequested(Uri contactLookupUri,
+ ArrayList<ContentValues> contentValues);
+
+ /**
+ * Contact is being created for an external account that provides its own
+ * new contact activity.
+ */
+ void onCustomCreateContactActivityRequested(AccountWithDataSet account,
+ Bundle intentExtras);
+
+ /**
+ * The edited raw contact belongs to an external account that provides
+ * its own edit activity.
+ *
+ * @param redirect indicates that the current editor should be closed
+ * before the custom editor is shown.
+ */
+ void onCustomEditContactActivityRequested(AccountWithDataSet account, Uri rawContactUri,
+ Bundle intentExtras, boolean redirect);
+
+ /**
+ * User has requested that contact be deleted.
+ */
+ void onDeleteRequested(Uri contactUri);
+ }
+
+ /**
+ * Returns a legacy version of the given contactLookupUri if a legacy Uri was originally
+ * passed to the contact editor.
+ *
+ * @param contactLookupUri The Uri to possibly convert to legacy format.
+ * @param requestLookupUri The lookup Uri originally passed to the contact editor
+ * (via Intent data), may be null.
+ */
+ protected static Uri maybeConvertToLegacyLookupUri(Context context, Uri contactLookupUri,
+ Uri requestLookupUri) {
+ final String legacyAuthority = "contacts";
+ final String requestAuthority = requestLookupUri == null
+ ? null : requestLookupUri.getAuthority();
+ if (legacyAuthority.equals(requestAuthority)) {
+ // Build a legacy Uri if that is what was requested by caller
+ final long contactId = ContentUris.parseId(Contacts.lookupContact(
+ context.getContentResolver(), contactLookupUri));
+ final Uri legacyContentUri = Uri.parse("content://contacts/people");
+ return ContentUris.withAppendedId(legacyContentUri, contactId);
+ }
+ // Otherwise pass back a lookup-style Uri
+ return contactLookupUri;
+ }
+
+ /**
+ * Creates the result Intent for the given contactLookupUri that should started after a
+ * successful saving a contact.
+ */
+ protected static Intent composeQuickContactsIntent(Context context, Uri contactLookupUri) {
+ final Intent intent = QuickContact.composeQuickContactsIntent(
+ context, (Rect) null, contactLookupUri, QuickContactActivity.MODE_FULLY_EXPANDED,
+ /* excludedMimes =*/ null);
+ // Make sure not to show QuickContacts on top of another QuickContacts.
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ return intent;
+ }
+}
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 2ad1e703c..0a8a9676c 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -21,12 +21,10 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
-import android.app.Fragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ActivityNotFoundException;
import android.content.ContentUris;
-import android.content.ContentValues;
import android.content.Context;
import android.content.CursorLoader;
import android.content.DialogInterface;
@@ -34,7 +32,6 @@ import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.graphics.Bitmap;
-import android.graphics.Rect;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
@@ -45,10 +42,8 @@ import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
-import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.Intents;
-import android.provider.ContactsContract.QuickContact;
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.util.Log;
@@ -70,6 +65,9 @@ import com.android.contacts.GroupMetaDataLoader;
import com.android.contacts.R;
import com.android.contacts.activities.ContactEditorAccountsChangedActivity;
import com.android.contacts.activities.ContactEditorActivity;
+import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
+import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor.SaveMode;
+import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor.Status;
import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.Contact;
import com.android.contacts.common.model.ContactLoader;
@@ -86,7 +84,6 @@ import com.android.contacts.detail.PhotoSelectionHandler;
import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion;
import com.android.contacts.editor.Editor.EditorListener;
import com.android.contacts.list.UiIntentActions;
-import com.android.contacts.quickcontact.QuickContactActivity;
import com.android.contacts.util.ContactPhotoUtils;
import com.android.contacts.util.HelpUtils;
import com.android.contacts.util.PhoneCapabilityTester;
@@ -96,18 +93,18 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.io.FileNotFoundException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-public class ContactEditorFragment extends Fragment implements
- SplitContactConfirmationDialogFragment.Listener,
+/**
+ * Contact editor with all fields displayed.
+ */
+public class ContactEditorFragment extends ContactEditorBaseFragment implements
+ ContactEditor, SplitContactConfirmationDialogFragment.Listener,
AggregationSuggestionEngine.Listener, AggregationSuggestionView.Listener,
RawContactReadOnlyEditorView.Listener {
- private static final String TAG = ContactEditorFragment.class.getSimpleName();
-
private static final int LOADER_DATA = 1;
private static final int LOADER_GROUPS = 2;
@@ -149,67 +146,6 @@ public class ContactEditorFragment extends Fragment implements
public static final String INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION =
"disableDeleteMenuOption";
- /**
- * Modes that specify what the AsyncTask has to perform after saving
- */
- public interface SaveMode {
- /**
- * Close the editor after saving
- */
- public static final int CLOSE = 0;
-
- /**
- * Reload the data so that the user can continue editing
- */
- public static final int RELOAD = 1;
-
- /**
- * Split the contact after saving
- */
- public static final int SPLIT = 2;
-
- /**
- * Join another contact after saving
- */
- public static final int JOIN = 3;
-
- /**
- * Navigate to Contacts Home activity after saving.
- */
- public static final int HOME = 4;
- }
-
- private interface Status {
- /**
- * The loader is fetching data
- */
- public static final int LOADING = 0;
-
- /**
- * Not currently busy. We are waiting for the user to enter data
- */
- public static final int EDITING = 1;
-
- /**
- * The data is currently being saved. This is used to prevent more
- * auto-saves (they shouldn't overlap)
- */
- public static final int SAVING = 2;
-
- /**
- * Prevents any more saves. This is used if in the following cases:
- * - After Save/Close
- * - After Revert
- * - After the user has accepted an edit suggestion
- */
- public static final int CLOSING = 3;
-
- /**
- * Prevents saving while running a child activity.
- */
- public static final int SUB_ACTIVITY = 4;
- }
-
private static final int REQUEST_CODE_JOIN = 0;
private static final int REQUEST_CODE_ACCOUNTS_CHANGED = 1;
private static final int REQUEST_CODE_PICK_RINGTONE = 2;
@@ -484,6 +420,7 @@ public class ContactEditorFragment extends Fragment implements
super.onStart();
}
+ @Override
public void load(String action, Uri lookupUri, Bundle intentExtras) {
mAction = action;
mLookupUri = lookupUri;
@@ -496,6 +433,7 @@ public class ContactEditorFragment extends Fragment implements
&& mIntentExtras.getBoolean(INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION);
}
+ @Override
public void setListener(Listener value) {
mListener = value;
}
@@ -1221,10 +1159,7 @@ public class ContactEditorFragment extends Fragment implements
return RawContactModifier.hasChanges(mState, accountTypes);
}
- /**
- * Saves or creates the contact based on the mode, and if successful
- * finishes the activity.
- */
+ @Override
public boolean save(int saveMode) {
if (!hasValidState() || mStatus != Status.EDITING) {
return false;
@@ -1372,27 +1307,9 @@ public class ContactEditorFragment extends Fragment implements
case SaveMode.HOME:
final Intent resultIntent;
if (saveSucceeded && contactLookupUri != null) {
- final String requestAuthority =
- mLookupUri == null ? null : mLookupUri.getAuthority();
-
- final String legacyAuthority = "contacts";
- final Uri lookupUri;
- if (legacyAuthority.equals(requestAuthority)) {
- // Build legacy Uri when requested by caller
- final long contactId = ContentUris.parseId(Contacts.lookupContact(
- mContext.getContentResolver(), contactLookupUri));
- final Uri legacyContentUri = Uri.parse("content://contacts/people");
- final Uri legacyUri = ContentUris.withAppendedId(
- legacyContentUri, contactId);
- lookupUri = legacyUri;
- } else {
- // Otherwise pass back a lookup-style Uri
- lookupUri = contactLookupUri;
- }
- resultIntent = QuickContact.composeQuickContactsIntent(getActivity(),
- (Rect) null, lookupUri, QuickContactActivity.MODE_FULLY_EXPANDED, null);
- // Make sure not to show QuickContacts on top of another QuickContacts.
- resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ final Uri lookupUri = maybeConvertToLegacyLookupUri(
+ mContext, contactLookupUri, mLookupUri);
+ resultIntent = composeQuickContactsIntent(mContext, lookupUri);
} else {
resultIntent = null;
}
@@ -1476,57 +1393,6 @@ public class ContactEditorFragment extends Fragment implements
return mNewLocalProfile || mIsUserProfile;
}
- public static interface Listener {
- /**
- * Contact was not found, so somehow close this fragment. This is raised after a contact
- * is removed via Menu/Delete
- */
- void onContactNotFound();
-
- /**
- * Contact was split, so we can close now.
- * @param newLookupUri The lookup uri of the new contact that should be shown to the user.
- * The editor tries best to chose the most natural contact here.
- */
- void onContactSplit(Uri newLookupUri);
-
- /**
- * User has tapped Revert, close the fragment now.
- */
- void onReverted();
-
- /**
- * Contact was saved and the Fragment can now be closed safely.
- */
- void onSaveFinished(Intent resultIntent);
-
- /**
- * User switched to editing a different contact (a suggestion from the
- * aggregation engine).
- */
- void onEditOtherContactRequested(
- Uri contactLookupUri, ArrayList<ContentValues> contentValues);
-
- /**
- * Contact is being created for an external account that provides its own
- * new contact activity.
- */
- void onCustomCreateContactActivityRequested(AccountWithDataSet account,
- Bundle intentExtras);
-
- /**
- * The edited raw contact belongs to an external account that provides
- * its own edit activity.
- *
- * @param redirect indicates that the current editor should be closed
- * before the custom editor is shown.
- */
- void onCustomEditContactActivityRequested(AccountWithDataSet account, Uri rawContactUri,
- Bundle intentExtras, boolean redirect);
-
- void onDeleteRequested(Uri contactUri);
- }
-
/**
* Returns the contact ID for the currently edited contact or 0 if the contact is new.
*/