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