AllInOneActivity.java 22.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.calendar;

19 20
import static android.provider.Calendar.EVENT_BEGIN_TIME;
import static android.provider.Calendar.EVENT_END_TIME;
21
import static android.provider.Calendar.AttendeesColumns.ATTENDEE_STATUS;
22

Michael Chan's avatar
Michael Chan committed
23
import com.android.calendar.CalendarController.EventHandler;
24
import com.android.calendar.CalendarController.EventInfo;
Michael Chan's avatar
Michael Chan committed
25
import com.android.calendar.CalendarController.EventType;
26
import com.android.calendar.CalendarController.ViewType;
27
import com.android.calendar.agenda.AgendaFragment;
28
import com.android.calendar.event.EditEventHelper;
Erik's avatar
Erik committed
29
import com.android.calendar.month.MonthByWeekFragment;
30
import com.android.calendar.selectcalendars.SelectCalendarsFragment;
Michael Chan's avatar
Michael Chan committed
31

32
import android.app.ActionBar;
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
33
import android.app.ActionBar.Tab;
34
import android.app.Activity;
Michael Chan's avatar
Michael Chan committed
35
import android.app.Fragment;
36
import android.app.FragmentTransaction;
Erik's avatar
Erik committed
37
import android.content.ContentResolver;
38
import android.content.Intent;
39 40
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
41
import android.content.res.Configuration;
Erik's avatar
Erik committed
42
import android.database.ContentObserver;
43
import android.net.Uri;
44
import android.os.Bundle;
Erik's avatar
Erik committed
45 46
import android.os.Handler;
import android.provider.Calendar;
Erik's avatar
Erik committed
47 48
import android.text.TextUtils;
import android.text.format.DateFormat;
49
import android.text.format.DateUtils;
Michael Chan's avatar
Michael Chan committed
50
import android.text.format.Time;
Erik's avatar
Erik committed
51
import android.util.Log;
52
import android.view.Menu;
53
import android.view.MenuItem;
54
import android.view.View;
55
import android.widget.SearchView;
Erik's avatar
Erik committed
56 57
import android.widget.TextView;

58
import java.util.List;
Erik's avatar
Erik committed
59 60
import java.util.Locale;
import java.util.TimeZone;
61

62
public class AllInOneActivity extends Activity implements EventHandler,
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
63 64
        OnSharedPreferenceChangeListener, SearchView.OnQueryChangeListener,
        ActionBar.TabListener {
65
    private static final String TAG = "AllInOneActivity";
Erik's avatar
Erik committed
66
    private static final boolean DEBUG = false;
Michael Chan's avatar
Michael Chan committed
67
    private static final long INITIAL_HEAP_SIZE = 4*1024*1024;
68
    private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
69 70
    private static final String BUNDLE_KEY_RESTORE_EDIT = "key_restore_edit";
    private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
71
    private static final int HANDLER_KEY = 0;
72
    private static CalendarController mController;
73
    private static boolean mIsMultipane;
74
    private boolean mOnSaveInstanceStateCalled = false;
Erik's avatar
Erik committed
75
    private ContentResolver mContentResolver;
Erik's avatar
Erik committed
76 77
    private int mPreviousView;
    private int mCurrentView;
78 79
    private boolean mPaused = true;
    private boolean mUpdateOnResume = false;
Erik's avatar
Erik committed
80
    private TextView mHomeTime;
81
    private String mTimeZone;
Erik's avatar
Erik committed
82

83 84 85 86 87
    private long mViewEventId = -1;
    private long mIntentEventStartMillis = -1;
    private long mIntentEventEndMillis = -1;
    private int mIntentAttendeeResponse = EditEventHelper.ATTENDEE_NO_RESPONSE;

Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
88 89 90 91 92 93
    // Action bar and Navigation bar (left side of Action bar)
    private ActionBar mActionBar;
    private ActionBar.Tab mDayTab;
    private ActionBar.Tab mWeekTab;
    private ActionBar.Tab mMonthTab;

Erik's avatar
Erik committed
94 95 96 97 98 99
    private Runnable mHomeTimeUpdater = new Runnable() {
        @Override
        public void run() {
            updateHomeClock();
        }
    };
Erik's avatar
Erik committed
100 101 102

    // Create an observer so that we can update the views whenever a
    // Calendar event changes.
103
    private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik's avatar
Erik committed
104 105 106 107 108 109 110 111 112 113
        @Override
        public boolean deliverSelfNotifications() {
            return true;
        }

        @Override
        public void onChange(boolean selfChange) {
            eventsChanged();
        }
    };
