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