AllInOneActivity.java revision 8d1b2fd416920c5462189ad38c2b4da96ac26b87
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.Calendar.EVENT_BEGIN_TIME; 20import static android.provider.Calendar.EVENT_END_TIME; 21import static android.provider.Calendar.AttendeesColumns.ATTENDEE_STATUS; 22 23import com.android.calendar.CalendarController.EventHandler; 24import com.android.calendar.CalendarController.EventInfo; 25import com.android.calendar.CalendarController.EventType; 26import com.android.calendar.CalendarController.ViewType; 27import com.android.calendar.agenda.AgendaFragment; 28import com.android.calendar.month.MonthByWeekFragment; 29import com.android.calendar.selectcalendars.SelectCalendarsFragment; 30 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.ContentResolver; 39import android.content.Intent; 40import android.content.SharedPreferences; 41import android.content.SharedPreferences.OnSharedPreferenceChangeListener; 42import android.content.res.Configuration; 43import android.content.res.Resources; 44import android.database.ContentObserver; 45import android.net.Uri; 46import android.os.Bundle; 47import android.os.Handler; 48import android.provider.Calendar; 49import android.text.TextUtils; 50import android.text.format.DateFormat; 51import android.text.format.DateUtils; 52import android.text.format.Time; 53import android.util.Log; 54import android.view.Menu; 55import android.view.MenuItem; 56import android.view.View; 57import android.view.View.OnClickListener; 58import android.view.accessibility.AccessibilityEvent; 59import android.widget.RelativeLayout; 60import android.widget.RelativeLayout.LayoutParams; 61import android.widget.SearchView; 62import android.widget.TextView; 63 64import java.util.List; 65import java.util.Locale; 66import java.util.TimeZone; 67 68public class AllInOneActivity extends Activity implements EventHandler, 69 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, 70 ActionBar.TabListener { 71 private static final String TAG = "AllInOneActivity"; 72 private static final boolean DEBUG = false; 73 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment"; 74 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time"; 75 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id"; 76 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view"; 77 private static final int HANDLER_KEY = 0; 78 private static final long CONTROLS_ANIMATE_DURATION = 400; 79 private static int CONTROLS_ANIMATE_WIDTH = 283; 80 private static int CONTROLS_MARGIN_RIGHT = 16; 81 private static float mScale = 0; 82 83 private static CalendarController mController; 84 private static boolean mIsMultipane; 85 private boolean mOnSaveInstanceStateCalled = false; 86 private ContentResolver mContentResolver; 87 private int mPreviousView; 88 private int mCurrentView; 89 private boolean mPaused = true; 90 private boolean mUpdateOnResume = false; 91 private boolean mHideControls = false; 92 private TextView mHomeTime; 93 private TextView mDateRange; 94 private View mMiniMonth; 95 private View mCalendarsList; 96 private View mMiniMonthContainer; 97 private String mTimeZone; 98 99 private long mViewEventId = -1; 100 private long mIntentEventStartMillis = -1; 101 private long mIntentEventEndMillis = -1; 102 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE; 103 104 // Action bar and Navigation bar (left side of Action bar) 105 private ActionBar mActionBar; 106 private ActionBar.Tab mDayTab; 107 private ActionBar.Tab mWeekTab; 108 private ActionBar.Tab mMonthTab; 109 private SearchView mSearchView; 110 private MenuItem mControlsMenu; 111 112 private String mHideString = "Hide controls"; 113 private String mShowString = "Show controls"; 114 115 // Params for animating the controls on the right 116 LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0); 117 118 private Runnable mHomeTimeUpdater = new Runnable() { 119 @Override 120 public void run() { 121 updateHomeClock(); 122 } 123 }; 124 125 // Create an observer so that we can update the views whenever a 126 // Calendar event changes. 127 private ContentObserver mObserver = new ContentObserver(new Handler()) { 128 @Override 129 public boolean deliverSelfNotifications() { 130 return true; 131 } 132 133 @Override 134 public void onChange(boolean selfChange) { 135 eventsChanged(); 136 } 137 }; 138 139 @Override 140 protected void onNewIntent(Intent intent) { 141 String action = intent.getAction(); 142 if (Intent.ACTION_VIEW.equals(action)) { 143 parseViewAction(intent); 144 } 145 } 146 147 @Override 148 protected void onCreate(Bundle icicle) { 149 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) { 150 setTheme(R.style.CalendarTheme_WithActionBarWallpaper); 151 } 152 super.onCreate(icicle); 153 154 // This needs to be created before setContentView 155 mController = CalendarController.getInstance(this); 156 // Get time from intent or icicle 157 long timeMillis = -1; 158 int viewType = -1; 159 final Intent intent = getIntent(); 160 if (icicle != null) { 161 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); 162 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1); 163 } else { 164 String action = intent.getAction(); 165 if (Intent.ACTION_VIEW.equals(action)) { 166 // Open EventInfo later 167 timeMillis = parseViewAction(intent); 168 } 169 170 if (timeMillis == -1) { 171 timeMillis = Utils.timeFromIntentInMillis(intent); 172 } 173 } 174 175 if (viewType == -1) { 176 viewType = Utils.getViewTypeFromIntentAndSharedPref(this); 177 } 178 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); 179 Time t = new Time(mTimeZone); 180 t.set(timeMillis); 181 182 if (icicle != null && intent != null) { 183 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); 184 } else { 185 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); 186 } 187 188 Resources res = getResources(); 189 if (mScale == 0) { 190 mScale = res.getDisplayMetrics().density; 191 CONTROLS_ANIMATE_WIDTH *= mScale; 192 CONTROLS_MARGIN_RIGHT *= mScale; 193 } 194 mHideString = res.getString(R.string.hide_controls); 195 mShowString = res.getString(R.string.show_controls); 196 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 197 mControlsParams.rightMargin = CONTROLS_MARGIN_RIGHT; 198 199 mIsMultipane = 200 (res.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_XLARGE) != 0; 201 202 Utils.setAllowWeekForDetailView(mIsMultipane); 203 204 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); 205 206 // setContentView must be called before configureActionBar 207 setContentView(R.layout.all_in_one); 208 // configureActionBar auto-selects the first tab you add, so we need to 209 // call it before we set up our own fragments to make sure it doesn't 210 // overwrite us 211 configureActionBar(); 212 213 // Must be the first to register because this activity can modify the 214 // list of event handlers in it's handle method. This affects who the 215 // rest of the handlers the controller dispatches to are. 216 mController.registerEventHandler(HANDLER_KEY, this); 217 218 mHomeTime = (TextView) findViewById(R.id.home_time); 219 mMiniMonth = findViewById(R.id.mini_month); 220 mCalendarsList = findViewById(R.id.calendar_list); 221 mMiniMonthContainer = findViewById(R.id.mini_month_container); 222 223 initFragments(timeMillis, viewType, icicle); 224 225 226 // Listen for changes that would require this to be refreshed 227 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 228 prefs.registerOnSharedPreferenceChangeListener(this); 229 230 mContentResolver = getContentResolver(); 231 } 232 233 private long parseViewAction(final Intent intent) { 234 long timeMillis = -1; 235 Uri data = intent.getData(); 236 if (data != null && data.isHierarchical()) { 237 List<String> path = data.getPathSegments(); 238 if (path.size() == 2 && path.get(0).equals("events")) { 239 try { 240 mViewEventId = Long.valueOf(data.getLastPathSegment()); 241 if(mViewEventId != -1) { 242 mIntentEventStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0); 243 mIntentEventEndMillis = intent.getLongExtra(EVENT_END_TIME, 0); 244 mIntentAttendeeResponse = intent.getIntExtra( 245 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE); 246 timeMillis = mIntentEventStartMillis; 247 } 248 } catch (NumberFormatException e) { 249 // Ignore if mViewEventId can't be parsed 250 } 251 } 252 } 253 return timeMillis; 254 } 255 256 private void configureActionBar() { 257 mActionBar = getActionBar(); 258 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 259 if (mActionBar == null) { 260 Log.w(TAG, "ActionBar is null."); 261 } else { 262 mDayTab = mActionBar.newTab(); 263 mDayTab.setText(getString(R.string.day_view)); 264 mDayTab.setTabListener(this); 265 mActionBar.addTab(mDayTab); 266 mWeekTab = mActionBar.newTab(); 267 mWeekTab.setText(getString(R.string.week_view)); 268 mWeekTab.setTabListener(this); 269 mActionBar.addTab(mWeekTab); 270 mMonthTab = mActionBar.newTab(); 271 mMonthTab.setText(getString(R.string.month_view)); 272 mMonthTab.setTabListener(this); 273 mActionBar.addTab(mMonthTab); 274 mActionBar.setCustomView(mDateRange); 275 mActionBar.setDisplayOptions( 276 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); 277 } 278 } 279 280 @Override 281 protected void onResume() { 282 super.onResume(); 283 mContentResolver.registerContentObserver(Calendar.Events.CONTENT_URI, true, mObserver); 284 if (mUpdateOnResume) { 285 initFragments(mController.getTime(), mController.getViewType(), null); 286 mUpdateOnResume = false; 287 } 288 updateHomeClock(); 289 if (mControlsMenu != null) { 290 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); 291 } 292 mPaused = false; 293 mOnSaveInstanceStateCalled = false; 294 295 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) { 296 long currentMillis = System.currentTimeMillis(); 297 long selectedTime = -1; 298 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) { 299 selectedTime = currentMillis; 300 } 301 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId, 302 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1, mIntentAttendeeResponse, 303 selectedTime); 304 mViewEventId = -1; 305 mIntentEventStartMillis = -1; 306 mIntentEventEndMillis = -1; 307 } 308 } 309 310 @Override 311 protected void onPause() { 312 super.onPause(); 313 mPaused = true; 314 mHomeTime.removeCallbacks(mHomeTimeUpdater); 315 mContentResolver.unregisterContentObserver(mObserver); 316 if (isFinishing()) { 317 // Stop listening for changes that would require this to be refreshed 318 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 319 prefs.unregisterOnSharedPreferenceChangeListener(this); 320 } 321 // FRAG_TODO save highlighted days of the week; 322 if (mController.getViewType() != ViewType.EDIT) { 323 Utils.setDefaultView(this, mController.getViewType()); 324 } 325 } 326 327 @Override 328 protected void onUserLeaveHint() { 329 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT); 330 super.onUserLeaveHint(); 331 } 332 333 @Override 334 public void onSaveInstanceState(Bundle outState) { 335 mOnSaveInstanceStateCalled = true; 336 super.onSaveInstanceState(outState); 337 338 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime()); 339 if (mCurrentView == ViewType.EDIT) { 340 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView); 341 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId()); 342 } 343 } 344 345 @Override 346 protected void onDestroy() { 347 super.onDestroy(); 348 349 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 350 prefs.unregisterOnSharedPreferenceChangeListener(this); 351 CalendarController.removeInstance(this); 352 } 353 354 private void initFragments(long timeMillis, int viewType, Bundle icicle) { 355 FragmentTransaction ft = getFragmentManager().beginTransaction(); 356 357 if (mIsMultipane) { 358 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true); 359 ft.replace(R.id.mini_month, miniMonthFrag); 360 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag); 361 362 Fragment selectCalendarsFrag = new SelectCalendarsFragment(); 363 ft.replace(R.id.calendar_list, selectCalendarsFrag); 364 mController.registerEventHandler( 365 R.id.calendar_list, (EventHandler) selectCalendarsFrag); 366 } 367 if (!mIsMultipane || viewType == ViewType.EDIT) { 368 mMiniMonth.setVisibility(View.GONE); 369 mCalendarsList.setVisibility(View.GONE); 370 } 371 372 EventInfo info = null; 373 if (viewType == ViewType.EDIT) { 374 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt( 375 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW); 376 377 long eventId = -1; 378 Intent intent = getIntent(); 379 Uri data = intent.getData(); 380 if (data != null) { 381 try { 382 eventId = Long.parseLong(data.getLastPathSegment()); 383 } catch (NumberFormatException e) { 384 if (DEBUG) { 385 Log.d(TAG, "Create new event"); 386 } 387 } 388 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) { 389 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID); 390 } 391 392 long begin = intent.getLongExtra(EVENT_BEGIN_TIME, -1); 393 long end = intent.getLongExtra(EVENT_END_TIME, -1); 394 info = new EventInfo(); 395 if (end != -1) { 396 info.endTime = new Time(); 397 info.endTime.set(end); 398 } 399 if (begin != -1) { 400 info.startTime = new Time(); 401 info.startTime.set(begin); 402 } 403 info.id = eventId; 404 // We set the viewtype so if the user presses back when they are 405 // done editing the controller knows we were in the Edit Event 406 // screen. Likewise for eventId 407 mController.setViewType(viewType); 408 mController.setEventId(eventId); 409 } else { 410 mPreviousView = viewType; 411 } 412 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true); 413 414 ft.commit(); // this needs to be after setMainPane() 415 416 Time t = new Time(mTimeZone); 417 t.set(timeMillis); 418 if (viewType != ViewType.EDIT) { 419 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType); 420 } 421 } 422 423 @Override 424 public void onBackPressed() { 425 if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) { 426 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView); 427 } else { 428 super.onBackPressed(); 429 } 430 } 431 432 @Override 433 public boolean onCreateOptionsMenu(Menu menu) { 434 super.onCreateOptionsMenu(menu); 435 436 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu); 437 438 mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); 439 if (mSearchView != null) { 440 mSearchView.setIconifiedByDefault(true); 441 mSearchView.setOnQueryTextListener(this); 442 mSearchView.setSubmitButtonEnabled(true); 443 } 444 mControlsMenu = menu.findItem(R.id.action_hide_controls); 445 if (mControlsMenu != null && mController != null 446 && mController.getViewType() == ViewType.MONTH) { 447 mControlsMenu.setVisible(false); 448 mControlsMenu.setEnabled(false); 449 } 450 451 return true; 452 } 453 454 @Override 455 public boolean onOptionsItemSelected(MenuItem item) { 456 Time t = null; 457 int viewType = ViewType.CURRENT; 458 switch (item.getItemId()) { 459 case R.id.action_refresh: 460 mController.refreshCalendars(); 461 return true; 462 case R.id.action_today: 463 viewType = ViewType.CURRENT; 464 t = new Time(mTimeZone); 465 t.setToNow(); 466 break; 467 case R.id.action_create_event: 468 mController.sendEventRelatedEvent(this, EventType.CREATE_EVENT, -1, 0, 0, 0, 0, -1); 469 return true; 470 case R.id.action_settings: 471 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0); 472 return true; 473 case R.id.action_hide_controls: 474 mHideControls = !mHideControls; 475 item.setTitle(mHideControls ? mShowString : mHideString); 476 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 477 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH, 478 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0); 479 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION); 480 ObjectAnimator.setFrameDelay(0); 481 slideAnimation.start(); 482 return true; 483 default: 484 return false; 485 } 486 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType); 487 return true; 488 } 489 490 /** 491 * Sets the offset of the controls on the right for animating them off/on 492 * screen. ProGuard strips this if it's not in proguard.flags 493 * 494 * @param controlsOffset The current offset in pixels 495 */ 496 public void setControlsOffset(int controlsOffset) { 497 mMiniMonth.setTranslationX(controlsOffset); 498 mCalendarsList.setTranslationX(controlsOffset); 499 mHomeTime.setTranslationX(controlsOffset); 500 mControlsParams.width = Math.max( 501 0, CONTROLS_ANIMATE_WIDTH - controlsOffset - mControlsParams.rightMargin); 502 mMiniMonthContainer.setLayoutParams(mControlsParams); 503 } 504 505 @Override 506 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { 507 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) { 508 if (mPaused) { 509 mUpdateOnResume = true; 510 } else { 511 initFragments(mController.getTime(), mController.getViewType(), null); 512 } 513 } 514 } 515 516 private void setMainPane( 517 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) { 518 if (mOnSaveInstanceStateCalled) { 519 return; 520 } 521 if (!force && mCurrentView == viewType) { 522 return; 523 } 524 525 if (viewType != mCurrentView) { 526 // The rules for this previous view are different than the 527 // controller's and are used for intercepting the back button. 528 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) { 529 mPreviousView = mCurrentView; 530 } 531 mCurrentView = viewType; 532 } 533 // Create new fragment 534 Fragment frag; 535 switch (viewType) { 536 case ViewType.AGENDA: 537 frag = new AgendaFragment(timeMillis); 538 break; 539 case ViewType.DAY: 540 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) { 541 mActionBar.selectTab(mDayTab); 542 } 543 frag = new DayFragment(timeMillis, 1); 544 break; 545 case ViewType.WEEK: 546 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) { 547 mActionBar.selectTab(mWeekTab); 548 } 549 frag = new DayFragment(timeMillis, 7); 550 break; 551 case ViewType.MONTH: 552 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) { 553 mActionBar.selectTab(mMonthTab); 554 } 555 frag = new MonthByWeekFragment(timeMillis, false); 556 break; 557 default: 558 throw new IllegalArgumentException( 559 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType); 560 } 561 562 boolean doCommit = false; 563 if (ft == null) { 564 doCommit = true; 565 ft = getFragmentManager().beginTransaction(); 566 } 567 568 ft.replace(viewId, frag); 569 570 if (DEBUG) { 571 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType); 572 } 573 // If the key is already registered this will replace it 574 mController.registerEventHandler(viewId, (EventHandler) frag); 575 576 if (doCommit) { 577 ft.commit(); 578 } 579 } 580 581 private void setTitleInActionBar(EventInfo event) { 582 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) { 583 return; 584 } 585 586 final long start = event.startTime.toMillis(false /* use isDst */); 587 final long end; 588 if (event.endTime != null) { 589 end = event.endTime.toMillis(false /* use isDst */); 590 } else { 591 end = start; 592 } 593 594 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong); 595 CharSequence oldDate = mDateRange.getText(); 596 mDateRange.setText(msg); 597 if (!TextUtils.equals(oldDate, msg)) { 598 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); 599 } 600 } 601 602 private void updateHomeClock() { 603 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); 604 if (mIsMultipane && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK) 605 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) { 606 Time time = new Time(mTimeZone); 607 time.setToNow(); 608 long millis = time.toMillis(true); 609 boolean isDST = time.isDst != 0; 610 int flags = DateUtils.FORMAT_SHOW_TIME; 611 if (DateFormat.is24HourFormat(this)) { 612 flags |= DateUtils.FORMAT_24HOUR; 613 } 614 // Formats the time as 615 String timeString = (new StringBuilder( 616 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append( 617 TimeZone.getTimeZone(mTimeZone).getDisplayName( 618 isDST, TimeZone.SHORT, Locale.getDefault())).toString(); 619 mHomeTime.setText(timeString); 620 mHomeTime.setVisibility(View.VISIBLE); 621 // Update when the minute changes 622 mHomeTime.postDelayed( 623 mHomeTimeUpdater, 624 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS)); 625 } else { 626 mHomeTime.setVisibility(View.GONE); 627 } 628 } 629 630 @Override 631 public long getSupportedEventTypes() { 632 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE; 633 } 634 635 @Override 636 public void handleEvent(EventInfo event) { 637 if (event.eventType == EventType.GO_TO) { 638 setMainPane( 639 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false); 640 if (mSearchView != null) { 641 mSearchView.clearFocus(); 642 } 643 if (!mIsMultipane) { 644 return; 645 } 646 if (event.viewType == ViewType.MONTH) { 647 // hide minimonth and calendar frag 648 mMiniMonth.setVisibility(View.GONE); 649 mCalendarsList.setVisibility(View.GONE); 650 mMiniMonthContainer.setVisibility(View.GONE); 651 if (mControlsMenu != null) { 652 mControlsMenu.setVisible(false); 653 mControlsMenu.setEnabled(false); 654 } 655 } else { 656 // show minimonth and calendar frag 657 mMiniMonth.setVisibility(View.VISIBLE); 658 mCalendarsList.setVisibility(View.VISIBLE); 659 mMiniMonthContainer.setVisibility(View.VISIBLE); 660 if (mControlsMenu != null) { 661 mControlsMenu.setVisible(true); 662 mControlsMenu.setEnabled(true); 663 } 664 } 665 } else if (event.eventType == EventType.VIEW_EVENT) { 666 EventInfoFragment fragment = new EventInfoFragment(this, 667 event.id, event.startTime.toMillis(false), event.endTime.toMillis(false), 668 (int) event.extraLong); 669 if (event.selectedTime != null) { 670 mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, 671 -1, ViewType.DETAIL); 672 } 673 fragment.setDialogParams(event.x, event.y); 674 FragmentManager fm = getFragmentManager(); 675 FragmentTransaction ft = fm.beginTransaction(); 676 // if we have an old popup close it 677 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG); 678 if (fOld != null) { 679 ft.remove(fOld); 680 } 681 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG); 682 ft.commit(); 683 } else if (event.eventType == EventType.UPDATE_TITLE) { 684 setTitleInActionBar(event); 685 } 686 updateHomeClock(); 687 } 688 689 @Override 690 public void eventsChanged() { 691 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT); 692 } 693 694 @Override 695 public boolean onQueryTextChange(String newText) { 696 return false; 697 } 698 699 @Override 700 public boolean onQueryTextSubmit(String query) { 701 if (TextUtils.equals(query, "TARDIS")) { 702 Utils.tardis(); 703 } 704 mSearchView.clearFocus(); 705 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, -1, query, 706 getComponentName()); 707 return false; 708 } 709 710 @Override 711 public void onTabSelected(Tab tab, FragmentTransaction ft) { 712 if (tab == mDayTab && mCurrentView != ViewType.DAY) { 713 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY); 714 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) { 715 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK); 716 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) { 717 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH); 718 } else { 719 Log.w(TAG, "TabSelected event from unknown tab: " 720 + (tab == null ? "null" : tab.getText())); 721 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab 722 + " Week:" + mWeekTab + " Month:" + mMonthTab); 723 } 724 } 725 726 @Override 727 public void onTabReselected(Tab tab, FragmentTransaction ft) { 728 } 729 730 @Override 731 public void onTabUnselected(Tab tab, FragmentTransaction ft) { 732 } 733} 734