EventInfoActivity.java revision 53aad911d4d901d19afba320cc626da2dab68025
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 // Remove the application title 96 ActionBar bar = getActionBar(); 97 if (bar != null) { 98 bar.setDisplayOptions (0, ActionBar.DISPLAY_SHOW_TITLE); 99 } 100 101 // Create a new fragment if none exists 102 if (mInfoFragment == null) { 103 FragmentManager fragmentManager = getFragmentManager(); 104 FragmentTransaction ft = fragmentManager.beginTransaction(); 105 mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, 106 attendeeResponse, isDialog); 107 ft.replace(R.id.event_info_fullscreen, 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