Michael Chan's avatar
Michael Chan committed
114

115
    @Override
Michael Chan's avatar
Michael Chan committed
116
    protected void onCreate(Bundle icicle) {
117
//        setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
Michael Chan's avatar
Michael Chan committed
118 119 120
        super.onCreate(icicle);

        // This needs to be created before setContentView
121
        mController = CalendarController.getInstance(this);
Erik's avatar
Erik committed
122
        // Get time from intent or icicle
123 124 125 126
        long timeMillis = -1;
        int viewType = -1;
        boolean restoreEdit = false;
        final Intent intent = getIntent();
Erik's avatar
Erik committed
127 128
        if (icicle != null) {
            timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
129
            restoreEdit = icicle.getBoolean(BUNDLE_KEY_RESTORE_EDIT, false);
130 131
            viewType = ViewType.EDIT;
        } else {
132 133 134 135 136 137 138 139 140 141 142 143
            String action = intent.getAction();
            if (Intent.ACTION_VIEW.equals(action)) {
                // Open EventInfo later
                timeMillis = parseViewAction(intent);
            }

            if (timeMillis == -1) {
                timeMillis = Utils.timeFromIntentInMillis(intent);
            }
        }

        if (!restoreEdit) {
144 145
            viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
        }
146 147
        mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
        Time t = new Time(mTimeZone);
Erik's avatar
Erik committed
148 149
        t.set(timeMillis);

150 151
        if (icicle != null && intent != null) {
            Log.d(TAG, "both, icicle:" + icicle.toString() + "  intent:" + intent.toString());
152
        } else {
153
            Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
154 155 156 157
        }

        mIsMultipane = (getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_XLARGE) != 0;
158

Erik's avatar
Erik committed
159 160 161 162 163 164 165
        // setContentView must be called before configureActionBar
        setContentView(R.layout.all_in_one);
        // configureActionBar auto-selects the first tab you add, so we need to
        // call it before we set up our own fragments to make sure it doesn't
        // overwrite us
        configureActionBar();

166 167 168 169
        // Must be the first to register because this activity can modify the
        // list of event handlers in it's handle method. This affects who the
        // rest of the handlers the controller dispatches to are.
        mController.registerEventHandler(HANDLER_KEY, this);
Michael Chan's avatar
Michael Chan committed
170

Erik's avatar
Erik committed
171
        mHomeTime = (TextView) findViewById(R.id.home_time);
Michael Chan's avatar
Michael Chan committed
172

173
        initFragments(timeMillis, viewType, icicle);
174

Erik's avatar
Erik committed
175

176
        // Listen for changes that would require this to be refreshed
177
        SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
178
        prefs.registerOnSharedPreferenceChangeListener(this);
179

Erik's avatar
Erik committed
180
        mContentResolver = getContentResolver();
Erik's avatar
Erik committed
181
    }
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
182

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    private long parseViewAction(final Intent intent) {
        long timeMillis = -1;
        Uri data = intent.getData();
        if (data != null && data.isHierarchical()) {
            List<String> path = data.getPathSegments();
            if (path.size() == 2 && path.get(0).equals("events")) {
                try {
                    mViewEventId = Long.valueOf(data.getLastPathSegment());
                    if(mViewEventId != -1) {
                        mIntentEventStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0);
                        mIntentEventEndMillis = intent.getLongExtra(EVENT_END_TIME, 0);
                        mIntentAttendeeResponse = intent.getIntExtra(
                                ATTENDEE_STATUS, EditEventHelper.ATTENDEE_NO_RESPONSE);
                        timeMillis = mIntentEventStartMillis;
                    }
                } catch (NumberFormatException e) {
                    // Ignore if mViewEventId can't be parsed
                }
            }
        }
        return timeMillis;
    }

