blob: ad5ca37675536aa660575d0bac74f27634d3a81c [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
RoboErika7c03902011-06-14 11:06:44 -070019import static android.provider.CalendarContract.EVENT_BEGIN_TIME;
20import static android.provider.CalendarContract.EVENT_END_TIME;
21import 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;
Mason Tang9a3cb142010-07-27 12:16:41 -070030import com.android.calendar.selectcalendars.SelectCalendarsFragment;
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;
Isaac Katzenelson6a182582011-04-21 15:46:33 -070043import android.content.Context;
Erikdd95df52010-08-27 09:31:18 -070044import android.content.Intent;
Mason Tang8e3d4302010-07-12 17:39:30 -070045import android.content.SharedPreferences;
46import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Michael Chanab29d9e2010-07-21 06:08:47 -070047import android.content.res.Configuration;
Erikeaafa2b2010-12-23 14:30:37 -080048import android.content.res.Resources;
Erik954c8712010-08-06 10:12:34 -070049import android.database.ContentObserver;
Erikdd95df52010-08-27 09:31:18 -070050import android.net.Uri;
Michael Chan49701592010-06-30 11:04:03 -070051import android.os.Bundle;
Erik954c8712010-08-06 10:12:34 -070052import android.os.Handler;
RoboErika7c03902011-06-14 11:06:44 -070053import android.provider.CalendarContract;
54import android.provider.CalendarContract.Events;
Erik6c255102010-09-29 14:43:00 -070055import android.text.TextUtils;
56import android.text.format.DateFormat;
Michael Chan3458a172010-07-13 17:58:21 -070057import android.text.format.DateUtils;
Michael Chan83b0fe32010-07-08 16:46:26 -070058import android.text.format.Time;
Erik954c8712010-08-06 10:12:34 -070059import android.util.Log;
Erik2051f122010-07-02 13:45:45 -070060import android.view.Menu;
Michael Chan3458a172010-07-13 17:58:21 -070061import android.view.MenuItem;
Michael Chanab29d9e2010-07-21 06:08:47 -070062import android.view.View;
Erik259b8f92011-01-12 14:01:12 -080063import android.view.accessibility.AccessibilityEvent;
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070064import android.widget.ArrayAdapter;
RoboErikde20d762011-02-08 17:52:25 -080065import android.widget.RelativeLayout;
66import android.widget.RelativeLayout.LayoutParams;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -070067import android.widget.SearchView;
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070068import android.widget.SpinnerAdapter;
Erik6c255102010-09-29 14:43:00 -070069import android.widget.TextView;
70
Michael Chan2c7c8512010-12-10 14:12:57 -080071import java.util.List;
Erik6c255102010-09-29 14:43:00 -070072import java.util.Locale;
73import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070074
Michael Chanab29d9e2010-07-21 06:08:47 -070075public class AllInOneActivity extends Activity implements EventHandler,
Adam Powell28f9b352011-01-20 18:36:10 -080076 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener,
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070077 ActionBar.TabListener, ActionBar.OnNavigationListener {
Michael Chand6734db2010-07-22 00:48:08 -070078 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070079 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080080 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070081 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070082 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080083 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
Erik3f348f32010-08-10 13:17:19 -070084 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080085 private static final long CONTROLS_ANIMATE_DURATION = 400;
Michael Chan5756bbc2011-03-02 18:22:07 -080086 private static int CONTROLS_ANIMATE_WIDTH = 267;
RoboErikde20d762011-02-08 17:52:25 -080087 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -080088
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070089 // Indices of buttons for the drop down menu (tabs replacement)
90 // Must match the strings in the array buttons_list in arrays.xml and the
91 // OnNavigationListener
92 private static final int BUTTON_DAY_INDEX = 0;
93 private static final int BUTTON_WEEK_INDEX = 1;
94 private static final int BUTTON_MONTH_INDEX = 2;
95 private static final int BUTTON_AGENDA_INDEX = 3;
96
Michael Chan0558def2010-07-22 21:30:32 -070097 private static CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -070098 private static boolean mIsMultipane;
Isaac Katzenelson62967cb2011-06-14 13:27:20 -070099 private static boolean mIsTabletConfig;
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700100 private static boolean mShowAgendaWithMonth;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700101 private static boolean mShowEventDetailsWithAgenda;
Michael Chan6191c122010-11-02 16:23:47 -0700102 private boolean mOnSaveInstanceStateCalled = false;
Erik954c8712010-08-06 10:12:34 -0700103 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700104 private int mPreviousView;
105 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700106 private boolean mPaused = true;
107 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800108 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800109 private boolean mShowSideViews = true;
Erik6c255102010-09-29 14:43:00 -0700110 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800111 private TextView mDateRange;
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;
Erik6c255102010-09-29 14:43:00 -0700119
Michael Chan2c7c8512010-12-10 14:12:57 -0800120 private long mViewEventId = -1;
121 private long mIntentEventStartMillis = -1;
122 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800123 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800124
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700125 // Action bar and Navigation bar (left side of Action bar)
126 private ActionBar mActionBar;
127 private ActionBar.Tab mDayTab;
128 private ActionBar.Tab mWeekTab;
129 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700130 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800131 private SearchView mSearchView;
RoboErikde20d762011-02-08 17:52:25 -0800132 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700133 private Menu mOptionsMenu;
RoboErikde20d762011-02-08 17:52:25 -0800134
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700135 private String mHideString;
136 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800137
RoboErikb8549562011-02-15 14:25:23 -0800138 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800139 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
140
141 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
142
143 @Override
144 public void onAnimationCancel(Animator animation) {
145 }
146
147 @Override
148 public void onAnimationEnd(android.animation.Animator animation) {
149 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
150 mMiniMonth.setVisibility(visibility);
151 mCalendarsList.setVisibility(visibility);
152 mMiniMonthContainer.setVisibility(visibility);
153 }
154
155 @Override
156 public void onAnimationRepeat(android.animation.Animator animation) {
157 }
158
159 @Override
160 public void onAnimationStart(android.animation.Animator animation) {
161 }
162 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700163
Erik6c255102010-09-29 14:43:00 -0700164 private Runnable mHomeTimeUpdater = new Runnable() {
165 @Override
166 public void run() {
167 updateHomeClock();
168 }
169 };
Erik954c8712010-08-06 10:12:34 -0700170
171 // Create an observer so that we can update the views whenever a
172 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700173 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700174 @Override
175 public boolean deliverSelfNotifications() {
176 return true;
177 }
178
179 @Override
180 public void onChange(boolean selfChange) {
181 eventsChanged();
182 }
183 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700184
Michael Chan49701592010-06-30 11:04:03 -0700185 @Override
Erik63cd0532011-01-26 14:16:03 -0800186 protected void onNewIntent(Intent intent) {
187 String action = intent.getAction();
188 if (Intent.ACTION_VIEW.equals(action)) {
189 parseViewAction(intent);
190 }
191 }
192
193 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700194 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800195 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
196 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
197 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700198 super.onCreate(icicle);
199
200 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700201 mController = CalendarController.getInstance(this);
Erik954c8712010-08-06 10:12:34 -0700202 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800203 long timeMillis = -1;
204 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800205 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700206 if (icicle != null) {
207 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800208 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700209 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800210 String action = intent.getAction();
211 if (Intent.ACTION_VIEW.equals(action)) {
212 // Open EventInfo later
213 timeMillis = parseViewAction(intent);
214 }
215
216 if (timeMillis == -1) {
217 timeMillis = Utils.timeFromIntentInMillis(intent);
218 }
219 }
220
RoboErik277eb972011-02-24 16:05:04 -0800221 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700222 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
223 }
Erikc5f92d72010-11-11 16:18:34 -0800224 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
225 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700226 t.set(timeMillis);
227
Michael Chan2c7c8512010-12-10 14:12:57 -0800228 if (icicle != null && intent != null) {
229 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700230 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800231 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700232 }
233
Erikeaafa2b2010-12-23 14:30:37 -0800234 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800235 if (mScale == 0) {
236 mScale = res.getDisplayMetrics().density;
237 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800238 }
239 mHideString = res.getString(R.string.hide_controls);
240 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800241 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800242
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700243 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700244 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700245 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700246 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700247 mShowEventDetailsWithAgenda =
248 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700249 mShowEventInfoFullScreen =
250 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700251
Erik63cd0532011-01-26 14:16:03 -0800252 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800253
Erikbe8191c2010-10-26 16:50:08 -0700254 // setContentView must be called before configureActionBar
255 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700256
257 if (mIsTabletConfig) {
258 mDateRange = (TextView) findViewById(R.id.date_bar);
259 } else {
260 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
261 }
262
Erikbe8191c2010-10-26 16:50:08 -0700263 // configureActionBar auto-selects the first tab you add, so we need to
264 // call it before we set up our own fragments to make sure it doesn't
265 // overwrite us
266 configureActionBar();
267
Erik3f348f32010-08-10 13:17:19 -0700268 // Must be the first to register because this activity can modify the
269 // list of event handlers in it's handle method. This affects who the
270 // rest of the handlers the controller dispatches to are.
271 mController.registerEventHandler(HANDLER_KEY, this);
Michael Chan83b0fe32010-07-08 16:46:26 -0700272
Erik6c255102010-09-29 14:43:00 -0700273 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800274 mMiniMonth = findViewById(R.id.mini_month);
275 mCalendarsList = findViewById(R.id.calendar_list);
276 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700277 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700278
Erik7b92da22010-09-23 14:55:22 -0700279 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700280
281 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700282 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700283 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700284
Erik954c8712010-08-06 10:12:34 -0700285 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700286 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700287
Michael Chan2c7c8512010-12-10 14:12:57 -0800288 private long parseViewAction(final Intent intent) {
289 long timeMillis = -1;
290 Uri data = intent.getData();
291 if (data != null && data.isHierarchical()) {
292 List<String> path = data.getPathSegments();
293 if (path.size() == 2 && path.get(0).equals("events")) {
294 try {
295 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700296 if (mViewEventId != -1) {
Michael Chan2c7c8512010-12-10 14:12:57 -0800297 mIntentEventStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0);
298 mIntentEventEndMillis = intent.getLongExtra(EVENT_END_TIME, 0);
299 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800300 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800301 timeMillis = mIntentEventStartMillis;
302 }
303 } catch (NumberFormatException e) {
304 // Ignore if mViewEventId can't be parsed
305 }
306 }
307 }
308 return timeMillis;
309 }
310
Erikbe8191c2010-10-26 16:50:08 -0700311 private void configureActionBar() {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700312 if (mIsTabletConfig) {
313 createTabs();
314 } else {
315 createButtonsSpinner();
316 mActionBar.setCustomView(mDateRange);
317 }
318 }
319
320 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700321 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700322 if (mActionBar == null) {
323 Log.w(TAG, "ActionBar is null.");
324 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700325 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700326 mDayTab = mActionBar.newTab();
327 mDayTab.setText(getString(R.string.day_view));
328 mDayTab.setTabListener(this);
329 mActionBar.addTab(mDayTab);
330 mWeekTab = mActionBar.newTab();
331 mWeekTab.setText(getString(R.string.week_view));
332 mWeekTab.setTabListener(this);
333 mActionBar.addTab(mWeekTab);
334 mMonthTab = mActionBar.newTab();
335 mMonthTab.setText(getString(R.string.month_view));
336 mMonthTab.setTabListener(this);
337 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700338 mAgendaTab = mActionBar.newTab();
339 mAgendaTab.setText(getString(R.string.agenda_view));
340 mAgendaTab.setTabListener(this);
341 mActionBar.addTab(mAgendaTab);
Isaac Katzenelson0b1bd102011-04-07 14:26:29 -0700342 if (mIsMultipane) {
343 mActionBar.setDisplayOptions(
344 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700345 } else {
346 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
347 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700348 }
Erik954c8712010-08-06 10:12:34 -0700349 }
350
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700351 private void createButtonsSpinner() {
352 SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.buttons_list,
353 android.R.layout.simple_spinner_dropdown_item);
354 mActionBar = getActionBar();
355 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
356 mActionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_USE_LOGO|
357 ActionBar.DISPLAY_SHOW_TITLE);
358 mActionBar.setListNavigationCallbacks(mSpinnerAdapter, this);
359 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700360 // Clear buttons used in the agenda view
361 private void clearOptionsMenu() {
362 if (mOptionsMenu == null) {
363 return;
364 }
365 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
366 MenuItem deleteItem = mOptionsMenu.findItem(R.id.action_delete);
367 MenuItem editItem = mOptionsMenu.findItem(R.id.action_edit);
368 if (cancelItem != null) {
369 cancelItem.setVisible(false);
370 }
371 if (deleteItem != null) {
372 deleteItem.setVisible(false);
373 }
374 if (editItem != null) {
375 editItem.setVisible(false);
376 }
377 }
378
Erik954c8712010-08-06 10:12:34 -0700379 @Override
380 protected void onResume() {
381 super.onResume();
RoboErika7c03902011-06-14 11:06:44 -0700382 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI, true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700383 if (mUpdateOnResume) {
384 initFragments(mController.getTime(), mController.getViewType(), null);
385 mUpdateOnResume = false;
386 }
Erik6c255102010-09-29 14:43:00 -0700387 updateHomeClock();
RoboErik3b3af612011-02-24 13:42:57 -0800388 if (mControlsMenu != null) {
389 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
390 }
Erikcb811892010-09-28 13:44:19 -0700391 mPaused = false;
Michael Chan6191c122010-11-02 16:23:47 -0700392 mOnSaveInstanceStateCalled = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800393
394 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800395 long currentMillis = System.currentTimeMillis();
396 long selectedTime = -1;
397 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
398 selectedTime = currentMillis;
399 }
Michael Chanf0868f62011-01-11 19:37:35 -0800400 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700401 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
402 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800403 mViewEventId = -1;
404 mIntentEventStartMillis = -1;
405 mIntentEventEndMillis = -1;
406 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700407 }
408
409 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700410 protected void onPause() {
411 super.onPause();
Erikcb811892010-09-28 13:44:19 -0700412 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700413 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Erik954c8712010-08-06 10:12:34 -0700414 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700415 if (isFinishing()) {
416 // Stop listening for changes that would require this to be refreshed
417 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
418 prefs.unregisterOnSharedPreferenceChangeListener(this);
419 }
Erik7b92da22010-09-23 14:55:22 -0700420 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700421 if (mController.getViewType() != ViewType.EDIT) {
422 Utils.setDefaultView(this, mController.getViewType());
423 }
Michael Chand6734db2010-07-22 00:48:08 -0700424 }
425
426 @Override
Erik7b92da22010-09-23 14:55:22 -0700427 protected void onUserLeaveHint() {
428 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
429 super.onUserLeaveHint();
430 }
431
432 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700433 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700434 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700435 super.onSaveInstanceState(outState);
436
437 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700438 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800439 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700440 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
441 }
Michael Chand6734db2010-07-22 00:48:08 -0700442 }
443
444 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700445 protected void onDestroy() {
446 super.onDestroy();
447
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700448 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700449 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700450 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700451 }
452
Erik7b92da22010-09-23 14:55:22 -0700453 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
Dianne Hackborn12b33302011-01-17 12:30:13 -0800454 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700455
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700456 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800457 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700458 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700459 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700460
461 Fragment selectCalendarsFrag = new SelectCalendarsFragment();
462 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800463 mController.registerEventHandler(
464 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700465 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700466 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800467 mMiniMonth.setVisibility(View.GONE);
468 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700469 }
Michael Chan3458a172010-07-13 17:58:21 -0700470
Erikdd95df52010-08-27 09:31:18 -0700471 EventInfo info = null;
472 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700473 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700474 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700475
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700476 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700477 Intent intent = getIntent();
478 Uri data = intent.getData();
479 if (data != null) {
480 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700481 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700482 } catch (NumberFormatException e) {
483 if (DEBUG) {
484 Log.d(TAG, "Create new event");
485 }
486 }
Erik7b92da22010-09-23 14:55:22 -0700487 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
488 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700489 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700490
Erikdd95df52010-08-27 09:31:18 -0700491 long begin = intent.getLongExtra(EVENT_BEGIN_TIME, -1);
492 long end = intent.getLongExtra(EVENT_END_TIME, -1);
493 info = new EventInfo();
494 if (end != -1) {
495 info.endTime = new Time();
496 info.endTime.set(end);
497 }
498 if (begin != -1) {
499 info.startTime = new Time();
500 info.startTime.set(begin);
501 }
502 info.id = eventId;
503 // We set the viewtype so if the user presses back when they are
504 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700505 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700506 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700507 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700508 } else {
509 mPreviousView = viewType;
510 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700511
Erik63cd0532011-01-26 14:16:03 -0800512 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700513 ft.commit(); // this needs to be after setMainPane()
514
Erikc5f92d72010-11-11 16:18:34 -0800515 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700516 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700517 if (viewType != ViewType.EDIT) {
518 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
519 }
Michael Chan49701592010-06-30 11:04:03 -0700520 }
Erik2051f122010-07-02 13:45:45 -0700521
522 @Override
Erik648c59c2010-08-13 12:49:26 -0700523 public void onBackPressed() {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700524 if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) {
Erikdd95df52010-08-27 09:31:18 -0700525 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700526 } else {
527 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700528 }
529 }
530
531 @Override
Erik2051f122010-07-02 13:45:45 -0700532 public boolean onCreateOptionsMenu(Menu menu) {
533 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700534 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700535 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700536
Erikcb830312011-01-19 14:41:41 -0800537 mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
538 if (mSearchView != null) {
539 mSearchView.setIconifiedByDefault(true);
Adam Powell28f9b352011-01-20 18:36:10 -0800540 mSearchView.setOnQueryTextListener(this);
Erikcb830312011-01-19 14:41:41 -0800541 mSearchView.setSubmitButtonEnabled(true);
Michael Chan09b1b2e2011-04-05 11:24:32 -0700542 if (!mIsMultipane)
543 mSearchView.setVisibility(View.GONE);
Michael Chan71b221a2010-10-25 17:55:44 -0700544 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700545
546 // Hide the "show/hide controls" button if this is a phone
547 // or the view type is "Month".
548
RoboErikde20d762011-02-08 17:52:25 -0800549 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700550 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700551 if (mControlsMenu != null) {
552 mControlsMenu.setVisible(false);
553 mControlsMenu.setEnabled(false);
554 }
555 } else if (mControlsMenu != null && mController != null
556 && mController.getViewType() == ViewType.MONTH) {
RoboErikde20d762011-02-08 17:52:25 -0800557 mControlsMenu.setVisible(false);
558 mControlsMenu.setEnabled(false);
559 }
Erik2051f122010-07-02 13:45:45 -0700560 return true;
561 }
Michael Chan3458a172010-07-13 17:58:21 -0700562
563 @Override
564 public boolean onOptionsItemSelected(MenuItem item) {
565 Time t = null;
566 int viewType = ViewType.CURRENT;
567 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700568 case R.id.action_refresh:
569 mController.refreshCalendars();
570 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700571 case R.id.action_today:
572 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800573 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700574 t.setToNow();
575 break;
576 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800577 t = new Time();
578 t.set(mController.getTime());
579 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800580 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800581 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800582 } else {
583 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800584 }
585 mController.sendEventRelatedEvent(
586 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700587 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700588 case R.id.action_settings:
589 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
590 return true;
RoboErikde20d762011-02-08 17:52:25 -0800591 case R.id.action_hide_controls:
592 mHideControls = !mHideControls;
593 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800594 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
595 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
596 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
597 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
598 ObjectAnimator.setFrameDelay(0);
599 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800600 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700601 default:
602 return false;
603 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700604 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700605 return true;
606 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700607
RoboErikb8549562011-02-15 14:25:23 -0800608 /**
609 * Sets the offset of the controls on the right for animating them off/on
610 * screen. ProGuard strips this if it's not in proguard.flags
611 *
612 * @param controlsOffset The current offset in pixels
613 */
614 public void setControlsOffset(int controlsOffset) {
615 mMiniMonth.setTranslationX(controlsOffset);
616 mCalendarsList.setTranslationX(controlsOffset);
617 mHomeTime.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800618 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800619 mMiniMonthContainer.setLayoutParams(mControlsParams);
620 }
RoboErikde20d762011-02-08 17:52:25 -0800621
Mason Tang8e3d4302010-07-12 17:39:30 -0700622 @Override
623 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700624 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700625 if (mPaused) {
626 mUpdateOnResume = true;
627 } else {
628 initFragments(mController.getTime(), mController.getViewType(), null);
629 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700630 }
631 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700632
Erik63cd0532011-01-26 14:16:03 -0800633 private void setMainPane(
634 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700635 if (mOnSaveInstanceStateCalled) {
636 return;
637 }
Erik7b92da22010-09-23 14:55:22 -0700638 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700639 return;
640 }
641
Michael Chan5756bbc2011-03-02 18:22:07 -0800642 // Remove this when transition to and from month view looks fine.
643 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700644 FragmentManager fragmentManager = getFragmentManager();
645 // Check if our previous view was an Agenda view
646 // TODO remove this if framework ever supports nested fragments
647 if (mCurrentView == ViewType.AGENDA) {
648 // If it was, we need to do some cleanup on it to prevent the
649 // edit/delete buttons from coming back on a rotation.
650 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
651 if (oldFrag instanceof AgendaFragment) {
652 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
653 }
654 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800655
Erik648c59c2010-08-13 12:49:26 -0700656 if (viewType != mCurrentView) {
657 // The rules for this previous view are different than the
658 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700659 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
660 mPreviousView = mCurrentView;
661 }
Erik648c59c2010-08-13 12:49:26 -0700662 mCurrentView = viewType;
663 }
Erik3f348f32010-08-10 13:17:19 -0700664 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700665 Fragment frag = null;
666 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700667 switch (viewType) {
668 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700669 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
670 mActionBar.selectTab(mAgendaTab);
671 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700672 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700673 break;
674 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700675 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
676 mActionBar.selectTab(mDayTab);
677 }
Michael Chan75d9b562010-07-26 16:54:25 -0700678 frag = new DayFragment(timeMillis, 1);
679 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700680 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700681 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
682 mActionBar.selectTab(mWeekTab);
683 }
Michael Chan75d9b562010-07-26 16:54:25 -0700684 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700685 break;
686 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700687 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
688 mActionBar.selectTab(mMonthTab);
689 }
Erik40bcd102010-11-16 15:46:40 -0800690 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700691 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700692 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700693 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700694 break;
695 default:
Michael Chand6734db2010-07-22 00:48:08 -0700696 throw new IllegalArgumentException(
697 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700698 }
699
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700700 // Clear unnecessary buttons from the option menu when switching from the agenda view
701 if (viewType != ViewType.AGENDA) {
702 clearOptionsMenu();
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700703 if (mIsTabletConfig) {
704 mDateRange.setVisibility(View.VISIBLE);
705 }
706 } else {
707 if (mIsTabletConfig) {
708 mDateRange.setVisibility(View.GONE);
709 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700710 }
711
Michael Chanab29d9e2010-07-21 06:08:47 -0700712 boolean doCommit = false;
713 if (ft == null) {
714 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700715 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700716 }
717
Michael Chan5756bbc2011-03-02 18:22:07 -0800718 if (doTransition) {
719 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
720 }
721
Michael Chanab29d9e2010-07-21 06:08:47 -0700722 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700723 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700724
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700725 // Show/hide secondary fragment
726
727 if (secFrag != null) {
728 ft.replace(R.id.secondary_pane, secFrag);
729 mSecondaryPane.setVisibility(View.VISIBLE);
730 } else {
731 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700732 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700733 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700734 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700735 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700736 mController.deregisterEventHandler(R.id.secondary_pane);
737 }
738 }
Erik954c8712010-08-06 10:12:34 -0700739 if (DEBUG) {
740 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
741 }
Erik3f348f32010-08-10 13:17:19 -0700742 // If the key is already registered this will replace it
743 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700744 if (secFrag != null) {
745 mController.registerEventHandler(viewId, (EventHandler) secFrag);
746 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700747
748 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800749 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700750 ft.commit();
751 }
752 }
753
754 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800755 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700756 return;
757 }
758
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700759 final long start = event.startTime.toMillis(false /* use isDst */);
760 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700761 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700762 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700763 } else {
764 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700765 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700766
Erikeaafa2b2010-12-23 14:30:37 -0800767 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800768 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800769 mDateRange.setText(msg);
Erik259b8f92011-01-12 14:01:12 -0800770 if (!TextUtils.equals(oldDate, msg)) {
771 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
772 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700773 }
774
Erik6c255102010-09-29 14:43:00 -0700775 private void updateHomeClock() {
Erikc5f92d72010-11-11 16:18:34 -0800776 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
Erik6c255102010-09-29 14:43:00 -0700777 if (mIsMultipane && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK)
Erikc5f92d72010-11-11 16:18:34 -0800778 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
779 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700780 time.setToNow();
781 long millis = time.toMillis(true);
782 boolean isDST = time.isDst != 0;
783 int flags = DateUtils.FORMAT_SHOW_TIME;
784 if (DateFormat.is24HourFormat(this)) {
785 flags |= DateUtils.FORMAT_24HOUR;
786 }
787 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800788 String timeString = (new StringBuilder(
789 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
790 TimeZone.getTimeZone(mTimeZone).getDisplayName(
791 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700792 mHomeTime.setText(timeString);
793 mHomeTime.setVisibility(View.VISIBLE);
794 // Update when the minute changes
795 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700796 mHomeTimeUpdater,
797 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
Erik6c255102010-09-29 14:43:00 -0700798 } else {
799 mHomeTime.setVisibility(View.GONE);
800 }
801 }
802
Erik3f348f32010-08-10 13:17:19 -0700803 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700804 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800805 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700806 }
807
Erik3f348f32010-08-10 13:17:19 -0700808 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700809 public void handleEvent(EventInfo event) {
Michael Chane8f45c62011-03-01 14:41:03 -0800810 Log.d(TAG, "handleEvent AllInOne=" + this);
Michael Chanab29d9e2010-07-21 06:08:47 -0700811 if (event.eventType == EventType.GO_TO) {
Erik63cd0532011-01-26 14:16:03 -0800812 setMainPane(
813 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800814 if (mSearchView != null) {
815 mSearchView.clearFocus();
816 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700817
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700818 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700819 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700820 // hide minimonth and calendar frag
821 mShowSideViews = false;
822 if (mControlsMenu != null) {
823 mControlsMenu.setVisible(false);
824 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800825
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700826 if (!mHideControls) {
827 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
828 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
829 slideAnimation.addListener(mSlideAnimationDoneListener);
830 slideAnimation.setDuration(220);
831 ObjectAnimator.setFrameDelay(0);
832 slideAnimation.start();
833 }
834 } else {
835 mMiniMonth.setVisibility(View.GONE);
836 mCalendarsList.setVisibility(View.GONE);
837 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -0800838 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800839 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700840 // show minimonth and calendar frag
841 mShowSideViews = true;
842 mMiniMonth.setVisibility(View.VISIBLE);
843 mCalendarsList.setVisibility(View.VISIBLE);
844 mMiniMonthContainer.setVisibility(View.VISIBLE);
845 if (mControlsMenu != null) {
846 mControlsMenu.setVisible(true);
847 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700848 if (!mHideControls &&
849 (mController.getPreviousViewType() == ViewType.MONTH ||
850 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700851 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
852 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
853 slideAnimation.setDuration(220);
854 ObjectAnimator.setFrameDelay(0);
855 slideAnimation.start();
856 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800857 }
RoboErikde20d762011-02-08 17:52:25 -0800858 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700859 }
Michael Chan71d08832010-08-25 18:28:59 -0700860 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700861
862 // If in Agenda view and "show_event_details_with_agenda" is "true",
863 // do not create the event info fragment here, it will be created by the Agenda
864 // fragment
865
866 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
867 if (event.selectedTime != null) {
868 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
869 event.selectedTime, event.id, ViewType.AGENDA);
870 }
871 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700872 if (mShowEventInfoFullScreen) {
873 // start event info as activity
874 Intent intent = new Intent(Intent.ACTION_VIEW);
875 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
876 intent.setData(eventUri);
877 intent.setClassName(this, EventInfoActivity.class.getName());
878 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
879 Intent.FLAG_ACTIVITY_SINGLE_TOP);
880 intent.putExtra(EVENT_BEGIN_TIME, event.startTime.toMillis(false));
881 intent.putExtra(EVENT_END_TIME, event.endTime.toMillis(false));
882 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
883 startActivity(intent);
884 } else {
885 // start event info as a dialog
886 EventInfoFragment fragment = new EventInfoFragment(this,
887 event.id, event.startTime.toMillis(false),
888 event.endTime.toMillis(false), (int) event.extraLong, true);
889 // TODO Fix the temp hack below: && mCurrentView !=
890 // ViewType.AGENDA
891 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
892 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
893 event.selectedTime, -1, ViewType.DETAIL);
894 }
895 fragment.setDialogParams(event.x, event.y);
896 FragmentManager fm = getFragmentManager();
897 FragmentTransaction ft = fm.beginTransaction();
898 // if we have an old popup close it
899 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
900 if (fOld != null && fOld.isAdded()) {
901 ft.remove(fOld);
902 }
903 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
904 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700905 }
Erik63cd0532011-01-26 14:16:03 -0800906 }
Erikeaafa2b2010-12-23 14:30:37 -0800907 } else if (event.eventType == EventType.UPDATE_TITLE) {
908 setTitleInActionBar(event);
Michael Chanab29d9e2010-07-21 06:08:47 -0700909 }
Erik6c255102010-09-29 14:43:00 -0700910 updateHomeClock();
Michael Chanab29d9e2010-07-21 06:08:47 -0700911 }
912
Erik3f348f32010-08-10 13:17:19 -0700913 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700914 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -0700915 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -0700916 }
917
Erik3f348f32010-08-10 13:17:19 -0700918 @Override
Adam Powell28f9b352011-01-20 18:36:10 -0800919 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700920 return false;
921 }
922
923 @Override
Adam Powell28f9b352011-01-20 18:36:10 -0800924 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -0700925 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -0800926 Utils.tardis();
927 }
Erikcb830312011-01-19 14:41:41 -0800928 mSearchView.clearFocus();
Michael Chan46a8b112010-12-14 16:36:27 -0800929 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, -1, query,
Erik7b92da22010-09-23 14:55:22 -0700930 getComponentName());
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700931 return false;
932 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700933
934 @Override
935 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -0800936 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700937 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700938 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700939 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700940 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700941 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700942 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700943 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
944 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700945 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -0800946 Log.w(TAG, "TabSelected event from unknown tab: "
947 + (tab == null ? "null" : tab.getText()));
948 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700949 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700950 }
951 }
952
953 @Override
954 public void onTabReselected(Tab tab, FragmentTransaction ft) {
955 }
956
957 @Override
958 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
959 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700960
961
962 @Override
963 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
964 switch (itemPosition) {
965 case BUTTON_DAY_INDEX:
966 if (mCurrentView != ViewType.DAY) {
967 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
968 }
969 break;
970 case BUTTON_WEEK_INDEX:
971 if (mCurrentView != ViewType.WEEK) {
972 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
973 }
974 break;
975 case BUTTON_MONTH_INDEX:
976 if (mCurrentView != ViewType.MONTH) {
977 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
978 }
979 break;
980 case BUTTON_AGENDA_INDEX:
981 if (mCurrentView != ViewType.AGENDA) {
982 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
983 }
984 break;
985 default:
986 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
987 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
988 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
989 " Agenda:" + mAgendaTab);
990 break;
991 }
992 return false;
993 }
Michael Chan49701592010-06-30 11:04:03 -0700994}