blob: 359f8f431ce6ec94a80b5b0a04892fb5e59d1ead [file] [log] [blame]
Michael Chan49701592010-06-30 11:04:03 -07001/*
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
RoboErika27a8862011-06-23 15:26:23 -070019import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
20import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
RoboErika7c03902011-06-14 11:06:44 -070021import static android.provider.CalendarContract.Attendees.ATTENDEE_STATUS;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070022import static com.android.calendar.CalendarController.EVENT_ATTENDEE_RESPONSE;
Erikdd95df52010-08-27 09:31:18 -070023
Michael Chan83b0fe32010-07-08 16:46:26 -070024import com.android.calendar.CalendarController.EventHandler;
Michael Chanab29d9e2010-07-21 06:08:47 -070025import com.android.calendar.CalendarController.EventInfo;
Michael Chan83b0fe32010-07-08 16:46:26 -070026import com.android.calendar.CalendarController.EventType;
Michael Chan3458a172010-07-13 17:58:21 -070027import com.android.calendar.CalendarController.ViewType;
Mason Tang00b8c1a2010-08-23 12:02:00 -070028import com.android.calendar.agenda.AgendaFragment;
Erik981874e2010-10-05 16:52:52 -070029import com.android.calendar.month.MonthByWeekFragment;
Michael Chan2aeb8d92011-07-10 13:32:09 -070030import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
Michael Chan83b0fe32010-07-08 16:46:26 -070031
Michael Chan5756bbc2011-03-02 18:22:07 -080032import android.animation.Animator;
33import android.animation.Animator.AnimatorListener;
RoboErikd97f7982011-03-02 15:13:05 -080034import android.animation.ObjectAnimator;
Michael Chanab29d9e2010-07-21 06:08:47 -070035import android.app.ActionBar;
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -070036import android.app.ActionBar.Tab;
Michael Chan49701592010-06-30 11:04:03 -070037import android.app.Activity;
Michael Chan83b0fe32010-07-08 16:46:26 -070038import android.app.Fragment;
Erik63cd0532011-01-26 14:16:03 -080039import android.app.FragmentManager;
Michael Chan3458a172010-07-13 17:58:21 -070040import android.app.FragmentTransaction;
Erik954c8712010-08-06 10:12:34 -070041import android.content.ContentResolver;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070042import android.content.ContentUris;
Erikdd95df52010-08-27 09:31:18 -070043import android.content.Intent;
Mason Tang8e3d4302010-07-12 17:39:30 -070044import android.content.SharedPreferences;
45import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Erikeaafa2b2010-12-23 14:30:37 -080046import android.content.res.Resources;
Erik954c8712010-08-06 10:12:34 -070047import android.database.ContentObserver;
Erikdd95df52010-08-27 09:31:18 -070048import android.net.Uri;
Michael Chan49701592010-06-30 11:04:03 -070049import android.os.Bundle;
Erik954c8712010-08-06 10:12:34 -070050import android.os.Handler;
RoboErika7c03902011-06-14 11:06:44 -070051import android.provider.CalendarContract;
52import android.provider.CalendarContract.Events;
Erik6c255102010-09-29 14:43:00 -070053import android.text.TextUtils;
54import android.text.format.DateFormat;
Michael Chan3458a172010-07-13 17:58:21 -070055import android.text.format.DateUtils;
Michael Chan83b0fe32010-07-08 16:46:26 -070056import android.text.format.Time;
Erik954c8712010-08-06 10:12:34 -070057import android.util.Log;
Erik2051f122010-07-02 13:45:45 -070058import android.view.Menu;
Michael Chan3458a172010-07-13 17:58:21 -070059import android.view.MenuItem;
Michael Chanab29d9e2010-07-21 06:08:47 -070060import android.view.View;
Erik259b8f92011-01-12 14:01:12 -080061import android.view.accessibility.AccessibilityEvent;
RoboErikde20d762011-02-08 17:52:25 -080062import android.widget.RelativeLayout;
63import android.widget.RelativeLayout.LayoutParams;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -070064import android.widget.SearchView;
RoboErike635aec2011-07-15 11:22:13 -070065import android.widget.SearchView.OnCloseListener;
Erik6c255102010-09-29 14:43:00 -070066import android.widget.TextView;
67
Michael Chan2c7c8512010-12-10 14:12:57 -080068import java.util.List;
Erik6c255102010-09-29 14:43:00 -070069import java.util.Locale;
70import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070071
Michael Chanab29d9e2010-07-21 06:08:47 -070072public class AllInOneActivity extends Activity implements EventHandler,
RoboErike635aec2011-07-15 11:22:13 -070073 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener,
74 ActionBar.OnNavigationListener, OnCloseListener {
Michael Chand6734db2010-07-22 00:48:08 -070075 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070076 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080077 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070078 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070079 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080080 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
Erik3f348f32010-08-10 13:17:19 -070081 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080082 private static final long CONTROLS_ANIMATE_DURATION = 400;
RoboErike9cd8f42011-07-01 16:36:11 -070083 private static int CONTROLS_ANIMATE_WIDTH = 280;
RoboErikde20d762011-02-08 17:52:25 -080084 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -080085
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070086 // Indices of buttons for the drop down menu (tabs replacement)
87 // Must match the strings in the array buttons_list in arrays.xml and the
88 // OnNavigationListener
89 private static final int BUTTON_DAY_INDEX = 0;
90 private static final int BUTTON_WEEK_INDEX = 1;
91 private static final int BUTTON_MONTH_INDEX = 2;
92 private static final int BUTTON_AGENDA_INDEX = 3;
93
Michael Chan0558def2010-07-22 21:30:32 -070094 private static CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -070095 private static boolean mIsMultipane;
Isaac Katzenelson62967cb2011-06-14 13:27:20 -070096 private static boolean mIsTabletConfig;
Isaac Katzenelson6a182582011-04-21 15:46:33 -070097 private static boolean mShowAgendaWithMonth;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -070098 private static boolean mShowEventDetailsWithAgenda;
Michael Chan6191c122010-11-02 16:23:47 -070099 private boolean mOnSaveInstanceStateCalled = false;
Erik954c8712010-08-06 10:12:34 -0700100 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700101 private int mPreviousView;
102 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700103 private boolean mPaused = true;
104 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800105 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800106 private boolean mShowSideViews = true;
RoboErik14e82b42011-07-19 09:46:39 -0700107 private boolean mShowWeekNum = false;
Erik6c255102010-09-29 14:43:00 -0700108 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800109 private TextView mDateRange;
RoboErik14e82b42011-07-19 09:46:39 -0700110 private TextView mWeekTextView;
RoboErikde20d762011-02-08 17:52:25 -0800111 private View mMiniMonth;
112 private View mCalendarsList;
113 private View mMiniMonthContainer;
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700114 private View mSecondaryPane;
Erikc5f92d72010-11-11 16:18:34 -0800115 private String mTimeZone;
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700116 private boolean mShowCalendarControls;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700117 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700118 private int mWeekNum;
Erik6c255102010-09-29 14:43:00 -0700119
Michael Chan2c7c8512010-12-10 14:12:57 -0800120 private long mViewEventId = -1;
121 private long mIntentEventStartMillis = -1;
122 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800123 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800124
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700125 // Action bar and Navigation bar (left side of Action bar)
126 private ActionBar mActionBar;
127 private ActionBar.Tab mDayTab;
128 private ActionBar.Tab mWeekTab;
129 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700130 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800131 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700132 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800133 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700134 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700135 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErikde20d762011-02-08 17:52:25 -0800136
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700137 private String mHideString;
138 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800139
RoboErikb8549562011-02-15 14:25:23 -0800140 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800141 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
142
143 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
144
145 @Override
146 public void onAnimationCancel(Animator animation) {
147 }
148
149 @Override
150 public void onAnimationEnd(android.animation.Animator animation) {
151 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
152 mMiniMonth.setVisibility(visibility);
153 mCalendarsList.setVisibility(visibility);
154 mMiniMonthContainer.setVisibility(visibility);
155 }
156
157 @Override
158 public void onAnimationRepeat(android.animation.Animator animation) {
159 }
160
161 @Override
162 public void onAnimationStart(android.animation.Animator animation) {
163 }
164 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700165
Erik6c255102010-09-29 14:43:00 -0700166 private Runnable mHomeTimeUpdater = new Runnable() {
167 @Override
168 public void run() {
RoboErik14e82b42011-07-19 09:46:39 -0700169 updateHomeClockAndWeekNum(-1);
Erik6c255102010-09-29 14:43:00 -0700170 }
171 };
Erik954c8712010-08-06 10:12:34 -0700172
173 // Create an observer so that we can update the views whenever a
174 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700175 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700176 @Override
177 public boolean deliverSelfNotifications() {
178 return true;
179 }
180
181 @Override
182 public void onChange(boolean selfChange) {
183 eventsChanged();
184 }
185 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700186
Michael Chan49701592010-06-30 11:04:03 -0700187 @Override
Erik63cd0532011-01-26 14:16:03 -0800188 protected void onNewIntent(Intent intent) {
189 String action = intent.getAction();
190 if (Intent.ACTION_VIEW.equals(action)) {
191 parseViewAction(intent);
192 }
193 }
194
195 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700196 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800197 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
198 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
199 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700200 super.onCreate(icicle);
201
202 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700203 mController = CalendarController.getInstance(this);
Erik954c8712010-08-06 10:12:34 -0700204 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800205 long timeMillis = -1;
206 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800207 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700208 if (icicle != null) {
209 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800210 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700211 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800212 String action = intent.getAction();
213 if (Intent.ACTION_VIEW.equals(action)) {
214 // Open EventInfo later
215 timeMillis = parseViewAction(intent);
216 }
217
218 if (timeMillis == -1) {
219 timeMillis = Utils.timeFromIntentInMillis(intent);
220 }
221 }
222
RoboErik277eb972011-02-24 16:05:04 -0800223 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700224 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
225 }
Erikc5f92d72010-11-11 16:18:34 -0800226 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
227 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700228 t.set(timeMillis);
229
Michael Chan2c7c8512010-12-10 14:12:57 -0800230 if (icicle != null && intent != null) {
231 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700232 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800233 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700234 }
235
Erikeaafa2b2010-12-23 14:30:37 -0800236 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800237 if (mScale == 0) {
238 mScale = res.getDisplayMetrics().density;
239 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800240 }
241 mHideString = res.getString(R.string.hide_controls);
242 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800243 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800244
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700245 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700246 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700247 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700248 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700249 mShowEventDetailsWithAgenda =
250 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700251 mShowEventInfoFullScreen =
252 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700253
Erik63cd0532011-01-26 14:16:03 -0800254 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800255
Erikbe8191c2010-10-26 16:50:08 -0700256 // setContentView must be called before configureActionBar
257 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700258
259 if (mIsTabletConfig) {
260 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700261 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700262 } else {
263 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
264 }
265
Erikbe8191c2010-10-26 16:50:08 -0700266 // configureActionBar auto-selects the first tab you add, so we need to
267 // call it before we set up our own fragments to make sure it doesn't
268 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700269 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700270
Erik3f348f32010-08-10 13:17:19 -0700271 // Must be the first to register because this activity can modify the
272 // list of event handlers in it's handle method. This affects who the
273 // rest of the handlers the controller dispatches to are.
274 mController.registerEventHandler(HANDLER_KEY, this);
Michael Chan83b0fe32010-07-08 16:46:26 -0700275
Erik6c255102010-09-29 14:43:00 -0700276 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800277 mMiniMonth = findViewById(R.id.mini_month);
278 mCalendarsList = findViewById(R.id.calendar_list);
279 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700280 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700281
Erik7b92da22010-09-23 14:55:22 -0700282 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700283
284 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700285 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700286 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700287
Erik954c8712010-08-06 10:12:34 -0700288 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700289 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700290
Michael Chan2c7c8512010-12-10 14:12:57 -0800291 private long parseViewAction(final Intent intent) {
292 long timeMillis = -1;
293 Uri data = intent.getData();
294 if (data != null && data.isHierarchical()) {
295 List<String> path = data.getPathSegments();
296 if (path.size() == 2 && path.get(0).equals("events")) {
297 try {
298 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700299 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700300 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
301 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800302 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800303 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800304 timeMillis = mIntentEventStartMillis;
305 }
306 } catch (NumberFormatException e) {
307 // Ignore if mViewEventId can't be parsed
308 }
309 }
310 }
311 return timeMillis;
312 }
313
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700314 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700315 if (mIsTabletConfig) {
316 createTabs();
317 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700318 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700319 mActionBar.setCustomView(mDateRange);
320 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700321 if (mIsMultipane) {
322 mActionBar.setDisplayOptions(
323 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
324 } else {
325 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
326 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700327 }
328
329 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700330 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700331 if (mActionBar == null) {
332 Log.w(TAG, "ActionBar is null.");
333 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700334 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700335 mDayTab = mActionBar.newTab();
336 mDayTab.setText(getString(R.string.day_view));
337 mDayTab.setTabListener(this);
338 mActionBar.addTab(mDayTab);
339 mWeekTab = mActionBar.newTab();
340 mWeekTab.setText(getString(R.string.week_view));
341 mWeekTab.setTabListener(this);
342 mActionBar.addTab(mWeekTab);
343 mMonthTab = mActionBar.newTab();
344 mMonthTab.setText(getString(R.string.month_view));
345 mMonthTab.setTabListener(this);
346 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700347 mAgendaTab = mActionBar.newTab();
348 mAgendaTab.setText(getString(R.string.agenda_view));
349 mAgendaTab.setTabListener(this);
350 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700351 }
Erik954c8712010-08-06 10:12:34 -0700352 }
353
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700354 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700355 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700356 mActionBar = getActionBar();
357 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
358 mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_USE_LOGO|
359 ActionBar.DISPLAY_SHOW_TITLE);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700360 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700361 switch (viewType) {
362 case ViewType.AGENDA:
363 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
364 break;
365 case ViewType.DAY:
366 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
367 break;
368 case ViewType.WEEK:
369 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
370 break;
371 case ViewType.MONTH:
372 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
373 break;
374 default:
375 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
376 break;
377 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700378 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700379 // Clear buttons used in the agenda view
380 private void clearOptionsMenu() {
381 if (mOptionsMenu == null) {
382 return;
383 }
384 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700385 MenuItem editItem = mOptionsMenu.findItem(R.id.action_edit);
386 if (cancelItem != null) {
387 cancelItem.setVisible(false);
388 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700389 if (editItem != null) {
390 editItem.setVisible(false);
391 }
392 }
393
Erik954c8712010-08-06 10:12:34 -0700394 @Override
395 protected void onResume() {
396 super.onResume();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700397 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
398 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700399 if (mUpdateOnResume) {
400 initFragments(mController.getTime(), mController.getViewType(), null);
401 mUpdateOnResume = false;
402 }
RoboErik14e82b42011-07-19 09:46:39 -0700403 updateHomeClockAndWeekNum(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700404 // Make sure the drop-down menu will get its date updated at midnight
405 if (mActionBarMenuSpinnerAdapter != null) {
406 mActionBarMenuSpinnerAdapter.setMidnightHandler();
407 }
408
RoboErik3b3af612011-02-24 13:42:57 -0800409 if (mControlsMenu != null) {
410 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
411 }
Erikcb811892010-09-28 13:44:19 -0700412 mPaused = false;
Michael Chan6191c122010-11-02 16:23:47 -0700413 mOnSaveInstanceStateCalled = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800414
415 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800416 long currentMillis = System.currentTimeMillis();
417 long selectedTime = -1;
418 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
419 selectedTime = currentMillis;
420 }
Michael Chanf0868f62011-01-11 19:37:35 -0800421 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700422 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
423 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800424 mViewEventId = -1;
425 mIntentEventStartMillis = -1;
426 mIntentEventEndMillis = -1;
427 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700428 }
429
430 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700431 protected void onPause() {
432 super.onPause();
Erikcb811892010-09-28 13:44:19 -0700433 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700434 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700435 if (mActionBarMenuSpinnerAdapter != null) {
436 mActionBarMenuSpinnerAdapter.resetMidnightHandler();
437 }
Erik954c8712010-08-06 10:12:34 -0700438 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700439 if (isFinishing()) {
440 // Stop listening for changes that would require this to be refreshed
441 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
442 prefs.unregisterOnSharedPreferenceChangeListener(this);
443 }
Erik7b92da22010-09-23 14:55:22 -0700444 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700445 if (mController.getViewType() != ViewType.EDIT) {
446 Utils.setDefaultView(this, mController.getViewType());
447 }
Michael Chand6734db2010-07-22 00:48:08 -0700448 }
449
450 @Override
Erik7b92da22010-09-23 14:55:22 -0700451 protected void onUserLeaveHint() {
452 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
453 super.onUserLeaveHint();
454 }
455
456 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700457 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700458 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700459 super.onSaveInstanceState(outState);
460
461 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700462 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800463 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700464 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
465 }
Michael Chand6734db2010-07-22 00:48:08 -0700466 }
467
468 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700469 protected void onDestroy() {
470 super.onDestroy();
471
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700472 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700473 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700474 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700475 }
476
Erik7b92da22010-09-23 14:55:22 -0700477 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700478 if (DEBUG) {
479 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
480 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800481 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700482
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700483 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800484 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700485 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700486 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700487
Michael Chan2aeb8d92011-07-10 13:32:09 -0700488 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700489 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800490 mController.registerEventHandler(
491 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700492 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700493 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800494 mMiniMonth.setVisibility(View.GONE);
495 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700496 }
Michael Chan3458a172010-07-13 17:58:21 -0700497
Erikdd95df52010-08-27 09:31:18 -0700498 EventInfo info = null;
499 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700500 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700501 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700502
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700503 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700504 Intent intent = getIntent();
505 Uri data = intent.getData();
506 if (data != null) {
507 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700508 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700509 } catch (NumberFormatException e) {
510 if (DEBUG) {
511 Log.d(TAG, "Create new event");
512 }
513 }
Erik7b92da22010-09-23 14:55:22 -0700514 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
515 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700516 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700517
RoboErika27a8862011-06-23 15:26:23 -0700518 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
519 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700520 info = new EventInfo();
521 if (end != -1) {
522 info.endTime = new Time();
523 info.endTime.set(end);
524 }
525 if (begin != -1) {
526 info.startTime = new Time();
527 info.startTime.set(begin);
528 }
529 info.id = eventId;
530 // We set the viewtype so if the user presses back when they are
531 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700532 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700533 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700534 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700535 } else {
536 mPreviousView = viewType;
537 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700538
Erik63cd0532011-01-26 14:16:03 -0800539 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700540 ft.commit(); // this needs to be after setMainPane()
541
Erikc5f92d72010-11-11 16:18:34 -0800542 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700543 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700544 if (viewType != ViewType.EDIT) {
545 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
546 }
Michael Chan49701592010-06-30 11:04:03 -0700547 }
Erik2051f122010-07-02 13:45:45 -0700548
549 @Override
Erik648c59c2010-08-13 12:49:26 -0700550 public void onBackPressed() {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700551 if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) {
Erikdd95df52010-08-27 09:31:18 -0700552 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700553 } else {
554 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700555 }
556 }
557
558 @Override
Erik2051f122010-07-02 13:45:45 -0700559 public boolean onCreateOptionsMenu(Menu menu) {
560 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700561 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700562 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700563
RoboErike635aec2011-07-15 11:22:13 -0700564 mSearchMenu = menu.findItem(R.id.action_search);
565 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800566 if (mSearchView != null) {
567 mSearchView.setIconifiedByDefault(true);
Adam Powell28f9b352011-01-20 18:36:10 -0800568 mSearchView.setOnQueryTextListener(this);
Erikcb830312011-01-19 14:41:41 -0800569 mSearchView.setSubmitButtonEnabled(true);
RoboErike635aec2011-07-15 11:22:13 -0700570 mSearchView.setOnCloseListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700571 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700572
573 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700574 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700575
RoboErikde20d762011-02-08 17:52:25 -0800576 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700577 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700578 if (mControlsMenu != null) {
579 mControlsMenu.setVisible(false);
580 mControlsMenu.setEnabled(false);
581 }
582 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700583 && (mController.getViewType() == ViewType.MONTH ||
584 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800585 mControlsMenu.setVisible(false);
586 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700587 } else if (mControlsMenu != null){
588 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800589 }
Erik2051f122010-07-02 13:45:45 -0700590 return true;
591 }
Michael Chan3458a172010-07-13 17:58:21 -0700592
593 @Override
594 public boolean onOptionsItemSelected(MenuItem item) {
595 Time t = null;
596 int viewType = ViewType.CURRENT;
597 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700598 case R.id.action_refresh:
599 mController.refreshCalendars();
600 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700601 case R.id.action_today:
602 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800603 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700604 t.setToNow();
605 break;
606 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800607 t = new Time();
608 t.set(mController.getTime());
609 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800610 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800611 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800612 } else {
613 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800614 }
615 mController.sendEventRelatedEvent(
616 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700617 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700618 case R.id.action_select_visible_calendars:
619 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
620 0, 0);
621 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700622 case R.id.action_settings:
623 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
624 return true;
RoboErikde20d762011-02-08 17:52:25 -0800625 case R.id.action_hide_controls:
626 mHideControls = !mHideControls;
627 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800628 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
629 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
630 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
631 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
632 ObjectAnimator.setFrameDelay(0);
633 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800634 return true;
RoboErike635aec2011-07-15 11:22:13 -0700635 case R.id.action_search:
636 if (!mIsMultipane && mSearchView != null) {
637 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
638 mSearchView.setActivated(true);
639 mSearchView.setIconified(false);
640 }
Michael Chan3458a172010-07-13 17:58:21 -0700641 default:
642 return false;
643 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700644 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700645 return true;
646 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700647
RoboErikb8549562011-02-15 14:25:23 -0800648 /**
649 * Sets the offset of the controls on the right for animating them off/on
650 * screen. ProGuard strips this if it's not in proguard.flags
651 *
652 * @param controlsOffset The current offset in pixels
653 */
654 public void setControlsOffset(int controlsOffset) {
655 mMiniMonth.setTranslationX(controlsOffset);
656 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800657 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800658 mMiniMonthContainer.setLayoutParams(mControlsParams);
659 }
RoboErikde20d762011-02-08 17:52:25 -0800660
Mason Tang8e3d4302010-07-12 17:39:30 -0700661 @Override
662 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700663 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700664 if (mPaused) {
665 mUpdateOnResume = true;
666 } else {
667 initFragments(mController.getTime(), mController.getViewType(), null);
668 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700669 }
670 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700671
Erik63cd0532011-01-26 14:16:03 -0800672 private void setMainPane(
673 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700674 if (mOnSaveInstanceStateCalled) {
675 return;
676 }
Erik7b92da22010-09-23 14:55:22 -0700677 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700678 return;
679 }
680
Michael Chan5756bbc2011-03-02 18:22:07 -0800681 // Remove this when transition to and from month view looks fine.
682 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700683 FragmentManager fragmentManager = getFragmentManager();
684 // Check if our previous view was an Agenda view
685 // TODO remove this if framework ever supports nested fragments
686 if (mCurrentView == ViewType.AGENDA) {
687 // If it was, we need to do some cleanup on it to prevent the
688 // edit/delete buttons from coming back on a rotation.
689 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
690 if (oldFrag instanceof AgendaFragment) {
691 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
692 }
693 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800694
Erik648c59c2010-08-13 12:49:26 -0700695 if (viewType != mCurrentView) {
696 // The rules for this previous view are different than the
697 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700698 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
699 mPreviousView = mCurrentView;
700 }
Erik648c59c2010-08-13 12:49:26 -0700701 mCurrentView = viewType;
702 }
Erik3f348f32010-08-10 13:17:19 -0700703 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700704 Fragment frag = null;
705 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700706 switch (viewType) {
707 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700708 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
709 mActionBar.selectTab(mAgendaTab);
710 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700711 if (mActionBarMenuSpinnerAdapter != null) {
712 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
713 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700714 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700715 break;
716 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700717 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
718 mActionBar.selectTab(mDayTab);
719 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700720 if (mActionBarMenuSpinnerAdapter != null) {
721 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
722 }
Michael Chan75d9b562010-07-26 16:54:25 -0700723 frag = new DayFragment(timeMillis, 1);
724 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700725 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700726 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
727 mActionBar.selectTab(mWeekTab);
728 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700729 if (mActionBarMenuSpinnerAdapter != null) {
730 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
731 }
Michael Chan75d9b562010-07-26 16:54:25 -0700732 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700733 break;
734 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700735 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
736 mActionBar.selectTab(mMonthTab);
737 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700738 if (mActionBarMenuSpinnerAdapter != null) {
739 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
740 }
Erik40bcd102010-11-16 15:46:40 -0800741 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700742 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700743 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700744 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700745 break;
746 default:
Michael Chand6734db2010-07-22 00:48:08 -0700747 throw new IllegalArgumentException(
748 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700749 }
750
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700751 // Update the current view so that the menu can update its look according to the
752 // current view.
753 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
754 mActionBarMenuSpinnerAdapter.setMainView(viewType);
755 }
756
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700757
758 // Show date only on tablet configurations in views different than Agenda
759 if (!mIsTabletConfig) {
760 mDateRange.setVisibility(View.GONE);
761 } else if (viewType != ViewType.AGENDA) {
762 mDateRange.setVisibility(View.VISIBLE);
763 } else {
764 mDateRange.setVisibility(View.GONE);
765 }
766
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700767 // Clear unnecessary buttons from the option menu when switching from the agenda view
768 if (viewType != ViewType.AGENDA) {
769 clearOptionsMenu();
770 }
771
Michael Chanab29d9e2010-07-21 06:08:47 -0700772 boolean doCommit = false;
773 if (ft == null) {
774 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700775 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700776 }
777
Michael Chan5756bbc2011-03-02 18:22:07 -0800778 if (doTransition) {
779 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
780 }
781
Michael Chanab29d9e2010-07-21 06:08:47 -0700782 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700783 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700784
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700785 // Show/hide secondary fragment
786
787 if (secFrag != null) {
788 ft.replace(R.id.secondary_pane, secFrag);
789 mSecondaryPane.setVisibility(View.VISIBLE);
790 } else {
791 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700792 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700793 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700794 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700795 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700796 mController.deregisterEventHandler(R.id.secondary_pane);
797 }
798 }
Erik954c8712010-08-06 10:12:34 -0700799 if (DEBUG) {
800 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
801 }
Erik3f348f32010-08-10 13:17:19 -0700802 // If the key is already registered this will replace it
803 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700804 if (secFrag != null) {
805 mController.registerEventHandler(viewId, (EventHandler) secFrag);
806 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700807
808 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800809 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700810 ft.commit();
811 }
812 }
813
814 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800815 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700816 return;
817 }
818
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700819 final long start = event.startTime.toMillis(false /* use isDst */);
820 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700821 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700822 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700823 } else {
824 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700825 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700826
Erikeaafa2b2010-12-23 14:30:37 -0800827 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800828 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800829 mDateRange.setText(msg);
RoboErik14e82b42011-07-19 09:46:39 -0700830 updateHomeClockAndWeekNum(start);
Erik259b8f92011-01-12 14:01:12 -0800831 if (!TextUtils.equals(oldDate, msg)) {
832 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700833 if (mShowWeekNum && mWeekTextView != null) {
834 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
835 }
Erik259b8f92011-01-12 14:01:12 -0800836 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700837 }
838
RoboErik14e82b42011-07-19 09:46:39 -0700839 private void updateHomeClockAndWeekNum(long visibleMillisSinceEpoch) {
840 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800841 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700842 if (visibleMillisSinceEpoch != -1) {
843 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
844 mWeekNum = weekNum;
845 }
846
847 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
848 && mWeekTextView != null) {
849 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
850 mWeekNum);
851 mWeekTextView.setText(weekString);
852 mWeekTextView.setVisibility(View.VISIBLE);
853 } else if (mWeekTextView != null) {
854 mWeekTextView.setVisibility(View.GONE);
855 }
856 if (mHomeTime != null
857 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
858 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800859 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
860 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700861 time.setToNow();
862 long millis = time.toMillis(true);
863 boolean isDST = time.isDst != 0;
864 int flags = DateUtils.FORMAT_SHOW_TIME;
865 if (DateFormat.is24HourFormat(this)) {
866 flags |= DateUtils.FORMAT_24HOUR;
867 }
868 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800869 String timeString = (new StringBuilder(
870 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
871 TimeZone.getTimeZone(mTimeZone).getDisplayName(
872 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700873 mHomeTime.setText(timeString);
874 mHomeTime.setVisibility(View.VISIBLE);
875 // Update when the minute changes
876 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700877 mHomeTimeUpdater,
878 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700879 } else if (mHomeTime != null) {
880 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700881 }
882 }
883
Erik3f348f32010-08-10 13:17:19 -0700884 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700885 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800886 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700887 }
888
Erik3f348f32010-08-10 13:17:19 -0700889 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700890 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700891 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700892 if (event.eventType == EventType.GO_TO) {
Erik63cd0532011-01-26 14:16:03 -0800893 setMainPane(
894 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800895 if (mSearchView != null) {
896 mSearchView.clearFocus();
897 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700898
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700899 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700900 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700901 // hide minimonth and calendar frag
902 mShowSideViews = false;
903 if (mControlsMenu != null) {
904 mControlsMenu.setVisible(false);
905 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800906
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700907 if (!mHideControls) {
908 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
909 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
910 slideAnimation.addListener(mSlideAnimationDoneListener);
911 slideAnimation.setDuration(220);
912 ObjectAnimator.setFrameDelay(0);
913 slideAnimation.start();
914 }
915 } else {
916 mMiniMonth.setVisibility(View.GONE);
917 mCalendarsList.setVisibility(View.GONE);
918 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -0800919 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800920 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700921 // show minimonth and calendar frag
922 mShowSideViews = true;
923 mMiniMonth.setVisibility(View.VISIBLE);
924 mCalendarsList.setVisibility(View.VISIBLE);
925 mMiniMonthContainer.setVisibility(View.VISIBLE);
926 if (mControlsMenu != null) {
927 mControlsMenu.setVisible(true);
928 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700929 if (!mHideControls &&
930 (mController.getPreviousViewType() == ViewType.MONTH ||
931 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700932 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
933 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
934 slideAnimation.setDuration(220);
935 ObjectAnimator.setFrameDelay(0);
936 slideAnimation.start();
937 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800938 }
RoboErikde20d762011-02-08 17:52:25 -0800939 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700940 }
RoboErik14e82b42011-07-19 09:46:39 -0700941 displayTime = event.startTime.toMillis(true);
Michael Chan71d08832010-08-25 18:28:59 -0700942 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700943
944 // If in Agenda view and "show_event_details_with_agenda" is "true",
945 // do not create the event info fragment here, it will be created by the Agenda
946 // fragment
947
RoboErikd6c93ce2011-07-22 17:54:40 -0700948 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -0700949 if (event.startTime != null && event.endTime != null) {
950 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
951 event.id, ViewType.AGENDA);
952 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700953 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
954 event.selectedTime, event.id, ViewType.AGENDA);
955 }
956 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700957 if (mShowEventInfoFullScreen) {
958 // start event info as activity
959 Intent intent = new Intent(Intent.ACTION_VIEW);
960 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
961 intent.setData(eventUri);
962 intent.setClassName(this, EventInfoActivity.class.getName());
963 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
964 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -0700965 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
966 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700967 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
968 startActivity(intent);
969 } else {
970 // start event info as a dialog
971 EventInfoFragment fragment = new EventInfoFragment(this,
972 event.id, event.startTime.toMillis(false),
973 event.endTime.toMillis(false), (int) event.extraLong, true);
974 // TODO Fix the temp hack below: && mCurrentView !=
975 // ViewType.AGENDA
976 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
977 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
978 event.selectedTime, -1, ViewType.DETAIL);
979 }
980 fragment.setDialogParams(event.x, event.y);
981 FragmentManager fm = getFragmentManager();
982 FragmentTransaction ft = fm.beginTransaction();
983 // if we have an old popup close it
984 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
985 if (fOld != null && fOld.isAdded()) {
986 ft.remove(fOld);
987 }
988 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
989 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700990 }
Erik63cd0532011-01-26 14:16:03 -0800991 }
RoboErik14e82b42011-07-19 09:46:39 -0700992 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -0800993 } else if (event.eventType == EventType.UPDATE_TITLE) {
994 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700995 if (!mIsTabletConfig) {
996 mActionBarMenuSpinnerAdapter.setTime(event.startTime.toMillis(false));
997 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700998 }
RoboErik14e82b42011-07-19 09:46:39 -0700999 updateHomeClockAndWeekNum(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001000 }
1001
Michael Chan2aeb8d92011-07-10 13:32:09 -07001002 // Needs to be in proguard whitelist
1003 // Specified as listener via android:onClick in a layout xml
1004 public void handleSelectSyncedCalendarsClicked(View v) {
1005 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1006 CalendarController.EXTRA_GOTO_TIME, null,
1007 null);
1008 }
1009
Erik3f348f32010-08-10 13:17:19 -07001010 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001011 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001012 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001013 }
1014
Erik3f348f32010-08-10 13:17:19 -07001015 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001016 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001017 return false;
1018 }
1019
1020 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001021 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001022 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001023 Utils.tardis();
1024 }
Erikcb830312011-01-19 14:41:41 -08001025 mSearchView.clearFocus();
Michael Chan46a8b112010-12-14 16:36:27 -08001026 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, -1, query,
Erik7b92da22010-09-23 14:55:22 -07001027 getComponentName());
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001028 return false;
1029 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001030
1031 @Override
1032 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001033 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001034 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001035 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001036 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001037 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001038 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001039 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001040 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1041 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001042 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001043 Log.w(TAG, "TabSelected event from unknown tab: "
1044 + (tab == null ? "null" : tab.getText()));
1045 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001046 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001047 }
1048 }
1049
1050 @Override
1051 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1052 }
1053
1054 @Override
1055 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1056 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001057
1058
1059 @Override
1060 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1061 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001062 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001063 if (mCurrentView != ViewType.DAY) {
1064 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1065 }
1066 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001067 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001068 if (mCurrentView != ViewType.WEEK) {
1069 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1070 }
1071 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001072 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001073 if (mCurrentView != ViewType.MONTH) {
1074 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1075 }
1076 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001077 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001078 if (mCurrentView != ViewType.AGENDA) {
1079 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1080 }
1081 break;
1082 default:
1083 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1084 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1085 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1086 " Agenda:" + mAgendaTab);
1087 break;
1088 }
1089 return false;
1090 }
RoboErike635aec2011-07-15 11:22:13 -07001091
1092 /*
1093 * Handles the search view being closed.
1094 */
1095 @Override
1096 public boolean onClose() {
1097 if (!mIsMultipane) {
1098 mSearchMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
1099 invalidateOptionsMenu();
1100 }
1101 return false;
1102 }
Michael Chan49701592010-06-30 11:04:03 -07001103}