EventInfoActivity.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 */
16package com.android.calendar;
17
18import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
19import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
20import static com.android.calendar.CalendarController.ATTENDEE_NO_RESPONSE;
21import static com.android.calendar.CalendarController.EVENT_ATTENDEE_RESPONSE;
22
23import android.app.ActionBar;
24import android.app.Activity;
25import android.app.FragmentManager;
26import android.app.FragmentTransaction;
27import android.content.Intent;
28import android.net.Uri;
29import android.os.Bundle;
30import android.util.Log;
31
32public class EventInfoActivity extends Activity {
33//        implements CalendarController.EventHandler, SearchView.OnQueryTextListener,
34//        SearchView.OnCloseListener {
35
36    private static final String TAG = "EventInfoActivity";
37    private EventInfoFragment mInfoFragment;
38    private long mStartMillis, mEndMillis;
39    private long mEventId;
40
41    @Override
42    protected void onCreate(Bundle icicle) {
43        super.onCreate(icicle);
44
45        setContentView(R.layout.simple_frame_layout);
46
47        // Make sure the home button is visible
48        getActionBar().setDisplayOptions(
49                ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
50
51        // Get the fragment if exists
52        mInfoFragment = (EventInfoFragment)
53                getFragmentManager().findFragmentById(R.id.main_frame);
54
55
56        // Get the info needed for the fragment
57        Intent intent = getIntent();
58        int attendeeResponse = 0;
59        mEventId = 0;
60        boolean isDialog = false;
61
62        if (icicle != null) {
63            mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID);
64            mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS);
65            mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS);
66            attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE);
67            isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG);
68        } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
69            mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
70            mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
71            attendeeResponse = intent.getIntExtra(EVENT_ATTENDEE_RESPONSE, ATTENDEE_NO_RESPONSE);
72            Uri data = intent.getData();
73            if (data != null) {
74                try {
75                    mEventId = Long.parseLong(data.getLastPathSegment());
76                } catch (NumberFormatException e) {
77                    Log.wtf(TAG,"No event id");
78                }
79            }
80        }
81
82        // Remove the application title
83        ActionBar bar = getActionBar();
84        if (bar != null) {
85            bar.setDisplayOptions (0, ActionBar.DISPLAY_SHOW_TITLE);
86        }
87
88        // Create a new fragment if none exists
89        if (mInfoFragment == null) {
90            FragmentManager fragmentManager = getFragmentManager();
91            FragmentTransaction ft = fragmentManager.beginTransaction();
92            mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis,
93                    attendeeResponse, isDialog);
94            ft.replace(R.id.main_frame, mInfoFragment);
95            ft.commit();
96        }
97    }
98
99//    @Override
100//    public boolean onOptionsItemSelected(MenuItem item) {
101//
102//        // Handles option menu selections:
103//        // Home button - close event info activity and start the main calendar one
104//        // Edit button - start the event edit activity and close the info activity
105//        // Delete button - start a delete query that calls a runnable that close the info activity
106//
107//        switch (item.getItemId()) {
108//            case android.R.id.home:
109//                Intent launchIntent = new Intent();
110//                launchIntent.setAction(Intent.ACTION_VIEW);
111//                launchIntent.setData(Uri.parse(CalendarContract.CONTENT_URI + "/time"));
112//                launchIntent.setFlags(
113//                        Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
114//                startActivity(launchIntent);
115//                finish();
116//                return true;
117//            case R.id.info_action_edit:
118//                Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId);
119//                Intent intent = new Intent(Intent.ACTION_EDIT, uri);
120//                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis);
121//                intent.putExtra(EXTRA_EVENT_END_TIME, mEndMillis);
122//                intent.setClass(this, EditEventActivity.class);
123//                intent.putExtra(EVENT_EDIT_ON_LAUNCH, true);
124//                startActivity(intent);
125//                finish ();
126//                break;
127//            case R.id.info_action_delete:
128//                DeleteEventHelper deleteHelper = new DeleteEventHelper(
129//                        this, this, true /* exitWhenDone */);
130//                deleteHelper.delete(mStartMillis, mEndMillis, mEventId, -1, onDeleteRunnable);
131//                break;
132//            default:
133//                break;
134//        }
135//        return super.onOptionsItemSelected(item);
136//    }
137
138    // runs at the end of a delete action and closes the activity
139//    private Runnable onDeleteRunnable = new Runnable() {
140//        @Override
141//        public void run() {
142//            finish ();
143//        }
144//    };
145
146    @Override
147    protected void onNewIntent(Intent intent) {
148        // From the Android Dev Guide: "It's important to note that when
149        // onNewIntent(Intent) is called, the Activity has not been restarted,
150        // so the getIntent() method will still return the Intent that was first
151        // received with onCreate(). This is why setIntent(Intent) is called
152        // inside onNewIntent(Intent) (just in case you call getIntent() at a
153        // later time)."
154        setIntent(intent);
155    }
156
157
158    @Override
159    public void onSaveInstanceState(Bundle outState) {
160        super.onSaveInstanceState(outState);
161    }
162
163    @Override
164    protected void onResume() {
165        super.onResume();
166    }
167
168    @Override
169    protected void onPause() {
170        super.onPause();
171    }
172
173    @Override
174    protected void onDestroy() {
175        super.onDestroy();
176    }
177}
178