Erik's avatar
Erik committed
206
    private void configureActionBar() {
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
        mActionBar = getActionBar();
        mActionBar.setTabNavigationMode();
        if (mActionBar == null) {
            Log.w(TAG, "ActionBar is null.");
        } else {
            mDayTab = mActionBar.newTab();
            mDayTab.setText(getString(R.string.day_view));
            mDayTab.setTabListener(this);
            mActionBar.addTab(mDayTab);
            mWeekTab = mActionBar.newTab();
            mWeekTab.setText(getString(R.string.week_view));
            mWeekTab.setTabListener(this);
            mActionBar.addTab(mWeekTab);
            mMonthTab = mActionBar.newTab();
            mMonthTab.setText(getString(R.string.month_view));
            mMonthTab.setTabListener(this);
            mActionBar.addTab(mMonthTab);
        }
Erik's avatar
Erik committed
225 226 227 228 229 230
    }

    @Override
    protected void onResume() {
        super.onResume();
        mContentResolver.registerContentObserver(Calendar.Events.CONTENT_URI, true, mObserver);
231 232 233 234
        if (mUpdateOnResume) {
            initFragments(mController.getTime(), mController.getViewType(), null);
            mUpdateOnResume = false;
        }
Erik's avatar
Erik committed
235
        updateHomeClock();
236
        mPaused = false;
237
        mOnSaveInstanceStateCalled = false;
238 239 240 241 242 243 244 245

        if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
            mController.sendEventRelatedEvent(this, EventType.VIEW_EVENT, mViewEventId,
                    mIntentEventStartMillis, mIntentEventEndMillis, -1, -1);
            mViewEventId = -1;
            mIntentEventStartMillis = -1;
            mIntentEventEndMillis = -1;
        }
246 247
    }

248 249 250
    @Override
    protected void onPause() {
        super.onPause();
251
        mPaused = true;
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
252
        mHomeTime.removeCallbacks(mHomeTimeUpdater);
Erik's avatar
Erik committed
253
        mContentResolver.unregisterContentObserver(mObserver);
254 255 256 257 258
        if (isFinishing()) {
            // Stop listening for changes that would require this to be refreshed
            SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
            prefs.unregisterOnSharedPreferenceChangeListener(this);
        }
259
        // FRAG_TODO save highlighted days of the week;
260 261 262
        if (mController.getViewType() != ViewType.EDIT) {
            Utils.setDefaultView(this, mController.getViewType());
        }
263 264
    }

265 266 267 268 269 270
    @Override
    protected void onUserLeaveHint() {
        mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
        super.onUserLeaveHint();
    }

271 272
    @Override
    public void onSaveInstanceState(Bundle outState) {
273
        mOnSaveInstanceStateCalled = true;
274 275 276
        super.onSaveInstanceState(outState);

        outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
277 278 279 280
        if (mCurrentView == ViewType.EDIT) {
            outState.putBoolean(BUNDLE_KEY_RESTORE_EDIT, true);
            outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
        }
281 282
    }

283 284 285 286
    @Override
    protected void onDestroy() {
        super.onDestroy();

287
        SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
288
        prefs.unregisterOnSharedPreferenceChangeListener(this);
Erik's avatar
Erik committed
289
        CalendarController.removeInstance(this);
290 291
    }

292
    private void initFragments(long timeMillis, int viewType, Bundle icicle) {
293
        FragmentTransaction ft = getFragmentManager().openTransaction();
294

295
        if (mIsMultipane) {
296
            Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
297
            ft.replace(R.id.mini_month, miniMonthFrag);
298
            mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
299 300 301

            Fragment selectCalendarsFrag = new SelectCalendarsFragment();
            ft.replace(R.id.calendar_list, selectCalendarsFrag);
302
        }
303
        if (!mIsMultipane || viewType == ViewType.EDIT) {
304 305 306
            findViewById(R.id.mini_month).setVisibility(View.GONE);
            findViewById(R.id.calendar_list).setVisibility(View.GONE);
        }
307

308 309
        EventInfo info = null;
        if (viewType == ViewType.EDIT) {
310
            mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
311
                    GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
312

313
            long eventId = -1;
314 315 316 317
            Intent intent = getIntent();
            Uri data = intent.getData();
            if (data != null) {
                try {
318
                    eventId = Long.parseLong(data.getLastPathSegment());
319 320 321 322 323
                } catch (NumberFormatException e) {
                    if (DEBUG) {
                        Log.d(TAG, "Create new event");
                    }
                }
324 325
            } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
                eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
326
            }
327

328 329 330 331 332 333 334 335 336 337 338 339 340 341
            long begin = intent.getLongExtra(EVENT_BEGIN_TIME, -1);
            long end = intent.getLongExtra(EVENT_END_TIME, -1);
            info = new EventInfo();
            if (end != -1) {
                info.endTime = new Time();
                info.endTime.set(end);
            }
            if (begin != -1) {
                info.startTime = new Time();
                info.startTime.set(begin);
            }
            info.id = eventId;
            // We set the viewtype so if the user presses back when they are
            // done editing the controller knows we were in the Edit Event
342
            // screen. Likewise for eventId
343
            mController.setViewType(viewType);
344
            mController.setEventId(eventId);
345 346 347 348
        } else {
            mPreviousView = viewType;
        }
        setMainPane(ft, R.id.main_pane, viewType, timeMillis, true, info);
