blob: 9cbc0c6fc2df62e53211515c70cb119819033623 [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
RoboErik6c892a22011-09-08 16:54:04 -070024import android.accounts.AccountManager;
25import android.accounts.AccountManagerCallback;
26import android.accounts.AccountManagerFuture;
27import android.accounts.AuthenticatorException;
28import android.accounts.OperationCanceledException;
Michael Chan5756bbc2011-03-02 18:22:07 -080029import android.animation.Animator;
30import android.animation.Animator.AnimatorListener;
RoboErikd97f7982011-03-02 15:13:05 -080031import android.animation.ObjectAnimator;
Michael Chanab29d9e2010-07-21 06:08:47 -070032import android.app.ActionBar;
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -070033import android.app.ActionBar.Tab;
Michael Chan49701592010-06-30 11:04:03 -070034import android.app.Activity;
Michael Chan83b0fe32010-07-08 16:46:26 -070035import android.app.Fragment;
Erik63cd0532011-01-26 14:16:03 -080036import android.app.FragmentManager;
Michael Chan3458a172010-07-13 17:58:21 -070037import android.app.FragmentTransaction;
RoboErik6c892a22011-09-08 16:54:04 -070038import android.content.AsyncQueryHandler;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070039import android.content.BroadcastReceiver;
Erik954c8712010-08-06 10:12:34 -070040import android.content.ContentResolver;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070041import android.content.ContentUris;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070042import android.content.Context;
Erikdd95df52010-08-27 09:31:18 -070043import android.content.Intent;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070044import android.content.IntentFilter;
Mason Tang8e3d4302010-07-12 17:39:30 -070045import android.content.SharedPreferences;
46import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -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;
RoboErik6c892a22011-09-08 16:54:04 -070050import android.database.Cursor;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070051import android.graphics.drawable.LayerDrawable;
Erikdd95df52010-08-27 09:31:18 -070052import android.net.Uri;
Michael Chan49701592010-06-30 11:04:03 -070053import android.os.Bundle;
Erik954c8712010-08-06 10:12:34 -070054import android.os.Handler;
RoboErika7c03902011-06-14 11:06:44 -070055import android.provider.CalendarContract;
RoboErik6c892a22011-09-08 16:54:04 -070056import android.provider.CalendarContract.Calendars;
RoboErika7c03902011-06-14 11:06:44 -070057import android.provider.CalendarContract.Events;
Erik6c255102010-09-29 14:43:00 -070058import android.text.TextUtils;
59import android.text.format.DateFormat;
Michael Chan3458a172010-07-13 17:58:21 -070060import android.text.format.DateUtils;
Michael Chan83b0fe32010-07-08 16:46:26 -070061import android.text.format.Time;
Erik954c8712010-08-06 10:12:34 -070062import android.util.Log;
Erik2051f122010-07-02 13:45:45 -070063import android.view.Menu;
Michael Chan3458a172010-07-13 17:58:21 -070064import android.view.MenuItem;
Michael Chanab29d9e2010-07-21 06:08:47 -070065import android.view.View;
Erik259b8f92011-01-12 14:01:12 -080066import android.view.accessibility.AccessibilityEvent;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -070067import android.widget.LinearLayout;
RoboErikde20d762011-02-08 17:52:25 -080068import android.widget.RelativeLayout;
69import android.widget.RelativeLayout.LayoutParams;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -070070import android.widget.SearchView;
RoboErik17664072011-08-16 16:22:39 -070071import android.widget.SearchView.OnSuggestionListener;
Erik6c255102010-09-29 14:43:00 -070072import android.widget.TextView;
73
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070074import com.android.calendar.CalendarController.EventHandler;
75import com.android.calendar.CalendarController.EventInfo;
76import com.android.calendar.CalendarController.EventType;
77import com.android.calendar.CalendarController.ViewType;
78import com.android.calendar.agenda.AgendaFragment;
79import com.android.calendar.month.MonthByWeekFragment;
80import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
81
RoboErik6c892a22011-09-08 16:54:04 -070082import java.io.IOException;
Michael Chan2c7c8512010-12-10 14:12:57 -080083import java.util.List;
Erik6c255102010-09-29 14:43:00 -070084import java.util.Locale;
85import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070086
Michael Chanab29d9e2010-07-21 06:08:47 -070087public class AllInOneActivity extends Activity implements EventHandler,
RoboErike635aec2011-07-15 11:22:13 -070088 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener,
RoboErik17664072011-08-16 16:22:39 -070089 ActionBar.OnNavigationListener, OnSuggestionListener {
Michael Chand6734db2010-07-22 00:48:08 -070090 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070091 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080092 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070093 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070094 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080095 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
RoboErik6c892a22011-09-08 16:54:04 -070096 private static final String BUNDLE_KEY_CHECK_ACCOUNTS = "key_check_for_accounts";
Erik3f348f32010-08-10 13:17:19 -070097 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080098 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -080099
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700100 // Indices of buttons for the drop down menu (tabs replacement)
101 // Must match the strings in the array buttons_list in arrays.xml and the
102 // OnNavigationListener
103 private static final int BUTTON_DAY_INDEX = 0;
104 private static final int BUTTON_WEEK_INDEX = 1;
105 private static final int BUTTON_MONTH_INDEX = 2;
106 private static final int BUTTON_AGENDA_INDEX = 3;
107
RoboErikd69ccdf2011-08-05 14:50:27 -0700108 private CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -0700109 private static boolean mIsMultipane;
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700110 private static boolean mIsTabletConfig;
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700111 private static boolean mShowAgendaWithMonth;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700112 private static boolean mShowEventDetailsWithAgenda;
Michael Chan6191c122010-11-02 16:23:47 -0700113 private boolean mOnSaveInstanceStateCalled = false;
Michael Chanfb0ec222011-08-12 17:39:30 -0700114 private boolean mBackToPreviousView = false;
Erik954c8712010-08-06 10:12:34 -0700115 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700116 private int mPreviousView;
117 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700118 private boolean mPaused = true;
119 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800120 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800121 private boolean mShowSideViews = true;
RoboErik14e82b42011-07-19 09:46:39 -0700122 private boolean mShowWeekNum = false;
Erik6c255102010-09-29 14:43:00 -0700123 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800124 private TextView mDateRange;
RoboErik14e82b42011-07-19 09:46:39 -0700125 private TextView mWeekTextView;
RoboErikde20d762011-02-08 17:52:25 -0800126 private View mMiniMonth;
127 private View mCalendarsList;
128 private View mMiniMonthContainer;
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700129 private View mSecondaryPane;
Erikc5f92d72010-11-11 16:18:34 -0800130 private String mTimeZone;
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700131 private boolean mShowCalendarControls;
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700132 private boolean mShowEventInfoFullScreenAgenda;
Isaac Katzenelson998e66e2011-11-08 11:25:55 -0800133 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700134 private int mWeekNum;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700135 private int mCalendarControlsAnimationTime;
136 private int mControlsAnimateWidth;
137 private int mControlsAnimateHeight;
Erik6c255102010-09-29 14:43:00 -0700138
Michael Chan2c7c8512010-12-10 14:12:57 -0800139 private long mViewEventId = -1;
140 private long mIntentEventStartMillis = -1;
141 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800142 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800143
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700144 // Action bar and Navigation bar (left side of Action bar)
145 private ActionBar mActionBar;
146 private ActionBar.Tab mDayTab;
147 private ActionBar.Tab mWeekTab;
148 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700149 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800150 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700151 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800152 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700153 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700154 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErik6c892a22011-09-08 16:54:04 -0700155 private QueryHandler mHandler;
156 private boolean mCheckForAccounts = true;
RoboErikde20d762011-02-08 17:52:25 -0800157
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700158 private String mHideString;
159 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800160
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700161 DayOfMonthDrawable mDayOfMonthIcon;
162 Handler mMidnightUpdaterHandler;
163
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700164 int mOrientation;
Michael Chan5756bbc2011-03-02 18:22:07 -0800165
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700166 // Params for animating the controls on the right
167 private LayoutParams mControlsParams;
168 private LinearLayout.LayoutParams mVerticalControlsParams;
169
170 private final AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
Michael Chan5756bbc2011-03-02 18:22:07 -0800171
172 @Override
173 public void onAnimationCancel(Animator animation) {
174 }
175
176 @Override
177 public void onAnimationEnd(android.animation.Animator animation) {
178 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
179 mMiniMonth.setVisibility(visibility);
180 mCalendarsList.setVisibility(visibility);
181 mMiniMonthContainer.setVisibility(visibility);
182 }
183
184 @Override
185 public void onAnimationRepeat(android.animation.Animator animation) {
186 }
187
188 @Override
189 public void onAnimationStart(android.animation.Animator animation) {
190 }
191 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700192
RoboErik6c892a22011-09-08 16:54:04 -0700193 private class QueryHandler extends AsyncQueryHandler {
194 public QueryHandler(ContentResolver cr) {
195 super(cr);
196 }
197
198 @Override
199 protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
200 mCheckForAccounts = false;
201 // If the query didn't return a cursor for some reason return
202 if (cursor == null || cursor.getCount() > 0 || isFinishing()) {
203 return;
204 }
205 Bundle options = new Bundle();
206 options.putCharSequence("introMessage",
207 getResources().getString(R.string.create_an_account_desc));
208 options.putBoolean("allowSkip", true);
209
210 AccountManager am = AccountManager.get(AllInOneActivity.this);
211 am.addAccount("com.google", CalendarContract.AUTHORITY, null, options,
212 AllInOneActivity.this,
213 new AccountManagerCallback<Bundle>() {
214 @Override
215 public void run(AccountManagerFuture<Bundle> future) {
216 if (future.isCancelled()) {
217 return;
218 }
219 try {
220 Bundle result = future.getResult();
221 boolean setupSkipped = result.getBoolean("setupSkipped");
222
223 if (setupSkipped) {
224 Utils.setSharedPreference(AllInOneActivity.this,
225 GeneralPreferences.KEY_SKIP_SETUP, true);
226 }
227
228 } catch (OperationCanceledException ignore) {
229 // The account creation process was canceled
230 } catch (IOException ignore) {
231 } catch (AuthenticatorException ignore) {
232 }
233 }
234 }, null);
235 }
236 }
237
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700238 private final Runnable mHomeTimeUpdater = new Runnable() {
Erik6c255102010-09-29 14:43:00 -0700239 @Override
240 public void run() {
RoboErik4eb34322011-08-19 15:47:51 -0700241 updateSecondaryTitleFields(-1);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700242 AllInOneActivity.this.invalidateOptionsMenu();
Erik6c255102010-09-29 14:43:00 -0700243 }
244 };
Erik954c8712010-08-06 10:12:34 -0700245
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700246 // runs every midnight and refreshes the today icon
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700247 private final Runnable mMidnightUpdater = new Runnable() {
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700248 @Override
249 public void run() {
250 AllInOneActivity.this.invalidateOptionsMenu();
251 }
252 };
253
254
Erik954c8712010-08-06 10:12:34 -0700255 // Create an observer so that we can update the views whenever a
256 // Calendar event changes.
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700257 private final ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700258 @Override
259 public boolean deliverSelfNotifications() {
260 return true;
261 }
262
263 @Override
264 public void onChange(boolean selfChange) {
265 eventsChanged();
266 }
267 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700268
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700269 private class CalendarBroadcastReceiver extends BroadcastReceiver {
270
271 @Override
272 public void onReceive(Context context, Intent intent) {
273 if (intent.getAction().equals(Intent.ACTION_DATE_CHANGED) ||
274 intent.getAction().equals(Intent.ACTION_TIME_CHANGED) ||
275 intent.getAction().equals(Intent.ACTION_LOCALE_CHANGED) ||
276 intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
277 // Update the day of month in the today button by invalidating
278 // the option menu thus forcing it to redraw and update the day of month
279 Utils.setMidnightUpdater(mHandler, mMidnightUpdater, mTimeZone);
280 AllInOneActivity.this.invalidateOptionsMenu();
281 }
282 }
283 }
284
285 CalendarBroadcastReceiver mCalIntentReceiver;
286
Michael Chan49701592010-06-30 11:04:03 -0700287 @Override
Erik63cd0532011-01-26 14:16:03 -0800288 protected void onNewIntent(Intent intent) {
289 String action = intent.getAction();
RoboErik4ba19df2011-09-22 11:31:21 -0700290 if (DEBUG)
291 Log.d(TAG, "New intent received " + intent.toString());
292 // Don't change the date if we're just returning to the app's home
293 if (Intent.ACTION_VIEW.equals(action)
294 && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
RoboErik2c2dab42011-09-09 15:50:26 -0700295 long millis = parseViewAction(intent);
296 if (millis == -1) {
297 millis = Utils.timeFromIntentInMillis(intent);
298 }
299 if (millis != -1 && mViewEventId == -1 && mController != null) {
300 Time time = new Time(mTimeZone);
301 time.set(millis);
302 time.normalize(true);
303 mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
304 }
Erik63cd0532011-01-26 14:16:03 -0800305 }
306 }
307
308 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700309 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800310 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
311 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
312 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700313 super.onCreate(icicle);
314
RoboErik6c892a22011-09-08 16:54:04 -0700315 if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
316 mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
317 }
318 // Launch add google account if this is first time and there are no
319 // accounts yet
320 if (mCheckForAccounts
321 && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) {
322
323 mHandler = new QueryHandler(this.getContentResolver());
324 mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] {
325 Calendars._ID
326 }, null, null /* selection args */, null /* sort order */);
327 }
328
Michael Chan83b0fe32010-07-08 16:46:26 -0700329 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700330 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700331
332
Erik954c8712010-08-06 10:12:34 -0700333 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800334 long timeMillis = -1;
335 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800336 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700337 if (icicle != null) {
338 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800339 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700340 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800341 String action = intent.getAction();
342 if (Intent.ACTION_VIEW.equals(action)) {
343 // Open EventInfo later
344 timeMillis = parseViewAction(intent);
345 }
346
347 if (timeMillis == -1) {
348 timeMillis = Utils.timeFromIntentInMillis(intent);
349 }
350 }
351
RoboErik277eb972011-02-24 16:05:04 -0800352 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700353 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
354 }
Erikc5f92d72010-11-11 16:18:34 -0800355 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
356 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700357 t.set(timeMillis);
358
RoboErik8e62ac32011-09-09 10:13:07 -0700359 if (DEBUG) {
360 if (icicle != null && intent != null) {
361 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
362 } else {
363 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
364 }
Erik7b92da22010-09-23 14:55:22 -0700365 }
366
Erikeaafa2b2010-12-23 14:30:37 -0800367 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800368 mHideString = res.getString(R.string.hide_controls);
369 mShowString = res.getString(R.string.show_controls);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700370 mOrientation = res.getConfiguration().orientation;
371 if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
Isaac Katzenelsone0b4b272012-04-12 16:00:53 -0700372 mControlsAnimateWidth = (int)res.getDimension(R.dimen.calendar_controls_width);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700373 if (mControlsParams == null) {
374 mControlsParams = new LayoutParams(mControlsAnimateWidth, 0);
375 }
376 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Isaac Katzenelsone0b4b272012-04-12 16:00:53 -0700377 } else {
378 // Make sure width is in between allowed min and max width values
379 mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100,
380 (int)res.getDimension(R.dimen.min_portrait_calendar_controls_width));
381 mControlsAnimateWidth = Math.min(mControlsAnimateWidth,
382 (int)res.getDimension(R.dimen.max_portrait_calendar_controls_width));
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700383 }
384
385 mControlsAnimateHeight = (int)res.getDimension(R.dimen.calendar_controls_height);
RoboErikb8549562011-02-15 14:25:23 -0800386
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700387 mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700388 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700389 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700390 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700391 mShowEventDetailsWithAgenda =
392 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700393 mShowEventInfoFullScreenAgenda =
394 Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen);
Isaac Katzenelson998e66e2011-11-08 11:25:55 -0800395 mShowEventInfoFullScreen =
396 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700397 mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time);
Erik63cd0532011-01-26 14:16:03 -0800398 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800399
Erikbe8191c2010-10-26 16:50:08 -0700400 // setContentView must be called before configureActionBar
401 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700402
403 if (mIsTabletConfig) {
404 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700405 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700406 } else {
407 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
408 }
409
Erikbe8191c2010-10-26 16:50:08 -0700410 // configureActionBar auto-selects the first tab you add, so we need to
411 // call it before we set up our own fragments to make sure it doesn't
412 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700413 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700414
Erik6c255102010-09-29 14:43:00 -0700415 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800416 mMiniMonth = findViewById(R.id.mini_month);
Isaac Katzenelsone0b4b272012-04-12 16:00:53 -0700417 if (mOrientation == Configuration.ORIENTATION_PORTRAIT) {
418 mMiniMonth.setLayoutParams(new LinearLayout.LayoutParams(mControlsAnimateWidth,
419 mControlsAnimateHeight));
420 }
RoboErikde20d762011-02-08 17:52:25 -0800421 mCalendarsList = findViewById(R.id.calendar_list);
422 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700423 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700424
RoboErik3864be02011-07-25 15:56:50 -0700425 // Must register as the first activity because this activity can modify
426 // the list of event handlers in it's handle method. This affects who
427 // the rest of the handlers the controller dispatches to are.
428 mController.registerFirstEventHandler(HANDLER_KEY, this);
429
Erik7b92da22010-09-23 14:55:22 -0700430 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700431
432 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700433 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700434 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700435
Erik954c8712010-08-06 10:12:34 -0700436 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700437 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700438
Michael Chan2c7c8512010-12-10 14:12:57 -0800439 private long parseViewAction(final Intent intent) {
440 long timeMillis = -1;
441 Uri data = intent.getData();
442 if (data != null && data.isHierarchical()) {
443 List<String> path = data.getPathSegments();
444 if (path.size() == 2 && path.get(0).equals("events")) {
445 try {
446 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700447 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700448 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
449 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800450 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800451 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800452 timeMillis = mIntentEventStartMillis;
453 }
454 } catch (NumberFormatException e) {
455 // Ignore if mViewEventId can't be parsed
456 }
457 }
458 }
459 return timeMillis;
460 }
461
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700462 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700463 if (mIsTabletConfig) {
464 createTabs();
465 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700466 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700467 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700468 if (mIsMultipane) {
469 mActionBar.setDisplayOptions(
470 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
471 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700472 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700473 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700474 }
475
476 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700477 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700478 if (mActionBar == null) {
479 Log.w(TAG, "ActionBar is null.");
480 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700481 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700482 mDayTab = mActionBar.newTab();
483 mDayTab.setText(getString(R.string.day_view));
484 mDayTab.setTabListener(this);
485 mActionBar.addTab(mDayTab);
486 mWeekTab = mActionBar.newTab();
487 mWeekTab.setText(getString(R.string.week_view));
488 mWeekTab.setTabListener(this);
489 mActionBar.addTab(mWeekTab);
490 mMonthTab = mActionBar.newTab();
491 mMonthTab.setText(getString(R.string.month_view));
492 mMonthTab.setTabListener(this);
493 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700494 mAgendaTab = mActionBar.newTab();
495 mAgendaTab.setText(getString(R.string.agenda_view));
496 mAgendaTab.setTabListener(this);
497 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700498 }
Erik954c8712010-08-06 10:12:34 -0700499 }
500
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700501 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700502 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700503 mActionBar = getActionBar();
504 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700505 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700506 switch (viewType) {
507 case ViewType.AGENDA:
508 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
509 break;
510 case ViewType.DAY:
511 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
512 break;
513 case ViewType.WEEK:
514 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
515 break;
516 case ViewType.MONTH:
517 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
518 break;
519 default:
520 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
521 break;
522 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700523 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700524 // Clear buttons used in the agenda view
525 private void clearOptionsMenu() {
526 if (mOptionsMenu == null) {
527 return;
528 }
529 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700530 if (cancelItem != null) {
531 cancelItem.setVisible(false);
532 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700533 }
534
Erik954c8712010-08-06 10:12:34 -0700535 @Override
536 protected void onResume() {
537 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700538
539 // Must register as the first activity because this activity can modify
540 // the list of event handlers in it's handle method. This affects who
541 // the rest of the handlers the controller dispatches to are.
542 mController.registerFirstEventHandler(HANDLER_KEY, this);
543
Michael Chanf2cfa202011-08-19 17:58:16 -0700544 mOnSaveInstanceStateCalled = false;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700545 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
546 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700547 if (mUpdateOnResume) {
548 initFragments(mController.getTime(), mController.getViewType(), null);
549 mUpdateOnResume = false;
550 }
RoboErikc8e0f212011-10-13 17:57:39 -0700551 Time t = new Time(mTimeZone);
552 t.set(mController.getTime());
553 mController.sendEvent(this, EventType.UPDATE_TITLE, t, t, -1, ViewType.CURRENT,
554 mController.getDateFlags(), null, null);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700555 // Make sure the drop-down menu will get its date updated at midnight
556 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700557 mActionBarMenuSpinnerAdapter.refresh(this);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700558 }
559
RoboErik3b3af612011-02-24 13:42:57 -0800560 if (mControlsMenu != null) {
561 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
562 }
Erikcb811892010-09-28 13:44:19 -0700563 mPaused = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800564
565 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800566 long currentMillis = System.currentTimeMillis();
567 long selectedTime = -1;
568 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
569 selectedTime = currentMillis;
570 }
Michael Chanedecd9a2011-08-24 23:58:48 -0700571 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700572 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
573 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800574 mViewEventId = -1;
575 mIntentEventStartMillis = -1;
576 mIntentEventEndMillis = -1;
577 }
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700578 if (mMidnightUpdaterHandler == null) {
579 mMidnightUpdaterHandler = new Handler();
580 }
581 Utils.setMidnightUpdater(mHandler, mMidnightUpdater, mTimeZone);
582 // Make sure the today icon is up to date
583 invalidateOptionsMenu();
584
585 // Register for Intent broadcasts
586 IntentFilter filter = new IntentFilter();
587 filter.addAction(Intent.ACTION_TIME_CHANGED);
588 filter.addAction(Intent.ACTION_DATE_CHANGED);
589 filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
590 filter.addAction(Intent.ACTION_LOCALE_CHANGED);
591 if (mCalIntentReceiver == null) {
592 mCalIntentReceiver = new CalendarBroadcastReceiver();
593 }
594 registerReceiver(mCalIntentReceiver, filter);
Mason Tang8e3d4302010-07-12 17:39:30 -0700595 }
596
597 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700598 protected void onPause() {
599 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700600
601 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700602 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700603 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700604 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700605 mActionBarMenuSpinnerAdapter.onPause();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700606 }
Erik954c8712010-08-06 10:12:34 -0700607 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700608 if (isFinishing()) {
609 // Stop listening for changes that would require this to be refreshed
610 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
611 prefs.unregisterOnSharedPreferenceChangeListener(this);
612 }
Erik7b92da22010-09-23 14:55:22 -0700613 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700614 if (mController.getViewType() != ViewType.EDIT) {
615 Utils.setDefaultView(this, mController.getViewType());
616 }
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700617 Utils.resetMidnightUpdater(mHandler, mMidnightUpdater);
618 unregisterReceiver(mCalIntentReceiver);
Michael Chand6734db2010-07-22 00:48:08 -0700619 }
620
621 @Override
Erik7b92da22010-09-23 14:55:22 -0700622 protected void onUserLeaveHint() {
623 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
624 super.onUserLeaveHint();
625 }
626
627 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700628 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700629 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700630 super.onSaveInstanceState(outState);
631
632 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
RoboErik24c479e2011-11-14 10:32:58 -0800633 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700634 if (mCurrentView == ViewType.EDIT) {
Erik7b92da22010-09-23 14:55:22 -0700635 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
636 }
RoboErik6c892a22011-09-08 16:54:04 -0700637 outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts);
Michael Chand6734db2010-07-22 00:48:08 -0700638 }
639
640 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700641 protected void onDestroy() {
642 super.onDestroy();
643
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700644 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700645 prefs.unregisterOnSharedPreferenceChangeListener(this);
Paul Westbrook89af1892011-10-05 18:15:00 -0700646
Paul Westbrook61310b72011-10-07 15:43:00 -0700647 mController.deregisterAllEventHandlers();
Paul Westbrook89af1892011-10-05 18:15:00 -0700648
Eriked61b482010-08-13 13:59:50 -0700649 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700650 }
651
Erik7b92da22010-09-23 14:55:22 -0700652 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700653 if (DEBUG) {
654 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
655 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800656 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700657
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700658 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800659 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700660 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700661 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700662
Michael Chan2aeb8d92011-07-10 13:32:09 -0700663 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700664 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800665 mController.registerEventHandler(
666 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700667 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700668 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800669 mMiniMonth.setVisibility(View.GONE);
670 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700671 }
Michael Chan3458a172010-07-13 17:58:21 -0700672
Erikdd95df52010-08-27 09:31:18 -0700673 EventInfo info = null;
674 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700675 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700676 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700677
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700678 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700679 Intent intent = getIntent();
680 Uri data = intent.getData();
681 if (data != null) {
682 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700683 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700684 } catch (NumberFormatException e) {
685 if (DEBUG) {
686 Log.d(TAG, "Create new event");
687 }
688 }
Erik7b92da22010-09-23 14:55:22 -0700689 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
690 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700691 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700692
RoboErika27a8862011-06-23 15:26:23 -0700693 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
694 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700695 info = new EventInfo();
696 if (end != -1) {
697 info.endTime = new Time();
698 info.endTime.set(end);
699 }
700 if (begin != -1) {
701 info.startTime = new Time();
702 info.startTime.set(begin);
703 }
704 info.id = eventId;
705 // We set the viewtype so if the user presses back when they are
706 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700707 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700708 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700709 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700710 } else {
711 mPreviousView = viewType;
712 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700713
Erik63cd0532011-01-26 14:16:03 -0800714 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700715 ft.commit(); // this needs to be after setMainPane()
716
Erikc5f92d72010-11-11 16:18:34 -0800717 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700718 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700719 if (viewType != ViewType.EDIT) {
720 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
721 }
Michael Chan49701592010-06-30 11:04:03 -0700722 }
Erik2051f122010-07-02 13:45:45 -0700723
724 @Override
Erik648c59c2010-08-13 12:49:26 -0700725 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700726 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700727 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700728 } else {
729 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700730 }
731 }
732
733 @Override
Erik2051f122010-07-02 13:45:45 -0700734 public boolean onCreateOptionsMenu(Menu menu) {
735 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700736 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700737 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700738
RoboErike635aec2011-07-15 11:22:13 -0700739 mSearchMenu = menu.findItem(R.id.action_search);
740 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800741 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700742 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800743 mSearchView.setOnQueryTextListener(this);
RoboErik17664072011-08-16 16:22:39 -0700744 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700745 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700746
747 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700748 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700749
RoboErikde20d762011-02-08 17:52:25 -0800750 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700751 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700752 if (mControlsMenu != null) {
753 mControlsMenu.setVisible(false);
754 mControlsMenu.setEnabled(false);
755 }
756 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700757 && (mController.getViewType() == ViewType.MONTH ||
758 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800759 mControlsMenu.setVisible(false);
760 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700761 } else if (mControlsMenu != null){
762 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800763 }
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700764
765 // replace the default top layer drawable of the today icon with a custom drawable
766 // that shows the day of the month of today
767 LayerDrawable icon = (LayerDrawable)menu.findItem(R.id.action_today).getIcon();
768 setTodayIcon();
769 icon.mutate();
770 icon.setDrawableByLayerId(R.id.today_icon_day, mDayOfMonthIcon);
Erik2051f122010-07-02 13:45:45 -0700771 return true;
772 }
Michael Chan3458a172010-07-13 17:58:21 -0700773
774 @Override
775 public boolean onOptionsItemSelected(MenuItem item) {
776 Time t = null;
777 int viewType = ViewType.CURRENT;
RoboErik5b872522011-10-03 17:24:50 -0700778 long extras = CalendarController.EXTRA_GOTO_TIME;
Michael Chan3458a172010-07-13 17:58:21 -0700779 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700780 case R.id.action_refresh:
781 mController.refreshCalendars();
782 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700783 case R.id.action_today:
784 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800785 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700786 t.setToNow();
RoboErik5b872522011-10-03 17:24:50 -0700787 extras |= CalendarController.EXTRA_GOTO_TODAY;
Michael Chan3458a172010-07-13 17:58:21 -0700788 break;
789 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800790 t = new Time();
791 t.set(mController.getTime());
Isaac Katzenelson576521e2011-10-12 16:19:40 -0700792 if (t.minute > 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800793 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800794 t.minute = 0;
Isaac Katzenelson576521e2011-10-12 16:19:40 -0700795 } else if (t.minute > 0 && t.minute < 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800796 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800797 }
798 mController.sendEventRelatedEvent(
799 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700800 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700801 case R.id.action_select_visible_calendars:
802 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
803 0, 0);
804 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700805 case R.id.action_settings:
806 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
807 return true;
RoboErikde20d762011-02-08 17:52:25 -0800808 case R.id.action_hide_controls:
809 mHideControls = !mHideControls;
810 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800811 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700812 mHideControls ? 0 : mControlsAnimateWidth,
813 mHideControls ? mControlsAnimateWidth : 0);
814 slideAnimation.setDuration(mCalendarControlsAnimationTime);
RoboErikb8549562011-02-15 14:25:23 -0800815 ObjectAnimator.setFrameDelay(0);
816 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800817 return true;
RoboErike635aec2011-07-15 11:22:13 -0700818 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700819 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700820 default:
821 return false;
822 }
RoboErik5b872522011-10-03 17:24:50 -0700823 mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
Michael Chan3458a172010-07-13 17:58:21 -0700824 return true;
825 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700826
RoboErikb8549562011-02-15 14:25:23 -0800827 /**
828 * Sets the offset of the controls on the right for animating them off/on
829 * screen. ProGuard strips this if it's not in proguard.flags
830 *
831 * @param controlsOffset The current offset in pixels
832 */
833 public void setControlsOffset(int controlsOffset) {
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700834 if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
835 mMiniMonth.setTranslationX(controlsOffset);
836 mCalendarsList.setTranslationX(controlsOffset);
837 mControlsParams.width = Math.max(0, mControlsAnimateWidth - controlsOffset);
838 mMiniMonthContainer.setLayoutParams(mControlsParams);
839 } else {
840 mMiniMonth.setTranslationY(controlsOffset);
841 mCalendarsList.setTranslationY(controlsOffset);
842 if (mVerticalControlsParams == null) {
843 mVerticalControlsParams = new LinearLayout.LayoutParams(
844 LinearLayout.LayoutParams.MATCH_PARENT, mControlsAnimateHeight);
845 }
846 mVerticalControlsParams.height = Math.max(0, mControlsAnimateHeight - controlsOffset);
847 mMiniMonthContainer.setLayoutParams(mVerticalControlsParams);
848 }
RoboErikb8549562011-02-15 14:25:23 -0800849 }
RoboErikde20d762011-02-08 17:52:25 -0800850
Mason Tang8e3d4302010-07-12 17:39:30 -0700851 @Override
852 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700853 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700854 if (mPaused) {
855 mUpdateOnResume = true;
856 } else {
857 initFragments(mController.getTime(), mController.getViewType(), null);
858 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700859 }
860 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700861
Erik63cd0532011-01-26 14:16:03 -0800862 private void setMainPane(
863 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700864 if (mOnSaveInstanceStateCalled) {
865 return;
866 }
Erik7b92da22010-09-23 14:55:22 -0700867 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700868 return;
869 }
870
Michael Chan5756bbc2011-03-02 18:22:07 -0800871 // Remove this when transition to and from month view looks fine.
872 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700873 FragmentManager fragmentManager = getFragmentManager();
874 // Check if our previous view was an Agenda view
875 // TODO remove this if framework ever supports nested fragments
876 if (mCurrentView == ViewType.AGENDA) {
877 // If it was, we need to do some cleanup on it to prevent the
878 // edit/delete buttons from coming back on a rotation.
879 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
880 if (oldFrag instanceof AgendaFragment) {
881 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
882 }
883 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800884
Erik648c59c2010-08-13 12:49:26 -0700885 if (viewType != mCurrentView) {
886 // The rules for this previous view are different than the
887 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700888 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
889 mPreviousView = mCurrentView;
890 }
Erik648c59c2010-08-13 12:49:26 -0700891 mCurrentView = viewType;
892 }
Erik3f348f32010-08-10 13:17:19 -0700893 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700894 Fragment frag = null;
895 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700896 switch (viewType) {
897 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700898 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
899 mActionBar.selectTab(mAgendaTab);
900 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700901 if (mActionBarMenuSpinnerAdapter != null) {
902 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
903 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700904 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700905 break;
906 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700907 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
908 mActionBar.selectTab(mDayTab);
909 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700910 if (mActionBarMenuSpinnerAdapter != null) {
911 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
912 }
Michael Chan75d9b562010-07-26 16:54:25 -0700913 frag = new DayFragment(timeMillis, 1);
914 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700915 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700916 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
917 mActionBar.selectTab(mWeekTab);
918 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700919 if (mActionBarMenuSpinnerAdapter != null) {
920 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
921 }
Michael Chan75d9b562010-07-26 16:54:25 -0700922 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700923 break;
924 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700925 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
926 mActionBar.selectTab(mMonthTab);
927 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700928 if (mActionBarMenuSpinnerAdapter != null) {
929 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
930 }
Erik40bcd102010-11-16 15:46:40 -0800931 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700932 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700933 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700934 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700935 break;
936 default:
Michael Chand6734db2010-07-22 00:48:08 -0700937 throw new IllegalArgumentException(
938 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700939 }
940
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700941 // Update the current view so that the menu can update its look according to the
942 // current view.
943 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
RoboErike11975f2011-09-02 14:00:39 -0700944 mActionBarMenuSpinnerAdapter.setTime(timeMillis);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700945 mActionBarMenuSpinnerAdapter.setMainView(viewType);
946 }
947
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700948
949 // Show date only on tablet configurations in views different than Agenda
950 if (!mIsTabletConfig) {
951 mDateRange.setVisibility(View.GONE);
952 } else if (viewType != ViewType.AGENDA) {
953 mDateRange.setVisibility(View.VISIBLE);
954 } else {
955 mDateRange.setVisibility(View.GONE);
956 }
957
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700958 // Clear unnecessary buttons from the option menu when switching from the agenda view
959 if (viewType != ViewType.AGENDA) {
960 clearOptionsMenu();
961 }
962
Michael Chanab29d9e2010-07-21 06:08:47 -0700963 boolean doCommit = false;
964 if (ft == null) {
965 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700966 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700967 }
968
Michael Chan5756bbc2011-03-02 18:22:07 -0800969 if (doTransition) {
970 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
971 }
972
Michael Chanab29d9e2010-07-21 06:08:47 -0700973 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700974 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700975
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700976 // Show/hide secondary fragment
977
978 if (secFrag != null) {
979 ft.replace(R.id.secondary_pane, secFrag);
980 mSecondaryPane.setVisibility(View.VISIBLE);
981 } else {
982 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700983 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700984 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700985 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700986 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700987 mController.deregisterEventHandler(R.id.secondary_pane);
988 }
989 }
Erik954c8712010-08-06 10:12:34 -0700990 if (DEBUG) {
991 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
992 }
Erik3f348f32010-08-10 13:17:19 -0700993 // If the key is already registered this will replace it
994 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700995 if (secFrag != null) {
996 mController.registerEventHandler(viewId, (EventHandler) secFrag);
997 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700998
999 if (doCommit) {
RoboErik8e62ac32011-09-09 10:13:07 -07001000 if (DEBUG) {
1001 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
1002 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001003 ft.commit();
1004 }
1005 }
1006
1007 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -08001008 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -07001009 return;
1010 }
1011
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001012 final long start = event.startTime.toMillis(false /* use isDst */);
1013 final long end;
Michael Chand6734db2010-07-22 00:48:08 -07001014 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -07001015 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001016 } else {
1017 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -07001018 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001019
Erikeaafa2b2010-12-23 14:30:37 -08001020 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -08001021 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -08001022 mDateRange.setText(msg);
RoboErik8e62ac32011-09-09 10:13:07 -07001023 updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true)
1024 : start);
Erik259b8f92011-01-12 14:01:12 -08001025 if (!TextUtils.equals(oldDate, msg)) {
1026 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -07001027 if (mShowWeekNum && mWeekTextView != null) {
1028 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
1029 }
Erik259b8f92011-01-12 14:01:12 -08001030 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001031 }
1032
RoboErik4eb34322011-08-19 15:47:51 -07001033 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
RoboErik14e82b42011-07-19 09:46:39 -07001034 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -08001035 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -07001036 if (visibleMillisSinceEpoch != -1) {
1037 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
1038 mWeekNum = weekNum;
1039 }
1040
1041 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
1042 && mWeekTextView != null) {
1043 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
1044 mWeekNum);
1045 mWeekTextView.setText(weekString);
1046 mWeekTextView.setVisibility(View.VISIBLE);
RoboErik4eb34322011-08-19 15:47:51 -07001047 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null
1048 && mCurrentView == ViewType.DAY && mIsTabletConfig) {
1049 Time time = new Time(mTimeZone);
1050 time.set(visibleMillisSinceEpoch);
1051 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
1052 time.setToNow();
1053 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
1054 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay,
1055 visibleMillisSinceEpoch, this);
1056 mWeekTextView.setText(dayString);
1057 mWeekTextView.setVisibility(View.VISIBLE);
1058 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
RoboErik14e82b42011-07-19 09:46:39 -07001059 mWeekTextView.setVisibility(View.GONE);
1060 }
Michael Chanbe686752011-08-23 15:53:35 -07001061
RoboErik14e82b42011-07-19 09:46:39 -07001062 if (mHomeTime != null
1063 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
1064 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -08001065 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
1066 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -07001067 time.setToNow();
1068 long millis = time.toMillis(true);
1069 boolean isDST = time.isDst != 0;
1070 int flags = DateUtils.FORMAT_SHOW_TIME;
1071 if (DateFormat.is24HourFormat(this)) {
1072 flags |= DateUtils.FORMAT_24HOUR;
1073 }
1074 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -08001075 String timeString = (new StringBuilder(
1076 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
1077 TimeZone.getTimeZone(mTimeZone).getDisplayName(
1078 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -07001079 mHomeTime.setText(timeString);
1080 mHomeTime.setVisibility(View.VISIBLE);
1081 // Update when the minute changes
Michael Chan5d740e12011-11-16 16:51:10 -08001082 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Erik6c255102010-09-29 14:43:00 -07001083 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -07001084 mHomeTimeUpdater,
1085 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -07001086 } else if (mHomeTime != null) {
1087 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -07001088 }
1089 }
1090
Erik3f348f32010-08-10 13:17:19 -07001091 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001092 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -08001093 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -07001094 }
1095
Erik3f348f32010-08-10 13:17:19 -07001096 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001097 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -07001098 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -07001099 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -07001100 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
1101 mBackToPreviousView = true;
1102 } else if (event.viewType != mController.getPreviousViewType()
1103 && event.viewType != ViewType.EDIT) {
1104 // Clear the flag is change to a different view type
1105 mBackToPreviousView = false;
1106 }
1107
Erik63cd0532011-01-26 14:16:03 -08001108 setMainPane(
1109 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -08001110 if (mSearchView != null) {
1111 mSearchView.clearFocus();
1112 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001113
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001114 if (mShowCalendarControls) {
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001115 int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ?
1116 mControlsAnimateWidth : mControlsAnimateHeight;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001117 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001118 // hide minimonth and calendar frag
1119 mShowSideViews = false;
1120 if (mControlsMenu != null) {
1121 mControlsMenu.setVisible(false);
1122 mControlsMenu.setEnabled(false);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001123 }
1124 if (!mHideControls) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001125 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001126 "controlsOffset", 0, animationSize);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001127 slideAnimation.addListener(mSlideAnimationDoneListener);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001128 slideAnimation.setDuration(mCalendarControlsAnimationTime);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001129 ObjectAnimator.setFrameDelay(0);
1130 slideAnimation.start();
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001131 } else {
1132 mMiniMonth.setVisibility(View.GONE);
1133 mCalendarsList.setVisibility(View.GONE);
1134 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -08001135 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001136 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001137 // show minimonth and calendar frag
1138 mShowSideViews = true;
1139 mMiniMonth.setVisibility(View.VISIBLE);
1140 mCalendarsList.setVisibility(View.VISIBLE);
1141 mMiniMonthContainer.setVisibility(View.VISIBLE);
1142 if (mControlsMenu != null) {
1143 mControlsMenu.setVisible(true);
1144 mControlsMenu.setEnabled(true);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001145 }
1146 if (!mHideControls &&
1147 (mController.getPreviousViewType() == ViewType.MONTH ||
1148 mController.getPreviousViewType() == ViewType.AGENDA)) {
1149 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1150 "controlsOffset", animationSize, 0);
1151 slideAnimation.setDuration(mCalendarControlsAnimationTime);
1152 ObjectAnimator.setFrameDelay(0);
1153 slideAnimation.start();
Michael Chan5756bbc2011-03-02 18:22:07 -08001154 }
RoboErikde20d762011-02-08 17:52:25 -08001155 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001156 }
RoboErik8e62ac32011-09-09 10:13:07 -07001157 displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
1158 : event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -07001159 if (!mIsTabletConfig) {
1160 mActionBarMenuSpinnerAdapter.setTime(displayTime);
1161 }
Michael Chan71d08832010-08-25 18:28:59 -07001162 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001163
1164 // If in Agenda view and "show_event_details_with_agenda" is "true",
1165 // do not create the event info fragment here, it will be created by the Agenda
1166 // fragment
1167
RoboErikd6c93ce2011-07-22 17:54:40 -07001168 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -07001169 if (event.startTime != null && event.endTime != null) {
1170 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
1171 event.id, ViewType.AGENDA);
1172 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001173 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1174 event.selectedTime, event.id, ViewType.AGENDA);
1175 }
1176 } else {
RoboErik796db762011-09-12 14:56:23 -07001177 // TODO Fix the temp hack below: && mCurrentView !=
1178 // ViewType.AGENDA
1179 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
1180 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
RoboErik20911fa2011-09-13 17:07:47 -07001181 event.selectedTime, -1, ViewType.CURRENT);
RoboErik796db762011-09-12 14:56:23 -07001182 }
Isaac Katzenelson7ef29812011-10-25 18:00:50 -07001183 if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda) ||
Isaac Katzenelson998e66e2011-11-08 11:25:55 -08001184 ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK) ||
1185 mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)){
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001186 // start event info as activity
1187 Intent intent = new Intent(Intent.ACTION_VIEW);
1188 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
1189 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -07001190 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001191 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
1192 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -07001193 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
1194 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001195 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
1196 startActivity(intent);
1197 } else {
1198 // start event info as a dialog
1199 EventInfoFragment fragment = new EventInfoFragment(this,
1200 event.id, event.startTime.toMillis(false),
Isaac Katzenelson7ef29812011-10-25 18:00:50 -07001201 event.endTime.toMillis(false), (int) event.extraLong, true,
1202 EventInfoFragment.DIALOG_WINDOW_STYLE);
Isaac Katzenelson0aa0c612011-10-03 16:46:10 -07001203 fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001204 FragmentManager fm = getFragmentManager();
1205 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -07001206 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001207 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson80985d92011-11-11 14:09:04 -08001208 if (fOld != null && fOld.isAdded()) {
1209 ft.remove(fOld);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001210 }
Isaac Katzenelson80985d92011-11-11 14:09:04 -08001211 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001212 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001213 }
Erik63cd0532011-01-26 14:16:03 -08001214 }
RoboErik14e82b42011-07-19 09:46:39 -07001215 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001216 } else if (event.eventType == EventType.UPDATE_TITLE) {
1217 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001218 if (!mIsTabletConfig) {
RoboErike11975f2011-09-02 14:00:39 -07001219 mActionBarMenuSpinnerAdapter.setTime(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001220 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001221 }
RoboErik4eb34322011-08-19 15:47:51 -07001222 updateSecondaryTitleFields(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001223 }
1224
Michael Chan2aeb8d92011-07-10 13:32:09 -07001225 // Needs to be in proguard whitelist
1226 // Specified as listener via android:onClick in a layout xml
1227 public void handleSelectSyncedCalendarsClicked(View v) {
1228 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1229 CalendarController.EXTRA_GOTO_TIME, null,
1230 null);
1231 }
1232
Erik3f348f32010-08-10 13:17:19 -07001233 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001234 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001235 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001236 }
1237
Erik3f348f32010-08-10 13:17:19 -07001238 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001239 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001240 return false;
1241 }
1242
1243 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001244 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001245 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001246 Utils.tardis();
1247 }
RoboErika0954942011-07-27 17:43:14 -07001248 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001249 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001250 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001251 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001252 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001253
1254 @Override
1255 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001256 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001257 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001258 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001259 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001260 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001261 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001262 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001263 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1264 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001265 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001266 Log.w(TAG, "TabSelected event from unknown tab: "
1267 + (tab == null ? "null" : tab.getText()));
1268 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001269 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001270 }
1271 }
1272
1273 @Override
1274 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1275 }
1276
1277 @Override
1278 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1279 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001280
1281
1282 @Override
1283 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1284 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001285 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001286 if (mCurrentView != ViewType.DAY) {
1287 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1288 }
1289 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001290 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001291 if (mCurrentView != ViewType.WEEK) {
1292 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1293 }
1294 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001295 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001296 if (mCurrentView != ViewType.MONTH) {
1297 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1298 }
1299 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001300 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001301 if (mCurrentView != ViewType.AGENDA) {
1302 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1303 }
1304 break;
1305 default:
1306 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1307 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1308 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1309 " Agenda:" + mAgendaTab);
1310 break;
1311 }
1312 return false;
1313 }
RoboErik17664072011-08-16 16:22:39 -07001314
1315 @Override
1316 public boolean onSuggestionSelect(int position) {
1317 return false;
1318 }
1319
1320 @Override
1321 public boolean onSuggestionClick(int position) {
1322 mSearchMenu.collapseActionView();
1323 return false;
1324 }
RoboErikc6e314f2011-08-17 10:55:03 -07001325
1326 @Override
1327 public boolean onSearchRequested() {
1328 if (mSearchMenu != null) {
1329 mSearchMenu.expandActionView();
1330 }
1331 return false;
1332 }
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -07001333
1334 // Updates the day of the month drawable in the today icon
1335 private void setTodayIcon() {
1336 if (mDayOfMonthIcon == null) {
1337 mDayOfMonthIcon = new DayOfMonthDrawable();
1338 }
1339 Time now = new Time();
1340 now.set(System.currentTimeMillis());
1341 now.normalize(false);
1342 mDayOfMonthIcon.setDayOfMonth(now.monthDay);
1343 }
Michael Chan49701592010-06-30 11:04:03 -07001344}