blob: f68f81f197ca07e5a78812fce699ef2e0b110d2b [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 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700322 if (mIsMultipane) {
323 mActionBar.setDisplayOptions(
324 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
325 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700326 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700327 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700328 }
329
330 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700331 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700332 if (mActionBar == null) {
333 Log.w(TAG, "ActionBar is null.");
334 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700335 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700336 mDayTab = mActionBar.newTab();
337 mDayTab.setText(getString(R.string.day_view));
338 mDayTab.setTabListener(this);
339 mActionBar.addTab(mDayTab);
340 mWeekTab = mActionBar.newTab();
341 mWeekTab.setText(getString(R.string.week_view));
342 mWeekTab.setTabListener(this);
343 mActionBar.addTab(mWeekTab);
344 mMonthTab = mActionBar.newTab();
345 mMonthTab.setText(getString(R.string.month_view));
346 mMonthTab.setTabListener(this);
347 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700348 mAgendaTab = mActionBar.newTab();
349 mAgendaTab.setText(getString(R.string.agenda_view));
350 mAgendaTab.setTabListener(this);
351 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700352 }
Erik954c8712010-08-06 10:12:34 -0700353 }
354
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700355 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700356 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700357 mActionBar = getActionBar();
358 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700359 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700360 switch (viewType) {
361 case ViewType.AGENDA:
362 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
363 break;
364 case ViewType.DAY:
365 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
366 break;
367 case ViewType.WEEK:
368 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
369 break;
370 case ViewType.MONTH:
371 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
372 break;
373 default:
374 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
375 break;
376 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700377 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700378 // Clear buttons used in the agenda view
379 private void clearOptionsMenu() {
380 if (mOptionsMenu == null) {
381 return;
382 }
383 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700384 MenuItem editItem = mOptionsMenu.findItem(R.id.action_edit);
385 if (cancelItem != null) {
386 cancelItem.setVisible(false);
387 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700388 if (editItem != null) {
389 editItem.setVisible(false);
390 }
391 }
392
Erik954c8712010-08-06 10:12:34 -0700393 @Override
394 protected void onResume() {
395 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700396
397 // Must register as the first activity because this activity can modify
398 // the list of event handlers in it's handle method. This affects who
399 // the rest of the handlers the controller dispatches to are.
400 mController.registerFirstEventHandler(HANDLER_KEY, this);
401
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700402 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
403 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700404 if (mUpdateOnResume) {
405 initFragments(mController.getTime(), mController.getViewType(), null);
406 mUpdateOnResume = false;
407 }
RoboErik14e82b42011-07-19 09:46:39 -0700408 updateHomeClockAndWeekNum(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700409 // Make sure the drop-down menu will get its date updated at midnight
410 if (mActionBarMenuSpinnerAdapter != null) {
411 mActionBarMenuSpinnerAdapter.setMidnightHandler();
412 }
413
RoboErik3b3af612011-02-24 13:42:57 -0800414 if (mControlsMenu != null) {
415 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
416 }
Erikcb811892010-09-28 13:44:19 -0700417 mPaused = false;
Michael Chan6191c122010-11-02 16:23:47 -0700418 mOnSaveInstanceStateCalled = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800419
420 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800421 long currentMillis = System.currentTimeMillis();
422 long selectedTime = -1;
423 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
424 selectedTime = currentMillis;
425 }
Michael Chanf0868f62011-01-11 19:37:35 -0800426 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700427 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
428 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800429 mViewEventId = -1;
430 mIntentEventStartMillis = -1;
431 mIntentEventEndMillis = -1;
432 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700433 }
434
435 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700436 protected void onPause() {
437 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700438
439 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700440 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700441 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700442 if (mActionBarMenuSpinnerAdapter != null) {
443 mActionBarMenuSpinnerAdapter.resetMidnightHandler();
444 }
Erik954c8712010-08-06 10:12:34 -0700445 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700446 if (isFinishing()) {
447 // Stop listening for changes that would require this to be refreshed
448 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
449 prefs.unregisterOnSharedPreferenceChangeListener(this);
450 }
Erik7b92da22010-09-23 14:55:22 -0700451 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700452 if (mController.getViewType() != ViewType.EDIT) {
453 Utils.setDefaultView(this, mController.getViewType());
454 }
Michael Chand6734db2010-07-22 00:48:08 -0700455 }
456
457 @Override
Erik7b92da22010-09-23 14:55:22 -0700458 protected void onUserLeaveHint() {
459 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
460 super.onUserLeaveHint();
461 }
462
463 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700464 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700465 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700466 super.onSaveInstanceState(outState);
467
468 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700469 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800470 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700471 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
472 }
Michael Chand6734db2010-07-22 00:48:08 -0700473 }
474
475 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700476 protected void onDestroy() {
477 super.onDestroy();
478
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700479 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700480 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700481 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700482 }
483
Erik7b92da22010-09-23 14:55:22 -0700484 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700485 if (DEBUG) {
486 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
487 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800488 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700489
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700490 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800491 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700492 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700493 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700494
Michael Chan2aeb8d92011-07-10 13:32:09 -0700495 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700496 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800497 mController.registerEventHandler(
498 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700499 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700500 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800501 mMiniMonth.setVisibility(View.GONE);
502 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700503 }
Michael Chan3458a172010-07-13 17:58:21 -0700504
Erikdd95df52010-08-27 09:31:18 -0700505 EventInfo info = null;
506 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700507 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700508 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700509
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700510 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700511 Intent intent = getIntent();
512 Uri data = intent.getData();
513 if (data != null) {
514 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700515 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700516 } catch (NumberFormatException e) {
517 if (DEBUG) {
518 Log.d(TAG, "Create new event");
519 }
520 }
Erik7b92da22010-09-23 14:55:22 -0700521 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
522 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700523 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700524
RoboErika27a8862011-06-23 15:26:23 -0700525 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
526 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700527 info = new EventInfo();
528 if (end != -1) {
529 info.endTime = new Time();
530 info.endTime.set(end);
531 }
532 if (begin != -1) {
533 info.startTime = new Time();
534 info.startTime.set(begin);
535 }
536 info.id = eventId;
537 // We set the viewtype so if the user presses back when they are
538 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700539 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700540 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700541 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700542 } else {
543 mPreviousView = viewType;
544 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700545
Erik63cd0532011-01-26 14:16:03 -0800546 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700547 ft.commit(); // this needs to be after setMainPane()
548
Erikc5f92d72010-11-11 16:18:34 -0800549 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700550 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700551 if (viewType != ViewType.EDIT) {
552 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
553 }
Michael Chan49701592010-06-30 11:04:03 -0700554 }
Erik2051f122010-07-02 13:45:45 -0700555
556 @Override
Erik648c59c2010-08-13 12:49:26 -0700557 public void onBackPressed() {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700558 if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) {
Erikdd95df52010-08-27 09:31:18 -0700559 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700560 } else {
561 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700562 }
563 }
564
565 @Override
Erik2051f122010-07-02 13:45:45 -0700566 public boolean onCreateOptionsMenu(Menu menu) {
567 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700568 mOptionsMenu = menu;
RoboErik50f10942011-07-26 14:30:25 -0700569 Log.d(TAG, "OnCreateOptionsMenu is happening!");
Erik2051f122010-07-02 13:45:45 -0700570 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700571
RoboErike635aec2011-07-15 11:22:13 -0700572 mSearchMenu = menu.findItem(R.id.action_search);
573 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800574 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700575 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800576 mSearchView.setOnQueryTextListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700577 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700578
579 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700580 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700581
RoboErikde20d762011-02-08 17:52:25 -0800582 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700583 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700584 if (mControlsMenu != null) {
585 mControlsMenu.setVisible(false);
586 mControlsMenu.setEnabled(false);
587 }
588 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700589 && (mController.getViewType() == ViewType.MONTH ||
590 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800591 mControlsMenu.setVisible(false);
592 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700593 } else if (mControlsMenu != null){
594 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800595 }
Erik2051f122010-07-02 13:45:45 -0700596 return true;
597 }
Michael Chan3458a172010-07-13 17:58:21 -0700598
599 @Override
600 public boolean onOptionsItemSelected(MenuItem item) {
601 Time t = null;
602 int viewType = ViewType.CURRENT;
603 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700604 case R.id.action_refresh:
605 mController.refreshCalendars();
606 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700607 case R.id.action_today:
608 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800609 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700610 t.setToNow();
611 break;
612 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800613 t = new Time();
614 t.set(mController.getTime());
615 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800616 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800617 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800618 } else {
619 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800620 }
621 mController.sendEventRelatedEvent(
622 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700623 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700624 case R.id.action_select_visible_calendars:
625 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
626 0, 0);
627 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700628 case R.id.action_settings:
629 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
630 return true;
RoboErikde20d762011-02-08 17:52:25 -0800631 case R.id.action_hide_controls:
632 mHideControls = !mHideControls;
633 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800634 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
635 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
636 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
637 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
638 ObjectAnimator.setFrameDelay(0);
639 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800640 return true;
RoboErike635aec2011-07-15 11:22:13 -0700641 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700642 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700643 default:
644 return false;
645 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700646 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700647 return true;
648 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700649
RoboErikb8549562011-02-15 14:25:23 -0800650 /**
651 * Sets the offset of the controls on the right for animating them off/on
652 * screen. ProGuard strips this if it's not in proguard.flags
653 *
654 * @param controlsOffset The current offset in pixels
655 */
656 public void setControlsOffset(int controlsOffset) {
657 mMiniMonth.setTranslationX(controlsOffset);
658 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800659 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800660 mMiniMonthContainer.setLayoutParams(mControlsParams);
661 }
RoboErikde20d762011-02-08 17:52:25 -0800662
Mason Tang8e3d4302010-07-12 17:39:30 -0700663 @Override
664 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700665 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700666 if (mPaused) {
667 mUpdateOnResume = true;
668 } else {
669 initFragments(mController.getTime(), mController.getViewType(), null);
670 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700671 }
672 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700673
Erik63cd0532011-01-26 14:16:03 -0800674 private void setMainPane(
675 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700676 if (mOnSaveInstanceStateCalled) {
677 return;
678 }
Erik7b92da22010-09-23 14:55:22 -0700679 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700680 return;
681 }
682
Michael Chan5756bbc2011-03-02 18:22:07 -0800683 // Remove this when transition to and from month view looks fine.
684 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700685 FragmentManager fragmentManager = getFragmentManager();
686 // Check if our previous view was an Agenda view
687 // TODO remove this if framework ever supports nested fragments
688 if (mCurrentView == ViewType.AGENDA) {
689 // If it was, we need to do some cleanup on it to prevent the
690 // edit/delete buttons from coming back on a rotation.
691 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
692 if (oldFrag instanceof AgendaFragment) {
693 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
694 }
695 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800696
Erik648c59c2010-08-13 12:49:26 -0700697 if (viewType != mCurrentView) {
698 // The rules for this previous view are different than the
699 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700700 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
701 mPreviousView = mCurrentView;
702 }
Erik648c59c2010-08-13 12:49:26 -0700703 mCurrentView = viewType;
704 }
Erik3f348f32010-08-10 13:17:19 -0700705 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700706 Fragment frag = null;
707 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700708 switch (viewType) {
709 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700710 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
711 mActionBar.selectTab(mAgendaTab);
712 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700713 if (mActionBarMenuSpinnerAdapter != null) {
714 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
715 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700716 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700717 break;
718 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700719 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
720 mActionBar.selectTab(mDayTab);
721 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700722 if (mActionBarMenuSpinnerAdapter != null) {
723 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
724 }
Michael Chan75d9b562010-07-26 16:54:25 -0700725 frag = new DayFragment(timeMillis, 1);
726 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700727 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700728 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
729 mActionBar.selectTab(mWeekTab);
730 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700731 if (mActionBarMenuSpinnerAdapter != null) {
732 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
733 }
Michael Chan75d9b562010-07-26 16:54:25 -0700734 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700735 break;
736 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700737 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
738 mActionBar.selectTab(mMonthTab);
739 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700740 if (mActionBarMenuSpinnerAdapter != null) {
741 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
742 }
Erik40bcd102010-11-16 15:46:40 -0800743 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700744 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700745 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700746 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700747 break;
748 default:
Michael Chand6734db2010-07-22 00:48:08 -0700749 throw new IllegalArgumentException(
750 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700751 }
752
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700753 // Update the current view so that the menu can update its look according to the
754 // current view.
755 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
756 mActionBarMenuSpinnerAdapter.setMainView(viewType);
757 }
758
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700759
760 // Show date only on tablet configurations in views different than Agenda
761 if (!mIsTabletConfig) {
762 mDateRange.setVisibility(View.GONE);
763 } else if (viewType != ViewType.AGENDA) {
764 mDateRange.setVisibility(View.VISIBLE);
765 } else {
766 mDateRange.setVisibility(View.GONE);
767 }
768
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700769 // Clear unnecessary buttons from the option menu when switching from the agenda view
770 if (viewType != ViewType.AGENDA) {
771 clearOptionsMenu();
772 }
773
Michael Chanab29d9e2010-07-21 06:08:47 -0700774 boolean doCommit = false;
775 if (ft == null) {
776 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700777 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700778 }
779
Michael Chan5756bbc2011-03-02 18:22:07 -0800780 if (doTransition) {
781 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
782 }
783
Michael Chanab29d9e2010-07-21 06:08:47 -0700784 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700785 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700786
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700787 // Show/hide secondary fragment
788
789 if (secFrag != null) {
790 ft.replace(R.id.secondary_pane, secFrag);
791 mSecondaryPane.setVisibility(View.VISIBLE);
792 } else {
793 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700794 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700795 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700796 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700797 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700798 mController.deregisterEventHandler(R.id.secondary_pane);
799 }
800 }
Erik954c8712010-08-06 10:12:34 -0700801 if (DEBUG) {
802 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
803 }
Erik3f348f32010-08-10 13:17:19 -0700804 // If the key is already registered this will replace it
805 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700806 if (secFrag != null) {
807 mController.registerEventHandler(viewId, (EventHandler) secFrag);
808 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700809
810 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800811 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700812 ft.commit();
813 }
814 }
815
816 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800817 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700818 return;
819 }
820
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700821 final long start = event.startTime.toMillis(false /* use isDst */);
822 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700823 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700824 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700825 } else {
826 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700827 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700828
Erikeaafa2b2010-12-23 14:30:37 -0800829 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800830 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800831 mDateRange.setText(msg);
RoboErik14e82b42011-07-19 09:46:39 -0700832 updateHomeClockAndWeekNum(start);
Erik259b8f92011-01-12 14:01:12 -0800833 if (!TextUtils.equals(oldDate, msg)) {
834 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700835 if (mShowWeekNum && mWeekTextView != null) {
836 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
837 }
Erik259b8f92011-01-12 14:01:12 -0800838 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700839 }
840
RoboErik14e82b42011-07-19 09:46:39 -0700841 private void updateHomeClockAndWeekNum(long visibleMillisSinceEpoch) {
842 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800843 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700844 if (visibleMillisSinceEpoch != -1) {
845 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
846 mWeekNum = weekNum;
847 }
848
849 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
850 && mWeekTextView != null) {
851 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
852 mWeekNum);
853 mWeekTextView.setText(weekString);
854 mWeekTextView.setVisibility(View.VISIBLE);
855 } else if (mWeekTextView != null) {
856 mWeekTextView.setVisibility(View.GONE);
857 }
858 if (mHomeTime != null
859 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
860 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800861 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
862 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700863 time.setToNow();
864 long millis = time.toMillis(true);
865 boolean isDST = time.isDst != 0;
866 int flags = DateUtils.FORMAT_SHOW_TIME;
867 if (DateFormat.is24HourFormat(this)) {
868 flags |= DateUtils.FORMAT_24HOUR;
869 }
870 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800871 String timeString = (new StringBuilder(
872 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
873 TimeZone.getTimeZone(mTimeZone).getDisplayName(
874 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700875 mHomeTime.setText(timeString);
876 mHomeTime.setVisibility(View.VISIBLE);
877 // Update when the minute changes
878 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700879 mHomeTimeUpdater,
880 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700881 } else if (mHomeTime != null) {
882 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700883 }
884 }
885
Erik3f348f32010-08-10 13:17:19 -0700886 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700887 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800888 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700889 }
890
Erik3f348f32010-08-10 13:17:19 -0700891 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700892 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700893 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700894 if (event.eventType == EventType.GO_TO) {
Erik63cd0532011-01-26 14:16:03 -0800895 setMainPane(
896 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800897 if (mSearchView != null) {
898 mSearchView.clearFocus();
899 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700900
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700901 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700902 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700903 // hide minimonth and calendar frag
904 mShowSideViews = false;
905 if (mControlsMenu != null) {
906 mControlsMenu.setVisible(false);
907 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800908
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700909 if (!mHideControls) {
910 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
911 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
912 slideAnimation.addListener(mSlideAnimationDoneListener);
913 slideAnimation.setDuration(220);
914 ObjectAnimator.setFrameDelay(0);
915 slideAnimation.start();
916 }
917 } else {
918 mMiniMonth.setVisibility(View.GONE);
919 mCalendarsList.setVisibility(View.GONE);
920 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -0800921 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800922 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700923 // show minimonth and calendar frag
924 mShowSideViews = true;
925 mMiniMonth.setVisibility(View.VISIBLE);
926 mCalendarsList.setVisibility(View.VISIBLE);
927 mMiniMonthContainer.setVisibility(View.VISIBLE);
928 if (mControlsMenu != null) {
929 mControlsMenu.setVisible(true);
930 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700931 if (!mHideControls &&
932 (mController.getPreviousViewType() == ViewType.MONTH ||
933 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700934 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
935 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
936 slideAnimation.setDuration(220);
937 ObjectAnimator.setFrameDelay(0);
938 slideAnimation.start();
939 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800940 }
RoboErikde20d762011-02-08 17:52:25 -0800941 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700942 }
RoboErik14e82b42011-07-19 09:46:39 -0700943 displayTime = event.startTime.toMillis(true);
Michael Chan71d08832010-08-25 18:28:59 -0700944 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700945
946 // If in Agenda view and "show_event_details_with_agenda" is "true",
947 // do not create the event info fragment here, it will be created by the Agenda
948 // fragment
949
RoboErikd6c93ce2011-07-22 17:54:40 -0700950 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -0700951 if (event.startTime != null && event.endTime != null) {
952 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
953 event.id, ViewType.AGENDA);
954 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700955 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
956 event.selectedTime, event.id, ViewType.AGENDA);
957 }
958 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700959 if (mShowEventInfoFullScreen) {
960 // start event info as activity
961 Intent intent = new Intent(Intent.ACTION_VIEW);
962 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
963 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -0700964 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700965 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
966 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -0700967 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
968 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700969 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
970 startActivity(intent);
971 } else {
972 // start event info as a dialog
973 EventInfoFragment fragment = new EventInfoFragment(this,
974 event.id, event.startTime.toMillis(false),
975 event.endTime.toMillis(false), (int) event.extraLong, true);
976 // TODO Fix the temp hack below: && mCurrentView !=
977 // ViewType.AGENDA
978 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
979 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
980 event.selectedTime, -1, ViewType.DETAIL);
981 }
982 fragment.setDialogParams(event.x, event.y);
983 FragmentManager fm = getFragmentManager();
984 FragmentTransaction ft = fm.beginTransaction();
985 // if we have an old popup close it
986 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
987 if (fOld != null && fOld.isAdded()) {
988 ft.remove(fOld);
989 }
990 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
991 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700992 }
Erik63cd0532011-01-26 14:16:03 -0800993 }
RoboErik14e82b42011-07-19 09:46:39 -0700994 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -0800995 } else if (event.eventType == EventType.UPDATE_TITLE) {
996 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700997 if (!mIsTabletConfig) {
998 mActionBarMenuSpinnerAdapter.setTime(event.startTime.toMillis(false));
999 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001000 }
RoboErik14e82b42011-07-19 09:46:39 -07001001 updateHomeClockAndWeekNum(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001002 }
1003
Michael Chan2aeb8d92011-07-10 13:32:09 -07001004 // Needs to be in proguard whitelist
1005 // Specified as listener via android:onClick in a layout xml
1006 public void handleSelectSyncedCalendarsClicked(View v) {
1007 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1008 CalendarController.EXTRA_GOTO_TIME, null,
1009 null);
1010 }
1011
Erik3f348f32010-08-10 13:17:19 -07001012 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001013 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001014 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001015 }
1016
Erik3f348f32010-08-10 13:17:19 -07001017 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001018 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001019 return false;
1020 }
1021
1022 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001023 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001024 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001025 Utils.tardis();
1026 }
RoboErika0954942011-07-27 17:43:14 -07001027 mSearchMenu.collapseActionView();
Michael Chan46a8b112010-12-14 16:36:27 -08001028 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, -1, query,
Erik7b92da22010-09-23 14:55:22 -07001029 getComponentName());
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001030 return false;
1031 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001032
1033 @Override
1034 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001035 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001036 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001037 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001038 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001039 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001040 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001041 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001042 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1043 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001044 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001045 Log.w(TAG, "TabSelected event from unknown tab: "
1046 + (tab == null ? "null" : tab.getText()));
1047 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001048 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001049 }
1050 }
1051
1052 @Override
1053 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1054 }
1055
1056 @Override
1057 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1058 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001059
1060
1061 @Override
1062 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1063 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001064 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001065 if (mCurrentView != ViewType.DAY) {
1066 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1067 }
1068 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001069 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001070 if (mCurrentView != ViewType.WEEK) {
1071 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1072 }
1073 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001074 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001075 if (mCurrentView != ViewType.MONTH) {
1076 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1077 }
1078 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001079 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001080 if (mCurrentView != ViewType.AGENDA) {
1081 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1082 }
1083 break;
1084 default:
1085 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1086 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1087 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1088 " Agenda:" + mAgendaTab);
1089 break;
1090 }
1091 return false;
1092 }
Michael Chan49701592010-06-30 11:04:03 -07001093}