blob: 9297ce03e5b7a9c97ca56f30e6fe9e8651c5d8b4 [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.OnSuggestionListener;
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,
RoboErik17664072011-08-16 16:22:39 -070074 ActionBar.OnNavigationListener, OnSuggestionListener {
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;
Michael Chanfb0ec222011-08-12 17:39:30 -0700100 private boolean mBackToPreviousView = false;
Erik954c8712010-08-06 10:12:34 -0700101 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700102 private int mPreviousView;
103 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700104 private boolean mPaused = true;
105 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800106 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800107 private boolean mShowSideViews = true;
RoboErik14e82b42011-07-19 09:46:39 -0700108 private boolean mShowWeekNum = false;
Erik6c255102010-09-29 14:43:00 -0700109 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800110 private TextView mDateRange;
RoboErik14e82b42011-07-19 09:46:39 -0700111 private TextView mWeekTextView;
RoboErikde20d762011-02-08 17:52:25 -0800112 private View mMiniMonth;
113 private View mCalendarsList;
114 private View mMiniMonthContainer;
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700115 private View mSecondaryPane;
Erikc5f92d72010-11-11 16:18:34 -0800116 private String mTimeZone;
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700117 private boolean mShowCalendarControls;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700118 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700119 private int mWeekNum;
Erik6c255102010-09-29 14:43:00 -0700120
Michael Chan2c7c8512010-12-10 14:12:57 -0800121 private long mViewEventId = -1;
122 private long mIntentEventStartMillis = -1;
123 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800124 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800125
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700126 // Action bar and Navigation bar (left side of Action bar)
127 private ActionBar mActionBar;
128 private ActionBar.Tab mDayTab;
129 private ActionBar.Tab mWeekTab;
130 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700131 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800132 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700133 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800134 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700135 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700136 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErikde20d762011-02-08 17:52:25 -0800137
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700138 private String mHideString;
139 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800140
RoboErikb8549562011-02-15 14:25:23 -0800141 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800142 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
143
144 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
145
146 @Override
147 public void onAnimationCancel(Animator animation) {
148 }
149
150 @Override
151 public void onAnimationEnd(android.animation.Animator animation) {
152 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
153 mMiniMonth.setVisibility(visibility);
154 mCalendarsList.setVisibility(visibility);
155 mMiniMonthContainer.setVisibility(visibility);
156 }
157
158 @Override
159 public void onAnimationRepeat(android.animation.Animator animation) {
160 }
161
162 @Override
163 public void onAnimationStart(android.animation.Animator animation) {
164 }
165 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700166
Erik6c255102010-09-29 14:43:00 -0700167 private Runnable mHomeTimeUpdater = new Runnable() {
168 @Override
169 public void run() {
RoboErik4eb34322011-08-19 15:47:51 -0700170 updateSecondaryTitleFields(-1);
Erik6c255102010-09-29 14:43:00 -0700171 }
172 };
Erik954c8712010-08-06 10:12:34 -0700173
174 // Create an observer so that we can update the views whenever a
175 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700176 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700177 @Override
178 public boolean deliverSelfNotifications() {
179 return true;
180 }
181
182 @Override
183 public void onChange(boolean selfChange) {
184 eventsChanged();
185 }
186 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700187
Michael Chan49701592010-06-30 11:04:03 -0700188 @Override
Erik63cd0532011-01-26 14:16:03 -0800189 protected void onNewIntent(Intent intent) {
190 String action = intent.getAction();
191 if (Intent.ACTION_VIEW.equals(action)) {
192 parseViewAction(intent);
193 }
194 }
195
196 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700197 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800198 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
199 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
200 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700201 super.onCreate(icicle);
202
203 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700204 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700205
206
Erik954c8712010-08-06 10:12:34 -0700207 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800208 long timeMillis = -1;
209 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800210 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700211 if (icicle != null) {
212 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800213 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700214 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800215 String action = intent.getAction();
216 if (Intent.ACTION_VIEW.equals(action)) {
217 // Open EventInfo later
218 timeMillis = parseViewAction(intent);
219 }
220
221 if (timeMillis == -1) {
222 timeMillis = Utils.timeFromIntentInMillis(intent);
223 }
224 }
225
RoboErik277eb972011-02-24 16:05:04 -0800226 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700227 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
228 }
Erikc5f92d72010-11-11 16:18:34 -0800229 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
230 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700231 t.set(timeMillis);
232
Michael Chan2c7c8512010-12-10 14:12:57 -0800233 if (icicle != null && intent != null) {
234 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700235 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800236 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700237 }
238
Erikeaafa2b2010-12-23 14:30:37 -0800239 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800240 if (mScale == 0) {
241 mScale = res.getDisplayMetrics().density;
242 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800243 }
244 mHideString = res.getString(R.string.hide_controls);
245 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800246 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800247
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700248 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700249 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700250 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700251 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700252 mShowEventDetailsWithAgenda =
253 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700254 mShowEventInfoFullScreen =
255 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700256
Erik63cd0532011-01-26 14:16:03 -0800257 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800258
Erikbe8191c2010-10-26 16:50:08 -0700259 // setContentView must be called before configureActionBar
260 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700261
262 if (mIsTabletConfig) {
263 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700264 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700265 } else {
266 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
267 }
268
Erikbe8191c2010-10-26 16:50:08 -0700269 // configureActionBar auto-selects the first tab you add, so we need to
270 // call it before we set up our own fragments to make sure it doesn't
271 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700272 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700273
Erik6c255102010-09-29 14:43:00 -0700274 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800275 mMiniMonth = findViewById(R.id.mini_month);
276 mCalendarsList = findViewById(R.id.calendar_list);
277 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700278 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700279
RoboErik3864be02011-07-25 15:56:50 -0700280 // Must register as the first activity because this activity can modify
281 // the list of event handlers in it's handle method. This affects who
282 // the rest of the handlers the controller dispatches to are.
283 mController.registerFirstEventHandler(HANDLER_KEY, this);
284
Erik7b92da22010-09-23 14:55:22 -0700285 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700286
287 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700288 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700289 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700290
Erik954c8712010-08-06 10:12:34 -0700291 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700292 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700293
Michael Chan2c7c8512010-12-10 14:12:57 -0800294 private long parseViewAction(final Intent intent) {
295 long timeMillis = -1;
296 Uri data = intent.getData();
297 if (data != null && data.isHierarchical()) {
298 List<String> path = data.getPathSegments();
299 if (path.size() == 2 && path.get(0).equals("events")) {
300 try {
301 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700302 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700303 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
304 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800305 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800306 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800307 timeMillis = mIntentEventStartMillis;
308 }
309 } catch (NumberFormatException e) {
310 // Ignore if mViewEventId can't be parsed
311 }
312 }
313 }
314 return timeMillis;
315 }
316
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700317 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700318 if (mIsTabletConfig) {
319 createTabs();
320 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700321 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700322 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700323 if (mIsMultipane) {
324 mActionBar.setDisplayOptions(
325 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
326 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700327 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700328 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700329 }
330
331 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700332 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700333 if (mActionBar == null) {
334 Log.w(TAG, "ActionBar is null.");
335 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700336 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700337 mDayTab = mActionBar.newTab();
338 mDayTab.setText(getString(R.string.day_view));
339 mDayTab.setTabListener(this);
340 mActionBar.addTab(mDayTab);
341 mWeekTab = mActionBar.newTab();
342 mWeekTab.setText(getString(R.string.week_view));
343 mWeekTab.setTabListener(this);
344 mActionBar.addTab(mWeekTab);
345 mMonthTab = mActionBar.newTab();
346 mMonthTab.setText(getString(R.string.month_view));
347 mMonthTab.setTabListener(this);
348 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700349 mAgendaTab = mActionBar.newTab();
350 mAgendaTab.setText(getString(R.string.agenda_view));
351 mAgendaTab.setTabListener(this);
352 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700353 }
Erik954c8712010-08-06 10:12:34 -0700354 }
355
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700356 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700357 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700358 mActionBar = getActionBar();
359 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700360 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700361 switch (viewType) {
362 case ViewType.AGENDA:
363 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
364 break;
365 case ViewType.DAY:
366 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
367 break;
368 case ViewType.WEEK:
369 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
370 break;
371 case ViewType.MONTH:
372 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
373 break;
374 default:
375 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
376 break;
377 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700378 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700379 // Clear buttons used in the agenda view
380 private void clearOptionsMenu() {
381 if (mOptionsMenu == null) {
382 return;
383 }
384 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700385 MenuItem editItem = mOptionsMenu.findItem(R.id.action_edit);
386 if (cancelItem != null) {
387 cancelItem.setVisible(false);
388 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700389 if (editItem != null) {
390 editItem.setVisible(false);
391 }
392 }
393
Erik954c8712010-08-06 10:12:34 -0700394 @Override
395 protected void onResume() {
396 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700397
398 // Must register as the first activity because this activity can modify
399 // the list of event handlers in it's handle method. This affects who
400 // the rest of the handlers the controller dispatches to are.
401 mController.registerFirstEventHandler(HANDLER_KEY, this);
402
Michael Chanf2cfa202011-08-19 17:58:16 -0700403 mOnSaveInstanceStateCalled = false;
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 }
RoboErik4eb34322011-08-19 15:47:51 -0700410 updateSecondaryTitleFields(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) {
Michael Chanbe686752011-08-23 15:53:35 -0700413 mActionBarMenuSpinnerAdapter.refresh(this);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700414 }
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 Chan2c7c8512010-12-10 14:12:57 -0800420
421 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800422 long currentMillis = System.currentTimeMillis();
423 long selectedTime = -1;
424 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
425 selectedTime = currentMillis;
426 }
Michael Chanedecd9a2011-08-24 23:58:48 -0700427 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700428 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
429 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800430 mViewEventId = -1;
431 mIntentEventStartMillis = -1;
432 mIntentEventEndMillis = -1;
433 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700434 }
435
436 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700437 protected void onPause() {
438 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700439
440 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700441 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700442 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700443 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700444 mActionBarMenuSpinnerAdapter.onPause();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700445 }
Erik954c8712010-08-06 10:12:34 -0700446 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700447 if (isFinishing()) {
448 // Stop listening for changes that would require this to be refreshed
449 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
450 prefs.unregisterOnSharedPreferenceChangeListener(this);
451 }
Erik7b92da22010-09-23 14:55:22 -0700452 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700453 if (mController.getViewType() != ViewType.EDIT) {
454 Utils.setDefaultView(this, mController.getViewType());
455 }
Michael Chand6734db2010-07-22 00:48:08 -0700456 }
457
458 @Override
Erik7b92da22010-09-23 14:55:22 -0700459 protected void onUserLeaveHint() {
460 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
461 super.onUserLeaveHint();
462 }
463
464 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700465 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700466 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700467 super.onSaveInstanceState(outState);
468
469 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700470 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800471 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700472 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
473 }
Michael Chand6734db2010-07-22 00:48:08 -0700474 }
475
476 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700477 protected void onDestroy() {
478 super.onDestroy();
479
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700480 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700481 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700482 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700483 }
484
Erik7b92da22010-09-23 14:55:22 -0700485 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700486 if (DEBUG) {
487 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
488 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800489 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700490
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700491 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800492 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700493 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700494 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700495
Michael Chan2aeb8d92011-07-10 13:32:09 -0700496 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700497 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800498 mController.registerEventHandler(
499 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700500 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700501 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800502 mMiniMonth.setVisibility(View.GONE);
503 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700504 }
Michael Chan3458a172010-07-13 17:58:21 -0700505
Erikdd95df52010-08-27 09:31:18 -0700506 EventInfo info = null;
507 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700508 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700509 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700510
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700511 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700512 Intent intent = getIntent();
513 Uri data = intent.getData();
514 if (data != null) {
515 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700516 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700517 } catch (NumberFormatException e) {
518 if (DEBUG) {
519 Log.d(TAG, "Create new event");
520 }
521 }
Erik7b92da22010-09-23 14:55:22 -0700522 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
523 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700524 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700525
RoboErika27a8862011-06-23 15:26:23 -0700526 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
527 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700528 info = new EventInfo();
529 if (end != -1) {
530 info.endTime = new Time();
531 info.endTime.set(end);
532 }
533 if (begin != -1) {
534 info.startTime = new Time();
535 info.startTime.set(begin);
536 }
537 info.id = eventId;
538 // We set the viewtype so if the user presses back when they are
539 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700540 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700541 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700542 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700543 } else {
544 mPreviousView = viewType;
545 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700546
Erik63cd0532011-01-26 14:16:03 -0800547 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700548 ft.commit(); // this needs to be after setMainPane()
549
Erikc5f92d72010-11-11 16:18:34 -0800550 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700551 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700552 if (viewType != ViewType.EDIT) {
553 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
554 }
Michael Chan49701592010-06-30 11:04:03 -0700555 }
Erik2051f122010-07-02 13:45:45 -0700556
557 @Override
Erik648c59c2010-08-13 12:49:26 -0700558 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700559 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700560 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700561 } else {
562 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700563 }
564 }
565
566 @Override
Erik2051f122010-07-02 13:45:45 -0700567 public boolean onCreateOptionsMenu(Menu menu) {
568 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700569 mOptionsMenu = menu;
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);
RoboErik17664072011-08-16 16:22:39 -0700577 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700578 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700579
580 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700581 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700582
RoboErikde20d762011-02-08 17:52:25 -0800583 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700584 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700585 if (mControlsMenu != null) {
586 mControlsMenu.setVisible(false);
587 mControlsMenu.setEnabled(false);
588 }
589 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700590 && (mController.getViewType() == ViewType.MONTH ||
591 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800592 mControlsMenu.setVisible(false);
593 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700594 } else if (mControlsMenu != null){
595 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800596 }
Erik2051f122010-07-02 13:45:45 -0700597 return true;
598 }
Michael Chan3458a172010-07-13 17:58:21 -0700599
600 @Override
601 public boolean onOptionsItemSelected(MenuItem item) {
602 Time t = null;
603 int viewType = ViewType.CURRENT;
604 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700605 case R.id.action_refresh:
606 mController.refreshCalendars();
607 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700608 case R.id.action_today:
609 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800610 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700611 t.setToNow();
612 break;
613 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800614 t = new Time();
615 t.set(mController.getTime());
616 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800617 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800618 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800619 } else {
620 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800621 }
622 mController.sendEventRelatedEvent(
623 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700624 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700625 case R.id.action_select_visible_calendars:
626 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
627 0, 0);
628 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700629 case R.id.action_settings:
630 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
631 return true;
RoboErikde20d762011-02-08 17:52:25 -0800632 case R.id.action_hide_controls:
633 mHideControls = !mHideControls;
634 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800635 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
636 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
637 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
638 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
639 ObjectAnimator.setFrameDelay(0);
640 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800641 return true;
RoboErike635aec2011-07-15 11:22:13 -0700642 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700643 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700644 default:
645 return false;
646 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700647 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700648 return true;
649 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700650
RoboErikb8549562011-02-15 14:25:23 -0800651 /**
652 * Sets the offset of the controls on the right for animating them off/on
653 * screen. ProGuard strips this if it's not in proguard.flags
654 *
655 * @param controlsOffset The current offset in pixels
656 */
657 public void setControlsOffset(int controlsOffset) {
658 mMiniMonth.setTranslationX(controlsOffset);
659 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800660 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800661 mMiniMonthContainer.setLayoutParams(mControlsParams);
662 }
RoboErikde20d762011-02-08 17:52:25 -0800663
Mason Tang8e3d4302010-07-12 17:39:30 -0700664 @Override
665 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700666 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700667 if (mPaused) {
668 mUpdateOnResume = true;
669 } else {
670 initFragments(mController.getTime(), mController.getViewType(), null);
671 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700672 }
673 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700674
Erik63cd0532011-01-26 14:16:03 -0800675 private void setMainPane(
676 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700677 if (mOnSaveInstanceStateCalled) {
678 return;
679 }
Erik7b92da22010-09-23 14:55:22 -0700680 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700681 return;
682 }
683
Michael Chan5756bbc2011-03-02 18:22:07 -0800684 // Remove this when transition to and from month view looks fine.
685 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700686 FragmentManager fragmentManager = getFragmentManager();
687 // Check if our previous view was an Agenda view
688 // TODO remove this if framework ever supports nested fragments
689 if (mCurrentView == ViewType.AGENDA) {
690 // If it was, we need to do some cleanup on it to prevent the
691 // edit/delete buttons from coming back on a rotation.
692 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
693 if (oldFrag instanceof AgendaFragment) {
694 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
695 }
696 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800697
Erik648c59c2010-08-13 12:49:26 -0700698 if (viewType != mCurrentView) {
699 // The rules for this previous view are different than the
700 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700701 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
702 mPreviousView = mCurrentView;
703 }
Erik648c59c2010-08-13 12:49:26 -0700704 mCurrentView = viewType;
705 }
Erik3f348f32010-08-10 13:17:19 -0700706 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700707 Fragment frag = null;
708 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700709 switch (viewType) {
710 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700711 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
712 mActionBar.selectTab(mAgendaTab);
713 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700714 if (mActionBarMenuSpinnerAdapter != null) {
715 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
716 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700717 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700718 break;
719 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700720 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
721 mActionBar.selectTab(mDayTab);
722 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700723 if (mActionBarMenuSpinnerAdapter != null) {
724 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
725 }
Michael Chan75d9b562010-07-26 16:54:25 -0700726 frag = new DayFragment(timeMillis, 1);
727 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700728 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700729 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
730 mActionBar.selectTab(mWeekTab);
731 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700732 if (mActionBarMenuSpinnerAdapter != null) {
733 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
734 }
Michael Chan75d9b562010-07-26 16:54:25 -0700735 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700736 break;
737 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700738 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
739 mActionBar.selectTab(mMonthTab);
740 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700741 if (mActionBarMenuSpinnerAdapter != null) {
742 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
743 }
Erik40bcd102010-11-16 15:46:40 -0800744 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700745 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700746 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700747 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700748 break;
749 default:
Michael Chand6734db2010-07-22 00:48:08 -0700750 throw new IllegalArgumentException(
751 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700752 }
753
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700754 // Update the current view so that the menu can update its look according to the
755 // current view.
756 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
RoboErike11975f2011-09-02 14:00:39 -0700757 mActionBarMenuSpinnerAdapter.setTime(timeMillis);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700758 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);
RoboErik4eb34322011-08-19 15:47:51 -0700834 updateSecondaryTitleFields(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
RoboErik4eb34322011-08-19 15:47:51 -0700843 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
RoboErik14e82b42011-07-19 09:46:39 -0700844 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);
RoboErik4eb34322011-08-19 15:47:51 -0700857 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null
858 && mCurrentView == ViewType.DAY && mIsTabletConfig) {
859 Time time = new Time(mTimeZone);
860 time.set(visibleMillisSinceEpoch);
861 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
862 time.setToNow();
863 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
864 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay,
865 visibleMillisSinceEpoch, this);
866 mWeekTextView.setText(dayString);
867 mWeekTextView.setVisibility(View.VISIBLE);
868 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
RoboErik14e82b42011-07-19 09:46:39 -0700869 mWeekTextView.setVisibility(View.GONE);
870 }
Michael Chanbe686752011-08-23 15:53:35 -0700871
RoboErik14e82b42011-07-19 09:46:39 -0700872 if (mHomeTime != null
873 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
874 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800875 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
876 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700877 time.setToNow();
878 long millis = time.toMillis(true);
879 boolean isDST = time.isDst != 0;
880 int flags = DateUtils.FORMAT_SHOW_TIME;
881 if (DateFormat.is24HourFormat(this)) {
882 flags |= DateUtils.FORMAT_24HOUR;
883 }
884 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800885 String timeString = (new StringBuilder(
886 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
887 TimeZone.getTimeZone(mTimeZone).getDisplayName(
888 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700889 mHomeTime.setText(timeString);
890 mHomeTime.setVisibility(View.VISIBLE);
891 // Update when the minute changes
892 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700893 mHomeTimeUpdater,
894 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700895 } else if (mHomeTime != null) {
896 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700897 }
898 }
899
Erik3f348f32010-08-10 13:17:19 -0700900 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700901 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800902 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700903 }
904
Erik3f348f32010-08-10 13:17:19 -0700905 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700906 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700907 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700908 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -0700909 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
910 mBackToPreviousView = true;
911 } else if (event.viewType != mController.getPreviousViewType()
912 && event.viewType != ViewType.EDIT) {
913 // Clear the flag is change to a different view type
914 mBackToPreviousView = false;
915 }
916
Erik63cd0532011-01-26 14:16:03 -0800917 setMainPane(
918 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800919 if (mSearchView != null) {
920 mSearchView.clearFocus();
921 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700922
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700923 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700924 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700925 // hide minimonth and calendar frag
926 mShowSideViews = false;
927 if (mControlsMenu != null) {
928 mControlsMenu.setVisible(false);
929 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800930
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700931 if (!mHideControls) {
932 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
933 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
934 slideAnimation.addListener(mSlideAnimationDoneListener);
935 slideAnimation.setDuration(220);
936 ObjectAnimator.setFrameDelay(0);
937 slideAnimation.start();
938 }
939 } else {
940 mMiniMonth.setVisibility(View.GONE);
941 mCalendarsList.setVisibility(View.GONE);
942 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -0800943 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800944 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700945 // show minimonth and calendar frag
946 mShowSideViews = true;
947 mMiniMonth.setVisibility(View.VISIBLE);
948 mCalendarsList.setVisibility(View.VISIBLE);
949 mMiniMonthContainer.setVisibility(View.VISIBLE);
950 if (mControlsMenu != null) {
951 mControlsMenu.setVisible(true);
952 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700953 if (!mHideControls &&
954 (mController.getPreviousViewType() == ViewType.MONTH ||
955 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700956 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
957 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
958 slideAnimation.setDuration(220);
959 ObjectAnimator.setFrameDelay(0);
960 slideAnimation.start();
961 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800962 }
RoboErikde20d762011-02-08 17:52:25 -0800963 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700964 }
RoboErik14e82b42011-07-19 09:46:39 -0700965 displayTime = event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -0700966 if (!mIsTabletConfig) {
967 mActionBarMenuSpinnerAdapter.setTime(displayTime);
968 }
Michael Chan71d08832010-08-25 18:28:59 -0700969 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700970
971 // If in Agenda view and "show_event_details_with_agenda" is "true",
972 // do not create the event info fragment here, it will be created by the Agenda
973 // fragment
974
RoboErikd6c93ce2011-07-22 17:54:40 -0700975 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -0700976 if (event.startTime != null && event.endTime != null) {
977 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
978 event.id, ViewType.AGENDA);
979 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700980 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
981 event.selectedTime, event.id, ViewType.AGENDA);
982 }
983 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700984 if (mShowEventInfoFullScreen) {
985 // start event info as activity
986 Intent intent = new Intent(Intent.ACTION_VIEW);
987 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
988 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -0700989 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700990 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
991 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -0700992 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
993 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700994 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
995 startActivity(intent);
996 } else {
997 // start event info as a dialog
998 EventInfoFragment fragment = new EventInfoFragment(this,
999 event.id, event.startTime.toMillis(false),
1000 event.endTime.toMillis(false), (int) event.extraLong, true);
1001 // TODO Fix the temp hack below: && mCurrentView !=
1002 // ViewType.AGENDA
1003 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
1004 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1005 event.selectedTime, -1, ViewType.DETAIL);
1006 }
1007 fragment.setDialogParams(event.x, event.y);
1008 FragmentManager fm = getFragmentManager();
1009 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -07001010 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001011 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
RoboErika459d0b2011-08-15 13:46:36 -07001012 int oldId;
1013 if (fOld != null && fOld.isAdded() && (oldId = fOld.getId()) != 0) {
1014 ft.replace(oldId, fragment, EVENT_INFO_FRAGMENT_TAG);
1015 } else {
1016 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001017 }
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001018 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001019 }
Erik63cd0532011-01-26 14:16:03 -08001020 }
RoboErik14e82b42011-07-19 09:46:39 -07001021 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001022 } else if (event.eventType == EventType.UPDATE_TITLE) {
1023 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001024 if (!mIsTabletConfig) {
RoboErike11975f2011-09-02 14:00:39 -07001025 mActionBarMenuSpinnerAdapter.setTime(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001026 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001027 }
RoboErik4eb34322011-08-19 15:47:51 -07001028 updateSecondaryTitleFields(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001029 }
1030
Michael Chan2aeb8d92011-07-10 13:32:09 -07001031 // Needs to be in proguard whitelist
1032 // Specified as listener via android:onClick in a layout xml
1033 public void handleSelectSyncedCalendarsClicked(View v) {
1034 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1035 CalendarController.EXTRA_GOTO_TIME, null,
1036 null);
1037 }
1038
Erik3f348f32010-08-10 13:17:19 -07001039 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001040 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001041 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001042 }
1043
Erik3f348f32010-08-10 13:17:19 -07001044 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001045 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001046 return false;
1047 }
1048
1049 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001050 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001051 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001052 Utils.tardis();
1053 }
RoboErika0954942011-07-27 17:43:14 -07001054 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001055 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001056 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001057 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001058 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001059
1060 @Override
1061 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001062 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001063 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001064 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001065 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001066 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001067 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001068 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001069 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1070 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001071 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001072 Log.w(TAG, "TabSelected event from unknown tab: "
1073 + (tab == null ? "null" : tab.getText()));
1074 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001075 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001076 }
1077 }
1078
1079 @Override
1080 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1081 }
1082
1083 @Override
1084 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1085 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001086
1087
1088 @Override
1089 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1090 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001091 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001092 if (mCurrentView != ViewType.DAY) {
1093 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1094 }
1095 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001096 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001097 if (mCurrentView != ViewType.WEEK) {
1098 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1099 }
1100 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001101 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001102 if (mCurrentView != ViewType.MONTH) {
1103 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1104 }
1105 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001106 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001107 if (mCurrentView != ViewType.AGENDA) {
1108 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1109 }
1110 break;
1111 default:
1112 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1113 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1114 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1115 " Agenda:" + mAgendaTab);
1116 break;
1117 }
1118 return false;
1119 }
RoboErik17664072011-08-16 16:22:39 -07001120
1121 @Override
1122 public boolean onSuggestionSelect(int position) {
1123 return false;
1124 }
1125
1126 @Override
1127 public boolean onSuggestionClick(int position) {
1128 mSearchMenu.collapseActionView();
1129 return false;
1130 }
RoboErikc6e314f2011-08-17 10:55:03 -07001131
1132 @Override
1133 public boolean onSearchRequested() {
1134 if (mSearchMenu != null) {
1135 mSearchMenu.expandActionView();
1136 }
1137 return false;
1138 }
Michael Chan49701592010-06-30 11:04:03 -07001139}