summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2011-10-12 12:27:16 -0700
committerDaisuke Miyakawa <dmiyakawa@google.com>2011-10-18 14:35:05 -0700
commita8729cdf778f9ca927b06afde685f7ac6b8c917f (patch)
treed1c02f1af7e17d729ba635e40eed6eb495e1899d
parent0a65b8bbf7f00edb0cb0d17934f53bd4206b3ce7 (diff)
downloadandroid_packages_apps_Contacts-a8729cdf778f9ca927b06afde685f7ac6b8c917f.tar.gz
android_packages_apps_Contacts-a8729cdf778f9ca927b06afde685f7ac6b8c917f.tar.bz2
android_packages_apps_Contacts-a8729cdf778f9ca927b06afde685f7ac6b8c917f.zip
Introduce ActionBar in picker screens
This change focuses on phone screens. Tablet UI fix will be done later. - show SearchView on the action bar - show "create new contact" as a menu on the split action bar - keep "create new contact" button for tablet support. - a few visual tweaks for phone Also this removes "show all contacts" item in JoinContactActivity. Now all contacts are shown by default. Bug: 5394377 Change-Id: I82e59b374888d522c81cd4957cb3fde286b419f6
-rw-r--r--AndroidManifest.xml2
-rw-r--r--res/layout-sw580dp/contact_picker.xml52
-rw-r--r--res/layout/contact_picker.xml22
-rw-r--r--res/layout/join_contact_picker.xml14
-rw-r--r--res/layout/join_contact_picker_list_content.xml9
-rw-r--r--res/layout/join_contact_picker_section_header.xml (renamed from res/layout/join_contact_picker_section.xml)7
-rw-r--r--res/menu/contact_picker_options.xml22
-rw-r--r--res/values/strings.xml7
-rw-r--r--res/values/styles.xml5
-rw-r--r--src/com/android/contacts/activities/ContactSelectionActivity.java185
-rw-r--r--src/com/android/contacts/activities/JoinContactActivity.java36
-rw-r--r--src/com/android/contacts/list/JoinContactListAdapter.java41
-rw-r--r--src/com/android/contacts/list/JoinContactListFragment.java33
-rw-r--r--src/com/android/contacts/list/JoinContactLoader.java12
14 files changed, 290 insertions, 157 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 722fc46ce..d9482d05e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -274,7 +274,7 @@
android:theme="@style/ContactPickerTheme"
android:launchMode="singleTop"
android:clearTaskOnLaunch="true"
- >
+ android:uiOptions="splitActionBarWhenNarrow">
<intent-filter>
<action android:name="android.intent.action.INSERT_OR_EDIT" />
<category android:name="android.intent.category.DEFAULT" />
diff --git a/res/layout-sw580dp/contact_picker.xml b/res/layout-sw580dp/contact_picker.xml
new file mode 100644
index 000000000..d4ee22435
--- /dev/null
+++ b/res/layout-sw580dp/contact_picker.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<view
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ class="com.android.contacts.widget.FullHeightLinearLayout"
+ style="@style/ContactPickerLayout"
+ android:orientation="vertical"
+ android:layout_height="match_parent">
+ <view
+ class="android.widget.SearchView"
+ android:id="@+id/search_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="0dip"
+ android:layout_marginRight="32dip"
+ android:iconifiedByDefault="false" />
+ <!-- will contain an appropriate contacts list -->
+ <FrameLayout
+ android:id="@+id/list_container"
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1" />
+
+ <LinearLayout
+ style="?android:attr/buttonBarStyle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="16dip"
+ android:paddingRight="16dip">
+ <Button
+ android:id="@+id/new_contact"
+ style="?android:attr/buttonBarButtonStyle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAllCaps="true"
+ android:text="@string/pickerNewContactText" />
+ </LinearLayout>
+</view>
diff --git a/res/layout/contact_picker.xml b/res/layout/contact_picker.xml
index 96bf3345f..49be858e6 100644
--- a/res/layout/contact_picker.xml
+++ b/res/layout/contact_picker.xml
@@ -34,26 +34,4 @@
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
-
- <View
- android:id="@+id/divider"
- android:layout_width="match_parent"
- android:layout_height="1dip"
- android:layout_marginLeft="16dip"
- android:layout_marginRight="16dip"
- android:background="?android:attr/dividerHorizontal" />
-
- <LinearLayout
- style="?android:attr/buttonBarStyle"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingLeft="16dip"
- android:paddingRight="16dip">
- <Button
- style="?android:attr/buttonBarButtonStyle"
- android:id="@+id/cancel"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@android:string/cancel" />
- </LinearLayout>
</view>
diff --git a/res/layout/join_contact_picker.xml b/res/layout/join_contact_picker.xml
index ffea13750..ea0deaf63 100644
--- a/res/layout/join_contact_picker.xml
+++ b/res/layout/join_contact_picker.xml
@@ -33,18 +33,4 @@
android:layout_marginLeft="?attr/contact_browser_list_padding_left"
android:layout_marginRight="?attr/contact_browser_list_padding_right"
android:background="?android:attr/dividerHorizontal" />
-
- <LinearLayout
- style="?android:attr/buttonBarStyle"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="?attr/contact_browser_list_padding_left"
- android:layout_marginRight="?attr/contact_browser_list_padding_right">
- <Button
- style="?android:attr/buttonBarButtonStyle"
- android:id="@+id/cancel"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@android:string/cancel"/>
- </LinearLayout>
</view>
diff --git a/res/layout/join_contact_picker_list_content.xml b/res/layout/join_contact_picker_list_content.xml
index 1535539d2..40137e26e 100644
--- a/res/layout/join_contact_picker_list_content.xml
+++ b/res/layout/join_contact_picker_list_content.xml
@@ -19,17 +19,18 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingTop="8dip"
+ android:paddingTop="16dip"
android:orientation="vertical">
<TextView
android:id="@+id/join_contact_blurb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingLeft="16dip"
- android:paddingRight="16dip"
+ android:layout_marginLeft="@dimen/contact_browser_list_header_left_margin"
+ android:layout_marginRight="@dimen/contact_browser_list_header_right_margin"
+ android:paddingLeft="?attr/list_item_header_text_indent"
android:maxLines="2"
- android:textAppearance="?android:attr/textAppearanceMedium" />
+ android:textAppearance="?android:attr/textAppearanceSmall" />
<FrameLayout
android:id="@+id/pinned_header_list_layout"
diff --git a/res/layout/join_contact_picker_section.xml b/res/layout/join_contact_picker_section_header.xml
index 260ea2d6e..50dac7000 100644
--- a/res/layout/join_contact_picker_section.xml
+++ b/res/layout/join_contact_picker_section_header.xml
@@ -14,6 +14,7 @@
limitations under the License.
-->
+<!-- Layout used for "Join contacts" screen's section headers. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
@@ -24,9 +25,13 @@
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:minHeight="32dip"
android:paddingLeft="?attr/list_item_header_text_indent"
- android:minHeight="16dip"
android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textAllCaps="true"
+ android:textStyle="bold"
+ android:singleLine="true"
+ android:ellipsize="end"
android:gravity="center_vertical" />
<View style="@style/SectionDivider" />
diff --git a/res/menu/contact_picker_options.xml b/res/menu/contact_picker_options.xml
new file mode 100644
index 000000000..89196bacc
--- /dev/null
+++ b/res/menu/contact_picker_options.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+<!-- Used with DialtactsActivity's search mode. -->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/create_new_contact"
+ android:title="@string/pickerNewContactText"
+ android:showAsAction="ifRoom" />
+</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 62dac753a..2ac54a5d2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -209,9 +209,10 @@
for some reason doesn't exist anymore. -->
<string name="invalidContactMessage">The contact does not exist.</string>
- <!-- When picking a contact from a list of all contacts there is an entry at the top of the
- list that allows the user to create a new contact, which this string is used for -->
- <string name="pickerNewContactHeader">Create new contact</string>
+ <!-- Text for a "create new contact" button on the bottom of the contact picker screen.
+ The text will be all capitalized.
+ [CHAR LIMIT=30] -->
+ <string name="pickerNewContactText">Create new contact</string>
<!-- Header that expands to list all of the types of phone numbers when editing or creating a phone number for a contact [CHAR LIMIT=20] -->
<string name="phoneLabelsGroup">Phone</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 62a06f6d0..506fb619a 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -177,10 +177,7 @@
<item name="android:background">@drawable/action_bar_tab</item>
</style>
- <style name="ContactPickerTheme" parent="@style/PeopleTheme">
- <item name="android:windowActionBar">false</item>
- <item name="android:windowNoTitle">true</item>
- </style>
+ <style name="ContactPickerTheme" parent="@style/PeopleTheme" />
<style name="ContactPickerLayout" parent="ContactPickerTheme">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
diff --git a/src/com/android/contacts/activities/ContactSelectionActivity.java b/src/com/android/contacts/activities/ContactSelectionActivity.java
index 0ab5881a9..6305d8ef8 100644
--- a/src/com/android/contacts/activities/ContactSelectionActivity.java
+++ b/src/com/android/contacts/activities/ContactSelectionActivity.java
@@ -32,19 +32,29 @@ import com.android.contacts.list.PhoneNumberPickerFragment;
import com.android.contacts.list.PostalAddressPickerFragment;
import com.android.contacts.widget.ContextMenuAdapter;
+import android.app.ActionBar;
+import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.Fragment;
+import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents.Insert;
import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.View.OnFocusChangeListener;
+import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.SearchView;
+import android.widget.SearchView.OnCloseListener;
import android.widget.SearchView.OnQueryTextListener;
import java.util.Set;
@@ -54,7 +64,8 @@ import java.util.Set;
* purposes of selecting one.
*/
public class ContactSelectionActivity extends ContactsActivity
- implements View.OnCreateContextMenuListener, OnQueryTextListener, OnClickListener {
+ implements View.OnCreateContextMenuListener, OnQueryTextListener, OnClickListener,
+ OnCloseListener, OnFocusChangeListener {
private static final String TAG = "ContactSelectionActivity";
private static final int SUBACTIVITY_ADD_TO_EXISTING_CONTACT = 0;
@@ -72,6 +83,10 @@ public class ContactSelectionActivity extends ContactsActivity
private ContactsRequest mRequest;
private SearchView mSearchView;
+ /**
+ * Can be null. If null, the "Create New Contact" button should be on the menu.
+ */
+ private Button mCreateNewContactButton;
public ContactSelectionActivity() {
mIntentResolver = new ContactsIntentResolver(this);
@@ -113,31 +128,127 @@ public class ContactSelectionActivity extends ContactsActivity
setContentView(R.layout.contact_picker);
- configureListFragment();
+ if (mActionCode != mRequest.getActionCode()) {
+ mActionCode = mRequest.getActionCode();
+ configureListFragment();
+ }
+
+ prepareSearchViewAndActionBar();
- mSearchView = (SearchView)findViewById(R.id.search_view);
- mSearchView.setQueryHint(getString(R.string.hint_findContacts));
- mSearchView.setOnQueryTextListener(this);
+ mCreateNewContactButton = (Button) findViewById(R.id.new_contact);
+ if (mCreateNewContactButton != null) {
+ if (shouldShowCreateNewContactButton()) {
+ mCreateNewContactButton.setVisibility(View.VISIBLE);
+ mCreateNewContactButton.setOnClickListener(this);
+ } else {
+ mCreateNewContactButton.setVisibility(View.GONE);
+ }
+ }
+ }
- // TODO: re-enable search for postal addresses
+ private boolean shouldShowCreateNewContactButton() {
+ return (mActionCode == ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT
+ || (mActionCode == ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT
+ && !mRequest.isSearchMode()));
+ }
+
+ private void prepareSearchViewAndActionBar() {
+ // Postal address picker doesn't support search, so just show "HomeAsUp" button and title.
if (mRequest.getActionCode() == ContactsRequest.ACTION_PICK_POSTAL) {
- mSearchView.setVisibility(View.GONE);
+ findViewById(R.id.search_view).setVisibility(View.GONE);
+ final ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayShowHomeEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowTitleEnabled(true);
+ }
+ return;
+ }
+
+ // If ActionBar is available, show SearchView on it. If not, show SearchView inside the
+ // Activity's layout.
+ final ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ final View searchViewOnLayout = findViewById(R.id.search_view);
+ if (searchViewOnLayout != null) {
+ searchViewOnLayout.setVisibility(View.GONE);
+ }
+
+ final View searchViewContainer = LayoutInflater.from(actionBar.getThemedContext())
+ .inflate(R.layout.custom_action_bar, null);
+ mSearchView = (SearchView) searchViewContainer.findViewById(R.id.search_view);
+
+ // In order to make the SearchView look like "shown via search menu", we need to
+ // manually setup its state. See also DialtactsActivity.java and ActionBarAdapter.java.
+ mSearchView.setIconifiedByDefault(true);
+ mSearchView.setQueryHint(getString(R.string.hint_findContacts));
+ mSearchView.setIconified(false);
+
+ mSearchView.setOnQueryTextListener(this);
+ mSearchView.setOnCloseListener(this);
+ mSearchView.setOnQueryTextFocusChangeListener(this);
+
+ actionBar.setCustomView(searchViewContainer,
+ new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
+ actionBar.setDisplayShowCustomEnabled(true);
+ actionBar.setDisplayShowHomeEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
} else {
+ mSearchView = (SearchView) findViewById(R.id.search_view);
+ mSearchView.setQueryHint(getString(R.string.hint_findContacts));
+ mSearchView.setOnQueryTextListener(this);
+
// This is a hack to prevent the search view from grabbing focus
// at this point. If search view were visible, it would always grabs focus
// because it is the first focusable widget in the window.
mSearchView.setVisibility(View.INVISIBLE);
mSearchView.postDelayed(new Runnable() {
-
@Override
public void run() {
mSearchView.setVisibility(View.VISIBLE);
}
}, FOCUS_DELAY);
}
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // If we want "Create New Contact" button but there's no such a button in the layout,
+ // try showing a menu for it.
+ if (shouldShowCreateNewContactButton() && mCreateNewContactButton == null) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.contact_picker_options, menu);
+ }
+ return true;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
- Button cancel = (Button) findViewById(R.id.cancel);
- cancel.setOnClickListener(this);
+ if (mSearchView != null && mSearchView.getVisibility() == View.VISIBLE) {
+ if (mSearchView.hasFocus()) {
+ showInputMethod(mSearchView.findFocus());
+ } else {
+ mSearchView.requestFocus();
+ }
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // Go back to previous screen, intending "cancel"
+ setResult(RESULT_CANCELED);
+ finish();
+ return true;
+ case R.id.create_new_contact: {
+ startCreateNewContactActivity();
+ return true;
+ }
+ }
+ return super.onOptionsItemSelected(item);
}
@Override
@@ -205,15 +316,9 @@ public class ContactSelectionActivity extends ContactsActivity
* Creates the fragment based on the current request.
*/
public void configureListFragment() {
- if (mActionCode == mRequest.getActionCode()) {
- return;
- }
-
- mActionCode = mRequest.getActionCode();
switch (mActionCode) {
case ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT: {
ContactPickerFragment fragment = new ContactPickerFragment();
- fragment.setCreateContactEnabled(true);
fragment.setEditMode(true);
fragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_NONE);
mListFragment = fragment;
@@ -230,7 +335,6 @@ public class ContactSelectionActivity extends ContactsActivity
case ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT: {
ContactPickerFragment fragment = new ContactPickerFragment();
- fragment.setCreateContactEnabled(!mRequest.isSearchMode());
mListFragment = fragment;
break;
}
@@ -314,8 +418,7 @@ public class ContactSelectionActivity extends ContactsActivity
private final class ContactPickerActionListener implements OnContactPickerActionListener {
@Override
public void onCreateNewContactAction() {
- Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
- startActivityAndForwardResult(intent);
+ startCreateNewContactActivity();
}
@Override
@@ -443,6 +546,25 @@ public class ContactSelectionActivity extends ContactsActivity
return false;
}
+ @Override
+ public boolean onClose() {
+ if (!TextUtils.isEmpty(mSearchView.getQuery())) {
+ mSearchView.setQuery(null, true);
+ }
+ return true;
+ }
+
+ @Override
+ public void onFocusChange(View view, boolean hasFocus) {
+ switch (view.getId()) {
+ case R.id.search_view: {
+ if (hasFocus) {
+ showInputMethod(mSearchView.findFocus());
+ }
+ }
+ }
+ }
+
public void returnPickerResult(Uri data) {
Intent intent = new Intent();
intent.setData(data);
@@ -456,10 +578,27 @@ public class ContactSelectionActivity extends ContactsActivity
}
@Override
- public void onClick(View v) {
- if (v.getId() == R.id.cancel) {
- setResult(RESULT_CANCELED);
- finish();
+ public void onClick(View view) {
+ switch (view.getId()) {
+ case R.id.new_contact: {
+ startCreateNewContactActivity();
+ break;
+ }
+ }
+ }
+
+ private void startCreateNewContactActivity() {
+ Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
+ startActivityAndForwardResult(intent);
+ }
+
+ private void showInputMethod(View view) {
+ final InputMethodManager imm = (InputMethodManager)
+ getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm != null) {
+ if (!imm.showSoftInput(view, 0)) {
+ Log.w(TAG, "Failed to show soft input method.");
+ }
}
}
diff --git a/src/com/android/contacts/activities/JoinContactActivity.java b/src/com/android/contacts/activities/JoinContactActivity.java
index b948b7126..75a13d058 100644
--- a/src/com/android/contacts/activities/JoinContactActivity.java
+++ b/src/com/android/contacts/activities/JoinContactActivity.java
@@ -23,19 +23,19 @@ import com.android.contacts.list.ContactEntryListFragment;
import com.android.contacts.list.JoinContactListFragment;
import com.android.contacts.list.OnContactPickerActionListener;
+import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
+import android.view.MenuItem;
/**
* An activity that shows a list of contacts that can be joined with the target contact.
*/
-public class JoinContactActivity extends ContactsActivity implements OnClickListener {
+public class JoinContactActivity extends ContactsActivity {
private static final String TAG = "JoinContactActivity";
@@ -85,8 +85,6 @@ public class JoinContactActivity extends ContactsActivity implements OnClickList
setContentView(R.layout.join_contact_picker);
setTitle(R.string.titleJoinContactDataWith);
- findViewById(R.id.cancel).setOnClickListener(this);
-
if (mListFragment == null) {
mListFragment = new JoinContactListFragment();
@@ -94,9 +92,16 @@ public class JoinContactActivity extends ContactsActivity implements OnClickList
.replace(R.id.list_container, mListFragment)
.commitAllowingStateLoss();
}
+
+ final ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setDisplayShowHomeEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setDisplayShowTitleEnabled(true);
+ }
}
- public void setupActionListener() {
+ private void setupActionListener() {
mListFragment.setTargetContactId(mTargetContactId);
mListFragment.setOnContactPickerActionListener(new OnContactPickerActionListener() {
@Override
@@ -121,6 +126,18 @@ public class JoinContactActivity extends ContactsActivity implements OnClickList
}
@Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // Go back to previous screen, intending "cancel"
+ setResult(RESULT_CANCELED);
+ finish();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(KEY_TARGET_CONTACT_ID, mTargetContactId);
@@ -139,11 +156,4 @@ public class JoinContactActivity extends ContactsActivity implements OnClickList
mListFragment.onPickerResult(data);
}
}
-
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.cancel) {
- finish();
- }
- }
}
diff --git a/src/com/android/contacts/list/JoinContactListAdapter.java b/src/com/android/contacts/list/JoinContactListAdapter.java
index e7641258c..73bca5211 100644
--- a/src/com/android/contacts/list/JoinContactListAdapter.java
+++ b/src/com/android/contacts/list/JoinContactListAdapter.java
@@ -39,20 +39,12 @@ public class JoinContactListAdapter extends ContactListAdapter {
private static final int MAX_SUGGESTIONS = 4;
public static final int PARTITION_SUGGESTIONS = 0;
- public static final int PARTITION_SHOW_ALL_CONTACTS = 1;
- public static final int PARTITION_ALL_CONTACTS = 2;
+ public static final int PARTITION_ALL_CONTACTS = 1;
private long mTargetContactId;
private int mShowAllContactsViewType;
- /**
- * Determines whether we display a list item with the label
- * "Show all contacts" or actually show all contacts
- */
- private boolean mAllContactsListShown;
-
-
public JoinContactListAdapter(Context context) {
super(context);
setPinnedPartitionHeadersEnabled(true);
@@ -68,10 +60,7 @@ public class JoinContactListAdapter extends ContactListAdapter {
// Partition 0: suggestions
addPartition(false, true);
- // Partition 1: "Show all contacts"
- addPartition(false, false);
-
- // Partition 2: All contacts
+ // Partition 1: All contacts
addPartition(createDefaultDirectoryPartition());
}
@@ -82,7 +71,6 @@ public class JoinContactListAdapter extends ContactListAdapter {
@Override
public void configureLoader(CursorLoader cursorLoader, long directoryId) {
JoinContactLoader loader = (JoinContactLoader)cursorLoader;
- loader.setLoadSuggestionsAndAllContacts(mAllContactsListShown);
Builder builder = Contacts.CONTENT_URI.buildUpon();
builder.appendEncodedPath(String.valueOf(mTargetContactId));
@@ -118,21 +106,8 @@ public class JoinContactListAdapter extends ContactListAdapter {
return false;
}
- public boolean isAllContactsListShown() {
- return mAllContactsListShown;
- }
-
- public void setAllContactsListShown(boolean flag) {
- mAllContactsListShown = flag;
- }
-
public void setSuggestionsCursor(Cursor cursor) {
changeCursor(PARTITION_SUGGESTIONS, cursor);
- if (cursor != null && cursor.getCount() != 0 && !mAllContactsListShown) {
- changeCursor(PARTITION_SHOW_ALL_CONTACTS, getShowAllContactsLabelCursor());
- } else {
- changeCursor(PARTITION_SHOW_ALL_CONTACTS, null);
- }
}
@Override
@@ -153,9 +128,6 @@ public class JoinContactListAdapter extends ContactListAdapter {
@Override
public int getItemViewType(int partition, int position) {
- if (partition == PARTITION_SHOW_ALL_CONTACTS) {
- return mShowAllContactsViewType;
- }
return super.getItemViewType(partition, position);
}
@@ -164,13 +136,13 @@ public class JoinContactListAdapter extends ContactListAdapter {
ViewGroup parent) {
switch (partition) {
case PARTITION_SUGGESTIONS: {
- View view = inflate(R.layout.join_contact_picker_section, parent);
+ View view = inflate(R.layout.join_contact_picker_section_header, parent);
((TextView) view.findViewById(R.id.text)).setText(
R.string.separatorJoinAggregateSuggestions);
return view;
}
case PARTITION_ALL_CONTACTS: {
- View view = inflate(R.layout.join_contact_picker_section, parent);
+ View view = inflate(R.layout.join_contact_picker_section_header, parent);
((TextView) view.findViewById(R.id.text)).setText(
R.string.separatorJoinAggregateAll);
return view;
@@ -192,8 +164,6 @@ public class JoinContactListAdapter extends ContactListAdapter {
case PARTITION_SUGGESTIONS:
case PARTITION_ALL_CONTACTS:
return super.newView(context, partition, cursor, position, parent);
- case PARTITION_SHOW_ALL_CONTACTS:
- return inflate(R.layout.join_contact_picker_show_all, parent);
}
return null;
}
@@ -212,9 +182,6 @@ public class JoinContactListAdapter extends ContactListAdapter {
bindName(view, cursor);
break;
}
- case PARTITION_SHOW_ALL_CONTACTS: {
- break;
- }
case PARTITION_ALL_CONTACTS: {
final ContactListItemView view = (ContactListItemView)itemView;
bindSectionHeaderAndDivider(view, position, cursor);
diff --git a/src/com/android/contacts/list/JoinContactListFragment.java b/src/com/android/contacts/list/JoinContactListFragment.java
index 7931699c3..5b27bdfb5 100644
--- a/src/com/android/contacts/list/JoinContactListFragment.java
+++ b/src/com/android/contacts/list/JoinContactListFragment.java
@@ -15,7 +15,6 @@
*/
package com.android.contacts.list;
-import com.android.contacts.ContactsSearchManager;
import com.android.contacts.R;
import android.app.Activity;
@@ -39,13 +38,12 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
private static final int DISPLAY_NAME_LOADER = -2;
- private static final String KEY_ALL_CONTACTS_LIST_SHOWN = "allContactsShown";
+ private static final String KEY_TARGET_CONTACT_ID = "targetContactId";
private OnContactPickerActionListener mListener;
private long mTargetContactId;
- private boolean mAllContactsListShown = false;
- private LoaderCallbacks<Cursor> mLoaderCallbacks = new LoaderCallbacks<Cursor>() {
+ private final LoaderCallbacks<Cursor> mLoaderCallbacks = new LoaderCallbacks<Cursor>() {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
@@ -78,7 +76,7 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
break;
}
case JoinContactListAdapter.PARTITION_ALL_CONTACTS: {
- Cursor suggestionsCursor = ((JoinContactLoader)loader).getSuggestionsCursor();
+ Cursor suggestionsCursor = ((JoinContactLoader) loader).getSuggestionsCursor();
onContactListLoaded(suggestionsCursor, data);
break;
}
@@ -109,19 +107,16 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
null, mLoaderCallbacks);
}
- void onContactListLoaded(Cursor suggestionsCursor, Cursor allContacts) {
+ private void onContactListLoaded(Cursor suggestionsCursor, Cursor allContactsCursor) {
JoinContactListAdapter adapter = getAdapter();
adapter.setSuggestionsCursor(suggestionsCursor);
- if (suggestionsCursor == null || suggestionsCursor.getCount() == 0) {
- mAllContactsListShown = true;
- }
- setVisibleScrollbarEnabled(mAllContactsListShown);
- onPartitionLoaded(JoinContactListAdapter.PARTITION_ALL_CONTACTS, allContacts);
+ setVisibleScrollbarEnabled(true);
+ onPartitionLoaded(JoinContactListAdapter.PARTITION_ALL_CONTACTS, allContactsCursor);
}
private void showTargetContactName(String displayName) {
Activity activity = getActivity();
- TextView blurbView = (TextView)activity.findViewById(R.id.join_contact_blurb);
+ TextView blurbView = (TextView) activity.findViewById(R.id.join_contact_blurb);
String blurb = activity.getString(R.string.blurbJoinContactDataWith, displayName);
blurbView.setText(blurb);
}
@@ -139,7 +134,6 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
protected void configureAdapter() {
super.configureAdapter();
JoinContactListAdapter adapter = getAdapter();
- adapter.setAllContactsListShown(mAllContactsListShown);
adapter.setTargetContactId(mTargetContactId);
}
@@ -152,14 +146,7 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
protected void onItemClick(int position, long id) {
JoinContactListAdapter adapter = getAdapter();
int partition = adapter.getPartitionForPosition(position);
- if (partition == JoinContactListAdapter.PARTITION_SHOW_ALL_CONTACTS) {
- mAllContactsListShown = true;
- configureAdapter();
- getLoaderManager().restartLoader(JoinContactListAdapter.PARTITION_ALL_CONTACTS,
- null, mLoaderCallbacks);
- } else {
- mListener.onPickContactAction(adapter.getContactUri(position));
- }
+ mListener.onPickContactAction(adapter.getContactUri(position));
}
@Override
@@ -170,14 +157,14 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putBoolean(KEY_ALL_CONTACTS_LIST_SHOWN, mAllContactsListShown);
+ outState.putLong(KEY_TARGET_CONTACT_ID, mTargetContactId);
}
@Override
public void restoreSavedState(Bundle savedState) {
super.restoreSavedState(savedState);
if (savedState != null) {
- mAllContactsListShown = savedState.getBoolean(KEY_ALL_CONTACTS_LIST_SHOWN);
+ mTargetContactId = savedState.getLong(KEY_TARGET_CONTACT_ID);
}
}
}
diff --git a/src/com/android/contacts/list/JoinContactLoader.java b/src/com/android/contacts/list/JoinContactLoader.java
index a1379615e..2f1f9b0d3 100644
--- a/src/com/android/contacts/list/JoinContactLoader.java
+++ b/src/com/android/contacts/list/JoinContactLoader.java
@@ -27,7 +27,6 @@ import android.net.Uri;
*/
public class JoinContactLoader extends CursorLoader {
- private boolean mLoadSuggestionsAndAllContacts;
private String[] mProjection;
private Uri mSuggestionUri;
private MatrixCursor mSuggestionsCursor;
@@ -36,10 +35,6 @@ public class JoinContactLoader extends CursorLoader {
super(context, null, null, null, null, null);
}
- public void setLoadSuggestionsAndAllContacts(boolean flag) {
- mLoadSuggestionsAndAllContacts = flag;
- }
-
public void setSuggestionUri(Uri uri) {
this.mSuggestionUri = uri;
}
@@ -59,13 +54,6 @@ public class JoinContactLoader extends CursorLoader {
// First execute the suggestions query, then call super.loadInBackground
// to load the entire list
mSuggestionsCursor = loadSuggestions();
- if (!mLoadSuggestionsAndAllContacts && mSuggestionsCursor.getCount() != 0) {
- // In case we only need suggestions, send "0" as the search query, which
- // will always return an empty cursor (but we can still register to
- // listen for changes on it).
- setSelection("0");
- setSelectionArgs(null);
- }
return super.loadInBackground();
}