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