349 350 351

        ft.commit(); // this needs to be after setMainPane()

352
        Time t = new Time(mTimeZone);
353
        t.set(timeMillis);
354 355 356
        if (viewType != ViewType.EDIT) {
            mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
        }
357
    }
358

Erik's avatar
Erik committed
359 360
    @Override
    public void onBackPressed() {
361
        if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) {
362
            mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
363 364
        } else {
            super.onBackPressed();
Erik's avatar
Erik committed
365 366 367
        }
    }

368 369 370 371 372
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
373 374

        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
Michael Chan's avatar
Michael Chan committed
375 376 377 378
        if (searchView != null) {
            searchView.setIconifiedByDefault(true);
            searchView.setOnQueryChangeListener(this);
        }
379

380 381
        return true;
    }
382 383 384 385 386 387

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Time t = null;
        int viewType = ViewType.CURRENT;
        switch (item.getItemId()) {
Erik's avatar
Erik committed
388 389 390
            case R.id.action_refresh:
                mController.refreshCalendars();
                return true;
391 392
            case R.id.action_today:
                viewType = ViewType.CURRENT;
393
                t = new Time(mTimeZone);
394 395 396 397 398
                t.setToNow();
                break;
            case R.id.action_create_event:
                mController.sendEventRelatedEvent(this, EventType.CREATE_EVENT, -1, 0, 0, 0, 0);
                return true;
399 400 401
            case R.id.action_settings:
                mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
                return true;
402 403 404
            default:
                return false;
        }
405
        mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
406 407
        return true;
    }
408 409 410

    @Override
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
411
        if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
412 413 414 415 416
            if (mPaused) {
                mUpdateOnResume = true;
            } else {
                initFragments(mController.getTime(), mController.getViewType(), null);
            }
417 418
        }
    }
419

420 421
    private void setMainPane(FragmentTransaction ft, int viewId, int viewType, long timeMillis,
            boolean force, EventInfo e) {
422 423 424
        if (mOnSaveInstanceStateCalled) {
            return;
        }
425
        if (!force && mCurrentView == viewType) {
426 427 428
            return;
        }

Erik's avatar
Erik committed
429 430 431
        if (viewType != mCurrentView) {
            // The rules for this previous view are different than the
            // controller's and are used for intercepting the back button.
432 433 434
            if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
                mPreviousView = mCurrentView;
            }
Erik's avatar
Erik committed
435 436
            mCurrentView = viewType;
        }
437 438
        // Create new fragment
        Fragment frag;
439 440
        switch (viewType) {
            case ViewType.AGENDA:
441
                frag = new AgendaFragment(timeMillis);
442 443
                break;
            case ViewType.DAY:
444 445 446
                if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
                    mActionBar.selectTab(mDayTab);
                }
Michael Chan's avatar
Michael Chan committed
447 448
                frag = new DayFragment(timeMillis, 1);
                break;
449
            case ViewType.WEEK:
450 451 452
                if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
                    mActionBar.selectTab(mWeekTab);
                }
Michael Chan's avatar
Michael Chan committed
453
                frag = new DayFragment(timeMillis, 7);
454 455
                break;
            case ViewType.MONTH:
456 457 458
                if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
                    mActionBar.selectTab(mMonthTab);
                }
459
                frag = new MonthByWeekFragment(timeMillis, false);
460
                break;
Erik's avatar
Erik committed
461 462 463
//            case ViewType.EDIT:
//                frag = new EditEventFragment(e, mPreviousView);
//                break;
464
            default:
465 466
                throw new IllegalArgumentException(
                        "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
467 468 469 470 471
        }

        boolean doCommit = false;
        if (ft == null) {
            doCommit = true;
472
            ft = getFragmentManager().openTransaction();
473 474 475
        }

        ft.replace(viewId, frag);
476

