EditEventActivity.java revision 5f62079ab9daefe95ede87631766e99e8b4a2220
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.EventInfo; 24import com.android.calendar.R; 25 26import android.app.FragmentTransaction; 27import android.content.Intent; 28import android.net.Uri; 29import android.os.Bundle; 30import android.text.format.Time; 31import android.util.Log; 32import android.widget.FrameLayout; 33 34public class EditEventActivity extends AbstractCalendarActivity { 35 private static final String TAG = "EditEventActivity"; 36 37 private static final boolean DEBUG = false; 38 39 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id"; 40 41 private FrameLayout mView; 42 private EditEventFragment mEditFragment; 43 44 private EventInfo mEventInfo; 45 46 @Override 47 protected void onCreate(Bundle icicle) { 48 super.onCreate(icicle); 49 setContentView(R.layout.edit_event_fragment); 50 mView = (FrameLayout) findViewById(R.id.edit_event); 51 52 mEventInfo = getEventInfoFromIntent(icicle); 53 54 mEditFragment = new EditEventFragment(mEventInfo); 55 56 FragmentTransaction ft = getFragmentManager().openTransaction(); 57 ft.replace(R.id.edit_event, mEditFragment); 58 ft.show(mEditFragment); 59 ft.commit(); 60 } 61 62 private EventInfo getEventInfoFromIntent(Bundle icicle) { 63 EventInfo info = new EventInfo(); 64 long eventId = -1; 65 Intent intent = getIntent(); 66 Uri data = intent.getData(); 67 if (data != null) { 68 try { 69 eventId = Long.parseLong(data.getLastPathSegment()); 70 } catch (NumberFormatException e) { 71 if (DEBUG) { 72 Log.d(TAG, "Create new event"); 73 } 74 } 75 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { 76 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); 77 } 78 79 long begin = intent.getLongExtra(EVENT_BEGIN_TIME, -1); 80 long end = intent.getLongExtra(EVENT_END_TIME, -1); 81 if (end != -1) { 82 info.endTime = new Time(); 83 info.endTime.set(end); 84 } 85 if (begin != -1) { 86 info.startTime = new Time(); 87 info.startTime.set(begin); 88 } 89 info.id = eventId; 90 91 return info; 92 } 93} 94