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