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