Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.calendar.event; |
| 18 | |
James Kung | 09fbd8e | 2012-11-12 11:19:46 -0800 | [diff] [blame] | 19 | import static android.provider.CalendarContract.EXTRA_EVENT_ALL_DAY; |
RoboErik | a27a886 | 2011-06-23 15:26:23 -0700 | [diff] [blame] | 20 | import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME; |
| 21 | import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME; |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 22 | |
Erik | e584a7d | 2011-01-11 11:12:18 -0800 | [diff] [blame] | 23 | import android.app.ActionBar; |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 24 | import android.app.FragmentTransaction; |
| 25 | import android.content.Intent; |
| 26 | import android.net.Uri; |
| 27 | import android.os.Bundle; |
James Kung | 09fbd8e | 2012-11-12 11:19:46 -0800 | [diff] [blame] | 28 | import android.provider.CalendarContract.Events; |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 29 | import android.text.format.Time; |
| 30 | import android.util.Log; |
Erik | e584a7d | 2011-01-11 11:12:18 -0800 | [diff] [blame] | 31 | import android.view.MenuItem; |
Michael Chan | c250e2e | 2011-05-23 12:52:50 -0700 | [diff] [blame] | 32 | |
| 33 | import com.android.calendar.AbstractCalendarActivity; |
| 34 | import com.android.calendar.CalendarController; |
| 35 | import com.android.calendar.CalendarController.EventInfo; |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 36 | import com.android.calendar.CalendarEventModel.ReminderEntry; |
Michael Chan | c250e2e | 2011-05-23 12:52:50 -0700 | [diff] [blame] | 37 | import com.android.calendar.R; |
| 38 | import com.android.calendar.Utils; |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 39 | |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 40 | import java.util.ArrayList; |
| 41 | |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 42 | public class EditEventActivity extends AbstractCalendarActivity { |
| 43 | private static final String TAG = "EditEventActivity"; |
| 44 | |
| 45 | private static final boolean DEBUG = false; |
| 46 | |
| 47 | private static final String BUNDLE_KEY_EVENT_ID = "key_event_id"; |
| 48 | |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 49 | public static final String EXTRA_EVENT_COLOR = "event_color"; |
| 50 | |
| 51 | public static final String EXTRA_EVENT_REMINDERS = "reminders"; |
| 52 | |
Isaac Katzenelson | 5b2a907 | 2011-04-08 15:23:57 -0700 | [diff] [blame] | 53 | private static boolean mIsMultipane; |
| 54 | |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 55 | private EditEventFragment mEditFragment; |
| 56 | |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 57 | private ArrayList<ReminderEntry> mReminders; |
| 58 | |
| 59 | private int mEventColor; |
| 60 | |
James Kung | f56b149 | 2013-03-07 15:10:13 -0800 | [diff] [blame] | 61 | private boolean mEventColorInitialized; |
| 62 | |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 63 | private EventInfo mEventInfo; |
| 64 | |
| 65 | @Override |
| 66 | protected void onCreate(Bundle icicle) { |
| 67 | super.onCreate(icicle); |
Michael Chan | 81d45a9 | 2011-07-10 13:29:50 -0700 | [diff] [blame] | 68 | setContentView(R.layout.simple_frame_layout); |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 69 | |
| 70 | mEventInfo = getEventInfoFromIntent(icicle); |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 71 | mReminders = getReminderEntriesFromIntent(); |
James Kung | f56b149 | 2013-03-07 15:10:13 -0800 | [diff] [blame] | 72 | mEventColorInitialized = getIntent().hasExtra(EXTRA_EVENT_COLOR); |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 73 | mEventColor = getIntent().getIntExtra(EXTRA_EVENT_COLOR, -1); |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 74 | |
James Kung | f56b149 | 2013-03-07 15:10:13 -0800 | [diff] [blame] | 75 | |
Michael Chan | 81d45a9 | 2011-07-10 13:29:50 -0700 | [diff] [blame] | 76 | mEditFragment = (EditEventFragment) getFragmentManager().findFragmentById(R.id.main_frame); |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 77 | |
Isaac Katzenelson | 7ef2981 | 2011-10-25 18:00:50 -0700 | [diff] [blame] | 78 | mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config); |
Isaac Katzenelson | 5b2a907 | 2011-04-08 15:23:57 -0700 | [diff] [blame] | 79 | |
| 80 | if (mIsMultipane) { |
| 81 | getActionBar().setDisplayOptions( |
Andy Huang | 135b2d4 | 2011-09-01 20:38:43 -0700 | [diff] [blame] | 82 | ActionBar.DISPLAY_SHOW_TITLE, |
| 83 | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME |
| 84 | | ActionBar.DISPLAY_SHOW_TITLE); |
| 85 | getActionBar().setTitle( |
| 86 | mEventInfo.id == -1 ? R.string.event_create : R.string.event_edit); |
Isaac Katzenelson | 5b2a907 | 2011-04-08 15:23:57 -0700 | [diff] [blame] | 87 | } |
| 88 | else { |
Andy Huang | 135b2d4 | 2011-09-01 20:38:43 -0700 | [diff] [blame] | 89 | getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, |
Isaac Katzenelson | 016d576 | 2011-05-23 16:05:51 -0700 | [diff] [blame] | 90 | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME| |
Andy Huang | 135b2d4 | 2011-09-01 20:38:43 -0700 | [diff] [blame] | 91 | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); |
Isaac Katzenelson | 5b2a907 | 2011-04-08 15:23:57 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Erik | 59ead67 | 2010-11-29 15:47:08 -0800 | [diff] [blame] | 94 | if (mEditFragment == null) { |
Michael Chan | c250e2e | 2011-05-23 12:52:50 -0700 | [diff] [blame] | 95 | Intent intent = null; |
| 96 | if (mEventInfo.id == -1) { |
| 97 | intent = getIntent(); |
| 98 | } |
| 99 | |
James Kung | f56b149 | 2013-03-07 15:10:13 -0800 | [diff] [blame] | 100 | mEditFragment = new EditEventFragment(mEventInfo, mReminders, mEventColorInitialized, |
| 101 | mEventColor, false, intent); |
Erik | 59ead67 | 2010-11-29 15:47:08 -0800 | [diff] [blame] | 102 | |
Erik | a7694ee | 2010-12-07 15:46:18 -0800 | [diff] [blame] | 103 | mEditFragment.mShowModifyDialogOnLaunch = getIntent().getBooleanExtra( |
| 104 | CalendarController.EVENT_EDIT_ON_LAUNCH, false); |
| 105 | |
Dianne Hackborn | 12b3330 | 2011-01-17 12:30:13 -0800 | [diff] [blame] | 106 | FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Michael Chan | 81d45a9 | 2011-07-10 13:29:50 -0700 | [diff] [blame] | 107 | ft.replace(R.id.main_frame, mEditFragment); |
Erik | 59ead67 | 2010-11-29 15:47:08 -0800 | [diff] [blame] | 108 | ft.show(mEditFragment); |
| 109 | ft.commit(); |
| 110 | } |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 111 | } |
| 112 | |
James Kung | 1d1b1e4 | 2013-03-06 19:49:23 -0800 | [diff] [blame] | 113 | @SuppressWarnings("unchecked") |
| 114 | private ArrayList<ReminderEntry> getReminderEntriesFromIntent() { |
| 115 | Intent intent = getIntent(); |
| 116 | return (ArrayList<ReminderEntry>) intent.getSerializableExtra(EXTRA_EVENT_REMINDERS); |
| 117 | } |
| 118 | |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 119 | private EventInfo getEventInfoFromIntent(Bundle icicle) { |
| 120 | EventInfo info = new EventInfo(); |
| 121 | long eventId = -1; |
| 122 | Intent intent = getIntent(); |
| 123 | Uri data = intent.getData(); |
| 124 | if (data != null) { |
| 125 | try { |
| 126 | eventId = Long.parseLong(data.getLastPathSegment()); |
| 127 | } catch (NumberFormatException e) { |
| 128 | if (DEBUG) { |
| 129 | Log.d(TAG, "Create new event"); |
| 130 | } |
| 131 | } |
| 132 | } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { |
| 133 | eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); |
| 134 | } |
| 135 | |
Michael Chan | 8b1119b | 2012-01-06 16:04:55 -0800 | [diff] [blame] | 136 | boolean allDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false); |
| 137 | |
RoboErik | a27a886 | 2011-06-23 15:26:23 -0700 | [diff] [blame] | 138 | long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1); |
| 139 | long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1); |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 140 | if (end != -1) { |
| 141 | info.endTime = new Time(); |
Michael Chan | 8b1119b | 2012-01-06 16:04:55 -0800 | [diff] [blame] | 142 | if (allDay) { |
| 143 | info.endTime.timezone = Time.TIMEZONE_UTC; |
| 144 | } |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 145 | info.endTime.set(end); |
| 146 | } |
| 147 | if (begin != -1) { |
| 148 | info.startTime = new Time(); |
Michael Chan | 8b1119b | 2012-01-06 16:04:55 -0800 | [diff] [blame] | 149 | if (allDay) { |
| 150 | info.startTime.timezone = Time.TIMEZONE_UTC; |
| 151 | } |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 152 | info.startTime.set(begin); |
| 153 | } |
| 154 | info.id = eventId; |
James Kung | 09fbd8e | 2012-11-12 11:19:46 -0800 | [diff] [blame] | 155 | info.eventTitle = intent.getStringExtra(Events.TITLE); |
| 156 | info.calendarId = intent.getLongExtra(Events.CALENDAR_ID, -1); |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 157 | |
Michael Chan | 8b1119b | 2012-01-06 16:04:55 -0800 | [diff] [blame] | 158 | if (allDay) { |
Michael Chan | edecd9a | 2011-08-24 23:58:48 -0700 | [diff] [blame] | 159 | info.extraLong = CalendarController.EXTRA_CREATE_ALL_DAY; |
| 160 | } else { |
| 161 | info.extraLong = 0; |
| 162 | } |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 163 | return info; |
| 164 | } |
Erik | e584a7d | 2011-01-11 11:12:18 -0800 | [diff] [blame] | 165 | |
| 166 | @Override |
| 167 | public boolean onOptionsItemSelected(MenuItem item) { |
| 168 | if (item.getItemId() == android.R.id.home) { |
RoboErik | c0f6efe | 2011-07-11 15:46:34 -0700 | [diff] [blame] | 169 | Utils.returnToCalendarHome(this); |
Erik | e584a7d | 2011-01-11 11:12:18 -0800 | [diff] [blame] | 170 | return true; |
| 171 | } |
| 172 | return super.onOptionsItemSelected(item); |
| 173 | } |
Erik | 5f62079 | 2010-10-27 12:42:01 -0700 | [diff] [blame] | 174 | } |