EditEventActivity.java revision e584a7df962b8e643224bcbce022c9bea19fe221
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.Calendar.EVENT_BEGIN_TIME; 20import static android.provider.Calendar.EVENT_END_TIME; 21 22import com.android.calendar.AbstractCalendarActivity; 23import com.android.calendar.CalendarController; 24import com.android.calendar.CalendarController.EventInfo; 25import com.android.calendar.R; 26 27import android.app.ActionBar; 28import android.app.FragmentTransaction; 29import android.content.Intent; 30import android.net.Uri; 31import android.os.Bundle; 32import android.text.format.Time; 33import android.util.Log; 34import android.view.MenuItem; 35import android.widget.FrameLayout; 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 FrameLayout mView; 45 private EditEventFragment mEditFragment; 46 47 private EventInfo mEventInfo; 48 49 @Override 50 protected void onCreate(Bundle icicle) { 51 super.onCreate(icicle); 52 setContentView(R.layout.edit_event_fragment); 53 mView = (FrameLayout) findViewById(R.id.edit_event); 54 55 mEventInfo = getEventInfoFromIntent(icicle); 56 57 mEditFragment = (EditEventFragment) getFragmentManager().findFragmentById(R.id.edit_event); 58 59 getActionBar().setDisplayOptions( 60 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); 61 62 if (mEditFragment == null) { 63 mEditFragment = new EditEventFragment(mEventInfo, false); 64 65 mEditFragment.mShowModifyDialogOnLaunch = getIntent().getBooleanExtra( 66 CalendarController.EVENT_EDIT_ON_LAUNCH, false); 67 68 FragmentTransaction ft = getFragmentManager().openTransaction(); 69 ft.replace(R.id.edit_event, mEditFragment); 70 ft.show(mEditFragment); 71 ft.commit(); 72 } 73 } 74 75 private EventInfo getEventInfoFromIntent(Bundle icicle) { 76 EventInfo info = new EventInfo(); 77 long eventId = -1; 78 Intent intent = getIntent(); 79 Uri data = intent.getData(); 80 if (data != null) { 81 try { 82 eventId = Long.parseLong(data.getLastPathSegment()); 83 } catch (NumberFormatException e) { 84 if (DEBUG) { 85 Log.d(TAG, "Create new event"); 86 } 87 } 88 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { 89 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); 90 } 91 92 long begin = intent.getLongExtra(EVENT_BEGIN_TIME, -1); 93 long end = intent.getLongExtra(EVENT_END_TIME, -1); 94 if (end != -1) { 95 info.endTime = new Time(); 96 info.endTime.set(end); 97 } 98 if (begin != -1) { 99 info.startTime = new Time(); 100 info.startTime.set(begin); 101 } 102 info.id = eventId; 103 104 return info; 105 } 106 107 @Override 108 public boolean onOptionsItemSelected(MenuItem item) { 109 if (item.getItemId() == android.R.id.home) { 110 Intent launchIntent = new Intent(); 111 launchIntent.setAction(Intent.ACTION_VIEW); 112 launchIntent.setData(Uri.parse("content://com.android.calendar/time")); 113 launchIntent.setFlags( 114 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); 115 startActivity(launchIntent); 116 return true; 117 } 118 return super.onOptionsItemSelected(item); 119 } 120} 121