summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan <adnan@cyngn.com>2014-08-26 13:01:37 -0700
committerSteve Kondik <steve@cyngn.com>2015-10-18 13:52:41 -0700
commitbfdd8e20ff7e515c21fb55253ba4611de2f7fc5c (patch)
tree32b568b20b14413161a01daace10d451005940a9
parenta855dffd7b856729f7e6c473831a917f7043608a (diff)
downloadandroid_packages_apps_Calendar-bfdd8e20ff7e515c21fb55253ba4611de2f7fc5c.tar.gz
android_packages_apps_Calendar-bfdd8e20ff7e515c21fb55253ba4611de2f7fc5c.tar.bz2
android_packages_apps_Calendar-bfdd8e20ff7e515c21fb55253ba4611de2f7fc5c.zip
Calendar: Revamp deleting calendar events UI.
- Use contextual action bar instead of weird spinner/action bar combo - Actually influence behavior and let the user know they're deleting something Change-Id: Idec775f84b873211d6c6a46be120ea82b8a0b9e5
-rw-r--r--res/layout/action_mode.xml58
-rw-r--r--res/menu/delete_events_title_bar.xml3
-rw-r--r--src/com/android/calendar/DeleteEventsActivity.java168
3 files changed, 92 insertions, 137 deletions
diff --git a/res/layout/action_mode.xml b/res/layout/action_mode.xml
deleted file mode 100644
index f44ee5f4..00000000
--- a/res/layout/action_mode.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (c) 2014, The Linux Foundation. All rights reserved.
- Not a Contribution.
-
- Copyright (C) 2010 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.
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/navigation_bar"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentLeft="true" >
-
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_gravity="right"
- android:src="@drawable/dropdown_ic_arrow" />
-
- <Button
- android:id="@+id/selection_menu"
- style="?android:attr/actionButtonStyle"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:divider="?android:attr/listDividerAlertDialog"
- android:gravity="left|center_vertical"
- android:onClick="onSelectionButtonClicked"
- android:paddingRight="25dip"
- android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
- android:textColor="?android:attr/actionMenuTextColor" />
- </FrameLayout>
-
- <View
- android:layout_width="1dp"
- android:layout_height="match_parent"
- android:layout_alignParentRight="true"
- android:layout_marginBottom="9dp"
- android:layout_marginTop="9dp"
- android:background="#F0B0B0B0" />
-
-</RelativeLayout>
diff --git a/res/menu/delete_events_title_bar.xml b/res/menu/delete_events_title_bar.xml
index 87966453..4ab869fb 100644
--- a/res/menu/delete_events_title_bar.xml
+++ b/res/menu/delete_events_title_bar.xml
@@ -32,7 +32,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<item
android:id="@+id/action_delete"
- android:showAsAction="always|withText"
+ android:showAsAction="always"
+ android:icon="@drawable/ic_menu_trash_holo_light"
android:title="@string/action_delete"
android:visible="true">
</item>
diff --git a/src/com/android/calendar/DeleteEventsActivity.java b/src/com/android/calendar/DeleteEventsActivity.java
index 02a597e5..886d0bca 100644
--- a/src/com/android/calendar/DeleteEventsActivity.java
+++ b/src/com/android/calendar/DeleteEventsActivity.java
@@ -49,10 +49,12 @@ import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.EventsEntity;
import android.text.format.DateUtils;
import android.util.Log;
+import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.widget.AbsListView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
@@ -99,11 +101,11 @@ public class DeleteEventsActivity extends ListActivity
Calendars.CALENDAR_DISPLAY_NAME,
};
+ private ActionMode mActionMode;
private ListView mListView;
private EventListAdapter mAdapter;
private AsyncQueryService mService;
private TextView mHeaderTextView;
- private Button mSelectionButton;
private Map<Long, Long> mSelectedMap = new HashMap<Long, Long>();
private Map<Long, String> mCalendarsMap = new HashMap<Long, String>();
@@ -130,14 +132,8 @@ public class DeleteEventsActivity extends ListActivity
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
- actionBar.setCustomView(R.layout.action_mode);
- actionBar.setDisplayShowCustomEnabled(true);
- View view = actionBar.getCustomView();
- mSelectionButton = (Button) view.findViewById(R.id.selection_menu);
- updateTitle();
mListView = getListView();
- mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mHeaderTextView = new TextView(this);
mHeaderTextView.setPadding(16, 8, 8, 8);
@@ -147,6 +143,8 @@ public class DeleteEventsActivity extends ListActivity
mAdapter = new EventListAdapter(this, R.layout.event_list_item);
mListView.setAdapter(mAdapter);
+ mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
+ mListView.setMultiChoiceModeListener(mMultiChoiceModeListener);
mService = new AsyncQueryService(this) {
@Override
@@ -204,57 +202,13 @@ public class DeleteEventsActivity extends ListActivity
}
@Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.delete_events_title_bar, menu);
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_delete:
- if (DEBUG) Log.d(TAG, "Action: Delete");
-
- if (mSelectedMap.size() > 0) {
- CharSequence message = mSelectedMap.size() == mEventList.size() ?
- getResources().getText(R.string.evt_del_dlg_msg_all) :
- getResources().getText(R.string.evt_del_dlg_msg_selected);
- CharSequence title = getResources().getText(R.string.evt_del_dlg_title);
- DeleteDialogFragment dlgFrag = DeleteDialogFragment.newInstance(
- title.toString(), message.toString());
- dlgFrag.show(getFragmentManager(), "dialog");
- } else {
- Toast.makeText(this, mEventList.size() > 0 ? R.string.no_events_selected
- : R.string.no_events, Toast.LENGTH_SHORT).show();
- }
- return true;
- case R.id.action_select_all:
- if (DEBUG) Log.d(TAG, "Action: Select All");
- selectAll();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-
- @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
-
- if (DEBUG) Log.d(TAG, "onListItemClick: position: " + position + " Id: " + id);
-
- CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
- checkbox.toggle();
-
- if (checkbox.isChecked()) {
- mSelectedMap.put(id, id);
+ if (!l.isItemChecked(position)) {
+ l.setItemChecked(position, true);
} else {
- mSelectedMap.remove(id);
+ l.setItemChecked(position, false);
}
-
- if (DEBUG) Log.d(TAG, "Entries list: " + mSelectedMap.values());
- updateTitle();
}
@Override
@@ -294,6 +248,70 @@ public class DeleteEventsActivity extends ListActivity
mAdapter.swapCursor(null);
}
+ private AbsListView.MultiChoiceModeListener mMultiChoiceModeListener
+ = new AbsListView.MultiChoiceModeListener() {
+
+ @Override
+ public void onItemCheckedStateChanged(ActionMode mode, int position,
+ long id, boolean checked) {
+ View v = mListView.getChildAt(position);
+ CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
+ checkbox.toggle();
+
+ if (checkbox.isChecked()) {
+ mSelectedMap.put(id, id);
+ } else {
+ mSelectedMap.remove(id);
+ }
+ updateTitle();
+ }
+
+ @Override
+ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ mode.getMenuInflater().inflate(R.menu.delete_events_title_bar, menu);
+ mActionMode = mode;
+ return true;
+ }
+
+ @Override
+ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_delete:
+ if (DEBUG) Log.d(TAG, "Action: Delete");
+ if (mSelectedMap.size() > 0) {
+ CharSequence message = mSelectedMap.size() == mEventList.size() ?
+ getResources().getText(R.string.evt_del_dlg_msg_all) :
+ getResources().getText(R.string.evt_del_dlg_msg_selected);
+ CharSequence title = getResources().getText(R.string.evt_del_dlg_title);
+ DeleteDialogFragment dlgFrag = DeleteDialogFragment.newInstance(
+ title.toString(), message.toString());
+ dlgFrag.show(getFragmentManager(), "dialog");
+ } else {
+ Toast.makeText(DeleteEventsActivity.this,
+ mEventList.size() > 0 ? R.string.no_events_selected
+ : R.string.no_events, Toast.LENGTH_SHORT).show();
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onDestroyActionMode(ActionMode mode) {
+ mListView.clearChoices();
+ deselectAll();
+ mSelectedMap.clear();
+ mActionMode = null;
+ }
+
+ @Override
+ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+ // Here you can perform updates to the CAB due to
+ // an invalidate() request
+ return false;
+ }
+ };
+
private final class EventListAdapter extends ResourceCursorAdapter {
public EventListAdapter(Context context, int layout) {
super(context, layout, null);
@@ -355,8 +373,10 @@ public class DeleteEventsActivity extends ListActivity
}
private void updateTitle() {
- mSelectionButton.setText(" " + mSelectedMap.size() + " " +
- getResources().getText(R.string.selected));
+ if (mActionMode != null) {
+ mActionMode.setTitle(getString(R.string.events_delete));
+ mActionMode.setSubtitle(" " + mSelectedMap.size() + " " + getString(R.string.selected));
+ }
}
void onPositiveButtonSelected() {
@@ -375,10 +395,16 @@ public class DeleteEventsActivity extends ListActivity
where.toString(), null, 0);
mSelectedMap.clear();
updateTitle();
+
+ if (mActionMode != null) {
+ mActionMode.finish();
+ }
}
void onNegativeButtonSelected() {
-
+ if (mActionMode != null) {
+ mActionMode.finish();
+ }
}
public static class DeleteDialogFragment extends DialogFragment {
@@ -442,34 +468,20 @@ public class DeleteEventsActivity extends ListActivity
}
}
- public void onSelectionButtonClicked(View v) {
- if (DEBUG) Log.v(TAG, "onSelectionButtonClicked");
- PopupMenu popup = new PopupMenu(this, v);
- MenuInflater inflater = popup.getMenuInflater();
- Menu menu = popup.getMenu();
- inflater.inflate(R.menu.selection_popup, menu);
- MenuItem selectAll = menu.findItem(R.id.action_select_all);
- MenuItem selectNone = menu.findItem(R.id.action_select_none);
-
- if (mEventList.size() == 0) {
- selectAll.setVisible(true);
- selectAll.setEnabled(false);
- }
- else if (mSelectedMap.size() == mEventList.size()) {
- selectNone.setVisible(true);
- } else {
- selectAll.setVisible(true);
+ private void deselectAll() {
+ for (int i = 0; i < mListView.getCount(); i ++) {
+ if (mSelectedMap.containsKey(mListView.getItemIdAtPosition(i))) {
+ mListView.setItemChecked(i, false);
+ }
}
-
- popup.setOnMenuItemClickListener(this);
- popup.show();
+ mAdapter.notifyDataSetChanged();
+ updateTitle();
}
private void selectAll() {
mSelectedMap.clear();
for (Long event : mEventList){
mSelectedMap.put(event, event);
-
}
for (int i = 0; i < mListView.getCount(); i++) {