blob: ca640b34e6cc1cc98a10ea1265dfe7afdad02787 [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;
RoboErik17664072011-08-16 16:22:39 -070065import android.widget.SearchView.OnCloseListener;
66import android.widget.SearchView.OnSuggestionListener;
Erik6c255102010-09-29 14:43:00 -070067import android.widget.TextView;
68
Michael Chan2c7c8512010-12-10 14:12:57 -080069import java.util.List;
Erik6c255102010-09-29 14:43:00 -070070import java.util.Locale;
71import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070072
Michael Chanab29d9e2010-07-21 06:08:47 -070073public class AllInOneActivity extends Activity implements EventHandler,
RoboErike635aec2011-07-15 11:22:13 -070074 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener,
RoboErik17664072011-08-16 16:22:39 -070075 ActionBar.OnNavigationListener, OnSuggestionListener {
Michael Chand6734db2010-07-22 00:48:08 -070076 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070077 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080078 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070079 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070080 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080081 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
Erik3f348f32010-08-10 13:17:19 -070082 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080083 private static final long CONTROLS_ANIMATE_DURATION = 400;
RoboErike9cd8f42011-07-01 16:36:11 -070084 private static int CONTROLS_ANIMATE_WIDTH = 280;
RoboErikde20d762011-02-08 17:52:25 -080085 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -080086
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070087 // Indices of buttons for the drop down menu (tabs replacement)
88 // Must match the strings in the array buttons_list in arrays.xml and the
89 // OnNavigationListener
90 private static final int BUTTON_DAY_INDEX = 0;
91 private static final int BUTTON_WEEK_INDEX = 1;
92 private static final int BUTTON_MONTH_INDEX = 2;
93 private static final int BUTTON_AGENDA_INDEX = 3;
94
RoboErikd69ccdf2011-08-05 14:50:27 -070095 private CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -070096 private static boolean mIsMultipane;
Isaac Katzenelson62967cb2011-06-14 13:27:20 -070097 private static boolean mIsTabletConfig;
Isaac Katzenelson6a182582011-04-21 15:46:33 -070098 private static boolean mShowAgendaWithMonth;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -070099 private static boolean mShowEventDetailsWithAgenda;
Michael Chan6191c122010-11-02 16:23:47 -0700100 private boolean mOnSaveInstanceStateCalled = false;
Michael Chanfb0ec222011-08-12 17:39:30 -0700101 private boolean mBackToPreviousView = false;
Erik954c8712010-08-06 10:12:34 -0700102 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700103 private int mPreviousView;
104 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700105 private boolean mPaused = true;
106 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800107 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800108 private boolean mShowSideViews = true;
RoboErik14e82b42011-07-19 09:46:39 -0700109 private boolean mShowWeekNum = false;
Erik6c255102010-09-29 14:43:00 -0700110 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800111 private TextView mDateRange;
RoboErik14e82b42011-07-19 09:46:39 -0700112 private TextView mWeekTextView;
RoboErikde20d762011-02-08 17:52:25 -0800113 private View mMiniMonth;
114 private View mCalendarsList;
115 private View mMiniMonthContainer;
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700116 private View mSecondaryPane;
Erikc5f92d72010-11-11 16:18:34 -0800117 private String mTimeZone;
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700118 private boolean mShowCalendarControls;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700119 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700120 private int mWeekNum;
Erik6c255102010-09-29 14:43:00 -0700121
Michael Chan2c7c8512010-12-10 14:12:57 -0800122 private long mViewEventId = -1;
123 private long mIntentEventStartMillis = -1;
124 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800125 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800126
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700127 // Action bar and Navigation bar (left side of Action bar)
128 private ActionBar mActionBar;
129 private ActionBar.Tab mDayTab;
130 private ActionBar.Tab mWeekTab;
131 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700132 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800133 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700134 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800135 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700136 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700137 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErikde20d762011-02-08 17:52:25 -0800138
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700139 private String mHideString;
140 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800141
RoboErikb8549562011-02-15 14:25:23 -0800142 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800143 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
144
145 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
146
147 @Override
148 public void onAnimationCancel(Animator animation) {
149 }
150
151 @Override
152 public void onAnimationEnd(android.animation.Animator animation) {
153 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
154 mMiniMonth.setVisibility(visibility);
155 mCalendarsList.setVisibility(visibility);
156 mMiniMonthContainer.setVisibility(visibility);
157 }
158
159 @Override
160 public void onAnimationRepeat(android.animation.Animator animation) {
161 }
162
163 @Override
164 public void onAnimationStart(android.animation.Animator animation) {
165 }
166 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700167
Erik6c255102010-09-29 14:43:00 -0700168 private Runnable mHomeTimeUpdater = new Runnable() {
169 @Override
170 public void run() {
RoboErik14e82b42011-07-19 09:46:39 -0700171 updateHomeClockAndWeekNum(-1);
Erik6c255102010-09-29 14:43:00 -0700172 }
173 };
Erik954c8712010-08-06 10:12:34 -0700174
175 // Create an observer so that we can update the views whenever a
176 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700177 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700178 @Override
179 public boolean deliverSelfNotifications() {
180 return true;
181 }
182
183 @Override
184 public void onChange(boolean selfChange) {
185 eventsChanged();
186 }
187 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700188
Michael Chan49701592010-06-30 11:04:03 -0700189 @Override
Erik63cd0532011-01-26 14:16:03 -0800190 protected void onNewIntent(Intent intent) {
191 String action = intent.getAction();
192 if (Intent.ACTION_VIEW.equals(action)) {
193 parseViewAction(intent);
194 }
195 }
196
197 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700198 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800199 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
200 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
201 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700202 super.onCreate(icicle);
203
204 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700205 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700206
207
Erik954c8712010-08-06 10:12:34 -0700208 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800209 long timeMillis = -1;
210 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800211 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700212 if (icicle != null) {
213 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800214 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700215 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800216 String action = intent.getAction();
217 if (Intent.ACTION_VIEW.equals(action)) {
218 // Open EventInfo later
219 timeMillis = parseViewAction(intent);
220 }
221
222 if (timeMillis == -1) {
223 timeMillis = Utils.timeFromIntentInMillis(intent);
224 }
225 }
226
RoboErik277eb972011-02-24 16:05:04 -0800227 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700228 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
229 }
Erikc5f92d72010-11-11 16:18:34 -0800230 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
231 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700232 t.set(timeMillis);
233
Michael Chan2c7c8512010-12-10 14:12:57 -0800234 if (icicle != null && intent != null) {
235 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700236 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800237 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700238 }
239
Erikeaafa2b2010-12-23 14:30:37 -0800240 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800241 if (mScale == 0) {
242 mScale = res.getDisplayMetrics().density;
243 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800244 }
245 mHideString = res.getString(R.string.hide_controls);
246 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800247 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800248
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700249 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700250 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700251 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700252 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700253 mShowEventDetailsWithAgenda =
254 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700255 mShowEventInfoFullScreen =
256 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700257
Erik63cd0532011-01-26 14:16:03 -0800258 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800259
Erikbe8191c2010-10-26 16:50:08 -0700260 // setContentView must be called before configureActionBar
261 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700262
263 if (mIsTabletConfig) {
264 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700265 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700266 } else {
267 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
268 }
269
Erikbe8191c2010-10-26 16:50:08 -0700270 // configureActionBar auto-selects the first tab you add, so we need to
271 // call it before we set up our own fragments to make sure it doesn't
272 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700273 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700274
Erik6c255102010-09-29 14:43:00 -0700275 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800276 mMiniMonth = findViewById(R.id.mini_month);
277 mCalendarsList = findViewById(R.id.calendar_list);
278 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700279 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700280
RoboErik3864be02011-07-25 15:56:50 -0700281 // Must register as the first activity because this activity can modify
282 // the list of event handlers in it's handle method. This affects who
283 // the rest of the handlers the controller dispatches to are.
284 mController.registerFirstEventHandler(HANDLER_KEY, this);
285
Erik7b92da22010-09-23 14:55:22 -0700286 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700287
288 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700289 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700290 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700291
Erik954c8712010-08-06 10:12:34 -0700292 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700293 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700294
Michael Chan2c7c8512010-12-10 14:12:57 -0800295 private long parseViewAction(final Intent intent) {
296 long timeMillis = -1;
297 Uri data = intent.getData();
298 if (data != null && data.isHierarchical()) {
299 List<String> path = data.getPathSegments();
300 if (path.size() == 2 && path.get(0).equals("events")) {
301 try {
302 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700303 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700304 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
305 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800306 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800307 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800308 timeMillis = mIntentEventStartMillis;
309 }
310 } catch (NumberFormatException e) {
311 // Ignore if mViewEventId can't be parsed
312 }
313 }
314 }
315 return timeMillis;
316 }
317
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700318 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700319 if (mIsTabletConfig) {
320 createTabs();
321 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700322 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700323 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700324 if (mIsMultipane) {
325 mActionBar.setDisplayOptions(
326 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
327 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700328 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700329 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700330 }
331
332 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700333 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700334 if (mActionBar == null) {
335 Log.w(TAG, "ActionBar is null.");
336 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700337 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700338 mDayTab = mActionBar.newTab();
339 mDayTab.setText(getString(R.string.day_view));
340 mDayTab.setTabListener(this);
341 mActionBar.addTab(mDayTab);
342 mWeekTab = mActionBar.newTab();
343 mWeekTab.setText(getString(R.string.week_view));
344 mWeekTab.setTabListener(this);
345 mActionBar.addTab(mWeekTab);
346 mMonthTab = mActionBar.newTab();
347 mMonthTab.setText(getString(R.string.month_view));
348 mMonthTab.setTabListener(this);
349 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700350 mAgendaTab = mActionBar.newTab();
351 mAgendaTab.setText(getString(R.string.agenda_view));
352 mAgendaTab.setTabListener(this);
353 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700354 }
Erik954c8712010-08-06 10:12:34 -0700355 }
356
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700357 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700358 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700359 mActionBar = getActionBar();
360 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700361 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700362 switch (viewType) {
363 case ViewType.AGENDA:
364 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
365 break;
366 case ViewType.DAY:
367 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
368 break;
369 case ViewType.WEEK:
370 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
371 break;
372 case ViewType.MONTH:
373 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
374 break;
375 default:
376 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
377 break;
378 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700379 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700380 // Clear buttons used in the agenda view
381 private void clearOptionsMenu() {
382 if (mOptionsMenu == null) {
383 return;
384 }
385 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700386 MenuItem editItem = mOptionsMenu.findItem(R.id.action_edit);
387 if (cancelItem != null) {
388 cancelItem.setVisible(false);
389 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700390 if (editItem != null) {
391 editItem.setVisible(false);
392 }
393 }
394
Erik954c8712010-08-06 10:12:34 -0700395 @Override
396 protected void onResume() {
397 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700398
399 // Must register as the first activity because this activity can modify
400 // the list of event handlers in it's handle method. This affects who
401 // the rest of the handlers the controller dispatches to are.
402 mController.registerFirstEventHandler(HANDLER_KEY, this);
403
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700404 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
405 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700406 if (mUpdateOnResume) {
407 initFragments(mController.getTime(), mController.getViewType(), null);
408 mUpdateOnResume = false;
409 }
RoboErik14e82b42011-07-19 09:46:39 -0700410 updateHomeClockAndWeekNum(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700411 // Make sure the drop-down menu will get its date updated at midnight
412 if (mActionBarMenuSpinnerAdapter != null) {
413 mActionBarMenuSpinnerAdapter.setMidnightHandler();
414 }
415
RoboErik3b3af612011-02-24 13:42:57 -0800416 if (mControlsMenu != null) {
417 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
418 }
Erikcb811892010-09-28 13:44:19 -0700419 mPaused = false;
Michael Chan6191c122010-11-02 16:23:47 -0700420 mOnSaveInstanceStateCalled = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800421
422 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800423 long currentMillis = System.currentTimeMillis();
424 long selectedTime = -1;
425 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
426 selectedTime = currentMillis;
427 }
Michael Chanf0868f62011-01-11 19:37:35 -0800428 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700429 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
430 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800431 mViewEventId = -1;
432 mIntentEventStartMillis = -1;
433 mIntentEventEndMillis = -1;
434 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700435 }
436
437 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700438 protected void onPause() {
439 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700440
441 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700442 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700443 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700444 if (mActionBarMenuSpinnerAdapter != null) {
445 mActionBarMenuSpinnerAdapter.resetMidnightHandler();
446 }
Erik954c8712010-08-06 10:12:34 -0700447 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700448 if (isFinishing()) {
449 // Stop listening for changes that would require this to be refreshed
450 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
451 prefs.unregisterOnSharedPreferenceChangeListener(this);
452 }
Erik7b92da22010-09-23 14:55:22 -0700453 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700454 if (mController.getViewType() != ViewType.EDIT) {
455 Utils.setDefaultView(this, mController.getViewType());
456 }
Michael Chand6734db2010-07-22 00:48:08 -0700457 }
458
459 @Override
Erik7b92da22010-09-23 14:55:22 -0700460 protected void onUserLeaveHint() {
461 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
462 super.onUserLeaveHint();
463 }
464
465 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700466 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700467 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700468 super.onSaveInstanceState(outState);
469
470 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700471 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800472 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700473 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
474 }
Michael Chand6734db2010-07-22 00:48:08 -0700475 }
476
477 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700478 protected void onDestroy() {
479 super.onDestroy();
480
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700481 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700482 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700483 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700484 }
485
Erik7b92da22010-09-23 14:55:22 -0700486 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700487 if (DEBUG) {
488 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
489 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800490 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700491
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700492 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800493 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700494 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700495 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700496
Michael Chan2aeb8d92011-07-10 13:32:09 -0700497 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700498 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800499 mController.registerEventHandler(
500 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700501 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700502 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800503 mMiniMonth.setVisibility(View.GONE);
504 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700505 }
Michael Chan3458a172010-07-13 17:58:21 -0700506
Erikdd95df52010-08-27 09:31:18 -0700507 EventInfo info = null;
508 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700509 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700510 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700511
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700512 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700513 Intent intent = getIntent();
514 Uri data = intent.getData();
515 if (data != null) {
516 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700517 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700518 } catch (NumberFormatException e) {
519 if (DEBUG) {
520 Log.d(TAG, "Create new event");
521 }
522 }
Erik7b92da22010-09-23 14:55:22 -0700523 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
524 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700525 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700526
RoboErika27a8862011-06-23 15:26:23 -0700527 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
528 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700529 info = new EventInfo();
530 if (end != -1) {
531 info.endTime = new Time();
532 info.endTime.set(end);
533 }
534 if (begin != -1) {
535 info.startTime = new Time();
536 info.startTime.set(begin);
537 }
538 info.id = eventId;
539 // We set the viewtype so if the user presses back when they are
540 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700541 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700542 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700543 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700544 } else {
545 mPreviousView = viewType;
546 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700547
Erik63cd0532011-01-26 14:16:03 -0800548 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700549 ft.commit(); // this needs to be after setMainPane()
550
Erikc5f92d72010-11-11 16:18:34 -0800551 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700552 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700553 if (viewType != ViewType.EDIT) {
554 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
555 }
Michael Chan49701592010-06-30 11:04:03 -0700556 }
Erik2051f122010-07-02 13:45:45 -0700557
558 @Override
Erik648c59c2010-08-13 12:49:26 -0700559 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700560 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700561 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700562 } else {
563 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700564 }
565 }
566
567 @Override
Erik2051f122010-07-02 13:45:45 -0700568 public boolean onCreateOptionsMenu(Menu menu) {
569 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700570 mOptionsMenu = menu;
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);
RoboErik17664072011-08-16 16:22:39 -0700578 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700579 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700580
581 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700582 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700583
RoboErikde20d762011-02-08 17:52:25 -0800584 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700585 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700586 if (mControlsMenu != null) {
587 mControlsMenu.setVisible(false);
588 mControlsMenu.setEnabled(false);
589 }
590 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700591 && (mController.getViewType() == ViewType.MONTH ||
592 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800593 mControlsMenu.setVisible(false);
594 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700595 } else if (mControlsMenu != null){
596 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800597 }
Erik2051f122010-07-02 13:45:45 -0700598 return true;
599 }
Michael Chan3458a172010-07-13 17:58:21 -0700600
601 @Override
602 public boolean onOptionsItemSelected(MenuItem item) {
603 Time t = null;
604 int viewType = ViewType.CURRENT;
605 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700606 case R.id.action_refresh:
607 mController.refreshCalendars();
608 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700609 case R.id.action_today:
610 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800611 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700612 t.setToNow();
613 break;
614 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800615 t = new Time();
616 t.set(mController.getTime());
617 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800618 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800619 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800620 } else {
621 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800622 }
623 mController.sendEventRelatedEvent(
624 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700625 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700626 case R.id.action_select_visible_calendars:
627 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
628 0, 0);
629 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700630 case R.id.action_settings:
631 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
632 return true;
RoboErikde20d762011-02-08 17:52:25 -0800633 case R.id.action_hide_controls:
634 mHideControls = !mHideControls;
635 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800636 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
637 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
638 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
639 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
640 ObjectAnimator.setFrameDelay(0);
641 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800642 return true;
RoboErike635aec2011-07-15 11:22:13 -0700643 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700644 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700645 default:
646 return false;
647 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700648 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700649 return true;
650 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700651
RoboErikb8549562011-02-15 14:25:23 -0800652 /**
653 * Sets the offset of the controls on the right for animating them off/on
654 * screen. ProGuard strips this if it's not in proguard.flags
655 *
656 * @param controlsOffset The current offset in pixels
657 */
658 public void setControlsOffset(int controlsOffset) {
659 mMiniMonth.setTranslationX(controlsOffset);
660 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800661 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800662 mMiniMonthContainer.setLayoutParams(mControlsParams);
663 }
RoboErikde20d762011-02-08 17:52:25 -0800664
Mason Tang8e3d4302010-07-12 17:39:30 -0700665 @Override
666 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700667 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700668 if (mPaused) {
669 mUpdateOnResume = true;
670 } else {
671 initFragments(mController.getTime(), mController.getViewType(), null);
672 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700673 }
674 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700675
Erik63cd0532011-01-26 14:16:03 -0800676 private void setMainPane(
677 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700678 if (mOnSaveInstanceStateCalled) {
679 return;
680 }
Erik7b92da22010-09-23 14:55:22 -0700681 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700682 return;
683 }
684
Michael Chan5756bbc2011-03-02 18:22:07 -0800685 // Remove this when transition to and from month view looks fine.
686 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700687 FragmentManager fragmentManager = getFragmentManager();
688 // Check if our previous view was an Agenda view
689 // TODO remove this if framework ever supports nested fragments
690 if (mCurrentView == ViewType.AGENDA) {
691 // If it was, we need to do some cleanup on it to prevent the
692 // edit/delete buttons from coming back on a rotation.
693 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
694 if (oldFrag instanceof AgendaFragment) {
695 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
696 }
697 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800698
Erik648c59c2010-08-13 12:49:26 -0700699 if (viewType != mCurrentView) {
700 // The rules for this previous view are different than the
701 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700702 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
703 mPreviousView = mCurrentView;
704 }
Erik648c59c2010-08-13 12:49:26 -0700705 mCurrentView = viewType;
706 }
Erik3f348f32010-08-10 13:17:19 -0700707 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700708 Fragment frag = null;
709 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700710 switch (viewType) {
711 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700712 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
713 mActionBar.selectTab(mAgendaTab);
714 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700715 if (mActionBarMenuSpinnerAdapter != null) {
716 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
717 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700718 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700719 break;
720 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700721 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
722 mActionBar.selectTab(mDayTab);
723 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700724 if (mActionBarMenuSpinnerAdapter != null) {
725 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
726 }
Michael Chan75d9b562010-07-26 16:54:25 -0700727 frag = new DayFragment(timeMillis, 1);
728 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700729 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700730 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
731 mActionBar.selectTab(mWeekTab);
732 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700733 if (mActionBarMenuSpinnerAdapter != null) {
734 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
735 }
Michael Chan75d9b562010-07-26 16:54:25 -0700736 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700737 break;
738 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700739 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
740 mActionBar.selectTab(mMonthTab);
741 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700742 if (mActionBarMenuSpinnerAdapter != null) {
743 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
744 }
Erik40bcd102010-11-16 15:46:40 -0800745 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700746 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700747 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700748 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700749 break;
750 default:
Michael Chand6734db2010-07-22 00:48:08 -0700751 throw new IllegalArgumentException(
752 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700753 }
754
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700755 // Update the current view so that the menu can update its look according to the
756 // current view.
757 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
758 mActionBarMenuSpinnerAdapter.setMainView(viewType);
759 }
760
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700761
762 // Show date only on tablet configurations in views different than Agenda
763 if (!mIsTabletConfig) {
764 mDateRange.setVisibility(View.GONE);
765 } else if (viewType != ViewType.AGENDA) {
766 mDateRange.setVisibility(View.VISIBLE);
767 } else {
768 mDateRange.setVisibility(View.GONE);
769 }
770
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700771 // Clear unnecessary buttons from the option menu when switching from the agenda view
772 if (viewType != ViewType.AGENDA) {
773 clearOptionsMenu();
774 }
775
Michael Chanab29d9e2010-07-21 06:08:47 -0700776 boolean doCommit = false;
777 if (ft == null) {
778 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700779 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700780 }
781
Michael Chan5756bbc2011-03-02 18:22:07 -0800782 if (doTransition) {
783 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
784 }
785
Michael Chanab29d9e2010-07-21 06:08:47 -0700786 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700787 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700788
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700789 // Show/hide secondary fragment
790
791 if (secFrag != null) {
792 ft.replace(R.id.secondary_pane, secFrag);
793 mSecondaryPane.setVisibility(View.VISIBLE);
794 } else {
795 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700796 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700797 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700798 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700799 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700800 mController.deregisterEventHandler(R.id.secondary_pane);
801 }
802 }
Erik954c8712010-08-06 10:12:34 -0700803 if (DEBUG) {
804 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
805 }
Erik3f348f32010-08-10 13:17:19 -0700806 // If the key is already registered this will replace it
807 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700808 if (secFrag != null) {
809 mController.registerEventHandler(viewId, (EventHandler) secFrag);
810 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700811
812 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800813 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700814 ft.commit();
815 }
816 }
817
818 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800819 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700820 return;
821 }
822
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700823 final long start = event.startTime.toMillis(false /* use isDst */);
824 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700825 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700826 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700827 } else {
828 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700829 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700830
Erikeaafa2b2010-12-23 14:30:37 -0800831 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800832 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800833 mDateRange.setText(msg);
RoboErik14e82b42011-07-19 09:46:39 -0700834 updateHomeClockAndWeekNum(start);
Erik259b8f92011-01-12 14:01:12 -0800835 if (!TextUtils.equals(oldDate, msg)) {
836 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700837 if (mShowWeekNum && mWeekTextView != null) {
838 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
839 }
Erik259b8f92011-01-12 14:01:12 -0800840 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700841 }
842
RoboErik14e82b42011-07-19 09:46:39 -0700843 private void updateHomeClockAndWeekNum(long visibleMillisSinceEpoch) {
844 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800845 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700846 if (visibleMillisSinceEpoch != -1) {
847 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
848 mWeekNum = weekNum;
849 }
850
851 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
852 && mWeekTextView != null) {
853 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
854 mWeekNum);
855 mWeekTextView.setText(weekString);
856 mWeekTextView.setVisibility(View.VISIBLE);
857 } else if (mWeekTextView != null) {
858 mWeekTextView.setVisibility(View.GONE);
859 }
860 if (mHomeTime != null
861 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
862 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800863 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
864 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700865 time.setToNow();
866 long millis = time.toMillis(true);
867 boolean isDST = time.isDst != 0;
868 int flags = DateUtils.FORMAT_SHOW_TIME;
869 if (DateFormat.is24HourFormat(this)) {
870 flags |= DateUtils.FORMAT_24HOUR;
871 }
872 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800873 String timeString = (new StringBuilder(
874 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
875 TimeZone.getTimeZone(mTimeZone).getDisplayName(
876 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700877 mHomeTime.setText(timeString);
878 mHomeTime.setVisibility(View.VISIBLE);
879 // Update when the minute changes
880 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700881 mHomeTimeUpdater,
882 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700883 } else if (mHomeTime != null) {
884 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700885 }
886 }
887
Erik3f348f32010-08-10 13:17:19 -0700888 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700889 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800890 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700891 }
892
Erik3f348f32010-08-10 13:17:19 -0700893 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700894 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700895 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700896 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -0700897 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
898 mBackToPreviousView = true;
899 } else if (event.viewType != mController.getPreviousViewType()
900 && event.viewType != ViewType.EDIT) {
901 // Clear the flag is change to a different view type
902 mBackToPreviousView = false;
903 }
904
Erik63cd0532011-01-26 14:16:03 -0800905 setMainPane(
906 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800907 if (mSearchView != null) {
908 mSearchView.clearFocus();
909 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700910
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700911 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700912 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700913 // hide minimonth and calendar frag
914 mShowSideViews = false;
915 if (mControlsMenu != null) {
916 mControlsMenu.setVisible(false);
917 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800918
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700919 if (!mHideControls) {
920 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
921 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
922 slideAnimation.addListener(mSlideAnimationDoneListener);
923 slideAnimation.setDuration(220);
924 ObjectAnimator.setFrameDelay(0);
925 slideAnimation.start();
926 }
927 } else {
928 mMiniMonth.setVisibility(View.GONE);
929 mCalendarsList.setVisibility(View.GONE);
930 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -0800931 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800932 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700933 // show minimonth and calendar frag
934 mShowSideViews = true;
935 mMiniMonth.setVisibility(View.VISIBLE);
936 mCalendarsList.setVisibility(View.VISIBLE);
937 mMiniMonthContainer.setVisibility(View.VISIBLE);
938 if (mControlsMenu != null) {
939 mControlsMenu.setVisible(true);
940 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700941 if (!mHideControls &&
942 (mController.getPreviousViewType() == ViewType.MONTH ||
943 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700944 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
945 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
946 slideAnimation.setDuration(220);
947 ObjectAnimator.setFrameDelay(0);
948 slideAnimation.start();
949 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800950 }
RoboErikde20d762011-02-08 17:52:25 -0800951 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700952 }
RoboErik14e82b42011-07-19 09:46:39 -0700953 displayTime = event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -0700954 if (!mIsTabletConfig) {
955 mActionBarMenuSpinnerAdapter.setTime(displayTime);
956 }
Michael Chan71d08832010-08-25 18:28:59 -0700957 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700958
959 // If in Agenda view and "show_event_details_with_agenda" is "true",
960 // do not create the event info fragment here, it will be created by the Agenda
961 // fragment
962
RoboErikd6c93ce2011-07-22 17:54:40 -0700963 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -0700964 if (event.startTime != null && event.endTime != null) {
965 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
966 event.id, ViewType.AGENDA);
967 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700968 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
969 event.selectedTime, event.id, ViewType.AGENDA);
970 }
971 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700972 if (mShowEventInfoFullScreen) {
973 // start event info as activity
974 Intent intent = new Intent(Intent.ACTION_VIEW);
975 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
976 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -0700977 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700978 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
979 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -0700980 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
981 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700982 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
983 startActivity(intent);
984 } else {
985 // start event info as a dialog
986 EventInfoFragment fragment = new EventInfoFragment(this,
987 event.id, event.startTime.toMillis(false),
988 event.endTime.toMillis(false), (int) event.extraLong, true);
989 // TODO Fix the temp hack below: && mCurrentView !=
990 // ViewType.AGENDA
991 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
992 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
993 event.selectedTime, -1, ViewType.DETAIL);
994 }
995 fragment.setDialogParams(event.x, event.y);
996 FragmentManager fm = getFragmentManager();
997 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -0700998 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700999 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
RoboErika459d0b2011-08-15 13:46:36 -07001000 int oldId;
1001 if (fOld != null && fOld.isAdded() && (oldId = fOld.getId()) != 0) {
1002 ft.replace(oldId, fragment, EVENT_INFO_FRAGMENT_TAG);
1003 } else {
1004 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001005 }
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001006 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001007 }
Erik63cd0532011-01-26 14:16:03 -08001008 }
RoboErik14e82b42011-07-19 09:46:39 -07001009 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001010 } else if (event.eventType == EventType.UPDATE_TITLE) {
1011 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001012 if (!mIsTabletConfig) {
1013 mActionBarMenuSpinnerAdapter.setTime(event.startTime.toMillis(false));
1014 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001015 }
RoboErik14e82b42011-07-19 09:46:39 -07001016 updateHomeClockAndWeekNum(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001017 }
1018
Michael Chan2aeb8d92011-07-10 13:32:09 -07001019 // Needs to be in proguard whitelist
1020 // Specified as listener via android:onClick in a layout xml
1021 public void handleSelectSyncedCalendarsClicked(View v) {
1022 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1023 CalendarController.EXTRA_GOTO_TIME, null,
1024 null);
1025 }
1026
Erik3f348f32010-08-10 13:17:19 -07001027 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001028 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001029 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001030 }
1031
Erik3f348f32010-08-10 13:17:19 -07001032 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001033 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001034 return false;
1035 }
1036
1037 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001038 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001039 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001040 Utils.tardis();
1041 }
RoboErika0954942011-07-27 17:43:14 -07001042 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001043 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001044 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001045 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001046 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001047
1048 @Override
1049 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001050 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001051 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001052 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001053 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001054 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001055 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001056 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001057 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1058 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001059 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001060 Log.w(TAG, "TabSelected event from unknown tab: "
1061 + (tab == null ? "null" : tab.getText()));
1062 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001063 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001064 }
1065 }
1066
1067 @Override
1068 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1069 }
1070
1071 @Override
1072 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1073 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001074
1075
1076 @Override
1077 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1078 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001079 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001080 if (mCurrentView != ViewType.DAY) {
1081 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1082 }
1083 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001084 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001085 if (mCurrentView != ViewType.WEEK) {
1086 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1087 }
1088 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001089 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001090 if (mCurrentView != ViewType.MONTH) {
1091 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1092 }
1093 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001094 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001095 if (mCurrentView != ViewType.AGENDA) {
1096 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1097 }
1098 break;
1099 default:
1100 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1101 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1102 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1103 " Agenda:" + mAgendaTab);
1104 break;
1105 }
1106 return false;
1107 }
RoboErik17664072011-08-16 16:22:39 -07001108
1109 @Override
1110 public boolean onSuggestionSelect(int position) {
1111 return false;
1112 }
1113
1114 @Override
1115 public boolean onSuggestionClick(int position) {
1116 mSearchMenu.collapseActionView();
1117 return false;
1118 }
Michael Chan49701592010-06-30 11:04:03 -07001119}