Revert "Move some contact editor functionality into new base classes"
This reverts commit 5d1c571dbe5b4a60aec6cb81d69e9e595813268e.
Change-Id: Ia9df02198b460529c157fbee6012349b0eca0bf3
diff --git a/res/layout/compact_contact_editor_activity.xml b/res/layout/compact_contact_editor_activity.xml
deleted file mode 100644
index bb89d01..0000000
--- a/res/layout/compact_contact_editor_activity.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <fragment android:id="@+id/compact_contact_editor_fragment"
- class="com.android.contacts.editor.CompactContactEditorFragment"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
-
-</FrameLayout>
-
diff --git a/res/layout/compact_contact_editor_fragment.xml b/res/layout/compact_contact_editor_fragment.xml
deleted file mode 100644
index eb24510..0000000
--- a/res/layout/compact_contact_editor_fragment.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@color/background_primary"
- android:fadingEdge="none"
- android:fillViewport="true">
-
- <LinearLayout android:id="@+id/editors"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"/>
-
-</ScrollView>
diff --git a/src/com/android/contacts/activities/CompactContactEditorActivity.java b/src/com/android/contacts/activities/CompactContactEditorActivity.java
deleted file mode 100644
index 066297d..0000000
--- a/src/com/android/contacts/activities/CompactContactEditorActivity.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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 + "_COMPACT").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 d04578e..c350da9 100644
--- a/src/com/android/contacts/activities/ContactEditorActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorActivity.java
@@ -16,32 +16,243 @@
package com.android.contacts.activities;
-import com.android.contacts.R;
-import com.android.contacts.editor.ContactEditorFragment;
-import com.android.contacts.util.DialogManager;
-
+import android.app.ActionBar;
+import android.app.Dialog;
+import android.content.ContentValues;
+import android.content.Context;
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 android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.TextView;
-/**
- * Contact editor with all fields displayed.
- */
-public class ContactEditorActivity extends ContactEditorBaseActivity
+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;
+
+public class ContactEditorActivity extends ContactsActivity
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);
-
- final String action = getIntent().getAction();
- final Uri uri = Intent.ACTION_EDIT.equals(action) ? getIntent().getData() : null;
+ 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;
+ }
}
diff --git a/src/com/android/contacts/activities/ContactEditorBaseActivity.java b/src/com/android/contacts/activities/ContactEditorBaseActivity.java
deleted file mode 100644
index 94f694e..0000000
--- a/src/com/android/contacts/activities/ContactEditorBaseActivity.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * 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
deleted file mode 100644
index b88e403..0000000
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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 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 ContactEditorBaseFragment.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
deleted file mode 100644
index dfa51c2..0000000
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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);
-
- /**
- *
- */
- 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 fddb4b3..e98ba7d 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -21,10 +21,12 @@
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;
@@ -32,6 +34,7 @@
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;
@@ -42,8 +45,10 @@
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;
@@ -65,7 +70,6 @@
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.common.model.AccountTypeManager;
import com.android.contacts.common.model.ValuesDelta;
import com.android.contacts.common.model.account.AccountType;
@@ -83,6 +87,7 @@
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.RawContactModifier;
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;
@@ -91,19 +96,19 @@
import com.google.common.collect.Lists;
import java.io.FileNotFoundException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
-/**
- * Contact editor with all fields displayed.
- */
-public class ContactEditorFragment extends ContactEditorBaseFragment implements
- ContactEditor, SplitContactConfirmationDialogFragment.Listener,
+public class ContactEditorFragment extends Fragment implements
+ 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;
@@ -134,6 +139,7 @@
public static final String SAVE_MODE_EXTRA_KEY = "saveMode";
+
/**
* An intent extra that forces the editor to add the edited contact
* to the default group (e.g. "My Contacts").
@@ -145,6 +151,67 @@
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;
@@ -175,7 +242,7 @@
private String mAction;
private Uri mLookupUri;
private Bundle mIntentExtras;
- private ContactEditorBaseFragment.Listener mListener;
+ private Listener mListener;
private long mContactIdForJoin;
private boolean mContactWritableForJoin;
@@ -405,7 +472,6 @@
super.onStart();
}
- @Override
public void load(String action, Uri lookupUri, Bundle intentExtras) {
mAction = action;
mLookupUri = lookupUri;
@@ -418,7 +484,6 @@
&& mIntentExtras.getBoolean(INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION);
}
- @Override
public void setListener(Listener value) {
mListener = value;
}
@@ -1144,7 +1209,10 @@
return RawContactModifier.hasChanges(mState, accountTypes);
}
- @Override
+ /**
+ * Saves or creates the contact based on the mode, and if successful
+ * finishes the activity.
+ */
public boolean save(int saveMode) {
if (!hasValidState() || mStatus != Status.EDITING) {
return false;
@@ -1292,9 +1360,27 @@
case SaveMode.HOME:
final Intent resultIntent;
if (saveSucceeded && contactLookupUri != null) {
- final Uri lookupUri = maybeConvertToLegacyLookupUri(
- mContext, contactLookupUri, mLookupUri);
- resultIntent = composeQuickContactsIntent(mContext, lookupUri);
+ 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);
} else {
resultIntent = null;
}
@@ -1378,6 +1464,57 @@
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);
+ }
+
private class EntityDeltaComparator implements Comparator<RawContactDelta> {
/**
* Compare EntityDeltas for sorting the stack of editors.