AllInOneActivity.java revision f6b58a9b0585176a1435eb6b910895f85b5b68db
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_RESTORE_EDIT = "key_restore_edit"; 76 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id"; 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 boolean restoreEdit = false; 160 final Intent intent = getIntent(); 161 if (icicle != null) { 162 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); 163 restoreEdit = icicle.getBoolean(BUNDLE_KEY_RESTORE_EDIT, false); 164 viewType = ViewType.EDIT; 165 } else { 166 String action = intent.getAction(); 167 if (Intent.ACTION_VIEW.equals(action)) { 168 // Open EventInfo later 169 timeMillis = parseViewAction(intent); 170 } 171 172 if (timeMillis == -1) { 173 timeMillis = Utils.timeFromIntentInMillis(intent); 174 } 175 } 176 177 if (!restoreEdit) { 178 viewType = Utils.getViewTypeFromIntentAndSharedPref(this); 179 } 180 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); 181 Time t = new Time(mTimeZone); 182 t.set(timeMillis); 183 184 if (icicle != null && intent != null) { 185 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); 186 } else { 187 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); 188 } 189 190 Resources res = getResources(); 191 if (mScale == 0) { 192 mScale = res.getDisplayMetrics().density; 193 CONTROLS_ANIMATE_WIDTH *= mScale; 194 CONTROLS_MARGIN_RIGHT *= mScale; 195 } 196 mHideString = res.getString(R.string.hide_controls); 197 mShowString = res.getString(R.string.show_controls); 198 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 199 mControlsParams.rightMargin = CONTROLS_MARGIN_RIGHT; 200 201 mIsMultipane = 202 (res.getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_XLARGE) != 0; 203 204 Utils.setAllowWeekForDetailView(mIsMultipane); 205 206 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); 207 208 // setContentView must be called before configureActionBar 209 setContentView(R.layout.all_in_one); 210 // configureActionBar auto-selects the first tab you add, so we need to 211 // call it before we set up our own fragments to make sure it doesn't 212 // overwrite us 213 configureActionBar(); 214 215 // Must be the first to register because this activity can modify the 216 // list of event handlers in it's handle method. This affects who the 217 // rest of the handlers the controller dispatches to are. 218 mController.registerEventHandler(HANDLER_KEY, this); 219 220 mHomeTime = (TextView) findViewById(R.id.home_time); 221 mMiniMonth = findViewById(R.id.mini_month); 222 mCalendarsList = findViewById(R.id.calendar_list); 223 mMiniMonthContainer = findViewById(R.id.mini_month_container); 224 225 initFragments(timeMillis, viewType, icicle); 226 227 228 // Listen for changes that would require this to be refreshed 229 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 230 prefs.registerOnSharedPreferenceChangeListener(this); 231 232 mContentResolver = getContentResolver(); 233 } 234 235 private long parseViewAction(final Intent intent) { 236 long timeMillis = -1; 237 Uri data = intent.getData(); 238 if (data != null && data.isHierarchical()) { 239 List<String> path = data.getPathSegments(); 240 if (path.size() == 2 && path.get(0).equals("events")) { 241 try { 242 mViewEventId = Long.valueOf(data.getLastPathSegment()); 243 if(mViewEventId != -1) { 244 mIntentEventStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0); 245 mIntentEventEndMillis = intent.getLongExtra(EVENT_END_TIME, 0); 246 mIntentAttendeeResponse = intent.getIntExtra( 247 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE); 248 timeMillis = mIntentEventStartMillis; 249 } 250 } catch (NumberFormatException e) { 251 // Ignore if mViewEventId can't be parsed 252 } 253 } 254 } 255 return timeMillis; 256 } 257 258 private void configureActionBar() { 259 mActionBar = getActionBar(); 260 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 261 if (mActionBar == null) { 262 Log.w(TAG, "ActionBar is null."); 263 } else { 264 mDayTab = mActionBar.newTab(); 265 mDayTab.setText(getString(R.string.day_view)); 266 mDayTab.setTabListener(this); 267 mActionBar.addTab(mDayTab); 268 mWeekTab = mActionBar.newTab(); 269 mWeekTab.setText(getString(R.string.week_view)); 270 mWeekTab.setTabListener(this); 271 mActionBar.addTab(mWeekTab); 272 mMonthTab = mActionBar.newTab(); 273 mMonthTab.setText(getString(R.string.month_view)); 274 mMonthTab.setTabListener(this); 275 mActionBar.addTab(mMonthTab); 276 mActionBar.setCustomView(mDateRange); 277 mActionBar.setDisplayOptions( 278 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME); 279 } 280 } 281 282 @Override 283 protected void onResume() { 284 super.onResume(); 285 mContentResolver.registerContentObserver(Calendar.Events.CONTENT_URI, true, mObserver); 286 if (mUpdateOnResume) { 287 initFragments(mController.getTime(), mController.getViewType(), null); 288 mUpdateOnResume = false; 289 } 290 updateHomeClock(); 291 if (mControlsMenu != null) { 292 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString); 293 } 294 mPaused = false; 295 mOnSaveInstanceStateCalled = false; 296 297 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) { 298 long currentMillis = System.currentTimeMillis(); 299 long selectedTime = -1; 300 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) { 301 selectedTime = currentMillis; 302 } 303 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId, 304 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1, mIntentAttendeeResponse, 305 selectedTime); 306 mViewEventId = -1; 307 mIntentEventStartMillis = -1; 308 mIntentEventEndMillis = -1; 309 } 310 } 311 312 @Override 313 protected void onPause() { 314 super.onPause(); 315 mPaused = true; 316 mHomeTime.removeCallbacks(mHomeTimeUpdater); 317 mContentResolver.unregisterContentObserver(mObserver); 318 if (isFinishing()) { 319 // Stop listening for changes that would require this to be refreshed 320 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 321 prefs.unregisterOnSharedPreferenceChangeListener(this); 322 } 323 // FRAG_TODO save highlighted days of the week; 324 if (mController.getViewType() != ViewType.EDIT) { 325 Utils.setDefaultView(this, mController.getViewType()); 326 } 327 } 328 329 @Override 330 protected void onUserLeaveHint() { 331 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT); 332 super.onUserLeaveHint(); 333 } 334 335 @Override 336 public void onSaveInstanceState(Bundle outState) { 337 mOnSaveInstanceStateCalled = true; 338 super.onSaveInstanceState(outState); 339 340 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime()); 341 if (mCurrentView == ViewType.EDIT) { 342 outState.putBoolean(BUNDLE_KEY_RESTORE_EDIT, true); 343 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId()); 344 } 345 } 346 347 @Override 348 protected void onDestroy() { 349 super.onDestroy(); 350 351 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); 352 prefs.unregisterOnSharedPreferenceChangeListener(this); 353 CalendarController.removeInstance(this); 354 } 355 356 private void initFragments(long timeMillis, int viewType, Bundle icicle) { 357 FragmentTransaction ft = getFragmentManager().beginTransaction(); 358 359 if (mIsMultipane) { 360 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true); 361 ft.replace(R.id.mini_month, miniMonthFrag); 362 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag); 363 364 Fragment selectCalendarsFrag = new SelectCalendarsFragment(); 365 ft.replace(R.id.calendar_list, 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