Combining ContactListActivity and TwoPaneActivity into one.
Change-Id: I2ab37a0c87bf26c56cef6946fb53814a70e0ac85
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a0a2ab7..c5811ec 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -167,6 +167,7 @@
<activity android:name=".activities.ContactListActivity"
android:label="@string/contactsList"
android:clearTaskOnLaunch="true"
+ android:theme="@android:style/Theme.NoTitleBar"
>
<intent-filter>
<action android:name="com.android.contacts.action.LIST_DEFAULT" />
@@ -389,12 +390,6 @@
</intent-filter>
</activity>
- <!-- Shows the List and Details in two panes. This is probably temporary -->
- <activity android:name=".activities.TwoPaneActivity"
- android:label="Contacts Goop"
- android:theme="@style/TallTitleBarTheme">
- </activity>
-
<!-- Create a new or edit an existing contact -->
<activity
android:name=".activities.ContactEditorActivity"
diff --git a/src/com/android/contacts/activities/ContactListActivity.java b/src/com/android/contacts/activities/ContactListActivity.java
index e6a220a..234d8d9 100644
--- a/src/com/android/contacts/activities/ContactListActivity.java
+++ b/src/com/android/contacts/activities/ContactListActivity.java
@@ -34,6 +34,8 @@
import com.android.contacts.list.PostalAddressPickerFragment;
import com.android.contacts.list.StrequentContactListFragment;
import com.android.contacts.ui.ContactsPreferencesActivity;
+import com.android.contacts.views.detail.ContactDetailFragment;
+import com.android.contacts.views.editor.ContactEditorFragment;
import com.android.contacts.widget.ContextMenuAdapter;
import com.android.contacts.widget.SearchEditText;
import com.android.contacts.widget.SearchEditText.OnFilterTextListener;
@@ -43,19 +45,22 @@
import android.app.FragmentTransaction;
import android.content.ContentValues;
import android.content.Intent;
+import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.Settings;
+import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.widget.Toast;
/**
- * Displays a list of contacts. Usually is embedded into the ContactsActivity.
+ * Displays a list of contacts.
*/
public class ContactListActivity extends Activity implements View.OnCreateContextMenuListener {
@@ -74,6 +79,12 @@
private ContactDeletionInteraction mContactDeletionInteraction;
private ImportExportInteraction mImportExportInteraction;
+ private ContactDetailFragment mDetailFragment;
+ private DetailFragmentListener mDetailFragmentListener = new DetailFragmentListener();
+
+ private ContactEditorFragment mEditorFragment;
+ private EditorFragmentListener mEditorFragmentListener = new EditorFragmentListener();
+
private int mActionCode;
private boolean mSearchInitiated;
@@ -81,7 +92,7 @@
private ContactsRequest mRequest;
private SearchEditText mSearchEditText;
-
+ private boolean mTwoPaneLayout;
public ContactListActivity() {
mIntentResolver = new ContactsIntentResolver(this);
@@ -107,6 +118,32 @@
return;
}
+ // The user launched the config based front door, pick the right activity to go to
+ Configuration config = getResources().getConfiguration();
+ int screenLayoutSize = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
+ mTwoPaneLayout = (screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_XLARGE);
+ if (mTwoPaneLayout) {
+ configureTwoPaneLayout();
+ } else {
+ configureSinglePaneLayout();
+ }
+ }
+
+ private void configureTwoPaneLayout() {
+ setContentView(R.layout.two_pane_activity);
+
+ DefaultContactBrowseListFragment fragment =
+ (DefaultContactBrowseListFragment)findFragmentById(R.id.two_pane_list);
+ fragment.setOnContactListActionListener(new ContactBrowserActionListener());
+
+ mListFragment = fragment;
+
+ setupContactDetailFragment();
+
+ setupSearchUI();
+ }
+
+ private void configureSinglePaneLayout() {
setTitle(mRequest.getActivityTitle());
onCreateFragment();
@@ -119,6 +156,7 @@
} else {
listFragmentContainerId = android.R.id.content;
}
+
FragmentTransaction transaction = openFragmentTransaction();
transaction.add(listFragmentContainerId, mListFragment);
transaction.commit();
@@ -129,6 +167,9 @@
mSearchEditText.setText(mRequest.getQueryString());
mSearchEditText.setOnFilterTextListener(new OnFilterTextListener() {
public void onFilterChange(String queryString) {
+ if (mTwoPaneLayout) {
+ mListFragment.setSearchMode(!TextUtils.isEmpty(queryString));
+ }
mListFragment.setQueryString(queryString);
}
@@ -138,10 +179,50 @@
});
}
+ private void setupContactDetailFragment() {
+ // No editor here
+ if (mEditorFragment != null) {
+ mEditorFragment.setListener(null);
+ mEditorFragment = null;
+ }
+
+ // Already showing? Nothing to do
+ if (mDetailFragment != null) return;
+
+ mDetailFragment = new ContactDetailFragment();
+ mDetailFragment.setListener(mDetailFragmentListener);
+
+ // Nothing showing yet? Create (this happens during Activity-Startup)
+ openFragmentTransaction()
+ .replace(R.id.two_pane_right_view, mDetailFragment)
+ .commit();
+
+ }
+
+ private void setupContactEditorFragment() {
+ // No detail view here
+ if (mDetailFragment != null) {
+ mDetailFragment.setListener(null);
+ mDetailFragment = null;
+ }
+
+ // Already showing? Nothing to do
+ if (mEditorFragment != null) return;
+
+ mEditorFragment = new ContactEditorFragment();
+ mEditorFragment.setListener(mEditorFragmentListener);
+
+ // Nothing showing yet? Create (this happens during Activity-Startup)
+ openFragmentTransaction()
+ .replace(R.id.two_pane_right_view, mEditorFragment)
+ .commit();
+
+ }
+
@Override
protected void onResume() {
super.onResume();
- if (mRequest.isSearchMode()) {
+ if (!mTwoPaneLayout && mRequest.isSearchMode()) {
mSearchEditText.requestFocus();
}
}
@@ -286,7 +367,12 @@
private final class ContactBrowserActionListener implements OnContactBrowserActionListener {
public void onViewContactAction(Uri contactLookupUri) {
- startActivity(new Intent(Intent.ACTION_VIEW, contactLookupUri));
+ if (mTwoPaneLayout) {
+ setupContactDetailFragment();
+ mDetailFragment.loadUri(contactLookupUri);
+ } else {
+ startActivity(new Intent(Intent.ACTION_VIEW, contactLookupUri));
+ }
}
public void onCreateNewContactAction() {
@@ -377,6 +463,65 @@
}
}
+ private class DetailFragmentListener implements ContactDetailFragment.Listener {
+ public void onContactNotFound() {
+ Toast.makeText(ContactListActivity.this, "onContactNotFound", Toast.LENGTH_LONG).show();
+ }
+
+ public void onEditRequested(Uri contactLookupUri) {
+ setupContactEditorFragment();
+ mEditorFragment.load(Intent.ACTION_EDIT, contactLookupUri, Contacts.CONTENT_ITEM_TYPE,
+ new Bundle());
+ }
+
+ public void onItemClicked(Intent intent) {
+ startActivity(intent);
+ }
+
+ public void onDialogRequested(int id, Bundle bundle) {
+ showDialog(id, bundle);
+ }
+ }
+
+ private class EditorFragmentListener implements ContactEditorFragment.Listener {
+ @Override
+ public void closeAfterDelete() {
+ Toast.makeText(ContactListActivity.this, "closeAfterDelete", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void closeAfterRevert() {
+ Toast.makeText(ContactListActivity.this, "closeAfterRevert", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void closeAfterSaving(int resultCode, Intent resultIntent) {
+ Toast.makeText(ContactListActivity.this, "closeAfterSaving", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void closeAfterSplit() {
+ Toast.makeText(ContactListActivity.this, "closeAfterSplit", Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void closeBecauseAccountSelectorAborted() {
+ Toast.makeText(ContactListActivity.this, "closeBecauseAccountSelectorAborted",
+ Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void closeBecauseContactNotFound() {
+ Toast.makeText(ContactListActivity.this, "closeBecauseContactNotFound",
+ Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void setTitleTo(int resourceId) {
+ Toast.makeText(ContactListActivity.this, "setTitleTo", Toast.LENGTH_LONG).show();
+ }
+ }
+
public void startActivityAndForwardResult(final Intent intent) {
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
diff --git a/src/com/android/contacts/activities/ContactsFrontDoor.java b/src/com/android/contacts/activities/ContactsFrontDoor.java
index 773e135..f7995e2 100644
--- a/src/com/android/contacts/activities/ContactsFrontDoor.java
+++ b/src/com/android/contacts/activities/ContactsFrontDoor.java
@@ -40,7 +40,7 @@
int screenLayoutSize = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
if (screenLayoutSize == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
// XL screen, use two pane UI
- intent.setClass(this, TwoPaneActivity.class);
+ intent.setClass(this, ContactListActivity.class);
} else {
// Default to the normal dialtacts layout
intent.setClass(this, DialtactsActivity.class);
diff --git a/src/com/android/contacts/activities/TwoPaneActivity.java b/src/com/android/contacts/activities/TwoPaneActivity.java
deleted file mode 100644
index 9d8bd47..0000000
--- a/src/com/android/contacts/activities/TwoPaneActivity.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright (C) 2010 Google Inc.
- *
- * 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.list.DefaultContactBrowseListFragment;
-import com.android.contacts.list.OnContactBrowserActionListener;
-import com.android.contacts.views.detail.ContactDetailFragment;
-import com.android.contacts.views.editor.ContactEditorFragment;
-import com.android.contacts.widget.SearchEditText;
-import com.android.contacts.widget.SearchEditText.OnFilterTextListener;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.provider.ContactsContract.Contacts;
-import android.text.TextUtils;
-import android.widget.Toast;
-
-public class TwoPaneActivity extends Activity {
- private final static String TAG = "TwoPaneActivity";
-
- private DefaultContactBrowseListFragment mListFragment;
- private ListFragmentListener mListFragmentListener = new ListFragmentListener();
-
- private ContactDetailFragment mDetailFragment;
- private DetailFragmentListener mDetailFragmentListener = new DetailFragmentListener();
-
- private ContactEditorFragment mEditorFragment;
- private EditorFragmentListener mEditorFragmentListener = new EditorFragmentListener();
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.two_pane_activity);
-
- mListFragment = (DefaultContactBrowseListFragment) findFragmentById(R.id.two_pane_list);
- mListFragment.setOnContactListActionListener(mListFragmentListener);
-
- setupContactDetailFragment();
-
- setupSearchUI();
- }
-
- private void setupContactDetailFragment() {
- // No editor here
- if (mEditorFragment != null) {
- mEditorFragment.setListener(null);
- mEditorFragment = null;
- }
-
- // Already showing? Nothing to do
- if (mDetailFragment != null) return;
-
- mDetailFragment = new ContactDetailFragment();
- mDetailFragment.setListener(mDetailFragmentListener);
-
- // Nothing showing yet? Create (this happens during Activity-Startup)
- openFragmentTransaction()
- .replace(R.id.two_pane_right_view, mDetailFragment)
- .commit();
-
- }
-
- private void setupContactEditorFragment() {
- // No detail view here
- if (mDetailFragment != null) {
- mDetailFragment.setListener(null);
- mDetailFragment = null;
- }
-
- // Already showing? Nothing to do
- if (mEditorFragment != null) return;
-
- mEditorFragment = new ContactEditorFragment();
- mEditorFragment.setListener(mEditorFragmentListener);
-
- // Nothing showing yet? Create (this happens during Activity-Startup)
- openFragmentTransaction()
- .replace(R.id.two_pane_right_view, mEditorFragment)
- .commit();
-
- }
-
- private void setupSearchUI() {
- SearchEditText searchEditText = (SearchEditText)findViewById(R.id.search_src_text);
- searchEditText.setOnFilterTextListener(new OnFilterTextListener() {
- public void onFilterChange(String queryString) {
- mListFragment.setSearchMode(!TextUtils.isEmpty(queryString));
- mListFragment.setQueryString(queryString);
- }
-
- public void onCancelSearch() {
- }
- });
- }
-
- private class ListFragmentListener implements OnContactBrowserActionListener {
- public void onAddToFavoritesAction(Uri contactUri) {
- Toast.makeText(TwoPaneActivity.this, "onAddToFavoritesAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onCallContactAction(Uri contactUri) {
- Toast.makeText(TwoPaneActivity.this, "onCallContactAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onCreateNewContactAction() {
- Toast.makeText(TwoPaneActivity.this, "onCreateNewContactAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onDeleteContactAction(Uri contactUri) {
- Toast.makeText(TwoPaneActivity.this, "onDeleteContactAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onEditContactAction(Uri contactLookupUri) {
- Toast.makeText(TwoPaneActivity.this, "onEditContactAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onFinishAction() {
- Toast.makeText(TwoPaneActivity.this, "onFinishAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onRemoveFromFavoritesAction(Uri contactUri) {
- Toast.makeText(TwoPaneActivity.this, "onRemoveFromFavoritesAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onSearchAllContactsAction(String string) {
- Toast.makeText(TwoPaneActivity.this, "onSearchAllContactsAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onSmsContactAction(Uri contactUri) {
- Toast.makeText(TwoPaneActivity.this, "onSmsContactAction",
- Toast.LENGTH_LONG).show();
- }
-
- public void onViewContactAction(Uri contactLookupUri) {
- setupContactDetailFragment();
- mDetailFragment.loadUri(contactLookupUri);
- }
- }
-
- private class DetailFragmentListener implements ContactDetailFragment.Listener {
- public void onContactNotFound() {
- Toast.makeText(TwoPaneActivity.this, "onContactNotFound", Toast.LENGTH_LONG).show();
- }
-
- public void onEditRequested(Uri contactLookupUri) {
- setupContactEditorFragment();
- mEditorFragment.load(Intent.ACTION_EDIT, contactLookupUri, Contacts.CONTENT_ITEM_TYPE,
- new Bundle());
- }
-
- public void onItemClicked(Intent intent) {
- startActivity(intent);
- }
-
- public void onDialogRequested(int id, Bundle bundle) {
- showDialog(id, bundle);
- }
- }
-
- private class EditorFragmentListener implements ContactEditorFragment.Listener {
- @Override
- public void closeAfterDelete() {
- Toast.makeText(TwoPaneActivity.this, "closeAfterDelete", Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void closeAfterRevert() {
- Toast.makeText(TwoPaneActivity.this, "closeAfterRevert", Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void closeAfterSaving(int resultCode, Intent resultIntent) {
- Toast.makeText(TwoPaneActivity.this, "closeAfterSaving", Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void closeAfterSplit() {
- Toast.makeText(TwoPaneActivity.this, "closeAfterSplit", Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void closeBecauseAccountSelectorAborted() {
- Toast.makeText(TwoPaneActivity.this, "closeBecauseAccountSelectorAborted",
- Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void closeBecauseContactNotFound() {
- Toast.makeText(TwoPaneActivity.this, "closeBecauseContactNotFound",
- Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void setTitleTo(int resourceId) {
- Toast.makeText(TwoPaneActivity.this, "setTitleTo", Toast.LENGTH_LONG).show();
- }
- }
-}