Erik's avatar
Erik committed
477 478 479
        if (DEBUG) {
            Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
        }
480 481
        // If the key is already registered this will replace it
        mController.registerEventHandler(viewId, (EventHandler) frag);
482 483 484 485 486 487 488

        if (doCommit) {
            ft.commit();
        }
    }

    private void setTitleInActionBar(EventInfo event) {
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
489
        if (event.eventType != EventType.GO_TO || mActionBar == null) {
490 491 492
            return;
        }

Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
493 494
        final long start = event.startTime.toMillis(false /* use isDst */);
        final long end;
495
        if (event.endTime != null) {
496
            end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
497 498
        } else {
            end = start;
499 500
        }

Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
501 502
        final String msg = Utils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_DATE);
        // TODO: add title here.
503 504
    }

Erik's avatar
Erik committed
505
    private void updateHomeClock() {
506
        mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
Erik's avatar
Erik committed
507
        if (mIsMultipane && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK)
508 509
                && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
            Time time = new Time(mTimeZone);
Erik's avatar
Erik committed
510 511 512 513 514 515 516 517
            time.setToNow();
            long millis = time.toMillis(true);
            boolean isDST = time.isDst != 0;
            int flags = DateUtils.FORMAT_SHOW_TIME;
            if (DateFormat.is24HourFormat(this)) {
                flags |= DateUtils.FORMAT_24HOUR;
            }
            // Formats the time as
518 519 520 521
            String timeString = (new StringBuilder(
                    Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
                    TimeZone.getTimeZone(mTimeZone).getDisplayName(
                            isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik's avatar
Erik committed
522 523 524 525
            mHomeTime.setText(timeString);
            mHomeTime.setVisibility(View.VISIBLE);
            // Update when the minute changes
            mHomeTime.postDelayed(
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
526 527
                    mHomeTimeUpdater,
                    DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
Erik's avatar
Erik committed
528 529 530 531 532
        } else {
            mHomeTime.setVisibility(View.GONE);
        }
    }

533
    @Override
534
    public long getSupportedEventTypes() {
Erik's avatar
Erik committed
535
        return EventType.GO_TO | EventType.VIEW_EVENT;
536 537
    }

538
    @Override
539 540 541
    public void handleEvent(EventInfo event) {
        if (event.eventType == EventType.GO_TO) {
            // Set title bar
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
542 543 544
            // TODO: Currently we don't have an appropriate way to add title bar when
            //        ActionBar is in TabNavigation mode.
            // setTitleInActionBar(event);
545

546 547
            setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false),
                    false, event);
548

549 550 551
            if (!mIsMultipane) {
                return;
            }
552 553
            if (event.viewType == ViewType.MONTH) {
                // hide minimonth and calendar frag
554 555
                findViewById(R.id.mini_month).setVisibility(View.GONE);
                findViewById(R.id.calendar_list).setVisibility(View.GONE);
556 557
            } else {
                // show minimonth and calendar frag
558 559
                findViewById(R.id.mini_month).setVisibility(View.VISIBLE);
                findViewById(R.id.calendar_list).setVisibility(View.VISIBLE);
560
            }
Michael Chan's avatar
Michael Chan committed
561
        } else if (event.eventType == EventType.VIEW_EVENT) {
562 563
            EventInfoFragment fragment = new EventInfoFragment(
                    event.id, event.startTime.toMillis(false), event.endTime.toMillis(false));
Michael Chan's avatar
Michael Chan committed
564 565
            fragment.setDialogParams(event.x, event.y);
            fragment.show(getFragmentManager(), "EventInfoFragment");
566
        }
Erik's avatar
Erik committed
567
        updateHomeClock();
568 569
    }

570
    @Override
571
    public void eventsChanged() {
Erik's avatar
Erik committed
572
        mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
573 574
    }

575 576 577 578 579 580 581
    @Override
    public boolean onQueryTextChanged(String newText) {
        return false;
    }

    @Override
    public boolean onSubmitQuery(String query) {
582 583
        mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, query,
                getComponentName());
584 585
        return false;
    }
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
586 587 588

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
589
        if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
590
            mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
591
        } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
592
            mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
593
        } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa's avatar
Daisuke Miyakawa committed
594 595 596 597 598 599 600 601 602 603 604 605 606
            mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
        } else {
            Log.w(TAG, "TabSelected event from unknown tab: " + tab);
        }
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    }
607
}