EditEventActivity.java revision 07d9fee87bc02849c0dd7b66326a320d53cf5479
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 17package com.android.calendar.event; 18 19import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME; 20import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME; 21 22import android.app.ActionBar; 23import android.app.FragmentTransaction; 24import android.content.Intent; 25import android.net.Uri; 26import android.os.Bundle; 27import android.text.format.Time; 28import android.util.Log; 29import android.view.MenuItem; 30 31import com.android.calendar.AbstractCalendarActivity; 32import com.android.calendar.CalendarController; 33import com.android.calendar.CalendarController.EventInfo; 34import com.android.calendar.R; 35import com.android.calendar.Utils; 36 37public class EditEventActivity extends AbstractCalendarActivity { 38 private static final String TAG = "EditEventActivity"; 39 40 private static final boolean DEBUG = false; 41 42 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id"; 43 44 private static boolean mIsMultipane; 45 46 private EditEventFragment mEditFragment; 47 48 private EventInfo mEventInfo; 49 50 @Override 51 protected void onCreate(Bundle icicle) { 52 super.onCreate(icicle); 53 setContentView(R.layout.simple_frame_layout); 54 55 mEventInfo = getEventInfoFromIntent(icicle); 56 57 mEditFragment = (EditEventFragment) getFragmentManager().findFragmentById(R.id.main_frame); 58 59 mIsMultipane = Utils.isMultiPaneConfiguration (this); 60 61 if (mIsMultipane) { 62 getActionBar().setDisplayOptions( 63 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); 64 } 65 else { 66 getActionBar().setDisplayOptions(0, 67 ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME| 68 ActionBar.DISPLAY_SHOW_TITLE); 69 } 70 71 if (mEditFragment == null) { 72 Intent intent = null; 73 if (mEventInfo.id == -1) { 74 intent = getIntent(); 75 } 76 77 mEditFragment = new EditEventFragment(mEventInfo, false, intent); 78 79 mEditFragment.mShowModifyDialogOnLaunch = getIntent().getBooleanExtra( 80 CalendarController.EVENT_EDIT_ON_LAUNCH, false); 81 82 FragmentTransaction ft = getFragmentManager().beginTransaction(); 83 ft.replace(R.id.main_frame, mEditFragment); 84 ft.show(mEditFragment); 85 ft.commit(); 86 } 87 } 88 89 private EventInfo getEventInfoFromIntent(Bundle icicle) { 90 EventInfo info = new EventInfo(); 91 long eventId = -1; 92 Intent intent = getIntent(); 93 Uri data = intent.getData(); 94 if (data != null) { 95 try { 96 eventId = Long.parseLong(data.getLastPathSegment()); 97 } catch (NumberFormatException e) { 98 if (DEBUG) { 99 Log.d(TAG, "Create new event"); 100 } 101 } 102 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { 103 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); 104 } 105 106 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1); 107 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1); 108 if (end != -1) { 109 info.endTime = new Time(); 110 info.endTime.set(end); 111 } 112 if (begin != -1) { 113 info.startTime = new Time(); 114 info.startTime.set(begin); 115 } 116 info.id = eventId; 117 118 return info; 119 } 120 121 @Override 122 public boolean onOptionsItemSelected(MenuItem item) { 123 if (item.getItemId() == android.R.id.home) { 124 Utils.returnToCalendarHome(this); 125 return true; 126 } 127 return super.onOptionsItemSelected(item); 128 } 129} 130