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