AllInOneActivity.java revision 4d2f035beb502dbd557fe31095c821d23b13608c
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 */ 16 17package com.android.calendar; 18 19import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME; 20import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME; 21import static android.provider.CalendarContract.Attendees.ATTENDEE_STATUS; 22import static com.android.calendar.CalendarController.EVENT_ATTENDEE_RESPONSE; 23 24import android.accounts.AccountManager; 25import android.accounts.AccountManagerCallback; 26import android.accounts.AccountManagerFuture; 27import android.accounts.AuthenticatorException; 28import android.accounts.OperationCanceledException; 29import android.animation.Animator; 30import android.animation.Animator.AnimatorListener; 31import android.animation.ObjectAnimator; 32import android.app.ActionBar; 33import android.app.ActionBar.Tab; 34import android.app.Activity; 35import android.app.Fragment; 36import android.app.FragmentManager; 37import android.app.FragmentTransaction; 38import android.content.AsyncQueryHandler; 39import android.content.BroadcastReceiver; 40import android.content.ContentResolver; 41import android.content.ContentUris; 42import android.content.Context; 43import android.content.Intent; 44import android.content.IntentFilter; 45import android.content.SharedPreferences; 46import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 47import android.content.res.Configuration; 48import android.content.res.Resources; 49import android.database.ContentObserver; 50import android.database.Cursor; 51import android.graphics.drawable.LayerDrawable; 52import android.net.Uri; 53import android.os.Bundle; 54import android.os.Handler; 55import android.provider.CalendarContract; 56import android.provider.CalendarContract.Calendars; 57import android.provider.CalendarContract.Events; 58import android.text.TextUtils; 59import android.text.format.DateFormat; 60import android.text.format.DateUtils; 61import android.text.format.Time; 62import android.util.Log; 63import android.view.Menu; 64import android.view.MenuItem; 65import android.view.View; 66import android.view.accessibility.AccessibilityEvent; 67import android.widget.LinearLayout; 68import android.widget.RelativeLayout; 69import android.widget.RelativeLayout.LayoutParams; 70import android.widget.SearchView; 71import android.widget.SearchView.OnSuggestionListener; 72import android.widget.TextView; 73 74import com.android.calendar.CalendarController.EventHandler; 75import com.android.calendar.CalendarController.EventInfo; 76import com.android.calendar.CalendarController.EventType; 77import com.android.calendar.CalendarController.ViewType; 78import com.android.calendar.agenda.AgendaFragment; 79import com.android.calendar.month.MonthByWeekFragment; 80import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment; 81 82import java.io.IOException; 83import java.util.List; 84import java.util.Locale; 85import java.util.TimeZone; 86 87public class AllInOneActivity extends Activity implements EventHandler, 88 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener, 89 ActionBar.OnNavigationListener, OnSuggestionListener { 90 private static final String TAG = "AllInOneActivity"; 91 private static final boolean DEBUG = false; 92 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment"; 93 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time"; 94 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id"; 95 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view"; 96 private static final String BUNDLE_KEY_CHECK_ACCOUNTS = "key_check_for_accounts"; 97 private static final int HANDLER_KEY = 0; 98 private static float mScale = 0; 99 100 // Indices of buttons for the drop down menu (tabs replacement) 101 // Must match the strings in the array buttons_list in arrays.xml and the 102 // OnNavigationListener 103 private static final int BUTTON_DAY_INDEX = 0; 104 private static final int BUTTON_WEEK_INDEX = 1; 105 private static final int BUTTON_MONTH_INDEX = 2; 106 private static final int BUTTON_AGENDA_INDEX = 3; 107 108 private CalendarController mController; 109 private static boolean mIsMultipane; 110 private static boolean mIsTabletConfig; 111 private static boolean mShowAgendaWithMonth; 112 private static boolean mShowEventDetailsWithAgenda; 113 private boolean mOnSaveInstanceStateCalled = false; 114 private boolean mBackToPreviousView = false; 115 private ContentResolver mContentResolver; 116 private int mPreviousView; 117 private int mCurrentView; 118 private boolean mPaused = true; 119 private boolean mUpdateOnResume = false; 120 private boolean mHideControls = false; 121 private boolean mShowSideViews = true; 122 private boolean mShowWeekNum = false; 123 private TextView mHomeTime; 124 private TextView mDateRange; 125 private TextView mWeekTextView; 126 private View mMiniMonth; 127 private View mCalendarsList; 128 private View mMiniMonthContainer; 129 private View mSecondaryPane; 130 private String mTimeZone; 131 private boolean mShowCalendarControls; 132 private boolean mShowEventInfoFullScreenAgenda; 133 private boolean mShowEventInfoFullScreen; 134 private int mWeekNum; 135 private int mCalendarControlsAnimationTime; 136 private int mControlsAnimateWidth; 137 private int mControlsAnimateHeight; 138 139 private long mViewEventId = -1; 140 private long mIntentEventStartMillis = -1; 141 private long mIntentEventEndMillis = -1; 142 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE; 143 144 // Action bar and Navigation bar (left side of Action bar) 145 private ActionBar mActionBar; 146 private ActionBar.Tab mDayTab; 147 private ActionBar.Tab mWeekTab; 148 private ActionBar.Tab mMonthTab; 149 private ActionBar.Tab mAgendaTab; 150 private SearchView mSearchView; 151 private MenuItem mSearchMenu; 152 private MenuItem mControlsMenu; 153 private Menu mOptionsMenu; 154 private CalendarViewAdapter mActionBarMenuSpinnerAdapter; 155 private QueryHandler mHandler; 156 private boolean mCheckForAccounts = true; 157 158 private String mHideString; 159 private String mShowString; 160 161 DayOfMonthDrawable mDayOfMonthIcon; 162 Handler mMidnightUpdaterHandler; 163 164 int mOrientation; 165 166 // Params for animating the controls on the right 167 private LayoutParams mControlsParams; 168 private LinearLayout.LayoutParams mVerticalControlsParams; 169 170 private final AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() { 171 172 @Override 173 public void onAnimationCancel(Animator animation) { 174 } 175 176 @Override 177 public void onAnimationEnd(android.animation.Animator animation) { 178 int visibility = mShowSideViews ? View.VISIBLE : View.GONE; 179 mMiniMonth.setVisibility(visibility); 180 mCalendarsList.setVisibility(visibility); 181 mMiniMonthContainer.setVisibility(visibility); 182 } 183 184 @Override 185 public void onAnimationRepeat(android.animation.Animator animation) { 186 } 187 188 @Override 189 public void onAnimationStart(android.animation.Animator animation) { 190 } 191 }; 192 193 private class QueryHandler extends AsyncQueryHandler { 194 public QueryHandler(ContentResolver cr) { 195 super(cr); 196 } 197 198 @Override 199 protected void onQueryComplete(int token, Object cookie, Cursor cursor) { 200 mCheckForAccounts = false; 201 // If the query didn't return a cursor for some reason return 202 if (cursor == null || cursor.getCount() > 0 || isFinishing()) { 203 return; 204 } 205 Bundle options = new Bundle(); 206 options.putCharSequence("introMessage", 207 getResources().getString(R.string.create_an_account_desc)); 208 options.putBoolean("allowSkip", true); 209 210 AccountManager am = AccountManager.get(AllInOneActivity.this); 211 am.addAccount("com.google", CalendarContract.AUTHORITY, null, options, 212 AllInOneActivity.this, 213 new AccountManagerCallback<Bundle>() { 214 @Override 215 public void run(AccountManagerFuture<Bundle> future) { 216 if (future.isCancelled()) { 217 return; 218 } 219 try { 220 Bundle result = future.getResult(); 221 boolean setupSkipped = result.getBoolean("setupSkipped"); 222 223 if (setupSkipped) { 224 Utils.setSharedPreference(AllInOneActivity.this, 225 GeneralPreferences.KEY_SKIP_SETUP, true); 226 } 227 228 } catch (OperationCanceledException ignore) { 229 // The account creation process was canceled 230 } catch (IOException ignore) { 231 } catch (AuthenticatorException ignore) { 232 } 233 } 234 }, null); 235 } 236 } 237 238 private final Runnable mHomeTimeUpdater = new Runnable() { 239 @Override 240 public void run() { 241 updateSecondaryTitleFields(-1); 242 AllInOneActivity.this.invalidateOptionsMenu(); 243 } 244 }; 245 246 // runs every midnight and refreshes the today icon 247 private final Runnable mMidnightUpdater = new Runnable() { 248 @Override 249 public void run() { 250 AllInOneActivity.this.invalidateOptionsMenu(); 251 } 252 }; 253 254 255 // Create an observer so that we can update the views whenever a 256 // Calendar event changes. 257 private final ContentObserver mObserver = new ContentObserver(new Handler()) { 258 @Override 259 public boolean deliverSelfNotifications() { 260 return true; 261 } 262 263 @Override 264 public void onChange(boolean selfChange) { 265 eventsChanged(); 266 } 267 }; 268 269 private class CalendarBroadcastReceiver extends BroadcastReceiver { 270 271 @Override 272 public void onReceive(Context context, Intent intent) { 273 if (intent.getAction().equals(Intent.ACTION_DATE_CHANGED) || 274 intent.getAction().equals(Intent.ACTION_TIME_CHANGED) || 275 intent.getAction().equals(Intent.ACTION_LOCALE_CHANGED) || 276 intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) { 277 // Update the day of month in the today button by invalidating 278 // the option menu thus forcing it to redraw and update the day of month 279 Utils.setMidnightUpdater(mHandler, mMidnightUpdater, mTimeZone); 280 AllInOneActivity.this.invalidateOptionsMenu(); 281 } 282 } 283 } 284 285 CalendarBroadcastReceiver mCalIntentReceiver; 286 287 @Override 288 protected void onNewIntent(Intent intent) { 289 String action = intent.getAction(); 290 if (DEBUG) 291 Log.d(TAG, "New intent received " + intent.toString()); 292 // Don't change the date if we're just returning to the app's home 293 if (Intent.ACTION_VIEW.equals(action) 294 && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) { 295 long millis = parseViewAction(intent); 296 if (millis == -1) { 297 millis = Utils.timeFromIntentInMillis(intent); 298 } 299 if (millis != -1 && mViewEventId == -1 && mController != null) { 300 Time time = new Time(mTimeZone); 301 time.set(millis); 302 time.normalize(true); 303 mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT); 304 } 305 } 306 } 307 308 @Override 309 protected void onCreate(Bundle icicle) { 310 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) { 311 setTheme(R.style.CalendarTheme_WithActionBarWallpaper); 312 } 313 super.onCreate(icicle); 314 315 if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) { 316 mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS); 317 } 318 // Launch add google account if this is first time and there are no 319 // accounts yet 320 if (mCheckForAccounts 321 && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) { 322 323 mHandler = new QueryHandler(this.getContentResolver()); 324 mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] { 325 Calendars._ID 326 }, null, null /* selection args */, null /* sort order */); 327 } 328 329 // This needs to be created before setContentView 330 mController = CalendarController.getInstance(this); 331 332 333 // Get time from intent or icicle 334 long timeMillis = -1; 335 int viewType = -1; 336 final Intent intent = getIntent(); 337 if (icicle != null) { 338 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); 339 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1); 340 } else { 341 String action = intent.getAction(); 342 if (Intent.ACTION_VIEW.equals(action)) { 343 // Open EventInfo later 344 timeMillis = parseViewAction(intent); 345 } 346 347 if (timeMillis == -1) { 348 timeMillis = Utils.timeFromIntentInMillis(intent); 349 } 350 } 351 352 if (viewType == -1) { 353 viewType = Utils.getViewTypeFromIntentAndSharedPref(this); 354 } 355 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); 356 Time t = new Time(mTimeZone); 357 t.set(timeMillis); 358 359 if (DEBUG) { 360 if (icicle != null && intent != null) { 361 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); 362 } else { 363 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); 364 } 365 } 366 367 Resources res = getResources(); 368 mHideString = res.getString(R.string.hide_controls); 369 mShowString = res.getString(R.string.show_controls); 370 mOrientation = res.getConfiguration().orientation; 371 if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { 372 if (mControlsParams == null) { 373 mControlsParams = new LayoutParams(mControlsAnimateWidth, 0); 374 } 375 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 376 } 377 378 mControlsAnimateHeight = (int)res.getDimension(R.dimen.calendar_controls_height); 379 mControlsAnimateWidth = (int)res.getDimension(R.dimen.calendar_controls_width); 380 381 mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config); 382 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config); 383 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month); 384 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls); 385 mShowEventDetailsWithAgenda = 386 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda); 387 mShowEventInfoFullScreenAgenda = 388 Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen); 389 mShowEventInfoFullScreen = 390 Utils.getConfigBool(this, R.bool.show_event_info_full_screen); 391 mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time); 392 Utils.setAllowWeekForDetailView(mIsMultipane); 393 394 // setContentView must be called before configureActionBar 395 setContentView(R.layout.all_in_one); 396 397 if (mIsTabletConfig) { 398 mDateRange = (TextView) findViewById(R.id.date_bar); 399 mWeekTextView = (TextView) findViewById(R.id.week_num); 400 } else { 401 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); 402 } 403 404 // configureActionBar auto-selects the first tab you add, so we need to 405 // call it before we set up our own fragments to make sure it doesn't 406 // overwrite us 407 configureActionBar(viewType); 408 409 mHomeTime = (TextView) findViewById(R.id.home_time); 410 mMiniMonth = findViewById(R.id.mini_month); 411 mCalendarsList = findViewById(R.id.calendar_list); 412 mMiniMonthContainer = findViewById(R.id.mini_month_container); 413 mSecondaryPane = findViewById(R.id.secondary_pane); 414 415 // Must register as the first activity because this activity can modify 416 // the list of event handlers in it's handle method. This affects who 417 // the rest of the handlers the controller dispatches to are. 418 mController.registerFirstEventHandler(HANDLER_KEY, this); 419 420 initFragments(timeMillis, viewType, icicle); 421 422 // Listen for changes that would require this to be refreshed 423 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 424 prefs.registerOnSharedPreferenceChangeListener(this); 425 426 mContentResolver = getContentResolver(); 427 } 428 429 private long parseViewAction(final Intent intent) { 430 long timeMillis = -1; 431 Uri data = intent.getData(); 432 if (data != null && data.isHierarchical()) { 433 List<String> path = data.getPathSegments(); 434 if (path.size() == 2 && path.get(0).equals("events")) { 435 try { 436 mViewEventId = Long.valueOf(data.getLastPathSegment()); 437 if (mViewEventId != -1) { 438 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0); 439 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0); 440 mIntentAttendeeResponse = intent.getIntExtra( 441 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE); 442 timeMillis = mIntentEventStartMillis; 443 } 444 } catch (NumberFormatException e) { 445 // Ignore if mViewEventId can't be parsed 446 } 447 } 448 } 449 return timeMillis; 450 } 451 452 private void configureActionBar(int viewType) { 453 if (mIsTabletConfig) { 454 createTabs(); 455 } else { 456 createButtonsSpinner(viewType); 457 } 458 if (mIsMultipane) { 459 mActionBar.setDisplayOptions( 460 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); 461 } else { 462 mActionBar.setDisplayOptions(0); 463 } 464 } 465 466 private void createTabs() { 467 mActionBar = getActionBar(); 468 if (mActionBar == null) { 469 Log.w(TAG, "ActionBar is null."); 470 } else { 471 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 472 mDayTab = mActionBar.newTab(); 473 mDayTab.setText(getString(R.string.day_view)); 474 mDayTab.setTabListener(this); 475 mActionBar.addTab(mDayTab); 476 mWeekTab = mActionBar.newTab(); 477 mWeekTab.setText(getString(R.string.week_view)); 478 mWeekTab.setTabListener(this); 479 mActionBar.addTab(mWeekTab); 480 mMonthTab = mActionBar.newTab(); 481 mMonthTab.setText(getString(R.string.month_view)); 482 mMonthTab.setTabListener(this); 483 mActionBar.addTab(mMonthTab); 484 mAgendaTab = mActionBar.newTab(); 485 mAgendaTab.setText(getString(R.string.agenda_view)); 486 mAgendaTab.setTabListener(this); 487 mActionBar.addTab(mAgendaTab); 488 } 489 } 490 491 private void createButtonsSpinner(int viewType) { 492 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType); 493 mActionBar = getActionBar(); 494 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 495 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this); 496 switch (viewType) { 497 case ViewType.AGENDA: 498 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX); 499 break; 500 case ViewType.DAY: 501 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX); 502 break; 503 case ViewType.WEEK: 504 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX); 505 break; 506 case ViewType.MONTH: 507 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX); 508 break; 509 default: 510 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX); 511 break; 512 } 513 } 514 // Clear buttons used in the agenda view 515 private void clearOptionsMenu() { 516 if (mOptionsMenu == null) { 517 return; 518 } 519 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel); 520 if (cancelItem != null) { 521 cancelItem.setVisible(false); 522 } 523 } 524 525 @Override 526 protected void onResume() { 527 super.onResume(); 528 529 // Must register as the first activity because this activity can modify 530 // the list of event handlers in it's handle method. This affects who 531 // the rest of the handlers the controller dispatches to are. 532 mController.registerFirstEventHandler(HANDLER_KEY, this); 533 534 mOnSaveInstanceStateCalled = false; 535 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI, 536 true, mObserver); 537 if (mUpdateOnResume) { 538 initFragments(mController.getTime(), mController.getViewType(), null); 539 mUpdateOnResume = false; 540 } 541 Time t = new Time(mTimeZone); 542 t.set(mController.getTime()); 543 mController.sendEvent(this, EventType.UPDATE_TITLE, t, t, -1, ViewType.CURRENT, 544 mController.getDateFlags(), null, null); 545 // Make sure the drop-down menu will get its date updated at midnight 546 if (mActionBarMenuSpinnerAdapter != null) { 547 mActionBarMenuSpinnerAdapter.refresh(this); 548 } 549 550 if (mControlsMenu != null) { 551 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); 552 } 553 mPaused = false; 554 555 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) { 556 long currentMillis = System.currentTimeMillis(); 557 long selectedTime = -1; 558 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) { 559 selectedTime = currentMillis; 560 } 561 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId, 562 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1, 563 mIntentAttendeeResponse, selectedTime); 564 mViewEventId = -1; 565 mIntentEventStartMillis = -1; 566 mIntentEventEndMillis = -1; 567 } 568 if (mMidnightUpdaterHandler == null) { 569 mMidnightUpdaterHandler = new Handler(); 570 } 571 Utils.setMidnightUpdater(mHandler, mMidnightUpdater, mTimeZone); 572 // Make sure the today icon is up to date 573 invalidateOptionsMenu(); 574 575 // Register for Intent broadcasts 576 IntentFilter filter = new IntentFilter(); 577 filter.addAction(Intent.ACTION_TIME_CHANGED); 578 filter.addAction(Intent.ACTION_DATE_CHANGED); 579 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); 580 filter.addAction(Intent.ACTION_LOCALE_CHANGED); 581 if (mCalIntentReceiver == null) { 582 mCalIntentReceiver = new CalendarBroadcastReceiver(); 583 } 584 registerReceiver(mCalIntentReceiver, filter); 585 } 586 587 @Override 588 protected void onPause() { 589 super.onPause(); 590 591 mController.deregisterEventHandler(HANDLER_KEY); 592 mPaused = true; 593 mHomeTime.removeCallbacks(mHomeTimeUpdater); 594 if (mActionBarMenuSpinnerAdapter != null) { 595 mActionBarMenuSpinnerAdapter.onPause(); 596 } 597 mContentResolver.unregisterContentObserver(mObserver); 598 if (isFinishing()) { 599 // Stop listening for changes that would require this to be refreshed 600 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 601 prefs.unregisterOnSharedPreferenceChangeListener(this); 602 } 603 // FRAG_TODO save highlighted days of the week; 604 if (mController.getViewType() != ViewType.EDIT) { 605 Utils.setDefaultView(this, mController.getViewType()); 606 } 607 Utils.resetMidnightUpdater(mHandler, mMidnightUpdater); 608 unregisterReceiver(mCalIntentReceiver); 609 } 610 611 @Override 612 protected void onUserLeaveHint() { 613 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT); 614 super.onUserLeaveHint(); 615 } 616 617 @Override 618 public void onSaveInstanceState(Bundle outState) { 619 mOnSaveInstanceStateCalled = true; 620 super.onSaveInstanceState(outState); 621 622 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime()); 623 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView); 624 if (mCurrentView == ViewType.EDIT) { 625 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId()); 626 } 627 outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts); 628 } 629 630 @Override 631 protected void onDestroy() { 632 super.onDestroy(); 633 634 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 635 prefs.unregisterOnSharedPreferenceChangeListener(this); 636 637 mController.deregisterAllEventHandlers(); 638 639 CalendarController.removeInstance(this); 640 } 641 642 private void initFragments(long timeMillis, int viewType, Bundle icicle) { 643 if (DEBUG) { 644 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType); 645 } 646 FragmentTransaction ft = getFragmentManager().beginTransaction(); 647 648 if (mShowCalendarControls) { 649 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true); 650 ft.replace(R.id.mini_month, miniMonthFrag); 651 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag); 652 653 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment(); 654 ft.replace(R.id.calendar_list, selectCalendarsFrag); 655 mController.registerEventHandler( 656 R.id.calendar_list, (EventHandler) selectCalendarsFrag); 657 } 658 if (!mShowCalendarControls || viewType == ViewType.EDIT) { 659 mMiniMonth.setVisibility(View.GONE); 660 mCalendarsList.setVisibility(View.GONE); 661 } 662 663 EventInfo info = null; 664 if (viewType == ViewType.EDIT) { 665 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt( 666 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW); 667 668 long eventId = -1; 669 Intent intent = getIntent(); 670 Uri data = intent.getData(); 671 if (data != null) { 672 try { 673 eventId = Long.parseLong(data.getLastPathSegment()); 674 } catch (NumberFormatException e) { 675 if (DEBUG) { 676 Log.d(TAG, "Create new event"); 677 } 678 } 679 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { 680 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); 681 } 682 683 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1); 684 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1); 685 info = new EventInfo(); 686 if (end != -1) { 687 info.endTime = new Time(); 688 info.endTime.set(end); 689 } 690 if (begin != -1) { 691 info.startTime = new Time(); 692 info.startTime.set(begin); 693 } 694 info.id = eventId; 695 // We set the viewtype so if the user presses back when they are 696 // done editing the controller knows we were in the Edit Event 697 // screen. Likewise for eventId 698 mController.setViewType(viewType); 699 mController.setEventId(eventId); 700 } else { 701 mPreviousView = viewType; 702 } 703 704 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true); 705 ft.commit(); // this needs to be after setMainPane() 706 707 Time t = new Time(mTimeZone); 708 t.set(timeMillis); 709 if (viewType != ViewType.EDIT) { 710 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType); 711 } 712 } 713 714 @Override 715 public void onBackPressed() { 716 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) { 717 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView); 718 } else { 719 super.onBackPressed(); 720 } 721 } 722 723 @Override 724 public boolean onCreateOptionsMenu(Menu menu) { 725 super.onCreateOptionsMenu(menu); 726 mOptionsMenu = menu; 727 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu); 728 729 mSearchMenu = menu.findItem(R.id.action_search); 730 mSearchView = (SearchView) mSearchMenu.getActionView(); 731 if (mSearchView != null) { 732 Utils.setUpSearchView(mSearchView, this); 733 mSearchView.setOnQueryTextListener(this); 734 mSearchView.setOnSuggestionListener(this); 735 } 736 737 // Hide the "show/hide controls" button if this is a phone 738 // or the view type is "Month" or "Agenda". 739 740 mControlsMenu = menu.findItem(R.id.action_hide_controls); 741 if (!mShowCalendarControls) { 742 if (mControlsMenu != null) { 743 mControlsMenu.setVisible(false); 744 mControlsMenu.setEnabled(false); 745 } 746 } else if (mControlsMenu != null && mController != null 747 && (mController.getViewType() == ViewType.MONTH || 748 mController.getViewType() == ViewType.AGENDA)) { 749 mControlsMenu.setVisible(false); 750 mControlsMenu.setEnabled(false); 751 } else if (mControlsMenu != null){ 752 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); 753 } 754 755 // replace the default top layer drawable of the today icon with a custom drawable 756 // that shows the day of the month of today 757 LayerDrawable icon = (LayerDrawable)menu.findItem(R.id.action_today).getIcon(); 758 setTodayIcon(); 759 icon.mutate(); 760 icon.setDrawableByLayerId(R.id.today_icon_day, mDayOfMonthIcon); 761 return true; 762 } 763 764 @Override 765 public boolean onOptionsItemSelected(MenuItem item) { 766 Time t = null; 767 int viewType = ViewType.CURRENT; 768 long extras = CalendarController.EXTRA_GOTO_TIME; 769 switch (item.getItemId()) { 770 case R.id.action_refresh: 771 mController.refreshCalendars(); 772 return true; 773 case R.id.action_today: 774 viewType = ViewType.CURRENT; 775 t = new Time(mTimeZone); 776 t.setToNow(); 777 extras |= CalendarController.EXTRA_GOTO_TODAY; 778 break; 779 case R.id.action_create_event: 780 t = new Time(); 781 t.set(mController.getTime()); 782 if (t.minute > 30) { 783 t.hour++; 784 t.minute = 0; 785 } else if (t.minute > 0 && t.minute < 30) { 786 t.minute = 30; 787 } 788 mController.sendEventRelatedEvent( 789 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1); 790 return true; 791 case R.id.action_select_visible_calendars: 792 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null, 793 0, 0); 794 return true; 795 case R.id.action_settings: 796 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0); 797 return true; 798 case R.id.action_hide_controls: 799 mHideControls = !mHideControls; 800 item.setTitle(mHideControls ? mShowString : mHideString); 801 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 802 mHideControls ? 0 : mControlsAnimateWidth, 803 mHideControls ? mControlsAnimateWidth : 0); 804 slideAnimation.setDuration(mCalendarControlsAnimationTime); 805 ObjectAnimator.setFrameDelay(0); 806 slideAnimation.start(); 807 return true; 808 case R.id.action_search: 809 return false; 810 default: 811 return false; 812 } 813 mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null); 814 return true; 815 } 816 817 /** 818 * Sets the offset of the controls on the right for animating them off/on 819 * screen. ProGuard strips this if it's not in proguard.flags 820 * 821 * @param controlsOffset The current offset in pixels 822 */ 823 public void setControlsOffset(int controlsOffset) { 824 if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { 825 mMiniMonth.setTranslationX(controlsOffset); 826 mCalendarsList.setTranslationX(controlsOffset); 827 mControlsParams.width = Math.max(0, mControlsAnimateWidth - controlsOffset); 828 mMiniMonthContainer.setLayoutParams(mControlsParams); 829 } else { 830 mMiniMonth.setTranslationY(controlsOffset); 831 mCalendarsList.setTranslationY(controlsOffset); 832 if (mVerticalControlsParams == null) { 833 mVerticalControlsParams = new LinearLayout.LayoutParams( 834 LinearLayout.LayoutParams.MATCH_PARENT, mControlsAnimateHeight); 835 } 836 mVerticalControlsParams.height = Math.max(0, mControlsAnimateHeight - controlsOffset); 837 mMiniMonthContainer.setLayoutParams(mVerticalControlsParams); 838 } 839 } 840 841 @Override 842 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { 843 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) { 844 if (mPaused) { 845 mUpdateOnResume = true; 846 } else { 847 initFragments(mController.getTime(), mController.getViewType(), null); 848 } 849 } 850 } 851 852 private void setMainPane( 853 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) { 854 if (mOnSaveInstanceStateCalled) { 855 return; 856 } 857 if (!force && mCurrentView == viewType) { 858 return; 859 } 860 861 // Remove this when transition to and from month view looks fine. 862 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH; 863 FragmentManager fragmentManager = getFragmentManager(); 864 // Check if our previous view was an Agenda view 865 // TODO remove this if framework ever supports nested fragments 866 if (mCurrentView == ViewType.AGENDA) { 867 // If it was, we need to do some cleanup on it to prevent the 868 // edit/delete buttons from coming back on a rotation. 869 Fragment oldFrag = fragmentManager.findFragmentById(viewId); 870 if (oldFrag instanceof AgendaFragment) { 871 ((AgendaFragment) oldFrag).removeFragments(fragmentManager); 872 } 873 } 874 875 if (viewType != mCurrentView) { 876 // The rules for this previous view are different than the 877 // controller's and are used for intercepting the back button. 878 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) { 879 mPreviousView = mCurrentView; 880 } 881 mCurrentView = viewType; 882 } 883 // Create new fragment 884 Fragment frag = null; 885 Fragment secFrag = null; 886 switch (viewType) { 887 case ViewType.AGENDA: 888 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) { 889 mActionBar.selectTab(mAgendaTab); 890 } 891 if (mActionBarMenuSpinnerAdapter != null) { 892 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX); 893 } 894 frag = new AgendaFragment(timeMillis, false); 895 break; 896 case ViewType.DAY: 897 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) { 898 mActionBar.selectTab(mDayTab); 899 } 900 if (mActionBarMenuSpinnerAdapter != null) { 901 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX); 902 } 903 frag = new DayFragment(timeMillis, 1); 904 break; 905 case ViewType.WEEK: 906 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) { 907 mActionBar.selectTab(mWeekTab); 908 } 909 if (mActionBarMenuSpinnerAdapter != null) { 910 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX); 911 } 912 frag = new DayFragment(timeMillis, 7); 913 break; 914 case ViewType.MONTH: 915 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) { 916 mActionBar.selectTab(mMonthTab); 917 } 918 if (mActionBarMenuSpinnerAdapter != null) { 919 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX); 920 } 921 frag = new MonthByWeekFragment(timeMillis, false); 922 if (mShowAgendaWithMonth) { 923 secFrag = new AgendaFragment(timeMillis, false); 924 } 925 break; 926 default: 927 throw new IllegalArgumentException( 928 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType); 929 } 930 931 // Update the current view so that the menu can update its look according to the 932 // current view. 933 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) { 934 mActionBarMenuSpinnerAdapter.setTime(timeMillis); 935 mActionBarMenuSpinnerAdapter.setMainView(viewType); 936 } 937 938 939 // Show date only on tablet configurations in views different than Agenda 940 if (!mIsTabletConfig) { 941 mDateRange.setVisibility(View.GONE); 942 } else if (viewType != ViewType.AGENDA) { 943 mDateRange.setVisibility(View.VISIBLE); 944 } else { 945 mDateRange.setVisibility(View.GONE); 946 } 947 948 // Clear unnecessary buttons from the option menu when switching from the agenda view 949 if (viewType != ViewType.AGENDA) { 950 clearOptionsMenu(); 951 } 952 953 boolean doCommit = false; 954 if (ft == null) { 955 doCommit = true; 956 ft = fragmentManager.beginTransaction(); 957 } 958 959 if (doTransition) { 960 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 961 } 962 963 ft.replace(viewId, frag); 964 if (mShowAgendaWithMonth) { 965 966 // Show/hide secondary fragment 967 968 if (secFrag != null) { 969 ft.replace(R.id.secondary_pane, secFrag); 970 mSecondaryPane.setVisibility(View.VISIBLE); 971 } else { 972 mSecondaryPane.setVisibility(View.GONE); 973 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane); 974 if (f != null) { 975 ft.remove(f); 976 } 977 mController.deregisterEventHandler(R.id.secondary_pane); 978 } 979 } 980 if (DEBUG) { 981 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType); 982 } 983 // If the key is already registered this will replace it 984 mController.registerEventHandler(viewId, (EventHandler) frag); 985 if (secFrag != null) { 986 mController.registerEventHandler(viewId, (EventHandler) secFrag); 987 } 988 989 if (doCommit) { 990 if (DEBUG) { 991 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing()); 992 } 993 ft.commit(); 994 } 995 } 996 997 private void setTitleInActionBar(EventInfo event) { 998 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) { 999 return; 1000 } 1001 1002 final long start = event.startTime.toMillis(false /* use isDst */); 1003 final long end; 1004 if (event.endTime != null) { 1005 end = event.endTime.toMillis(false /* use isDst */); 1006 } else { 1007 end = start; 1008 } 1009 1010 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong); 1011 CharSequence oldDate = mDateRange.getText(); 1012 mDateRange.setText(msg); 1013 updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true) 1014 : start); 1015 if (!TextUtils.equals(oldDate, msg)) { 1016 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); 1017 if (mShowWeekNum && mWeekTextView != null) { 1018 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); 1019 } 1020 } 1021 } 1022 1023 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) { 1024 mShowWeekNum = Utils.getShowWeekNumber(this); 1025 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); 1026 if (visibleMillisSinceEpoch != -1) { 1027 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this); 1028 mWeekNum = weekNum; 1029 } 1030 1031 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig 1032 && mWeekTextView != null) { 1033 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum, 1034 mWeekNum); 1035 mWeekTextView.setText(weekString); 1036 mWeekTextView.setVisibility(View.VISIBLE); 1037 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null 1038 && mCurrentView == ViewType.DAY && mIsTabletConfig) { 1039 Time time = new Time(mTimeZone); 1040 time.set(visibleMillisSinceEpoch); 1041 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff); 1042 time.setToNow(); 1043 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff); 1044 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay, 1045 visibleMillisSinceEpoch, this); 1046 mWeekTextView.setText(dayString); 1047 mWeekTextView.setVisibility(View.VISIBLE); 1048 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) { 1049 mWeekTextView.setVisibility(View.GONE); 1050 } 1051 1052 if (mHomeTime != null 1053 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK 1054 || mCurrentView == ViewType.AGENDA) 1055 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) { 1056 Time time = new Time(mTimeZone); 1057 time.setToNow(); 1058 long millis = time.toMillis(true); 1059 boolean isDST = time.isDst != 0; 1060 int flags = DateUtils.FORMAT_SHOW_TIME; 1061 if (DateFormat.is24HourFormat(this)) { 1062 flags |= DateUtils.FORMAT_24HOUR; 1063 } 1064 // Formats the time as 1065 String timeString = (new StringBuilder( 1066 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append( 1067 TimeZone.getTimeZone(mTimeZone).getDisplayName( 1068 isDST, TimeZone.SHORT, Locale.getDefault())).toString(); 1069 mHomeTime.setText(timeString); 1070 mHomeTime.setVisibility(View.VISIBLE); 1071 // Update when the minute changes 1072 mHomeTime.removeCallbacks(mHomeTimeUpdater); 1073 mHomeTime.postDelayed( 1074 mHomeTimeUpdater, 1075 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS)); 1076 } else if (mHomeTime != null) { 1077 mHomeTime.setVisibility(View.GONE); 1078 } 1079 } 1080 1081 @Override 1082 public long getSupportedEventTypes() { 1083 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE; 1084 } 1085 1086 @Override 1087 public void handleEvent(EventInfo event) { 1088 long displayTime = -1; 1089 if (event.eventType == EventType.GO_TO) { 1090 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) { 1091 mBackToPreviousView = true; 1092 } else if (event.viewType != mController.getPreviousViewType() 1093 && event.viewType != ViewType.EDIT) { 1094 // Clear the flag is change to a different view type 1095 mBackToPreviousView = false; 1096 } 1097 1098 setMainPane( 1099 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false); 1100 if (mSearchView != null) { 1101 mSearchView.clearFocus(); 1102 } 1103 1104 if (mShowCalendarControls) { 1105 int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? 1106 mControlsAnimateWidth : mControlsAnimateHeight; 1107 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) { 1108 // hide minimonth and calendar frag 1109 mShowSideViews = false; 1110 if (mControlsMenu != null) { 1111 mControlsMenu.setVisible(false); 1112 mControlsMenu.setEnabled(false); 1113 } 1114 if (!mHideControls) { 1115 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, 1116 "controlsOffset", 0, animationSize); 1117 slideAnimation.addListener(mSlideAnimationDoneListener); 1118 slideAnimation.setDuration(mCalendarControlsAnimationTime); 1119 ObjectAnimator.setFrameDelay(0); 1120 slideAnimation.start(); 1121 } else { 1122 mMiniMonth.setVisibility(View.GONE); 1123 mCalendarsList.setVisibility(View.GONE); 1124 mMiniMonthContainer.setVisibility(View.GONE); 1125 } 1126 } else { 1127 // show minimonth and calendar frag 1128 mShowSideViews = true; 1129 mMiniMonth.setVisibility(View.VISIBLE); 1130 mCalendarsList.setVisibility(View.VISIBLE); 1131 mMiniMonthContainer.setVisibility(View.VISIBLE); 1132 if (mControlsMenu != null) { 1133 mControlsMenu.setVisible(true); 1134 mControlsMenu.setEnabled(true); 1135 } 1136 if (!mHideControls && 1137 (mController.getPreviousViewType() == ViewType.MONTH || 1138 mController.getPreviousViewType() == ViewType.AGENDA)) { 1139 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, 1140 "controlsOffset", animationSize, 0); 1141 slideAnimation.setDuration(mCalendarControlsAnimationTime); 1142 ObjectAnimator.setFrameDelay(0); 1143 slideAnimation.start(); 1144 } 1145 } 1146 } 1147 displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true) 1148 : event.startTime.toMillis(true); 1149 if (!mIsTabletConfig) { 1150 mActionBarMenuSpinnerAdapter.setTime(displayTime); 1151 } 1152 } else if (event.eventType == EventType.VIEW_EVENT) { 1153 1154 // If in Agenda view and "show_event_details_with_agenda" is "true", 1155 // do not create the event info fragment here, it will be created by the Agenda 1156 // fragment 1157 1158 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) { 1159 if (event.startTime != null && event.endTime != null) { 1160 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, 1161 event.id, ViewType.AGENDA); 1162 } else if (event.selectedTime != null) { 1163 mController.sendEvent(this, EventType.GO_TO, event.selectedTime, 1164 event.selectedTime, event.id, ViewType.AGENDA); 1165 } 1166 } else { 1167 // TODO Fix the temp hack below: && mCurrentView != 1168 // ViewType.AGENDA 1169 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) { 1170 mController.sendEvent(this, EventType.GO_TO, event.selectedTime, 1171 event.selectedTime, -1, ViewType.CURRENT); 1172 } 1173 if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda) || 1174 ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK) || 1175 mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)){ 1176 // start event info as activity 1177 Intent intent = new Intent(Intent.ACTION_VIEW); 1178 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id); 1179 intent.setData(eventUri); 1180 intent.setClass(this, EventInfoActivity.class); 1181 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | 1182 Intent.FLAG_ACTIVITY_SINGLE_TOP); 1183 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false)); 1184 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false)); 1185 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong); 1186 startActivity(intent); 1187 } else { 1188 // start event info as a dialog 1189 EventInfoFragment fragment = new EventInfoFragment(this, 1190 event.id, event.startTime.toMillis(false), 1191 event.endTime.toMillis(false), (int) event.extraLong, true, 1192 EventInfoFragment.DIALOG_WINDOW_STYLE); 1193 fragment.setDialogParams(event.x, event.y, mActionBar.getHeight()); 1194 FragmentManager fm = getFragmentManager(); 1195 FragmentTransaction ft = fm.beginTransaction(); 1196 // if we have an old popup replace it 1197 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG); 1198 if (fOld != null && fOld.isAdded()) { 1199 ft.remove(fOld); 1200 } 1201 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG); 1202 ft.commit(); 1203 } 1204 } 1205 displayTime = event.startTime.toMillis(true); 1206 } else if (event.eventType == EventType.UPDATE_TITLE) { 1207 setTitleInActionBar(event); 1208 if (!mIsTabletConfig) { 1209 mActionBarMenuSpinnerAdapter.setTime(mController.getTime()); 1210 } 1211 } 1212 updateSecondaryTitleFields(displayTime); 1213 } 1214 1215 // Needs to be in proguard whitelist 1216 // Specified as listener via android:onClick in a layout xml 1217 public void handleSelectSyncedCalendarsClicked(View v) { 1218 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0, 1219 CalendarController.EXTRA_GOTO_TIME, null, 1220 null); 1221 } 1222 1223 @Override 1224 public void eventsChanged() { 1225 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT); 1226 } 1227 1228 @Override 1229 public boolean onQueryTextChange(String newText) { 1230 return false; 1231 } 1232 1233 @Override 1234 public boolean onQueryTextSubmit(String query) { 1235 if ("TARDIS".equalsIgnoreCase(query)) { 1236 Utils.tardis(); 1237 } 1238 mSearchMenu.collapseActionView(); 1239 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query, 1240 getComponentName()); 1241 return true; 1242 } 1243 1244 @Override 1245 public void onTabSelected(Tab tab, FragmentTransaction ft) { 1246 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing()); 1247 if (tab == mDayTab && mCurrentView != ViewType.DAY) { 1248 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY); 1249 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) { 1250 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK); 1251 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) { 1252 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH); 1253 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) { 1254 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA); 1255 } else { 1256 Log.w(TAG, "TabSelected event from unknown tab: " 1257 + (tab == null ? "null" : tab.getText())); 1258 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab 1259 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab); 1260 } 1261 } 1262 1263 @Override 1264 public void onTabReselected(Tab tab, FragmentTransaction ft) { 1265 } 1266 1267 @Override 1268 public void onTabUnselected(Tab tab, FragmentTransaction ft) { 1269 } 1270 1271 1272 @Override 1273 public boolean onNavigationItemSelected(int itemPosition, long itemId) { 1274 switch (itemPosition) { 1275 case CalendarViewAdapter.DAY_BUTTON_INDEX: 1276 if (mCurrentView != ViewType.DAY) { 1277 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY); 1278 } 1279 break; 1280 case CalendarViewAdapter.WEEK_BUTTON_INDEX: 1281 if (mCurrentView != ViewType.WEEK) { 1282 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK); 1283 } 1284 break; 1285 case CalendarViewAdapter.MONTH_BUTTON_INDEX: 1286 if (mCurrentView != ViewType.MONTH) { 1287 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH); 1288 } 1289 break; 1290 case CalendarViewAdapter.AGENDA_BUTTON_INDEX: 1291 if (mCurrentView != ViewType.AGENDA) { 1292 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA); 1293 } 1294 break; 1295 default: 1296 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition); 1297 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition + 1298 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab + 1299 " Agenda:" + mAgendaTab); 1300 break; 1301 } 1302 return false; 1303 } 1304 1305 @Override 1306 public boolean onSuggestionSelect(int position) { 1307 return false; 1308 } 1309 1310 @Override 1311 public boolean onSuggestionClick(int position) { 1312 mSearchMenu.collapseActionView(); 1313 return false; 1314 } 1315 1316 @Override 1317 public boolean onSearchRequested() { 1318 if (mSearchMenu != null) { 1319 mSearchMenu.expandActionView(); 1320 } 1321 return false; 1322 } 1323 1324 // Updates the day of the month drawable in the today icon 1325 private void setTodayIcon() { 1326 if (mDayOfMonthIcon == null) { 1327 mDayOfMonthIcon = new DayOfMonthDrawable(); 1328 } 1329 Time now = new Time(); 1330 now.set(System.currentTimeMillis()); 1331 now.normalize(false); 1332 mDayOfMonthIcon.setDayOfMonth(now.monthDay); 1333 } 1334} 1335