Modify action bar for contact editor
- Use custom action bar for "Done" button (hide app icon and
get rid of "up" affordance")
- Move "Cancel" into the overflow menu and rename it to "Discard"
- Remove "delete" button from overflow menu in editor as specified
by the UX mocks b/c the user can delete the contact in the
contact card already
Change-Id: Ic389983a08a7b03fa24e7f4c1c37c95bd6c1c9fa
diff --git a/res/layout/contact_editor_custom_action_bar.xml b/res/layout/contact_editor_custom_action_bar.xml
new file mode 100644
index 0000000..ba09929
--- /dev/null
+++ b/res/layout/contact_editor_custom_action_bar.xml
@@ -0,0 +1,59 @@
+<?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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/save_menu_item"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:divider="?android:attr/dividerVertical"
+ android:showDividers="end"
+ android:dividerPadding="12dip"
+ android:orientation="horizontal"
+ style="?android:attr/actionButtonStyle">
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
+
+ <ImageView
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginRight="8dip"
+ android:src="@drawable/ic_menu_done_holo_light"
+ android:description="@string/menu_done" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginRight="20dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/menu_done"
+ style="@android:style/Widget.Holo.ActionBar.TabText" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+</FrameLayout>
\ No newline at end of file
diff --git a/res/menu/edit_contact.xml b/res/menu/edit_contact.xml
index 857c9c5..26b89df 100644
--- a/res/menu/edit_contact.xml
+++ b/res/menu/edit_contact.xml
@@ -18,20 +18,7 @@
<item
android:id="@+id/menu_done"
android:alphabeticShortcut="\n"
- android:icon="@drawable/ic_menu_done_holo_light"
- android:title="@string/menu_done"
- android:showAsAction="always|withText" />
-
- <item
- android:id="@+id/menu_discard"
- android:alphabeticShortcut="q"
- android:title="@string/menu_doNotSave"
- android:showAsAction="always|withText" />
-
- <item
- android:id="@+id/menu_delete"
- android:icon="@drawable/ic_menu_trash_holo_light"
- android:title="@string/menu_deleteContact" />
+ android:showAsAction="always" />
<item
android:id="@+id/menu_split"
@@ -42,4 +29,9 @@
android:id="@+id/menu_join"
android:icon="@drawable/ic_menu_merge_holo_light"
android:title="@string/menu_joinAggregate" />
+
+ <item
+ android:id="@+id/menu_discard"
+ android:alphabeticShortcut="q"
+ android:title="@string/menu_discard" />
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b90898d..03c4102 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -200,9 +200,12 @@
<!-- Menu item to indicate you are done editing a contact and want to save the changes you've made -->
<string name="menu_done">Done</string>
- <!-- Menu item to indicate you want to stop editing a contact and NOT save the changes you've made [CHAR LIMIT=12] -->
+ <!-- Menu item to indicate you want to stop editing a group and NOT save the changes you've made [CHAR LIMIT=12] -->
<string name="menu_doNotSave">Cancel</string>
+ <!-- Menu item to indicate you want to stop editing a contact and NOT save the changes you've made [CHAR LIMIT=12] -->
+ <string name="menu_discard">Discard</string>
+
<!-- The title of the activity that edits and existing contact -->
<string name="editContact_title_edit">Edit contact</string>
diff --git a/src/com/android/contacts/activities/ContactEditorActivity.java b/src/com/android/contacts/activities/ContactEditorActivity.java
index 28bc3a3..10be943 100644
--- a/src/com/android/contacts/activities/ContactEditorActivity.java
+++ b/src/com/android/contacts/activities/ContactEditorActivity.java
@@ -31,6 +31,7 @@
import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
+import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -38,6 +39,7 @@
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.RawContacts;
import android.util.Log;
+import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
@@ -76,11 +78,26 @@
setContentView(R.layout.contact_editor_activity);
- // This Activity will always fall back to the "top" Contacts screen when touched on the
- // app up icon, regardless of launch context.
ActionBar actionBar = getActionBar();
if (actionBar != null) {
- actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
+ // Inflate a custom action bar that contains the "done" button for saving changes
+ // to the contact
+ LayoutInflater inflater = (LayoutInflater) getSystemService
+ (Context.LAYOUT_INFLATER_SERVICE);
+ View customActionBarView = inflater.inflate(R.layout.contact_editor_custom_action_bar,
+ null);
+ View saveMenuItem = customActionBarView.findViewById(R.id.save_menu_item);
+ saveMenuItem.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mFragment.doSaveAction();
+ }
+ });
+ // Show the custom action bar but hide the home icon and title
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
+ ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME |
+ ActionBar.DISPLAY_SHOW_TITLE);
+ actionBar.setCustomView(customActionBarView);
}
mFragment = (ContactEditorFragment) getFragmentManager().findFragmentById(
@@ -129,17 +146,6 @@
mFragment.save(SaveMode.CLOSE);
}
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home: {
- mFragment.save(SaveMode.HOME);
- return true;
- }
- }
- return false;
- }
-
private final ContactEditorFragment.Listener mFragmentListener =
new ContactEditorFragment.Listener() {
@Override
@@ -176,11 +182,6 @@
}
@Override
- public void onDeleteRequested(Uri contactUri) {
- ContactDeletionInteraction.start(ContactEditorActivity.this, contactUri, true);
- }
-
- @Override
public void onEditOtherContactRequested(
Uri contactLookupUri, ArrayList<ContentValues> values) {
Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 85d21f3..9f1bbd2 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -725,6 +725,11 @@
@Override
public void onPrepareOptionsMenu(Menu menu) {
+ // This supports the keyboard shortcut to save changes to a contact but shouldn't be visible
+ // because the custom action bar contains the "save" button now (not the overflow menu).
+ // TODO: Find a better way to handle shortcuts, i.e. onKeyDown()?
+ menu.findItem(R.id.menu_done).setVisible(false);
+
menu.findItem(R.id.menu_split).setVisible(mState != null && mState.size() > 1);
int size = menu.size();
for (int i = 0; i < size; i++) {
@@ -739,8 +744,6 @@
return save(SaveMode.CLOSE);
case R.id.menu_discard:
return revert();
- case R.id.menu_delete:
- return doDeleteAction();
case R.id.menu_split:
return doSplitContactAction();
case R.id.menu_join:
@@ -749,23 +752,6 @@
return false;
}
- /**
- * Delete the entire contact currently being edited, which usually asks for
- * user confirmation before continuing.
- */
- private boolean doDeleteAction() {
- if (!hasValidState())
- return false;
-
- // TODO: Make sure Insert turns into Edit if/once it is autosaved
- if (Intent.ACTION_INSERT.equals(mAction)) {
- if (mListener != null) mListener.onReverted();
- } else {
- if (mListener != null) mListener.onDeleteRequested(mLookupUri);
- }
- return true;
- }
-
private boolean doSplitContactAction() {
if (!hasValidState()) return false;
@@ -958,6 +944,10 @@
if (mListener != null) mListener.onReverted();
}
+ public void doSaveAction() {
+ save(SaveMode.CLOSE);
+ }
+
public void onJoinCompleted(Uri uri) {
onSaveCompleted(false, SaveMode.RELOAD, uri);
}
@@ -1109,11 +1099,6 @@
void onSaveFinished(Intent resultIntent);
/**
- * User decided to delete the contact.
- */
- void onDeleteRequested(Uri lookupUri);
-
- /**
* User switched to editing a different contact (a suggestion from the
* aggregation engine).
*/