blob: 173a573515cc8392a371dcb1635ce4e9c2b238d3 [file] [log] [blame]
Erik5f620792010-10-27 12:42:01 -07001/*
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
17package com.android.calendar.event;
18
James Kung09fbd8e2012-11-12 11:19:46 -080019import static android.provider.CalendarContract.EXTRA_EVENT_ALL_DAY;
RoboErika27a8862011-06-23 15:26:23 -070020import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
21import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
Erik5f620792010-10-27 12:42:01 -070022
Erike584a7d2011-01-11 11:12:18 -080023import android.app.ActionBar;
Erik5f620792010-10-27 12:42:01 -070024import android.app.FragmentTransaction;
25import android.content.Intent;
26import android.net.Uri;
27import android.os.Bundle;
James Kung09fbd8e2012-11-12 11:19:46 -080028import android.provider.CalendarContract.Events;
Erik5f620792010-10-27 12:42:01 -070029import android.text.format.Time;
30import android.util.Log;
Erike584a7d2011-01-11 11:12:18 -080031import android.view.MenuItem;
Michael Chanc250e2e2011-05-23 12:52:50 -070032
33import com.android.calendar.AbstractCalendarActivity;
34import com.android.calendar.CalendarController;
35import com.android.calendar.CalendarController.EventInfo;
James Kung1d1b1e42013-03-06 19:49:23 -080036import com.android.calendar.CalendarEventModel.ReminderEntry;
Michael Chanc250e2e2011-05-23 12:52:50 -070037import com.android.calendar.R;
38import com.android.calendar.Utils;
Erik5f620792010-10-27 12:42:01 -070039
James Kung1d1b1e42013-03-06 19:49:23 -080040import java.util.ArrayList;
41
Erik5f620792010-10-27 12:42:01 -070042public 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 Kung1d1b1e42013-03-06 19:49:23 -080049 public static final String EXTRA_EVENT_COLOR = "event_color";
50
51 public static final String EXTRA_EVENT_REMINDERS = "reminders";
52
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -070053 private static boolean mIsMultipane;
54
Erik5f620792010-10-27 12:42:01 -070055 private EditEventFragment mEditFragment;
56
James Kung1d1b1e42013-03-06 19:49:23 -080057 private ArrayList<ReminderEntry> mReminders;
58
59 private int mEventColor;
60
James Kungf56b1492013-03-07 15:10:13 -080061 private boolean mEventColorInitialized;
62
Erik5f620792010-10-27 12:42:01 -070063 private EventInfo mEventInfo;
64
65 @Override
66 protected void onCreate(Bundle icicle) {
67 super.onCreate(icicle);
Michael Chan81d45a92011-07-10 13:29:50 -070068 setContentView(R.layout.simple_frame_layout);
Erik5f620792010-10-27 12:42:01 -070069
70 mEventInfo = getEventInfoFromIntent(icicle);
James Kung1d1b1e42013-03-06 19:49:23 -080071 mReminders = getReminderEntriesFromIntent();
James Kungf56b1492013-03-07 15:10:13 -080072 mEventColorInitialized = getIntent().hasExtra(EXTRA_EVENT_COLOR);
James Kung1d1b1e42013-03-06 19:49:23 -080073 mEventColor = getIntent().getIntExtra(EXTRA_EVENT_COLOR, -1);
Erik5f620792010-10-27 12:42:01 -070074
James Kungf56b1492013-03-07 15:10:13 -080075
Michael Chan81d45a92011-07-10 13:29:50 -070076 mEditFragment = (EditEventFragment) getFragmentManager().findFragmentById(R.id.main_frame);
Erik5f620792010-10-27 12:42:01 -070077
Isaac Katzenelson7ef29812011-10-25 18:00:50 -070078 mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config);
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -070079
80 if (mIsMultipane) {
81 getActionBar().setDisplayOptions(
Andy Huang135b2d42011-09-01 20:38:43 -070082 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 Katzenelson5b2a9072011-04-08 15:23:57 -070087 }
88 else {
Andy Huang135b2d42011-09-01 20:38:43 -070089 getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
Isaac Katzenelson016d5762011-05-23 16:05:51 -070090 ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME|
Andy Huang135b2d42011-09-01 20:38:43 -070091 ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -070092 }
93
Erik59ead672010-11-29 15:47:08 -080094 if (mEditFragment == null) {
Michael Chanc250e2e2011-05-23 12:52:50 -070095 Intent intent = null;
96 if (mEventInfo.id == -1) {
97 intent = getIntent();
98 }
99
James Kungf56b1492013-03-07 15:10:13 -0800100 mEditFragment = new EditEventFragment(mEventInfo, mReminders, mEventColorInitialized,
101 mEventColor, false, intent);
Erik59ead672010-11-29 15:47:08 -0800102
Erika7694ee2010-12-07 15:46:18 -0800103 mEditFragment.mShowModifyDialogOnLaunch = getIntent().getBooleanExtra(
104 CalendarController.EVENT_EDIT_ON_LAUNCH, false);
105
Dianne Hackborn12b33302011-01-17 12:30:13 -0800106 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan81d45a92011-07-10 13:29:50 -0700107 ft.replace(R.id.main_frame, mEditFragment);
Erik59ead672010-11-29 15:47:08 -0800108 ft.show(mEditFragment);
109 ft.commit();
110 }
Erik5f620792010-10-27 12:42:01 -0700111 }
112
James Kung1d1b1e42013-03-06 19:49:23 -0800113 @SuppressWarnings("unchecked")
114 private ArrayList<ReminderEntry> getReminderEntriesFromIntent() {
115 Intent intent = getIntent();
116 return (ArrayList<ReminderEntry>) intent.getSerializableExtra(EXTRA_EVENT_REMINDERS);
117 }
118
Erik5f620792010-10-27 12:42:01 -0700119 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 Chan8b1119b2012-01-06 16:04:55 -0800136 boolean allDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false);
137
RoboErika27a8862011-06-23 15:26:23 -0700138 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
139 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erik5f620792010-10-27 12:42:01 -0700140 if (end != -1) {
141 info.endTime = new Time();
Michael Chan8b1119b2012-01-06 16:04:55 -0800142 if (allDay) {
143 info.endTime.timezone = Time.TIMEZONE_UTC;
144 }
Erik5f620792010-10-27 12:42:01 -0700145 info.endTime.set(end);
146 }
147 if (begin != -1) {
148 info.startTime = new Time();
Michael Chan8b1119b2012-01-06 16:04:55 -0800149 if (allDay) {
150 info.startTime.timezone = Time.TIMEZONE_UTC;
151 }
Erik5f620792010-10-27 12:42:01 -0700152 info.startTime.set(begin);
153 }
154 info.id = eventId;
James Kung09fbd8e2012-11-12 11:19:46 -0800155 info.eventTitle = intent.getStringExtra(Events.TITLE);
156 info.calendarId = intent.getLongExtra(Events.CALENDAR_ID, -1);
Erik5f620792010-10-27 12:42:01 -0700157
Michael Chan8b1119b2012-01-06 16:04:55 -0800158 if (allDay) {
Michael Chanedecd9a2011-08-24 23:58:48 -0700159 info.extraLong = CalendarController.EXTRA_CREATE_ALL_DAY;
160 } else {
161 info.extraLong = 0;
162 }
Erik5f620792010-10-27 12:42:01 -0700163 return info;
164 }
Erike584a7d2011-01-11 11:12:18 -0800165
166 @Override
167 public boolean onOptionsItemSelected(MenuItem item) {
168 if (item.getItemId() == android.R.id.home) {
RoboErikc0f6efe2011-07-11 15:46:34 -0700169 Utils.returnToCalendarHome(this);
Erike584a7d2011-01-11 11:12:18 -0800170 return true;
171 }
172 return super.onOptionsItemSelected(item);
173 }
Erik5f620792010-10-27 12:42:01 -0700174}