EventInfoActivity.java revision 4afba187f8990ae2b3afaf8fcdb6039f231f4914
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 android.provider.CalendarContract.Attendees.ATTENDEE_STATUS; 21 22import android.app.ActionBar; 23import android.app.Activity; 24import android.app.FragmentManager; 25import android.app.FragmentTransaction; 26import android.content.Intent; 27import android.content.res.Resources; 28import android.database.ContentObserver; 29import android.net.Uri; 30import android.os.Bundle; 31import android.os.Handler; 32import android.provider.CalendarContract; 33import android.provider.CalendarContract.Attendees; 34import android.util.Log; 35import android.widget.Toast; 36 37import java.util.List; 38 39public class EventInfoActivity extends Activity { 40// implements CalendarController.EventHandler, SearchView.OnQueryTextListener, 41// SearchView.OnCloseListener { 42 43 private static final String TAG = "EventInfoActivity"; 44 private EventInfoFragment mInfoFragment; 45 private long mStartMillis, mEndMillis; 46 private long mEventId; 47 48 // Create an observer so that we can update the views whenever a 49 // Calendar event changes. 50 private final ContentObserver mObserver = new ContentObserver(new Handler()) { 51 @Override 52 public boolean deliverSelfNotifications() { 53 return false; 54 } 55 56 @Override 57 public void onChange(boolean selfChange) { 58 if (selfChange) return; 59 if (mInfoFragment != null) { 60 mInfoFragment.reloadEvents(); 61 } 62 } 63 }; 64 65 @Override 66 protected void onCreate(Bundle icicle) { 67 super.onCreate(icicle); 68 69 // Get the info needed for the fragment 70 Intent intent = getIntent(); 71 int attendeeResponse = 0; 72 mEventId = -1; 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(ATTENDEE_STATUS, 85 Attendees.ATTENDEE_STATUS_NONE); 86 Uri data = intent.getData(); 87 if (data != null) { 88 try { 89 List<String> pathSegments = data.getPathSegments(); 90 int size = pathSegments.size(); 91 if (size > 2 && "EventTime".equals(pathSegments.get(2))) { 92 // Support non-standard VIEW intent format: 93 //dat = content://com.android.calendar/events/[id]/EventTime/[start]/[end] 94 mEventId = Long.parseLong(pathSegments.get(1)); 95 if (size > 4) { 96 mStartMillis = Long.parseLong(pathSegments.get(3)); 97 mEndMillis = Long.parseLong(pathSegments.get(4)); 98 } 99 } else { 100 mEventId = Long.parseLong(data.getLastPathSegment()); 101 } 102 } catch (NumberFormatException e) { 103 if (mEventId == -1) { 104 // do nothing here , deal with it later 105 } else if (mStartMillis == 0 || mEndMillis ==0) { 106 // Parsing failed on the start or end time , make sure the times were not 107 // pulled from the intent's extras and reset them. 108 mStartMillis = 0; 109 mEndMillis = 0; 110 } 111 } 112 } 113 } 114 115 if (mEventId == -1) { 116 Log.w(TAG, "No event id"); 117 Toast.makeText(this, R.string.event_not_found, Toast.LENGTH_SHORT).show(); 118 finish(); 119 } 120 121 // If we do not support showing full screen event info in this configuration, 122 // close the activity and show the event in AllInOne. 123 Resources res = getResources(); 124 if (!res.getBoolean(R.bool.agenda_show_event_info_full_screen) 125 && !res.getBoolean(R.bool.show_event_info_full_screen)) { 126 CalendarController.getInstance(this) 127 .launchViewEvent(mEventId, mStartMillis, mEndMillis, attendeeResponse); 128 finish(); 129 return; 130 } 131 132 setContentView(R.layout.simple_frame_layout); 133 134 // Get the fragment if exists 135 mInfoFragment = (EventInfoFragment) 136 getFragmentManager().findFragmentById(R.id.main_frame); 137 138 139 // Remove the application title 140 ActionBar bar = getActionBar(); 141 if (bar != null) { 142 bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME); 143 } 144 145 // Create a new fragment if none exists 146 if (mInfoFragment == null) { 147 FragmentManager fragmentManager = getFragmentManager(); 148 FragmentTransaction ft = fragmentManager.beginTransaction(); 149 mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, 150 attendeeResponse, isDialog, isDialog ? 151 EventInfoFragment.DIALOG_WINDOW_STYLE : 152 EventInfoFragment.FULL_WINDOW_STYLE); 153 ft.replace(R.id.main_frame, mInfoFragment); 154 ft.commit(); 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 getContentResolver().registerContentObserver(CalendarContract.Events.CONTENT_URI, 179 true, mObserver); 180 } 181 182 @Override 183 protected void onPause() { 184 super.onPause(); 185 getContentResolver().unregisterContentObserver(mObserver); 186 } 187 188 @Override 189 protected void onDestroy() { 190 super.onDestroy(); 191 } 192} 193