blob: 1e8bec658cfeb9a8e6040d193da27e8a49854155 [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,
RoboErik50f10942011-07-26 14:30:25 -070074 ActionBar.OnNavigationListener {
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
RoboErikd69ccdf2011-08-05 14:50:27 -070094 private 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);
RoboErik3864be02011-07-25 15:56:50 -0700204
205
Erik954c8712010-08-06 10:12:34 -0700206 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800207 long timeMillis = -1;
208 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800209 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700210 if (icicle != null) {
211 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800212 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700213 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800214 String action = intent.getAction();
215 if (Intent.ACTION_VIEW.equals(action)) {
216 // Open EventInfo later
217 timeMillis = parseViewAction(intent);
218 }
219
220 if (timeMillis == -1) {
221 timeMillis = Utils.timeFromIntentInMillis(intent);
222 }
223 }
224
RoboErik277eb972011-02-24 16:05:04 -0800225 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700226 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
227 }
Erikc5f92d72010-11-11 16:18:34 -0800228 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
229 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700230 t.set(timeMillis);
231
Michael Chan2c7c8512010-12-10 14:12:57 -0800232 if (icicle != null && intent != null) {
233 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700234 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800235 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700236 }
237
Erikeaafa2b2010-12-23 14:30:37 -0800238 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800239 if (mScale == 0) {
240 mScale = res.getDisplayMetrics().density;
241 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800242 }
243 mHideString = res.getString(R.string.hide_controls);
244 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800245 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800246
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700247 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700248 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700249 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700250 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700251 mShowEventDetailsWithAgenda =
252 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700253 mShowEventInfoFullScreen =
254 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700255
Erik63cd0532011-01-26 14:16:03 -0800256 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800257
Erikbe8191c2010-10-26 16:50:08 -0700258 // setContentView must be called before configureActionBar
259 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700260
261 if (mIsTabletConfig) {
262 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700263 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700264 } else {
265 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
266 }
267
Erikbe8191c2010-10-26 16:50:08 -0700268 // configureActionBar auto-selects the first tab you add, so we need to
269 // call it before we set up our own fragments to make sure it doesn't
270 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700271 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700272
Erik6c255102010-09-29 14:43:00 -0700273 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800274 mMiniMonth = findViewById(R.id.mini_month);
275 mCalendarsList = findViewById(R.id.calendar_list);
276 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700277 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700278
RoboErik3864be02011-07-25 15:56:50 -0700279 // Must register as the first activity because this activity can modify
280 // the list of event handlers in it's handle method. This affects who
281 // the rest of the handlers the controller dispatches to are.
282 mController.registerFirstEventHandler(HANDLER_KEY, this);
283
Erik7b92da22010-09-23 14:55:22 -0700284 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700285
286 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700287 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700288 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700289
Erik954c8712010-08-06 10:12:34 -0700290 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700291 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700292
Michael Chan2c7c8512010-12-10 14:12:57 -0800293 private long parseViewAction(final Intent intent) {
294 long timeMillis = -1;
295 Uri data = intent.getData();
296 if (data != null && data.isHierarchical()) {
297 List<String> path = data.getPathSegments();
298 if (path.size() == 2 && path.get(0).equals("events")) {
299 try {
300 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700301 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700302 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
303 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800304 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800305 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800306 timeMillis = mIntentEventStartMillis;
307 }
308 } catch (NumberFormatException e) {
309 // Ignore if mViewEventId can't be parsed
310 }
311 }
312 }
313 return timeMillis;
314 }
315
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700316 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700317 if (mIsTabletConfig) {
318 createTabs();
319 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700320 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700321 mActionBar.setCustomView(mDateRange);
322 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700323 if (mIsMultipane) {
324 mActionBar.setDisplayOptions(
325 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
326 } else {
327 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
328 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700329 }
330
331 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700332 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700333 if (mActionBar == null) {
334 Log.w(TAG, "ActionBar is null.");
335 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700336 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700337 mDayTab = mActionBar.newTab();
338 mDayTab.setText(getString(R.string.day_view));
339 mDayTab.setTabListener(this);
340 mActionBar.addTab(mDayTab);
341 mWeekTab = mActionBar.newTab();
342 mWeekTab.setText(getString(R.string.week_view));
343 mWeekTab.setTabListener(this);
344 mActionBar.addTab(mWeekTab);
345 mMonthTab = mActionBar.newTab();
346 mMonthTab.setText(getString(R.string.month_view));
347 mMonthTab.setTabListener(this);
348 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700349 mAgendaTab = mActionBar.newTab();
350 mAgendaTab.setText(getString(R.string.agenda_view));
351 mAgendaTab.setTabListener(this);
352 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700353 }
Erik954c8712010-08-06 10:12:34 -0700354 }
355
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700356 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700357 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700358 mActionBar = getActionBar();
359 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
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();
RoboErik3864be02011-07-25 15:56:50 -0700397
398 // Must register as the first activity because this activity can modify
399 // the list of event handlers in it's handle method. This affects who
400 // the rest of the handlers the controller dispatches to are.
401 mController.registerFirstEventHandler(HANDLER_KEY, this);
402
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700403 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
404 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700405 if (mUpdateOnResume) {
406 initFragments(mController.getTime(), mController.getViewType(), null);
407 mUpdateOnResume = false;
408 }
RoboErik14e82b42011-07-19 09:46:39 -0700409 updateHomeClockAndWeekNum(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700410 // Make sure the drop-down menu will get its date updated at midnight
411 if (mActionBarMenuSpinnerAdapter != null) {
412 mActionBarMenuSpinnerAdapter.setMidnightHandler();
413 }
414
RoboErik3b3af612011-02-24 13:42:57 -0800415 if (mControlsMenu != null) {
416 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
417 }
Erikcb811892010-09-28 13:44:19 -0700418 mPaused = false;
Michael Chan6191c122010-11-02 16:23:47 -0700419 mOnSaveInstanceStateCalled = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800420
421 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800422 long currentMillis = System.currentTimeMillis();
423 long selectedTime = -1;
424 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
425 selectedTime = currentMillis;
426 }
Michael Chanf0868f62011-01-11 19:37:35 -0800427 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700428 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
429 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800430 mViewEventId = -1;
431 mIntentEventStartMillis = -1;
432 mIntentEventEndMillis = -1;
433 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700434 }
435
436 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700437 protected void onPause() {
438 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700439
440 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700441 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700442 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700443 if (mActionBarMenuSpinnerAdapter != null) {
444 mActionBarMenuSpinnerAdapter.resetMidnightHandler();
445 }
Erik954c8712010-08-06 10:12:34 -0700446 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700447 if (isFinishing()) {
448 // Stop listening for changes that would require this to be refreshed
449 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
450 prefs.unregisterOnSharedPreferenceChangeListener(this);
451 }
Erik7b92da22010-09-23 14:55:22 -0700452 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700453 if (mController.getViewType() != ViewType.EDIT) {
454 Utils.setDefaultView(this, mController.getViewType());
455 }
Michael Chand6734db2010-07-22 00:48:08 -0700456 }
457
458 @Override
Erik7b92da22010-09-23 14:55:22 -0700459 protected void onUserLeaveHint() {
460 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
461 super.onUserLeaveHint();
462 }
463
464 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700465 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700466 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700467 super.onSaveInstanceState(outState);
468
469 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700470 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800471 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700472 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
473 }
Michael Chand6734db2010-07-22 00:48:08 -0700474 }
475
476 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700477 protected void onDestroy() {
478 super.onDestroy();
479
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700480 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700481 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700482 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700483 }
484
Erik7b92da22010-09-23 14:55:22 -0700485 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700486 if (DEBUG) {
487 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
488 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800489 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700490
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700491 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800492 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700493 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700494 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700495
Michael Chan2aeb8d92011-07-10 13:32:09 -0700496 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700497 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800498 mController.registerEventHandler(
499 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700500 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700501 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800502 mMiniMonth.setVisibility(View.GONE);
503 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700504 }
Michael Chan3458a172010-07-13 17:58:21 -0700505
Erikdd95df52010-08-27 09:31:18 -0700506 EventInfo info = null;
507 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700508 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700509 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700510
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700511 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700512 Intent intent = getIntent();
513 Uri data = intent.getData();
514 if (data != null) {
515 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700516 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700517 } catch (NumberFormatException e) {
518 if (DEBUG) {
519 Log.d(TAG, "Create new event");
520 }
521 }
Erik7b92da22010-09-23 14:55:22 -0700522 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
523 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700524 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700525
RoboErika27a8862011-06-23 15:26:23 -0700526 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
527 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700528 info = new EventInfo();
529 if (end != -1) {
530 info.endTime = new Time();
531 info.endTime.set(end);
532 }
533 if (begin != -1) {
534 info.startTime = new Time();
535 info.startTime.set(begin);
536 }
537 info.id = eventId;
538 // We set the viewtype so if the user presses back when they are
539 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700540 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700541 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700542 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700543 } else {
544 mPreviousView = viewType;
545 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700546
Erik63cd0532011-01-26 14:16:03 -0800547 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700548 ft.commit(); // this needs to be after setMainPane()
549
Erikc5f92d72010-11-11 16:18:34 -0800550 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700551 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700552 if (viewType != ViewType.EDIT) {
553 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
554 }
Michael Chan49701592010-06-30 11:04:03 -0700555 }
Erik2051f122010-07-02 13:45:45 -0700556
557 @Override
Erik648c59c2010-08-13 12:49:26 -0700558 public void onBackPressed() {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700559 if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) {
Erikdd95df52010-08-27 09:31:18 -0700560 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700561 } else {
562 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700563 }
564 }
565
566 @Override
Erik2051f122010-07-02 13:45:45 -0700567 public boolean onCreateOptionsMenu(Menu menu) {
568 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700569 mOptionsMenu = menu;
RoboErik50f10942011-07-26 14:30:25 -0700570 Log.d(TAG, "OnCreateOptionsMenu is happening!");
Erik2051f122010-07-02 13:45:45 -0700571 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700572
RoboErike635aec2011-07-15 11:22:13 -0700573 mSearchMenu = menu.findItem(R.id.action_search);
574 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800575 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700576 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800577 mSearchView.setOnQueryTextListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700578 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700579
580 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700581 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700582
RoboErikde20d762011-02-08 17:52:25 -0800583 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700584 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700585 if (mControlsMenu != null) {
586 mControlsMenu.setVisible(false);
587 mControlsMenu.setEnabled(false);
588 }
589 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700590 && (mController.getViewType() == ViewType.MONTH ||
591 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800592 mControlsMenu.setVisible(false);
593 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700594 } else if (mControlsMenu != null){
595 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800596 }
Erik2051f122010-07-02 13:45:45 -0700597 return true;
598 }
Michael Chan3458a172010-07-13 17:58:21 -0700599
600 @Override
601 public boolean onOptionsItemSelected(MenuItem item) {
602 Time t = null;
603 int viewType = ViewType.CURRENT;
604 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700605 case R.id.action_refresh:
606 mController.refreshCalendars();
607 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700608 case R.id.action_today:
609 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800610 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700611 t.setToNow();
612 break;
613 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800614 t = new Time();
615 t.set(mController.getTime());
616 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800617 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800618 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800619 } else {
620 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800621 }
622 mController.sendEventRelatedEvent(
623 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700624 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700625 case R.id.action_select_visible_calendars:
626 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
627 0, 0);
628 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700629 case R.id.action_settings:
630 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
631 return true;
RoboErikde20d762011-02-08 17:52:25 -0800632 case R.id.action_hide_controls:
633 mHideControls = !mHideControls;
634 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800635 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
636 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
637 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
638 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
639 ObjectAnimator.setFrameDelay(0);
640 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800641 return true;
RoboErike635aec2011-07-15 11:22:13 -0700642 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700643 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700644 default:
645 return false;
646 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700647 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700648 return true;
649 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700650
RoboErikb8549562011-02-15 14:25:23 -0800651 /**
652 * Sets the offset of the controls on the right for animating them off/on
653 * screen. ProGuard strips this if it's not in proguard.flags
654 *
655 * @param controlsOffset The current offset in pixels
656 */
657 public void setControlsOffset(int controlsOffset) {
658 mMiniMonth.setTranslationX(controlsOffset);
659 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800660 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800661 mMiniMonthContainer.setLayoutParams(mControlsParams);
662 }
RoboErikde20d762011-02-08 17:52:25 -0800663
Mason Tang8e3d4302010-07-12 17:39:30 -0700664 @Override
665 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700666 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700667 if (mPaused) {
668 mUpdateOnResume = true;
669 } else {
670 initFragments(mController.getTime(), mController.getViewType(), null);
671 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700672 }
673 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700674
Erik63cd0532011-01-26 14:16:03 -0800675 private void setMainPane(
676 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700677 if (mOnSaveInstanceStateCalled) {
678 return;
679 }
Erik7b92da22010-09-23 14:55:22 -0700680 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700681 return;
682 }
683
Michael Chan5756bbc2011-03-02 18:22:07 -0800684 // Remove this when transition to and from month view looks fine.
685 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700686 FragmentManager fragmentManager = getFragmentManager();
687 // Check if our previous view was an Agenda view
688 // TODO remove this if framework ever supports nested fragments
689 if (mCurrentView == ViewType.AGENDA) {
690 // If it was, we need to do some cleanup on it to prevent the
691 // edit/delete buttons from coming back on a rotation.
692 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
693 if (oldFrag instanceof AgendaFragment) {
694 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
695 }
696 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800697
Erik648c59c2010-08-13 12:49:26 -0700698 if (viewType != mCurrentView) {
699 // The rules for this previous view are different than the
700 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700701 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
702 mPreviousView = mCurrentView;
703 }
Erik648c59c2010-08-13 12:49:26 -0700704 mCurrentView = viewType;
705 }
Erik3f348f32010-08-10 13:17:19 -0700706 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700707 Fragment frag = null;
708 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700709 switch (viewType) {
710 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700711 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
712 mActionBar.selectTab(mAgendaTab);
713 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700714 if (mActionBarMenuSpinnerAdapter != null) {
715 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
716 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700717 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700718 break;
719 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700720 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
721 mActionBar.selectTab(mDayTab);
722 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700723 if (mActionBarMenuSpinnerAdapter != null) {
724 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
725 }
Michael Chan75d9b562010-07-26 16:54:25 -0700726 frag = new DayFragment(timeMillis, 1);
727 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700728 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700729 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
730 mActionBar.selectTab(mWeekTab);
731 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700732 if (mActionBarMenuSpinnerAdapter != null) {
733 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
734 }
Michael Chan75d9b562010-07-26 16:54:25 -0700735 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700736 break;
737 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700738 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
739 mActionBar.selectTab(mMonthTab);
740 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700741 if (mActionBarMenuSpinnerAdapter != null) {
742 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
743 }
Erik40bcd102010-11-16 15:46:40 -0800744 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700745 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700746 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700747 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700748 break;
749 default:
Michael Chand6734db2010-07-22 00:48:08 -0700750 throw new IllegalArgumentException(
751 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700752 }
753
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700754 // Update the current view so that the menu can update its look according to the
755 // current view.
756 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
757 mActionBarMenuSpinnerAdapter.setMainView(viewType);
758 }
759
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700760
761 // Show date only on tablet configurations in views different than Agenda
762 if (!mIsTabletConfig) {
763 mDateRange.setVisibility(View.GONE);
764 } else if (viewType != ViewType.AGENDA) {
765 mDateRange.setVisibility(View.VISIBLE);
766 } else {
767 mDateRange.setVisibility(View.GONE);
768 }
769
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700770 // Clear unnecessary buttons from the option menu when switching from the agenda view
771 if (viewType != ViewType.AGENDA) {
772 clearOptionsMenu();
773 }
774
Michael Chanab29d9e2010-07-21 06:08:47 -0700775 boolean doCommit = false;
776 if (ft == null) {
777 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700778 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700779 }
780
Michael Chan5756bbc2011-03-02 18:22:07 -0800781 if (doTransition) {
782 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
783 }
784
Michael Chanab29d9e2010-07-21 06:08:47 -0700785 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700786 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700787
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700788 // Show/hide secondary fragment
789
790 if (secFrag != null) {
791 ft.replace(R.id.secondary_pane, secFrag);
792 mSecondaryPane.setVisibility(View.VISIBLE);
793 } else {
794 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700795 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700796 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700797 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700798 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700799 mController.deregisterEventHandler(R.id.secondary_pane);
800 }
801 }
Erik954c8712010-08-06 10:12:34 -0700802 if (DEBUG) {
803 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
804 }
Erik3f348f32010-08-10 13:17:19 -0700805 // If the key is already registered this will replace it
806 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700807 if (secFrag != null) {
808 mController.registerEventHandler(viewId, (EventHandler) secFrag);
809 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700810
811 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800812 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700813 ft.commit();
814 }
815 }
816
817 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800818 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700819 return;
820 }
821
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700822 final long start = event.startTime.toMillis(false /* use isDst */);
823 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700824 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700825 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700826 } else {
827 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700828 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700829
Erikeaafa2b2010-12-23 14:30:37 -0800830 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800831 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800832 mDateRange.setText(msg);
RoboErik14e82b42011-07-19 09:46:39 -0700833 updateHomeClockAndWeekNum(start);
Erik259b8f92011-01-12 14:01:12 -0800834 if (!TextUtils.equals(oldDate, msg)) {
835 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700836 if (mShowWeekNum && mWeekTextView != null) {
837 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
838 }
Erik259b8f92011-01-12 14:01:12 -0800839 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700840 }
841
RoboErik14e82b42011-07-19 09:46:39 -0700842 private void updateHomeClockAndWeekNum(long visibleMillisSinceEpoch) {
843 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800844 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700845 if (visibleMillisSinceEpoch != -1) {
846 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
847 mWeekNum = weekNum;
848 }
849
850 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
851 && mWeekTextView != null) {
852 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
853 mWeekNum);
854 mWeekTextView.setText(weekString);
855 mWeekTextView.setVisibility(View.VISIBLE);
856 } else if (mWeekTextView != null) {
857 mWeekTextView.setVisibility(View.GONE);
858 }
859 if (mHomeTime != null
860 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
861 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800862 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
863 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700864 time.setToNow();
865 long millis = time.toMillis(true);
866 boolean isDST = time.isDst != 0;
867 int flags = DateUtils.FORMAT_SHOW_TIME;
868 if (DateFormat.is24HourFormat(this)) {
869 flags |= DateUtils.FORMAT_24HOUR;
870 }
871 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800872 String timeString = (new StringBuilder(
873 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
874 TimeZone.getTimeZone(mTimeZone).getDisplayName(
875 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700876 mHomeTime.setText(timeString);
877 mHomeTime.setVisibility(View.VISIBLE);
878 // Update when the minute changes
879 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700880 mHomeTimeUpdater,
881 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700882 } else if (mHomeTime != null) {
883 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700884 }
885 }
886
Erik3f348f32010-08-10 13:17:19 -0700887 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700888 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800889 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700890 }
891
Erik3f348f32010-08-10 13:17:19 -0700892 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700893 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700894 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700895 if (event.eventType == EventType.GO_TO) {
Erik63cd0532011-01-26 14:16:03 -0800896 setMainPane(
897 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800898 if (mSearchView != null) {
899 mSearchView.clearFocus();
900 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700901
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700902 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700903 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700904 // hide minimonth and calendar frag
905 mShowSideViews = false;
906 if (mControlsMenu != null) {
907 mControlsMenu.setVisible(false);
908 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800909
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700910 if (!mHideControls) {
911 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
912 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
913 slideAnimation.addListener(mSlideAnimationDoneListener);
914 slideAnimation.setDuration(220);
915 ObjectAnimator.setFrameDelay(0);
916 slideAnimation.start();
917 }
918 } else {
919 mMiniMonth.setVisibility(View.GONE);
920 mCalendarsList.setVisibility(View.GONE);
921 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -0800922 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800923 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700924 // show minimonth and calendar frag
925 mShowSideViews = true;
926 mMiniMonth.setVisibility(View.VISIBLE);
927 mCalendarsList.setVisibility(View.VISIBLE);
928 mMiniMonthContainer.setVisibility(View.VISIBLE);
929 if (mControlsMenu != null) {
930 mControlsMenu.setVisible(true);
931 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700932 if (!mHideControls &&
933 (mController.getPreviousViewType() == ViewType.MONTH ||
934 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700935 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
936 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
937 slideAnimation.setDuration(220);
938 ObjectAnimator.setFrameDelay(0);
939 slideAnimation.start();
940 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800941 }
RoboErikde20d762011-02-08 17:52:25 -0800942 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700943 }
RoboErik14e82b42011-07-19 09:46:39 -0700944 displayTime = event.startTime.toMillis(true);
Michael Chan71d08832010-08-25 18:28:59 -0700945 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700946
947 // If in Agenda view and "show_event_details_with_agenda" is "true",
948 // do not create the event info fragment here, it will be created by the Agenda
949 // fragment
950
RoboErikd6c93ce2011-07-22 17:54:40 -0700951 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -0700952 if (event.startTime != null && event.endTime != null) {
953 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
954 event.id, ViewType.AGENDA);
955 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700956 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
957 event.selectedTime, event.id, ViewType.AGENDA);
958 }
959 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700960 if (mShowEventInfoFullScreen) {
961 // start event info as activity
962 Intent intent = new Intent(Intent.ACTION_VIEW);
963 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
964 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -0700965 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700966 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
967 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -0700968 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
969 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700970 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
971 startActivity(intent);
972 } else {
973 // start event info as a dialog
974 EventInfoFragment fragment = new EventInfoFragment(this,
975 event.id, event.startTime.toMillis(false),
976 event.endTime.toMillis(false), (int) event.extraLong, true);
977 // TODO Fix the temp hack below: && mCurrentView !=
978 // ViewType.AGENDA
979 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
980 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
981 event.selectedTime, -1, ViewType.DETAIL);
982 }
983 fragment.setDialogParams(event.x, event.y);
984 FragmentManager fm = getFragmentManager();
985 FragmentTransaction ft = fm.beginTransaction();
986 // if we have an old popup close it
987 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
988 if (fOld != null && fOld.isAdded()) {
989 ft.remove(fOld);
990 }
991 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
992 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700993 }
Erik63cd0532011-01-26 14:16:03 -0800994 }
RoboErik14e82b42011-07-19 09:46:39 -0700995 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -0800996 } else if (event.eventType == EventType.UPDATE_TITLE) {
997 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700998 if (!mIsTabletConfig) {
999 mActionBarMenuSpinnerAdapter.setTime(event.startTime.toMillis(false));
1000 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001001 }
RoboErik14e82b42011-07-19 09:46:39 -07001002 updateHomeClockAndWeekNum(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001003 }
1004
Michael Chan2aeb8d92011-07-10 13:32:09 -07001005 // Needs to be in proguard whitelist
1006 // Specified as listener via android:onClick in a layout xml
1007 public void handleSelectSyncedCalendarsClicked(View v) {
1008 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1009 CalendarController.EXTRA_GOTO_TIME, null,
1010 null);
1011 }
1012
Erik3f348f32010-08-10 13:17:19 -07001013 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001014 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001015 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001016 }
1017
Erik3f348f32010-08-10 13:17:19 -07001018 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001019 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001020 return false;
1021 }
1022
1023 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001024 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001025 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001026 Utils.tardis();
1027 }
RoboErika0954942011-07-27 17:43:14 -07001028 mSearchMenu.collapseActionView();
Michael Chan46a8b112010-12-14 16:36:27 -08001029 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, -1, query,
Erik7b92da22010-09-23 14:55:22 -07001030 getComponentName());
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001031 return false;
1032 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001033
1034 @Override
1035 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001036 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001037 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001038 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001039 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001040 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001041 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001042 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001043 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1044 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001045 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001046 Log.w(TAG, "TabSelected event from unknown tab: "
1047 + (tab == null ? "null" : tab.getText()));
1048 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001049 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001050 }
1051 }
1052
1053 @Override
1054 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1055 }
1056
1057 @Override
1058 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1059 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001060
1061
1062 @Override
1063 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1064 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001065 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001066 if (mCurrentView != ViewType.DAY) {
1067 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1068 }
1069 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001070 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001071 if (mCurrentView != ViewType.WEEK) {
1072 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1073 }
1074 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001075 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001076 if (mCurrentView != ViewType.MONTH) {
1077 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1078 }
1079 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001080 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001081 if (mCurrentView != ViewType.AGENDA) {
1082 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1083 }
1084 break;
1085 default:
1086 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1087 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1088 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1089 " Agenda:" + mAgendaTab);
1090 break;
1091 }
1092 return false;
1093 }
Michael Chan49701592010-06-30 11:04:03 -07001094}