summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar/event
diff options
context:
space:
mode:
authorErik <roboerik@android.com>2010-09-23 14:55:22 -0700
committerErik <roboerik@android.com>2010-09-24 15:56:02 -0700
commit7b92da258a480284dcc15a518ea570072329a31d (patch)
tree59ed5af4272950128ebe516b80bf66e5d04eed5b /src/com/android/calendar/event
parent0bf39a4f43e7b0b48fdc3ce424444fcc6a4e5d8b (diff)
downloadandroid_packages_apps_Calendar-7b92da258a480284dcc15a518ea570072329a31d.tar.gz
android_packages_apps_Calendar-7b92da258a480284dcc15a518ea570072329a31d.tar.bz2
android_packages_apps_Calendar-7b92da258a480284dcc15a518ea570072329a31d.zip
b/2988876 Stop crash on orientation change
EditEventFragment was triggering a fragment swap in onPause, which isn't supported. This fixes the behavior of Edit to handle moving the fragment around correctly. This change makes the behavior save the event when back is pressed and restore the event if the user goes home and returns. On orientation change changes get lost, however. Another change will be made to fix this. Change-Id: Iaef5eac6668a8e0ee4859f69e5a77ecb9a7a15a3
Diffstat (limited to 'src/com/android/calendar/event')
-rw-r--r--src/com/android/calendar/event/EditEventFragment.java117
-rw-r--r--src/com/android/calendar/event/EditEventView.java100
2 files changed, 119 insertions, 98 deletions
diff --git a/src/com/android/calendar/event/EditEventFragment.java b/src/com/android/calendar/event/EditEventFragment.java
index 1d521248..bef69201 100644
--- a/src/com/android/calendar/event/EditEventFragment.java
+++ b/src/com/android/calendar/event/EditEventFragment.java
@@ -230,18 +230,13 @@ public class EditEventFragment extends Fragment implements EventHandler {
mView.setModel(mModel);
break;
case TOKEN_CALENDARS:
- // startManagingCursor(cursor);
MatrixCursor matrixCursor = Utils.matrixCursorFromCursor(cursor);
- // Stop the spinner
-// mContext.getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS,
-// Window.PROGRESS_VISIBILITY_OFF);
-
if (DEBUG) {
Log.d(TAG, "onQueryComplete: setting cursor with "
+ matrixCursor.getCount() + " calendars");
}
- mView.setCalendarsCursor(matrixCursor);
+ mView.setCalendarsCursor(matrixCursor, isAdded() && isResumed());
cursor.close();
break;
}
@@ -443,48 +438,54 @@ public class EditEventFragment extends Fragment implements EventHandler {
// We only want this to get called once, either because the user
// pressed back/home or one of the buttons on screen
mSaveOnDetach = false;
- switch (mCode) {
- case Utils.DONE_REVERT:
- break;
- case Utils.DONE_SAVE:
- if (mModel != null && !mModel.equals(mOriginalModel)) {
- if (mHelper.saveEvent(mModel, mOriginalModel, mModification)) {
- if (mModel.mUri != null) {
- Toast.makeText(mContext, R.string.saving_event, Toast.LENGTH_SHORT)
- .show();
- } else {
- Toast.makeText(mContext, R.string.creating_event,
- Toast.LENGTH_SHORT).show();
- }
- start = new Time();
- start.set(mModel.mStart);
+
+ if ((mCode & Utils.DONE_SAVE) != 0) {
+ if (mModel != null && !mModel.equals(mOriginalModel)) {
+ if (mHelper.saveEvent(mModel, mOriginalModel, mModification)) {
+ if (mModel.mUri != null) {
+ Toast.makeText(mContext, R.string.saving_event, Toast.LENGTH_SHORT)
+ .show();
+ } else {
+ Toast.makeText(mContext, R.string.creating_event,
+ Toast.LENGTH_SHORT).show();
}
}
- break;
- case Utils.DONE_DELETE:
- long begin = mModel.mStart;
- long end = mModel.mEnd;
- int which = -1;
- switch (mModification) {
- case Utils.MODIFY_SELECTED:
- which = DeleteEventHelper.DELETE_SELECTED;
- break;
- case Utils.MODIFY_ALL_FOLLOWING:
- which = DeleteEventHelper.DELETE_ALL_FOLLOWING;
- break;
- case Utils.MODIFY_ALL:
- which = DeleteEventHelper.DELETE_ALL;
- break;
- }
- DeleteEventHelper deleteHelper = new DeleteEventHelper(mContext, mContext,
- false /* exitWhenDone */);
- // TODO update delete helper to use the model instead of the cursor
- deleteHelper.delete(begin, end, mModel, which);
- break;
- default:
- Log.e(TAG, "done: Unrecognized exit code.");
- break;
+ }
+ }
+
+ if ((mCode & Utils.DONE_DELETE) != 0) {
+ long begin = mModel.mStart;
+ long end = mModel.mEnd;
+ int which = -1;
+ switch (mModification) {
+ case Utils.MODIFY_SELECTED:
+ which = DeleteEventHelper.DELETE_SELECTED;
+ break;
+ case Utils.MODIFY_ALL_FOLLOWING:
+ which = DeleteEventHelper.DELETE_ALL_FOLLOWING;
+ break;
+ case Utils.MODIFY_ALL:
+ which = DeleteEventHelper.DELETE_ALL;
+ break;
+ }
+ DeleteEventHelper deleteHelper = new DeleteEventHelper(mContext, mContext,
+ false /* exitWhenDone */);
+ // TODO update delete helper to use the model instead of the cursor
+ deleteHelper.delete(begin, end, mModel, which);
}
+
+ if ((mCode & Utils.DONE_EXIT) != 0) {
+ // This will exit the edit event screen, should be called
+ // when we want to return to the main calendar views
+ if (mModel != null) {
+ start = new Time();
+ start.set(mModel.mStart);
+ }
+ CalendarController controller = CalendarController.getInstance(mContext);
+ controller.sendEvent(EditEventFragment.this, EventType.GO_TO, start, null, -1,
+ mReturnView);
+ }
+
// Hide a software keyboard so that user won't see it even after this Fragment's
// disappearing.
final View focusedView = mContext.getCurrentFocus();
@@ -492,23 +493,11 @@ public class EditEventFragment extends Fragment implements EventHandler {
mInputMethodManager.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
focusedView.clearFocus();
}
- CalendarController controller = CalendarController.getInstance(mContext);
- controller.sendEvent(EditEventFragment.this, EventType.GO_TO, start, null, -1,
- mReturnView);
- }
- }
-
- @Override
- public void onPause() {
- if (mSaveOnDetach && mView != null) {
- mView.onClick(mView.mSaveButton);
}
- super.onPause();
}
@Override
public void onDestroy() {
- super.onDestroy();
if (mView != null) {
mView.setModel(null);
}
@@ -516,6 +505,8 @@ public class EditEventFragment extends Fragment implements EventHandler {
mModifyDialog.dismiss();
mModifyDialog = null;
}
+
+ super.onDestroy();
}
@Override
@@ -535,7 +526,7 @@ public class EditEventFragment extends Fragment implements EventHandler {
@Override
public long getSupportedEventTypes() {
- return 0;
+ return EventType.USER_HOME;
}
@Override
@@ -548,5 +539,15 @@ public class EditEventFragment extends Fragment implements EventHandler {
@Override
public void handleEvent(EventInfo event) {
+ // It's currently unclear if we want to save the event or not when home
+ // is pressed. When creating a new event we shouldn't save since we
+ // can't get the id of the new event easily.
+ if ((false && event.eventType == EventType.USER_HOME) || (event.eventType == EventType.GO_TO
+ && mSaveOnDetach)) {
+ if (mView != null && mView.prepareForSave()) {
+ mOnDone.setDoneCode(Utils.DONE_SAVE);
+ mOnDone.run();
+ }
+ }
}
}
diff --git a/src/com/android/calendar/event/EditEventView.java b/src/com/android/calendar/event/EditEventView.java
index 92caea39..4dd51c1a 100644
--- a/src/com/android/calendar/event/EditEventView.java
+++ b/src/com/android/calendar/event/EditEventView.java
@@ -16,7 +16,6 @@
package com.android.calendar.event;
-import com.android.calendar.AllInOneActivity;
import com.android.calendar.CalendarEventModel;
import com.android.calendar.CalendarEventModel.Attendee;
import com.android.calendar.EmailAddressAdapter;
@@ -51,6 +50,7 @@ import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.text.format.Time;
import android.text.util.Rfc822Tokenizer;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
@@ -77,7 +77,7 @@ import java.util.TimeZone;
public class EditEventView implements View.OnClickListener, DialogInterface.OnCancelListener,
DialogInterface.OnClickListener {
- private static final String TAG = EditEventView.class.getSimpleName();
+ private static final String TAG = "EditEvent";
private static final int REMINDER_FLING_VELOCITY = 2000;
@@ -307,8 +307,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
builder.setSingleChoiceItems(
mTimezoneAdapter, mTimezoneAdapter.getRowById(mTimezone), this);
mTimezoneDialog = builder.create();
- mTimezoneFooterView.setText(
- mActivity.getString(R.string.edit_event_show_all) + " >");
+ mTimezoneFooterView.setText(mActivity.getString(R.string.edit_event_show_all) + " >");
mTimezoneFooterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -342,8 +341,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
DateUtils.getDayOfWeekString(Calendar.WEDNESDAY, DateUtils.LENGTH_MEDIUM),
DateUtils.getDayOfWeekString(Calendar.THURSDAY, DateUtils.LENGTH_MEDIUM),
DateUtils.getDayOfWeekString(Calendar.FRIDAY, DateUtils.LENGTH_MEDIUM),
- DateUtils.getDayOfWeekString(Calendar.SATURDAY, DateUtils.LENGTH_MEDIUM),
- };
+ DateUtils.getDayOfWeekString(Calendar.SATURDAY, DateUtils.LENGTH_MEDIUM), };
String[] ordinals = r.getStringArray(R.array.ordinal_labels);
// Only display "Custom" in the spinner if the device does not support
@@ -407,20 +405,20 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
break;
case EventRecurrence.WEEKLY:
if (mEventRecurrence.repeatsOnEveryWeekDay()) {
- position = recurrenceIndexes
- .indexOf(EditEventHelper.REPEATS_EVERY_WEEKDAY);
+ position = recurrenceIndexes.indexOf(
+ EditEventHelper.REPEATS_EVERY_WEEKDAY);
} else {
- position = recurrenceIndexes
- .indexOf(EditEventHelper.REPEATS_WEEKLY_ON_DAY);
+ position = recurrenceIndexes.indexOf(
+ EditEventHelper.REPEATS_WEEKLY_ON_DAY);
}
break;
case EventRecurrence.MONTHLY:
if (mEventRecurrence.repeatsMonthlyOnDayCount()) {
- position = recurrenceIndexes
- .indexOf(EditEventHelper.REPEATS_MONTHLY_ON_DAY_COUNT);
+ position = recurrenceIndexes.indexOf(
+ EditEventHelper.REPEATS_MONTHLY_ON_DAY_COUNT);
} else {
- position = recurrenceIndexes
- .indexOf(EditEventHelper.REPEATS_MONTHLY_ON_DAY);
+ position = recurrenceIndexes.indexOf(
+ EditEventHelper.REPEATS_MONTHLY_ON_DAY);
}
break;
case EventRecurrence.YEARLY:
@@ -490,8 +488,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
}
public void onClick(View v) {
- new DatePickerDialog(mActivity, new DateListener(v), mTime.year, mTime.month,
- mTime.monthDay).show();
+ new DatePickerDialog(
+ mActivity, new DateListener(v), mTime.year, mTime.month, mTime.monthDay).show();
}
}
@@ -528,6 +526,25 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
}
}
+ /**
+ * Does prep steps for saving a calendar event.
+ *
+ * This triggers a parse of the attendees list and checks if the event is
+ * ready to be saved. An event is ready to be saved so long as it has a
+ * calendar it can be associated with, either because it's an existing event
+ * or we've finished querying
+ *
+ * @return false if no calendar had been loaded yet, true otherwise
+ */
+ public boolean prepareForSave() {
+ if (mCalendarsCursor == null && mModel.mUri == null) {
+ return false;
+ }
+ mAddAttendeesListener.onClick(null);
+ fillModelFromUI();
+ return true;
+ }
+
// This is called if the user clicks on one of the buttons: "Save",
// "Discard", or "Delete". This is also called if the user clicks
// on the "remove reminder" button.
@@ -548,7 +565,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
mSaveAfterQueryComplete = true;
}
} else if (fillModelFromUI()) {
- mDone.setDoneCode(Utils.DONE_SAVE);
+ mDone.setDoneCode(Utils.DONE_SAVE | Utils.DONE_EXIT);
mDone.run();
} else {
mDone.setDoneCode(Utils.DONE_REVERT);
@@ -558,7 +575,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
}
if (v == mDeleteButton) {
- mDone.setDoneCode(Utils.DONE_DELETE);
+ mDone.setDoneCode(Utils.DONE_DELETE | Utils.DONE_EXIT);
mDone.run();
return;
}
@@ -614,8 +631,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
if (mModel == null) {
return false;
}
- mModel.mReminderMinutes = EventViewUtils.reminderItemsToMinutes(mReminderItems,
- mReminderValues);
+ mModel.mReminderMinutes = EventViewUtils.reminderItemsToMinutes(
+ mReminderItems, mReminderValues);
mModel.mHasAlarm = mReminderItems.size() > 0;
mModel.mTitle = mTitleTextView.getText().toString().trim();
mModel.mAllDay = mAllDayCheckBox.isChecked();
@@ -646,10 +663,10 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
mModel.mCalendarId = mCalendarsSpinner.getSelectedItemId();
int calendarCursorPosition = mCalendarsSpinner.getSelectedItemPosition();
if (mCalendarsCursor.moveToPosition(calendarCursorPosition)) {
- String defaultCalendar = mCalendarsCursor
- .getString(EditEventHelper.CALENDARS_INDEX_OWNER_ACCOUNT);
- Utils.setSharedPreference(mActivity,
- GeneralPreferences.KEY_DEFAULT_CALENDAR, defaultCalendar);
+ String defaultCalendar = mCalendarsCursor.getString(
+ EditEventHelper.CALENDARS_INDEX_OWNER_ACCOUNT);
+ Utils.setSharedPreference(
+ mActivity, GeneralPreferences.KEY_DEFAULT_CALENDAR, defaultCalendar);
mModel.mOwnerAccount = defaultCalendar;
mModel.mOrganizer = defaultCalendar;
mModel.mCalendarId = mCalendarsCursor.getLong(EditEventHelper.CALENDARS_INDEX_ID);
@@ -696,8 +713,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
selection = mRecurrenceIndexes.get(position);
}
- EditEventHelper.updateRecurrenceRule(selection, mModel,
- Utils.getFirstDayOfWeek(mActivity) + 1);
+ EditEventHelper.updateRecurrenceRule(
+ selection, mModel, Utils.getFirstDayOfWeek(mActivity) + 1);
// Save the timezone so we can display it as a standard option next time
if (!mModel.mAllDay) {
@@ -894,8 +911,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
mReminderLabels = new ArrayList<String>(Arrays.asList(labels));
SharedPreferences prefs = GeneralPreferences.getSharedPreferences(mActivity);
- String durationString = prefs.getString(GeneralPreferences.KEY_DEFAULT_REMINDER,
- "0");
+ String durationString = prefs.getString(GeneralPreferences.KEY_DEFAULT_REMINDER, "0");
mDefaultReminderMinutes = Integer.parseInt(durationString);
int numReminders = 0;
@@ -903,8 +919,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
ArrayList<Integer> minutes = model.mReminderMinutes;
numReminders = minutes.size();
for (Integer minute : minutes) {
- EventViewUtils.addMinutesToList( mActivity, mReminderValues, mReminderLabels,
- minute);
+ EventViewUtils.addMinutesToList(
+ mActivity, mReminderValues, mReminderLabels, minute);
EventViewUtils.addReminder(mActivity, mScrollView, this, mReminderItems,
mReminderValues, mReminderLabels, minute);
}
@@ -954,7 +970,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
return 0;
}
- public void setCalendarsCursor(Cursor cursor) {
+ public void setCalendarsCursor(Cursor cursor, boolean userVisible) {
// If there are no syncable calendars, then we cannot allow
// creating a new event.
mCalendarsCursor = cursor;
@@ -963,6 +979,9 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
if (mSaveAfterQueryComplete) {
mLoadingCalendarsDialog.cancel();
}
+ if (!userVisible) {
+ return;
+ }
// Create an error message for the user that, when clicked,
// will exit this activity without saving the event.
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
@@ -1002,12 +1021,15 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
}
if (mSaveAfterQueryComplete) {
mLoadingCalendarsDialog.cancel();
- if (fillModelFromUI()) {
- mDone.setDoneCode(Utils.DONE_SAVE);
+ if (prepareForSave() && fillModelFromUI()) {
+ int exit = userVisible ? Utils.DONE_EXIT : 0;
+ mDone.setDoneCode(Utils.DONE_SAVE | exit);
mDone.run();
- } else {
- mDone.setDoneCode(Utils.DONE_REVERT);
+ } else if (userVisible) {
+ mDone.setDoneCode(Utils.DONE_EXIT);
mDone.run();
+ } else if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "SetCalendarsCursor:Save failed and unable to exit view");
}
return;
}
@@ -1032,8 +1054,8 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
return -1;
}
- String defaultCalendar = Utils.getSharedPreference(mActivity,
- GeneralPreferences.KEY_DEFAULT_CALENDAR, null);
+ String defaultCalendar = Utils.getSharedPreference(
+ mActivity, GeneralPreferences.KEY_DEFAULT_CALENDAR, null);
if (defaultCalendar == null) {
return 0;
@@ -1107,9 +1129,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
* followed by any combination of letters and symbols, including one+ dots
* and zero commas, should insert an extra comma (followed by the space).
*/
- private static InputFilter[] sRecipientFilters = new InputFilter[] {
- new Rfc822InputFilter()
- };
+ private static InputFilter[] sRecipientFilters = new InputFilter[] { new Rfc822InputFilter() };
private void setDate(TextView view, long millis) {
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR