diff options
author | Aravind Asam <aasam@codeaurora.org> | 2014-03-05 19:09:25 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-18 13:52:40 -0700 |
commit | 6530e407118950ec80a720215a2371e992edc94f (patch) | |
tree | 3a40194e39e55486f86b9b7749cae187d77c05b4 /src | |
parent | 1c41bc410f1600165dce57714574b922a4cf11e8 (diff) | |
download | android_packages_apps_Calendar-6530e407118950ec80a720215a2371e992edc94f.tar.gz android_packages_apps_Calendar-6530e407118950ec80a720215a2371e992edc94f.tar.bz2 android_packages_apps_Calendar-6530e407118950ec80a720215a2371e992edc94f.zip |
Calendar: Support for deleting events (rest of the features)
* Includes highlight for selected items.
* Spinner-style select all, deselect all.
* Improvements asset files updated.
* Add the TW strings for it.
* Show the delete events menu as the config.
Change-Id: I1781bd8748487bc51da8988f7ae74927c0e179c1
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/calendar/AllInOneActivity.java | 53 | ||||
-rw-r--r-- | src/com/android/calendar/DeleteEventsActivity.java | 127 |
2 files changed, 162 insertions, 18 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java index 7567fa4c..66394591 100644 --- a/src/com/android/calendar/AllInOneActivity.java +++ b/src/com/android/calendar/AllInOneActivity.java @@ -32,13 +32,16 @@ import android.app.DialogFragment; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; +import android.app.LoaderManager; import android.content.AsyncQueryHandler; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; +import android.content.CursorLoader; import android.content.DialogInterface; +import android.content.Loader; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; @@ -96,6 +99,7 @@ import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME; public class AllInOneActivity extends AbstractCalendarActivity implements EventHandler, OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener, + LoaderManager.LoaderCallbacks<Cursor>, ActionBar.OnNavigationListener, OnSuggestionListener { private static final String TAG = "AllInOneActivity"; private static final boolean DEBUG = false; @@ -160,7 +164,6 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH private SearchView mSearchView; private MenuItem mSearchMenu; private MenuItem mControlsMenu; - private MenuItem mGoToMenu; private Menu mOptionsMenu; private CalendarViewAdapter mActionBarMenuSpinnerAdapter; private QueryHandler mHandler; @@ -781,9 +784,16 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); } - mGoToMenu = menu.findItem(R.id.action_goto); + MenuItem deleteEventsMenu = menu.findItem(R.id.action_delete_events); + if (!getResources().getBoolean(R.bool.show_delete_events_menu)) { + deleteEventsMenu.setVisible(false); + } else { + getLoaderManager().initLoader(0, null, this); + } + + MenuItem goToMenu = menu.findItem(R.id.action_goto); if (!getResources().getBoolean(R.bool.show_goto_menu)) { - mGoToMenu.setVisible(false); + goToMenu.setVisible(false); } MenuItem menuItem = menu.findItem(R.id.action_today); @@ -795,6 +805,7 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH } else { menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light); } + return true; } @@ -1380,6 +1391,42 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH return false; } + @Override + public Loader<Cursor> onCreateLoader(int id, Bundle args) { + final String[] PROJECTION = new String[] { + CalendarContract.Events._ID, + CalendarContract.Events.TITLE, + CalendarContract.EventsEntity.DELETED + }; + final String where = CalendarContract.EventsEntity.DELETED + "=0 AND " + + Calendars.CALENDAR_ACCESS_LEVEL + ">=" + Calendars.CAL_ACCESS_CONTRIBUTOR; + return new CursorLoader(this, CalendarContract.EventsEntity.CONTENT_URI, + PROJECTION, where, null, null); + } + + @Override + public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) { + if (mOptionsMenu == null) { + Log.w(TAG, "mOptionsMenu is null"); + return; + } + + MenuItem delEventsMenu = mOptionsMenu.findItem(R.id.action_delete_events); + if (delEventsMenu != null) { + if (cursor.getCount() == 0) { + delEventsMenu.setEnabled(false); + } else { + delEventsMenu.setEnabled(true); + } + } + } + + @Override + public void onLoaderReset(Loader<Cursor> arg0) { + // Do nothing. + return; + } + public static class GoToDialogFragment extends DialogFragment { private static final String KEY_TIMEZONE = "timezone"; diff --git a/src/com/android/calendar/DeleteEventsActivity.java b/src/com/android/calendar/DeleteEventsActivity.java index 9d0631dd..f763675c 100644 --- a/src/com/android/calendar/DeleteEventsActivity.java +++ b/src/com/android/calendar/DeleteEventsActivity.java @@ -29,11 +29,6 @@ package com.android.calendar; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import android.app.ActionBar; import android.app.AlertDialog; import android.app.Dialog; @@ -58,14 +53,25 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.CheckBox; import android.widget.ListView; +import android.widget.PopupMenu; +import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.ResourceCursorAdapter; import android.widget.TextView; import android.widget.Toast; +import com.android.calendarcommon2.DateException; +import com.android.calendarcommon2.Duration; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class DeleteEventsActivity extends ListActivity - implements LoaderManager.LoaderCallbacks<Cursor> { + implements LoaderManager.LoaderCallbacks<Cursor>, OnMenuItemClickListener { private static final String TAG = "DeleteEvents"; private static final boolean DEBUG = false; @@ -97,6 +103,7 @@ public class DeleteEventsActivity extends ListActivity 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>(); @@ -119,10 +126,14 @@ public class DeleteEventsActivity extends ListActivity super.onCreate(savedInstanceState); // actionbar setup - ActionBar actionBar = getActionBar(); + final ActionBar actionBar = getActionBar(); 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(); @@ -171,6 +182,17 @@ public class DeleteEventsActivity extends ListActivity @Override protected void onResume() { super.onResume(); + + if (mSelectedMap.isEmpty() && mListView.getCheckedItemCount() > 0) { + long[] checkedItem = mListView.getCheckedItemIds(); + for (int i = 0; i < checkedItem.length; i++) { + if (DEBUG) Log.v(TAG, "onResume: " + checkedItem[i]); + mSelectedMap.put(checkedItem[i], checkedItem[i]); + } + mAdapter.notifyDataSetChanged(); + updateTitle(); + } + getContentResolver().registerContentObserver(CalendarContract.Calendars.CONTENT_URI, true, mObserver); } @@ -209,13 +231,7 @@ public class DeleteEventsActivity extends ListActivity return true; case R.id.action_select_all: if (DEBUG) Log.d(TAG, "Action: Select All"); - - mSelectedMap.clear(); - for (Long event : mEventList){ - mSelectedMap.put(event, event); - } - mAdapter.notifyDataSetChanged(); - updateTitle(); + selectAll(); return true; default: return super.onOptionsItemSelected(item); @@ -263,6 +279,8 @@ public class DeleteEventsActivity extends ListActivity ", RRULE: " + cursor.getString(cursor.getColumnIndex(Events.RRULE)) + ", RDATE: " + cursor.getString(cursor.getColumnIndex(Events.RDATE)) + ", DURATION: " + cursor.getString(cursor.getColumnIndex(Events.DURATION)) + + ", DTSTART: " + cursor.getString(cursor.getColumnIndex(Events.DTSTART)) + + ", DTEND: " + cursor.getString(cursor.getColumnIndex(Events.DTEND)) + ", LAST_DATE: " + cursor.getString(cursor.getColumnIndex(Events.LAST_DATE))); } if (DEBUG) Log.d(TAG, "mEventList: " + mEventList); @@ -293,6 +311,21 @@ public class DeleteEventsActivity extends ListActivity final TextView eventTime = (TextView) view.findViewById(R.id.event_time); long start = cursor.getLong(cursor.getColumnIndex(Events.DTSTART)); long end = cursor.getLong(cursor.getColumnIndex(Events.DTEND)); + + // if DTEND invalid, check for duration + if (end == 0) { + String durationStr = cursor.getString(cursor.getColumnIndex(Events.DURATION)); + Duration duration = new Duration(); + try { + duration.parse(durationStr); + end = start + duration.getMillis(); + } catch (DateException e) { + Log.w(TAG, e.getLocalizedMessage()); + } + } + if (DEBUG) Log.v(TAG, + "title: " + cursor.getString(cursor.getColumnIndex(Events.TITLE)) + + ", start: " + start + ", end: " + end); boolean allDay = cursor.getInt(cursor.getColumnIndex(Events.ALL_DAY)) != 0; eventTime.setText(getEventTimeString(start, end, allDay)); @@ -319,7 +352,7 @@ public class DeleteEventsActivity extends ListActivity } private void updateTitle() { - getActionBar().setTitle(" " + mSelectedMap.size() + " " + + mSelectionButton.setText(" " + mSelectedMap.size() + " " + getResources().getText(R.string.selected)); } @@ -389,4 +422,68 @@ public class DeleteEventsActivity extends ListActivity return builder.create(); } } + + @Override + public boolean onMenuItemClick(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_select_all: + if (DEBUG) Log.d(TAG, "Select All"); + selectAll(); + return true; + case R.id.action_select_none: + if (DEBUG) Log.d(TAG, "Deselect all"); + selectNone(); + return true; + default: + return false; + } + } + + 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); + } + + popup.setOnMenuItemClickListener(this); + popup.show(); + } + + private void selectAll() { + mSelectedMap.clear(); + for (Long event : mEventList){ + mSelectedMap.put(event, event); + + } + + for (int i = 0; i < mListView.getCount(); i++) { + if (mSelectedMap.containsKey(mListView.getItemIdAtPosition(i))) { + mListView.setItemChecked(i, true); + } + } + mAdapter.notifyDataSetChanged(); + updateTitle(); + } + + private void selectNone() { + mSelectedMap.clear(); + for (int i = 0; i < mListView.getCount(); i++) { + mListView.setItemChecked(i, false); + } + mAdapter.notifyDataSetChanged(); + updateTitle(); + } } |