EventInfoActivity.java revision 88c483a0189cbe7132330cb1b563f07326f3bcf9
1/* 2 * Copyright (C) 2007 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 */ 16 17package com.android.calendar; 18 19import static android.provider.Calendar.EVENT_BEGIN_TIME; 20import static android.provider.Calendar.EVENT_END_TIME; 21import static android.provider.Calendar.AttendeesColumns.ATTENDEE_STATUS; 22 23import android.app.Activity; 24import android.content.ActivityNotFoundException; 25import android.content.AsyncQueryHandler; 26import android.content.ContentProviderOperation; 27import android.content.ContentResolver; 28import android.content.ContentUris; 29import android.content.ContentValues; 30import android.content.Context; 31import android.content.Intent; 32import android.content.OperationApplicationException; 33import android.content.SharedPreferences; 34import android.content.res.Resources; 35import android.database.Cursor; 36import android.graphics.PorterDuff; 37import android.graphics.Rect; 38import android.net.Uri; 39import android.os.Bundle; 40import android.os.RemoteException; 41import android.pim.EventRecurrence; 42import android.provider.Calendar; 43import android.provider.ContactsContract; 44import android.provider.Calendar.Attendees; 45import android.provider.Calendar.Calendars; 46import android.provider.Calendar.Events; 47import android.provider.Calendar.Reminders; 48import android.provider.ContactsContract.CommonDataKinds; 49import android.provider.ContactsContract.Contacts; 50import android.provider.ContactsContract.Data; 51import android.provider.ContactsContract.Intents; 52import android.provider.ContactsContract.Presence; 53import android.provider.ContactsContract.QuickContact; 54import android.provider.ContactsContract.CommonDataKinds.Email; 55import android.text.TextUtils; 56import android.text.format.DateFormat; 57import android.text.format.DateUtils; 58import android.text.format.Time; 59import android.text.util.Linkify; 60import android.text.util.Rfc822Token; 61import android.util.Log; 62import android.view.KeyEvent; 63import android.view.LayoutInflater; 64import android.view.Menu; 65import android.view.MenuItem; 66import android.view.MotionEvent; 67import android.view.View; 68import android.view.View.OnTouchListener; 69import android.widget.AdapterView; 70import android.widget.ArrayAdapter; 71import android.widget.ImageButton; 72import android.widget.ImageView; 73import android.widget.LinearLayout; 74import android.widget.QuickContactBadge; 75import android.widget.Spinner; 76import android.widget.TextView; 77import android.widget.Toast; 78 79import java.util.ArrayList; 80import java.util.Arrays; 81import java.util.HashMap; 82import java.util.TimeZone; 83import java.util.regex.Pattern; 84 85public class EventInfoActivity extends Activity implements View.OnClickListener, 86 AdapterView.OnItemSelectedListener { 87 public static final boolean DEBUG = false; 88 89 public static final String TAG = "EventInfoActivity"; 90 91 private static final int MAX_REMINDERS = 5; 92 93 /** 94 * These are the corresponding indices into the array of strings 95 * "R.array.change_response_labels" in the resource file. 96 */ 97 static final int UPDATE_SINGLE = 0; 98 static final int UPDATE_ALL = 1; 99 100 private static final String[] EVENT_PROJECTION = new String[] { 101 Events._ID, // 0 do not remove; used in DeleteEventHelper 102 Events.TITLE, // 1 do not remove; used in DeleteEventHelper 103 Events.RRULE, // 2 do not remove; used in DeleteEventHelper 104 Events.ALL_DAY, // 3 do not remove; used in DeleteEventHelper 105 Events.CALENDAR_ID, // 4 do not remove; used in DeleteEventHelper 106 Events.DTSTART, // 5 do not remove; used in DeleteEventHelper 107 Events._SYNC_ID, // 6 do not remove; used in DeleteEventHelper 108 Events.EVENT_TIMEZONE, // 7 do not remove; used in DeleteEventHelper 109 Events.DESCRIPTION, // 8 110 Events.EVENT_LOCATION, // 9 111 Events.HAS_ALARM, // 10 112 Calendars.ACCESS_LEVEL, // 11 113 Calendars.COLOR, // 12 114 Events.HAS_ATTENDEE_DATA, // 13 115 Events.GUESTS_CAN_MODIFY, // 14 116 // TODO Events.GUESTS_CAN_INVITE_OTHERS has not been implemented in calendar provider 117 Events.GUESTS_CAN_INVITE_OTHERS, // 15 118 Events.ORGANIZER, // 16 119 Events.ORIGINAL_EVENT // 17 do not remove; used in DeleteEventHelper 120 }; 121 private static final int EVENT_INDEX_ID = 0; 122 private static final int EVENT_INDEX_TITLE = 1; 123 private static final int EVENT_INDEX_RRULE = 2; 124 private static final int EVENT_INDEX_ALL_DAY = 3; 125 private static final int EVENT_INDEX_CALENDAR_ID = 4; 126 private static final int EVENT_INDEX_SYNC_ID = 6; 127 private static final int EVENT_INDEX_EVENT_TIMEZONE = 7; 128 private static final int EVENT_INDEX_DESCRIPTION = 8; 129 private static final int EVENT_INDEX_EVENT_LOCATION = 9; 130 private static final int EVENT_INDEX_HAS_ALARM = 10; 131 private static final int EVENT_INDEX_ACCESS_LEVEL = 11; 132 private static final int EVENT_INDEX_COLOR = 12; 133 private static final int EVENT_INDEX_HAS_ATTENDEE_DATA = 13; 134 private static final int EVENT_INDEX_GUESTS_CAN_MODIFY = 14; 135 private static final int EVENT_INDEX_CAN_INVITE_OTHERS = 15; 136 private static final int EVENT_INDEX_ORGANIZER = 16; 137 138 private static final String[] ATTENDEES_PROJECTION = new String[] { 139 Attendees._ID, // 0 140 Attendees.ATTENDEE_NAME, // 1 141 Attendees.ATTENDEE_EMAIL, // 2 142 Attendees.ATTENDEE_RELATIONSHIP, // 3 143 Attendees.ATTENDEE_STATUS, // 4 144 }; 145 private static final int ATTENDEES_INDEX_ID = 0; 146 private static final int ATTENDEES_INDEX_NAME = 1; 147 private static final int ATTENDEES_INDEX_EMAIL = 2; 148 private static final int ATTENDEES_INDEX_RELATIONSHIP = 3; 149 private static final int ATTENDEES_INDEX_STATUS = 4; 150 151 private static final String ATTENDEES_WHERE = Attendees.EVENT_ID + "=%d"; 152 153 private static final String ATTENDEES_SORT_ORDER = Attendees.ATTENDEE_NAME + " ASC, " 154 + Attendees.ATTENDEE_EMAIL + " ASC"; 155 156 static final String[] CALENDARS_PROJECTION = new String[] { 157 Calendars._ID, // 0 158 Calendars.DISPLAY_NAME, // 1 159 Calendars.OWNER_ACCOUNT, // 2 160 Calendars.ORGANIZER_CAN_RESPOND // 3 161 }; 162 static final int CALENDARS_INDEX_DISPLAY_NAME = 1; 163 static final int CALENDARS_INDEX_OWNER_ACCOUNT = 2; 164 static final int CALENDARS_INDEX_OWNER_CAN_RESPOND = 3; 165 166 static final String CALENDARS_WHERE = Calendars._ID + "=%d"; 167 static final String CALENDARS_DUPLICATE_NAME_WHERE = Calendars.DISPLAY_NAME + "=?"; 168 169 private static final String[] REMINDERS_PROJECTION = new String[] { 170 Reminders._ID, // 0 171 Reminders.MINUTES, // 1 172 }; 173 private static final int REMINDERS_INDEX_MINUTES = 1; 174 private static final String REMINDERS_WHERE = Reminders.EVENT_ID + "=%d AND (" + 175 Reminders.METHOD + "=" + Reminders.METHOD_ALERT + " OR " + Reminders.METHOD + "=" + 176 Reminders.METHOD_DEFAULT + ")"; 177 private static final String REMINDERS_SORT = Reminders.MINUTES; 178 179 private static final int MENU_GROUP_REMINDER = 1; 180 private static final int MENU_GROUP_EDIT = 2; 181 private static final int MENU_GROUP_DELETE = 3; 182 183 private static final int MENU_ADD_REMINDER = 1; 184 private static final int MENU_EDIT = 2; 185 private static final int MENU_DELETE = 3; 186 187 private static final int ATTENDEE_ID_NONE = -1; 188 private static final int ATTENDEE_NO_RESPONSE = -1; 189 private static final int[] ATTENDEE_VALUES = { 190 ATTENDEE_NO_RESPONSE, 191 Attendees.ATTENDEE_STATUS_ACCEPTED, 192 Attendees.ATTENDEE_STATUS_TENTATIVE, 193 Attendees.ATTENDEE_STATUS_DECLINED, 194 }; 195 196 private LinearLayout mRemindersContainer; 197 private LinearLayout mOrganizerContainer; 198 private TextView mOrganizerView; 199 200 private Uri mUri; 201 private long mEventId; 202 private Cursor mEventCursor; 203 private Cursor mAttendeesCursor; 204 private Cursor mCalendarsCursor; 205 206 private long mStartMillis; 207 private long mEndMillis; 208 209 private boolean mHasAttendeeData; 210 private boolean mIsOrganizer; 211 private long mCalendarOwnerAttendeeId = ATTENDEE_ID_NONE; 212 private boolean mOrganizerCanRespond; 213 private String mCalendarOwnerAccount; 214 private boolean mCanModifyCalendar; 215 private boolean mIsBusyFreeCalendar; 216 private boolean mCanModifyEvent; 217 private int mNumOfAttendees; 218 private String mOrganizer; 219 220 private ArrayList<Integer> mOriginalMinutes = new ArrayList<Integer>(); 221 private ArrayList<LinearLayout> mReminderItems = new ArrayList<LinearLayout>(0); 222 private ArrayList<Integer> mReminderValues; 223 private ArrayList<String> mReminderLabels; 224 private int mDefaultReminderMinutes; 225 private boolean mOriginalHasAlarm; 226 227 private DeleteEventHelper mDeleteEventHelper; 228 private EditResponseHelper mEditResponseHelper; 229 230 private int mResponseOffset; 231 private int mOriginalAttendeeResponse; 232 private int mAttendeeResponseFromIntent = ATTENDEE_NO_RESPONSE; 233 private boolean mIsRepeating; 234 private boolean mIsDuplicateName; 235 236 private Pattern mWildcardPattern = Pattern.compile("^.*$"); 237 private LayoutInflater mLayoutInflater; 238 private LinearLayout mReminderAdder; 239 240 // TODO This can be removed when the contacts content provider doesn't return duplicates 241 private int mUpdateCounts; 242 private static class ViewHolder { 243 QuickContactBadge badge; 244 ImageView presence; 245 int updateCounts; 246 } 247 private HashMap<String, ViewHolder> mViewHolders = new HashMap<String, ViewHolder>(); 248 private PresenceQueryHandler mPresenceQueryHandler; 249 250 private static final Uri CONTACT_DATA_WITH_PRESENCE_URI = Data.CONTENT_URI; 251 252 int PRESENCE_PROJECTION_CONTACT_ID_INDEX = 0; 253 int PRESENCE_PROJECTION_PRESENCE_INDEX = 1; 254 int PRESENCE_PROJECTION_EMAIL_INDEX = 2; 255 int PRESENCE_PROJECTION_PHOTO_ID_INDEX = 3; 256 257 private static final String[] PRESENCE_PROJECTION = new String[] { 258 Email.CONTACT_ID, // 0 259 Email.CONTACT_PRESENCE, // 1 260 Email.DATA, // 2 261 Email.PHOTO_ID, // 3 262 }; 263 264 ArrayList<Attendee> mAcceptedAttendees = new ArrayList<Attendee>(); 265 ArrayList<Attendee> mDeclinedAttendees = new ArrayList<Attendee>(); 266 ArrayList<Attendee> mTentativeAttendees = new ArrayList<Attendee>(); 267 ArrayList<Attendee> mNoResponseAttendees = new ArrayList<Attendee>(); 268 private int mColor; 269 270 // This is called when one of the "remove reminder" buttons is selected. 271 public void onClick(View v) { 272 LinearLayout reminderItem = (LinearLayout) v.getParent(); 273 LinearLayout parent = (LinearLayout) reminderItem.getParent(); 274 parent.removeView(reminderItem); 275 mReminderItems.remove(reminderItem); 276 updateRemindersVisibility(); 277 } 278 279 public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { 280 // If they selected the "No response" option, then don't display the 281 // dialog asking which events to change. 282 if (id == 0 && mResponseOffset == 0) { 283 return; 284 } 285 286 // If this is not a repeating event, then don't display the dialog 287 // asking which events to change. 288 if (!mIsRepeating) { 289 return; 290 } 291 292 // If the selection is the same as the original, then don't display the 293 // dialog asking which events to change. 294 int index = findResponseIndexFor(mOriginalAttendeeResponse); 295 if (position == index + mResponseOffset) { 296 return; 297 } 298 299 // This is a repeating event. We need to ask the user if they mean to 300 // change just this one instance or all instances. 301 mEditResponseHelper.showDialog(mEditResponseHelper.getWhichEvents()); 302 } 303 304 public void onNothingSelected(AdapterView<?> parent) { 305 } 306 307 @Override 308 protected void onCreate(Bundle icicle) { 309 super.onCreate(icicle); 310 311 // Event cursor 312 Intent intent = getIntent(); 313 mUri = intent.getData(); 314 ContentResolver cr = getContentResolver(); 315 mStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0); 316 mEndMillis = intent.getLongExtra(EVENT_END_TIME, 0); 317 mAttendeeResponseFromIntent = intent.getIntExtra(ATTENDEE_STATUS, ATTENDEE_NO_RESPONSE); 318 mEventCursor = managedQuery(mUri, EVENT_PROJECTION, null, null, null); 319 if (initEventCursor()) { 320 // The cursor is empty. This can happen if the event was deleted. 321 finish(); 322 return; 323 } 324 325 setContentView(R.layout.event_info_activity); 326 mPresenceQueryHandler = new PresenceQueryHandler(this, cr); 327 mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 328 mRemindersContainer = (LinearLayout) findViewById(R.id.reminders_container); 329 mOrganizerContainer = (LinearLayout) findViewById(R.id.organizer_container); 330 mOrganizerView = (TextView) findViewById(R.id.organizer); 331 332 // Calendars cursor 333 Uri uri = Calendars.CONTENT_URI; 334 String where = String.format(CALENDARS_WHERE, mEventCursor.getLong(EVENT_INDEX_CALENDAR_ID)); 335 mCalendarsCursor = managedQuery(uri, CALENDARS_PROJECTION, where, null, null); 336 mCalendarOwnerAccount = ""; 337 if (mCalendarsCursor != null) { 338 mCalendarsCursor.moveToFirst(); 339 String tempAccount = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT); 340 mCalendarOwnerAccount = (tempAccount == null) ? "" : tempAccount; 341 mOrganizerCanRespond = mCalendarsCursor.getInt(CALENDARS_INDEX_OWNER_CAN_RESPOND) != 0; 342 343 String displayName = mCalendarsCursor.getString(CALENDARS_INDEX_DISPLAY_NAME); 344 mIsDuplicateName = isDuplicateName(displayName); 345 } 346 String eventOrganizer = mEventCursor.getString(EVENT_INDEX_ORGANIZER); 347 mIsOrganizer = mCalendarOwnerAccount.equalsIgnoreCase(eventOrganizer); 348 mHasAttendeeData = mEventCursor.getInt(EVENT_INDEX_HAS_ATTENDEE_DATA) != 0; 349 350 updateView(); 351 352 // Attendees cursor 353 uri = Attendees.CONTENT_URI; 354 where = String.format(ATTENDEES_WHERE, mEventId); 355 mAttendeesCursor = managedQuery(uri, ATTENDEES_PROJECTION, where, null, 356 ATTENDEES_SORT_ORDER); 357 initAttendeesCursor(); 358 359 mOrganizer = eventOrganizer; 360 mCanModifyCalendar = 361 mEventCursor.getInt(EVENT_INDEX_ACCESS_LEVEL) >= Calendars.CONTRIBUTOR_ACCESS; 362 mIsBusyFreeCalendar = 363 mEventCursor.getInt(EVENT_INDEX_ACCESS_LEVEL) == Calendars.FREEBUSY_ACCESS; 364 365 mCanModifyEvent = mCanModifyCalendar 366 && (mIsOrganizer || (mEventCursor.getInt(EVENT_INDEX_GUESTS_CAN_MODIFY) != 0)); 367 368 // Initialize the reminder values array. 369 Resources r = getResources(); 370 String[] strings = r.getStringArray(R.array.reminder_minutes_values); 371 int size = strings.length; 372 ArrayList<Integer> list = new ArrayList<Integer>(size); 373 for (int i = 0 ; i < size ; i++) { 374 list.add(Integer.parseInt(strings[i])); 375 } 376 mReminderValues = list; 377 String[] labels = r.getStringArray(R.array.reminder_minutes_labels); 378 mReminderLabels = new ArrayList<String>(Arrays.asList(labels)); 379 380 SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this); 381 String durationString = 382 prefs.getString(CalendarPreferenceActivity.KEY_DEFAULT_REMINDER, "0"); 383 mDefaultReminderMinutes = Integer.parseInt(durationString); 384 385 // Reminders cursor 386 boolean hasAlarm = mEventCursor.getInt(EVENT_INDEX_HAS_ALARM) != 0; 387 if (hasAlarm) { 388 uri = Reminders.CONTENT_URI; 389 where = String.format(REMINDERS_WHERE, mEventId); 390 Cursor reminderCursor = cr.query(uri, REMINDERS_PROJECTION, where, null, 391 REMINDERS_SORT); 392 try { 393 // First pass: collect all the custom reminder minutes (e.g., 394 // a reminder of 8 minutes) into a global list. 395 while (reminderCursor.moveToNext()) { 396 int minutes = reminderCursor.getInt(REMINDERS_INDEX_MINUTES); 397 EditEvent.addMinutesToList(this, mReminderValues, mReminderLabels, minutes); 398 } 399 400 // Second pass: create the reminder spinners 401 reminderCursor.moveToPosition(-1); 402 while (reminderCursor.moveToNext()) { 403 int minutes = reminderCursor.getInt(REMINDERS_INDEX_MINUTES); 404 mOriginalMinutes.add(minutes); 405 EditEvent.addReminder(this, this, mReminderItems, mReminderValues, 406 mReminderLabels, minutes); 407 } 408 } finally { 409 reminderCursor.close(); 410 } 411 } 412 mOriginalHasAlarm = hasAlarm; 413 414 // Setup the + Add Reminder Button 415 View.OnClickListener addReminderOnClickListener = new View.OnClickListener() { 416 public void onClick(View v) { 417 addReminder(); 418 } 419 }; 420 ImageButton reminderAddButton = (ImageButton) findViewById(R.id.reminder_add); 421 reminderAddButton.setOnClickListener(addReminderOnClickListener); 422 423 mReminderAdder = (LinearLayout) findViewById(R.id.reminder_adder); 424 updateRemindersVisibility(); 425 426 mDeleteEventHelper = new DeleteEventHelper(this, true /* exit when done */); 427 mEditResponseHelper = new EditResponseHelper(this); 428 } 429 430 @Override 431 protected void onResume() { 432 super.onResume(); 433 if (initEventCursor()) { 434 // The cursor is empty. This can happen if the event was deleted. 435 finish(); 436 return; 437 } 438 initCalendarsCursor(); 439 updateResponse(); 440 updateTitle(); 441 } 442 443 private void updateTitle() { 444 Resources res = getResources(); 445 if (mCanModifyCalendar && !mIsOrganizer) { 446 setTitle(res.getString(R.string.event_info_title_invite)); 447 } else { 448 setTitle(res.getString(R.string.event_info_title)); 449 } 450 } 451 452 boolean isDuplicateName(String displayName) { 453 Cursor dupNameCursor = managedQuery(Calendars.CONTENT_URI, CALENDARS_PROJECTION, 454 CALENDARS_DUPLICATE_NAME_WHERE, new String[] {displayName}, null); 455 boolean isDuplicateName = false; 456 if(dupNameCursor != null) { 457 if (dupNameCursor.getCount() > 1) { 458 isDuplicateName = true; 459 } 460 dupNameCursor.close(); 461 } 462 return isDuplicateName; 463 } 464 465 /** 466 * Initializes the event cursor, which is expected to point to the first 467 * (and only) result from a query. 468 * @return true if the cursor is empty. 469 */ 470 private boolean initEventCursor() { 471 if ((mEventCursor == null) || (mEventCursor.getCount() == 0)) { 472 return true; 473 } 474 mEventCursor.moveToFirst(); 475 mEventId = mEventCursor.getInt(EVENT_INDEX_ID); 476 String rRule = mEventCursor.getString(EVENT_INDEX_RRULE); 477 mIsRepeating = (rRule != null); 478 return false; 479 } 480 481 private static class Attendee { 482 String mName; 483 String mEmail; 484 485 Attendee(String name, String email) { 486 mName = name; 487 mEmail = email; 488 } 489 } 490 491 @SuppressWarnings("fallthrough") 492 private void initAttendeesCursor() { 493 mOriginalAttendeeResponse = ATTENDEE_NO_RESPONSE; 494 mCalendarOwnerAttendeeId = ATTENDEE_ID_NONE; 495 mNumOfAttendees = 0; 496 if (mAttendeesCursor != null) { 497 mNumOfAttendees = mAttendeesCursor.getCount(); 498 if (mAttendeesCursor.moveToFirst()) { 499 mAcceptedAttendees.clear(); 500 mDeclinedAttendees.clear(); 501 mTentativeAttendees.clear(); 502 mNoResponseAttendees.clear(); 503 504 do { 505 int status = mAttendeesCursor.getInt(ATTENDEES_INDEX_STATUS); 506 String name = mAttendeesCursor.getString(ATTENDEES_INDEX_NAME); 507 String email = mAttendeesCursor.getString(ATTENDEES_INDEX_EMAIL); 508 509 if (mAttendeesCursor.getInt(ATTENDEES_INDEX_RELATIONSHIP) == 510 Attendees.RELATIONSHIP_ORGANIZER) { 511 // Overwrites the one from Event table if available 512 if (name != null && name.length() > 0) { 513 mOrganizer = name; 514 } else if (email != null && email.length() > 0) { 515 mOrganizer = email; 516 } 517 } 518 519 if (mCalendarOwnerAttendeeId == ATTENDEE_ID_NONE && 520 mCalendarOwnerAccount.equalsIgnoreCase(email)) { 521 mCalendarOwnerAttendeeId = mAttendeesCursor.getInt(ATTENDEES_INDEX_ID); 522 mOriginalAttendeeResponse = mAttendeesCursor.getInt(ATTENDEES_INDEX_STATUS); 523 } else { 524 // Don't show your own status in the list because: 525 // 1) it doesn't make sense for event without other guests. 526 // 2) there's a spinner for that for events with guests. 527 switch(status) { 528 case Attendees.ATTENDEE_STATUS_ACCEPTED: 529 mAcceptedAttendees.add(new Attendee(name, email)); 530 break; 531 case Attendees.ATTENDEE_STATUS_DECLINED: 532 mDeclinedAttendees.add(new Attendee(name, email)); 533 break; 534 case Attendees.ATTENDEE_STATUS_NONE: 535 mNoResponseAttendees.add(new Attendee(name, email)); 536 // Fallthrough so that no response is a subset of tentative 537 default: 538 mTentativeAttendees.add(new Attendee(name, email)); 539 } 540 } 541 } while (mAttendeesCursor.moveToNext()); 542 mAttendeesCursor.moveToFirst(); 543 544 updateAttendees(); 545 } 546 } 547 // only show the organizer if we're not the organizer and if 548 // we have attendee data (might have been removed by the server 549 // for events with a lot of attendees). 550 if (!mIsOrganizer && mHasAttendeeData) { 551 mOrganizerContainer.setVisibility(View.VISIBLE); 552 mOrganizerView.setText(mOrganizer); 553 } else { 554 mOrganizerContainer.setVisibility(View.GONE); 555 } 556 } 557 558 private void initCalendarsCursor() { 559 if (mCalendarsCursor != null) { 560 mCalendarsCursor.moveToFirst(); 561 } 562 } 563 564 @Override 565 public void onPause() { 566 super.onPause(); 567 if (!isFinishing()) { 568 return; 569 } 570 ContentResolver cr = getContentResolver(); 571 ArrayList<Integer> reminderMinutes = EditEvent.reminderItemsToMinutes(mReminderItems, 572 mReminderValues); 573 ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(3); 574 boolean changed = EditEvent.saveReminders(ops, mEventId, reminderMinutes, mOriginalMinutes, 575 false /* no force save */); 576 try { 577 // TODO Run this in a background process. 578 cr.applyBatch(Calendars.CONTENT_URI.getAuthority(), ops); 579 // Update the "hasAlarm" field for the event 580 Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId); 581 int len = reminderMinutes.size(); 582 boolean hasAlarm = len > 0; 583 if (hasAlarm != mOriginalHasAlarm) { 584 ContentValues values = new ContentValues(); 585 values.put(Events.HAS_ALARM, hasAlarm ? 1 : 0); 586 cr.update(uri, values, null, null); 587 } 588 } catch (RemoteException e) { 589 Log.w(TAG, "Ignoring exception: ", e); 590 } catch (OperationApplicationException e) { 591 Log.w(TAG, "Ignoring exception: ", e); 592 } 593 594 changed |= saveResponse(cr); 595 if (changed) { 596 Toast.makeText(this, R.string.saving_event, Toast.LENGTH_SHORT).show(); 597 } 598 } 599 600 @Override 601 public boolean onCreateOptionsMenu(Menu menu) { 602 MenuItem item; 603 item = menu.add(MENU_GROUP_REMINDER, MENU_ADD_REMINDER, 0, 604 R.string.add_new_reminder); 605 item.setIcon(R.drawable.ic_menu_reminder); 606 item.setAlphabeticShortcut('r'); 607 608 item = menu.add(MENU_GROUP_EDIT, MENU_EDIT, 0, R.string.edit_event_label); 609 item.setIcon(android.R.drawable.ic_menu_edit); 610 item.setAlphabeticShortcut('e'); 611 612 item = menu.add(MENU_GROUP_DELETE, MENU_DELETE, 0, R.string.delete_event_label); 613 item.setIcon(android.R.drawable.ic_menu_delete); 614 615 return super.onCreateOptionsMenu(menu); 616 } 617 618 @Override 619 public boolean onPrepareOptionsMenu(Menu menu) { 620 boolean canAddReminders = canAddReminders(); 621 menu.setGroupVisible(MENU_GROUP_REMINDER, canAddReminders); 622 menu.setGroupEnabled(MENU_GROUP_REMINDER, canAddReminders); 623 624 menu.setGroupVisible(MENU_GROUP_EDIT, mCanModifyEvent); 625 menu.setGroupEnabled(MENU_GROUP_EDIT, mCanModifyEvent); 626 menu.setGroupVisible(MENU_GROUP_DELETE, mCanModifyCalendar); 627 menu.setGroupEnabled(MENU_GROUP_DELETE, mCanModifyCalendar); 628 629 return super.onPrepareOptionsMenu(menu); 630 } 631 632 private boolean canAddReminders() { 633 return !mIsBusyFreeCalendar && mReminderItems.size() < MAX_REMINDERS; 634 } 635 636 private void addReminder() { 637 // TODO: when adding a new reminder, make it different from the 638 // last one in the list (if any). 639 if (mDefaultReminderMinutes == 0) { 640 EditEvent.addReminder(this, this, mReminderItems, 641 mReminderValues, mReminderLabels, 10 /* minutes */); 642 } else { 643 EditEvent.addReminder(this, this, mReminderItems, 644 mReminderValues, mReminderLabels, mDefaultReminderMinutes); 645 } 646 updateRemindersVisibility(); 647 } 648 649 @Override 650 public boolean onOptionsItemSelected(MenuItem item) { 651 super.onOptionsItemSelected(item); 652 switch (item.getItemId()) { 653 case MENU_ADD_REMINDER: 654 addReminder(); 655 break; 656 case MENU_EDIT: 657 doEdit(); 658 break; 659 case MENU_DELETE: 660 doDelete(); 661 break; 662 } 663 return true; 664 } 665 666 @Override 667 public boolean onKeyDown(int keyCode, KeyEvent event) { 668 if (keyCode == KeyEvent.KEYCODE_DEL) { 669 doDelete(); 670 return true; 671 } 672 return super.onKeyDown(keyCode, event); 673 } 674 675 private void updateRemindersVisibility() { 676 if (mIsBusyFreeCalendar) { 677 mRemindersContainer.setVisibility(View.GONE); 678 } else { 679 mRemindersContainer.setVisibility(View.VISIBLE); 680 mReminderAdder.setVisibility(canAddReminders() ? View.VISIBLE : View.GONE); 681 } 682 } 683 684 /** 685 * Saves the response to an invitation if the user changed the response. 686 * Returns true if the database was updated. 687 * 688 * @param cr the ContentResolver 689 * @return true if the database was changed 690 */ 691 private boolean saveResponse(ContentResolver cr) { 692 if (mAttendeesCursor == null || mEventCursor == null) { 693 return false; 694 } 695 Spinner spinner = (Spinner) findViewById(R.id.response_value); 696 int position = spinner.getSelectedItemPosition() - mResponseOffset; 697 if (position <= 0) { 698 return false; 699 } 700 701 int status = ATTENDEE_VALUES[position]; 702 703 // If the status has not changed, then don't update the database 704 if (status == mOriginalAttendeeResponse) { 705 return false; 706 } 707 708 // If we never got an owner attendee id we can't set the status 709 if (mCalendarOwnerAttendeeId == ATTENDEE_ID_NONE) { 710 return false; 711 } 712 713 if (!mIsRepeating) { 714 // This is a non-repeating event 715 updateResponse(cr, mEventId, mCalendarOwnerAttendeeId, status); 716 return true; 717 } 718 719 // This is a repeating event 720 int whichEvents = mEditResponseHelper.getWhichEvents(); 721 switch (whichEvents) { 722 case -1: 723 return false; 724 case UPDATE_SINGLE: 725 createExceptionResponse(cr, mEventId, mCalendarOwnerAttendeeId, status); 726 return true; 727 case UPDATE_ALL: 728 updateResponse(cr, mEventId, mCalendarOwnerAttendeeId, status); 729 return true; 730 default: 731 Log.e(TAG, "Unexpected choice for updating invitation response"); 732 break; 733 } 734 return false; 735 } 736 737 private void updateResponse(ContentResolver cr, long eventId, long attendeeId, int status) { 738 // Update the attendee status in the attendees table. the provider 739 // takes care of updating the self attendance status. 740 ContentValues values = new ContentValues(); 741 742 if (!TextUtils.isEmpty(mCalendarOwnerAccount)) { 743 values.put(Attendees.ATTENDEE_EMAIL, mCalendarOwnerAccount); 744 } 745 values.put(Attendees.ATTENDEE_STATUS, status); 746 values.put(Attendees.EVENT_ID, eventId); 747 748 Uri uri = ContentUris.withAppendedId(Attendees.CONTENT_URI, attendeeId); 749 cr.update(uri, values, null /* where */, null /* selection args */); 750 } 751 752 private void createExceptionResponse(ContentResolver cr, long eventId, 753 long attendeeId, int status) { 754 // Fetch information about the repeating event. 755 Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId); 756 Cursor cursor = cr.query(uri, EVENT_PROJECTION, null, null, null); 757 if (cursor == null) { 758 return; 759 } 760 if(!cursor.moveToFirst()) { 761 cursor.close(); 762 return; 763 } 764 765 try { 766 ContentValues values = new ContentValues(); 767 768 String title = cursor.getString(EVENT_INDEX_TITLE); 769 String timezone = cursor.getString(EVENT_INDEX_EVENT_TIMEZONE); 770 int calendarId = cursor.getInt(EVENT_INDEX_CALENDAR_ID); 771 boolean allDay = cursor.getInt(EVENT_INDEX_ALL_DAY) != 0; 772 String syncId = cursor.getString(EVENT_INDEX_SYNC_ID); 773 774 values.put(Events.TITLE, title); 775 values.put(Events.EVENT_TIMEZONE, timezone); 776 values.put(Events.ALL_DAY, allDay ? 1 : 0); 777 values.put(Events.CALENDAR_ID, calendarId); 778 values.put(Events.DTSTART, mStartMillis); 779 values.put(Events.DTEND, mEndMillis); 780 values.put(Events.ORIGINAL_EVENT, syncId); 781 values.put(Events.ORIGINAL_INSTANCE_TIME, mStartMillis); 782 values.put(Events.ORIGINAL_ALL_DAY, allDay ? 1 : 0); 783 values.put(Events.STATUS, Events.STATUS_CONFIRMED); 784 values.put(Events.SELF_ATTENDEE_STATUS, status); 785 786 // Create a recurrence exception 787 cr.insert(Events.CONTENT_URI, values); 788 } finally { 789 cursor.close(); 790 } 791 } 792 793 private int findResponseIndexFor(int response) { 794 int size = ATTENDEE_VALUES.length; 795 for (int index = 0; index < size; index++) { 796 if (ATTENDEE_VALUES[index] == response) { 797 return index; 798 } 799 } 800 return 0; 801 } 802 803 private void doEdit() { 804 Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId); 805 Intent intent = new Intent(Intent.ACTION_EDIT, uri); 806 intent.putExtra(Calendar.EVENT_BEGIN_TIME, mStartMillis); 807 intent.putExtra(Calendar.EVENT_END_TIME, mEndMillis); 808 intent.setClass(EventInfoActivity.this, EditEventActivity.class); 809 startActivity(intent); 810 finish(); 811 } 812 813 private void doDelete() { 814 mDeleteEventHelper.delete(mStartMillis, mEndMillis, mEventCursor.getLong(EVENT_INDEX_ID), 815 -1); 816 } 817 818 private void updateView() { 819 if (mEventCursor == null) { 820 return; 821 } 822 823 String eventName = mEventCursor.getString(EVENT_INDEX_TITLE); 824 if (eventName == null || eventName.length() == 0) { 825 Resources res = getResources(); 826 eventName = res.getString(R.string.no_title_label); 827 } 828 829 boolean allDay = mEventCursor.getInt(EVENT_INDEX_ALL_DAY) != 0; 830 String location = mEventCursor.getString(EVENT_INDEX_EVENT_LOCATION); 831 String description = mEventCursor.getString(EVENT_INDEX_DESCRIPTION); 832 String rRule = mEventCursor.getString(EVENT_INDEX_RRULE); 833 boolean hasAlarm = mEventCursor.getInt(EVENT_INDEX_HAS_ALARM) != 0; 834 String eventTimezone = mEventCursor.getString(EVENT_INDEX_EVENT_TIMEZONE); 835 mColor = mEventCursor.getInt(EVENT_INDEX_COLOR) & 0xbbffffff; 836 837 View calBackground = findViewById(R.id.cal_background); 838 calBackground.setBackgroundColor(mColor); 839 840 TextView title = (TextView) findViewById(R.id.title); 841 title.setTextColor(mColor); 842 843 View divider = findViewById(R.id.divider); 844 divider.getBackground().setColorFilter(mColor, PorterDuff.Mode.SRC_IN); 845 846 // What 847 if (eventName != null) { 848 setTextCommon(R.id.title, eventName); 849 } 850 851 // When 852 String when; 853 int flags; 854 if (allDay) { 855 flags = DateUtils.FORMAT_UTC | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE; 856 } else { 857 flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE; 858 if (DateFormat.is24HourFormat(this)) { 859 flags |= DateUtils.FORMAT_24HOUR; 860 } 861 } 862 when = DateUtils.formatDateRange(this, mStartMillis, mEndMillis, flags); 863 setTextCommon(R.id.when, when); 864 865 // Show the event timezone if it is different from the local timezone 866 Time time = new Time(); 867 String localTimezone = time.timezone; 868 if (allDay) { 869 localTimezone = Time.TIMEZONE_UTC; 870 } 871 if (eventTimezone != null && !localTimezone.equals(eventTimezone) && !allDay) { 872 String displayName; 873 TimeZone tz = TimeZone.getTimeZone(localTimezone); 874 if (tz == null || tz.getID().equals("GMT")) { 875 displayName = localTimezone; 876 } else { 877 displayName = tz.getDisplayName(); 878 } 879 880 setTextCommon(R.id.timezone, displayName); 881 } else { 882 setVisibilityCommon(R.id.timezone_container, View.GONE); 883 } 884 885 // Repeat 886 if (rRule != null) { 887 EventRecurrence eventRecurrence = new EventRecurrence(); 888 eventRecurrence.parse(rRule); 889 Time date = new Time(); 890 if (allDay) { 891 date.timezone = Time.TIMEZONE_UTC; 892 } 893 date.set(mStartMillis); 894 eventRecurrence.setStartDate(date); 895 String repeatString = EventRecurrenceFormatter.getRepeatString(getResources(), 896 eventRecurrence); 897 setTextCommon(R.id.repeat, repeatString); 898 } else { 899 setVisibilityCommon(R.id.repeat_container, View.GONE); 900 } 901 902 // Where 903 if (location == null || location.length() == 0) { 904 setVisibilityCommon(R.id.where, View.GONE); 905 } else { 906 final TextView textView = (TextView) findViewById(R.id.where); 907 if (textView != null) { 908 textView.setAutoLinkMask(0); 909 textView.setText(location); 910 Linkify.addLinks(textView, mWildcardPattern, "geo:0,0?q="); 911 textView.setOnTouchListener(new OnTouchListener() { 912 public boolean onTouch(View v, MotionEvent event) { 913 try { 914 return v.onTouchEvent(event); 915 } catch (ActivityNotFoundException e) { 916 // ignore 917 return true; 918 } 919 } 920 }); 921 } 922 } 923 924 // Description 925 if (description == null || description.length() == 0) { 926 setVisibilityCommon(R.id.description, View.GONE); 927 } else { 928 setTextCommon(R.id.description, description); 929 } 930 931 // Calendar 932 if (mCalendarsCursor != null) { 933 String calendarName = mCalendarsCursor.getString(CALENDARS_INDEX_DISPLAY_NAME); 934 String ownerAccount = mCalendarsCursor.getString(CALENDARS_INDEX_OWNER_ACCOUNT); 935 if (mIsDuplicateName && !calendarName.equalsIgnoreCase(ownerAccount)) { 936 Resources res = getResources(); 937 TextView ownerText = (TextView) findViewById(R.id.owner); 938 ownerText.setText(ownerAccount); 939 ownerText.setTextColor(res.getColor(R.color.calendar_owner_text_color)); 940 } else { 941 setVisibilityCommon(R.id.owner, View.GONE); 942 } 943 setTextCommon(R.id.calendar, calendarName); 944 } else { 945 setVisibilityCommon(R.id.calendar_container, View.GONE); 946 } 947 } 948 949 private void updateAttendees() { 950 LinearLayout attendeesLayout = (LinearLayout) findViewById(R.id.attendee_list); 951 attendeesLayout.removeAllViewsInLayout(); 952 ++mUpdateCounts; 953 if(mAcceptedAttendees.size() == 0 && mDeclinedAttendees.size() == 0 && 954 mTentativeAttendees.size() == mNoResponseAttendees.size()) { 955 // If all guests have no response just list them as guests, 956 CharSequence guestsLabel = getResources().getText(R.string.attendees_label); 957 addAttendeesToLayout(mNoResponseAttendees, attendeesLayout, guestsLabel); 958 } else { 959 // If we have any responses then divide them up by response 960 CharSequence[] entries; 961 entries = getResources().getTextArray(R.array.response_labels2); 962 addAttendeesToLayout(mAcceptedAttendees, attendeesLayout, entries[0]); 963 addAttendeesToLayout(mDeclinedAttendees, attendeesLayout, entries[2]); 964 addAttendeesToLayout(mTentativeAttendees, attendeesLayout, entries[1]); 965 } 966 } 967 968 private void addAttendeesToLayout(ArrayList<Attendee> attendees, LinearLayout attendeeList, 969 CharSequence sectionTitle) { 970 if (attendees.size() == 0) { 971 return; 972 } 973 974 // Yes/No/Maybe Title 975 View titleView = mLayoutInflater.inflate(R.layout.contact_item, null); 976 titleView.findViewById(R.id.badge).setVisibility(View.GONE); 977 View divider = titleView.findViewById(R.id.separator); 978 divider.getBackground().setColorFilter(mColor, PorterDuff.Mode.SRC_IN); 979 980 TextView title = (TextView) titleView.findViewById(R.id.name); 981 title.setText(getString(R.string.response_label, sectionTitle, attendees.size())); 982 title.setTextAppearance(this, R.style.TextAppearance_EventInfo_Label); 983 attendeeList.addView(titleView); 984 985 // Attendees 986 int numOfAttendees = attendees.size(); 987 StringBuilder selection = new StringBuilder(Email.DATA + " IN ("); 988 String[] selectionArgs = new String[numOfAttendees]; 989 990 for (int i = 0; i < numOfAttendees; ++i) { 991 Attendee attendee = attendees.get(i); 992 selectionArgs[i] = attendee.mEmail; 993 994 View v = mLayoutInflater.inflate(R.layout.contact_item, null); 995 v.setTag(attendee); 996 997 View separator = v.findViewById(R.id.separator); 998 separator.getBackground().setColorFilter(mColor, PorterDuff.Mode.SRC_IN); 999 1000 // Text 1001 TextView tv = (TextView) v.findViewById(R.id.name); 1002 String name = attendee.mName; 1003 if (name == null || name.length() == 0) { 1004 name = attendee.mEmail; 1005 } 1006 tv.setText(name); 1007 1008 ViewHolder vh = new ViewHolder(); 1009 vh.badge = (QuickContactBadge) v.findViewById(R.id.badge); 1010 vh.badge.assignContactFromEmail(attendee.mEmail, true); 1011 vh.presence = (ImageView) v.findViewById(R.id.presence); 1012 mViewHolders.put(attendee.mEmail, vh); 1013 1014 if (i == 0) { 1015 selection.append('?'); 1016 } else { 1017 selection.append(", ?"); 1018 } 1019 1020 attendeeList.addView(v); 1021 } 1022 selection.append(')'); 1023 1024 mPresenceQueryHandler.startQuery(mUpdateCounts, attendees, CONTACT_DATA_WITH_PRESENCE_URI, 1025 PRESENCE_PROJECTION, selection.toString(), selectionArgs, null); 1026 } 1027 1028 private class PresenceQueryHandler extends AsyncQueryHandler { 1029 Context mContext; 1030 1031 public PresenceQueryHandler(Context context, ContentResolver cr) { 1032 super(cr); 1033 mContext = context; 1034 } 1035 1036 @Override 1037 protected void onQueryComplete(int queryIndex, Object cookie, Cursor cursor) { 1038 if (cursor == null) { 1039 if (DEBUG) { 1040 Log.e(TAG, "onQueryComplete: cursor == null"); 1041 } 1042 return; 1043 } 1044 1045 try { 1046 cursor.moveToPosition(-1); 1047 while (cursor.moveToNext()) { 1048 String email = cursor.getString(PRESENCE_PROJECTION_EMAIL_INDEX); 1049 int contactId = cursor.getInt(PRESENCE_PROJECTION_CONTACT_ID_INDEX); 1050 ViewHolder vh = mViewHolders.get(email); 1051 int photoId = cursor.getInt(PRESENCE_PROJECTION_PHOTO_ID_INDEX); 1052 if (DEBUG) { 1053 Log.e(TAG, "onQueryComplete Id: " + contactId + " PhotoId: " + photoId 1054 + " Email: " + email); 1055 } 1056 if (vh == null) { 1057 continue; 1058 } 1059 ImageView presenceView = vh.presence; 1060 if (presenceView != null) { 1061 int status = cursor.getInt(PRESENCE_PROJECTION_PRESENCE_INDEX); 1062 presenceView.setImageResource(Presence.getPresenceIconResourceId(status)); 1063 presenceView.setVisibility(View.VISIBLE); 1064 } 1065 1066 if (photoId > 0 && vh.updateCounts < queryIndex) { 1067 vh.updateCounts = queryIndex; 1068 Uri personUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); 1069 1070 // TODO, modify to batch queries together 1071 ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(mContext, vh.badge, 1072 personUri, R.drawable.ic_contact_picture); 1073 } 1074 } 1075 } finally { 1076 cursor.close(); 1077 } 1078 } 1079 } 1080 1081 void updateResponse() { 1082 // we only let the user accept/reject/etc. a meeting if: 1083 // a) you can edit the event's containing calendar AND 1084 // b) you're not the organizer and only attendee AND 1085 // c) organizerCanRespond is enabled for the calendar 1086 // (if the attendee data has been hidden, the visible number of attendees 1087 // will be 1 -- the calendar owner's). 1088 // (there are more cases involved to be 100% accurate, such as 1089 // paying attention to whether or not an attendee status was 1090 // included in the feed, but we're currently omitting those corner cases 1091 // for simplicity). 1092 if (!mCanModifyCalendar || (mHasAttendeeData && mIsOrganizer && mNumOfAttendees <= 1) || 1093 (mIsOrganizer && !mOrganizerCanRespond)) { 1094 setVisibilityCommon(R.id.response_container, View.GONE); 1095 return; 1096 } 1097 1098 setVisibilityCommon(R.id.response_container, View.VISIBLE); 1099 1100 Spinner spinner = (Spinner) findViewById(R.id.response_value); 1101 1102 mResponseOffset = 0; 1103 1104 /* If the user has previously responded to this event 1105 * we should not allow them to select no response again. 1106 * Switch the entries to a set of entries without the 1107 * no response option. 1108 */ 1109 if ((mOriginalAttendeeResponse != Attendees.ATTENDEE_STATUS_INVITED) 1110 && (mOriginalAttendeeResponse != ATTENDEE_NO_RESPONSE) 1111 && (mOriginalAttendeeResponse != Attendees.ATTENDEE_STATUS_NONE)) { 1112 CharSequence[] entries; 1113 entries = getResources().getTextArray(R.array.response_labels2); 1114 mResponseOffset = -1; 1115 ArrayAdapter<CharSequence> adapter = 1116 new ArrayAdapter<CharSequence>(this, 1117 android.R.layout.simple_spinner_item, entries); 1118 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 1119 spinner.setAdapter(adapter); 1120 } 1121 1122 int index; 1123 if (mAttendeeResponseFromIntent != ATTENDEE_NO_RESPONSE) { 1124 index = findResponseIndexFor(mAttendeeResponseFromIntent); 1125 } else { 1126 index = findResponseIndexFor(mOriginalAttendeeResponse); 1127 } 1128 spinner.setSelection(index + mResponseOffset); 1129 spinner.setOnItemSelectedListener(this); 1130 } 1131 1132 private void setTextCommon(int id, CharSequence text) { 1133 TextView textView = (TextView) findViewById(id); 1134 if (textView == null) 1135 return; 1136 textView.setText(text); 1137 } 1138 1139 private void setVisibilityCommon(int id, int visibility) { 1140 View v = findViewById(id); 1141 if (v != null) { 1142 v.setVisibility(visibility); 1143 } 1144 return; 1145 } 1146 1147 /** 1148 * Taken from com.google.android.gm.HtmlConversationActivity 1149 * 1150 * Send the intent that shows the Contact info corresponding to the email address. 1151 */ 1152 public void showContactInfo(Attendee attendee, Rect rect) { 1153 // First perform lookup query to find existing contact 1154 final ContentResolver resolver = getContentResolver(); 1155 final String address = attendee.mEmail; 1156 final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, 1157 Uri.encode(address)); 1158 final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri); 1159 1160 if (lookupUri != null) { 1161 // Found matching contact, trigger QuickContact 1162 QuickContact.showQuickContact(this, rect, lookupUri, QuickContact.MODE_MEDIUM, null); 1163 } else { 1164 // No matching contact, ask user to create one 1165 final Uri mailUri = Uri.fromParts("mailto", address, null); 1166 final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri); 1167 1168 // Pass along full E-mail string for possible create dialog 1169 Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null); 1170 intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString()); 1171 1172 // Only provide personal name hint if we have one 1173 final String senderPersonal = attendee.mName; 1174 if (!TextUtils.isEmpty(senderPersonal)) { 1175 intent.putExtra(Intents.Insert.NAME, senderPersonal); 1176 } 1177 1178 startActivity(intent); 1179 } 1180 } 1181} 1182