blob: 47d8db934cdd61339afb62035e1368d7430c4c45 [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
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -070019import static android.provider.CalendarContract.EXTRA_EVENT_ALL_DAY;
RoboErika27a8862011-06-23 15:26:23 -070020import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
21import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
RoboErika7c03902011-06-14 11:06:44 -070022import static android.provider.CalendarContract.Attendees.ATTENDEE_STATUS;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070023import static com.android.calendar.CalendarController.EVENT_ATTENDEE_RESPONSE;
Erikdd95df52010-08-27 09:31:18 -070024
RoboErik6c892a22011-09-08 16:54:04 -070025import android.accounts.AccountManager;
26import android.accounts.AccountManagerCallback;
27import android.accounts.AccountManagerFuture;
28import android.accounts.AuthenticatorException;
29import android.accounts.OperationCanceledException;
Michael Chan5756bbc2011-03-02 18:22:07 -080030import android.animation.Animator;
31import android.animation.Animator.AnimatorListener;
RoboErikd97f7982011-03-02 15:13:05 -080032import android.animation.ObjectAnimator;
Michael Chanab29d9e2010-07-21 06:08:47 -070033import android.app.ActionBar;
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -070034import android.app.ActionBar.Tab;
Michael Chan49701592010-06-30 11:04:03 -070035import android.app.Activity;
Michael Chan83b0fe32010-07-08 16:46:26 -070036import android.app.Fragment;
Erik63cd0532011-01-26 14:16:03 -080037import android.app.FragmentManager;
Michael Chan3458a172010-07-13 17:58:21 -070038import android.app.FragmentTransaction;
RoboErik6c892a22011-09-08 16:54:04 -070039import android.content.AsyncQueryHandler;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070040import android.content.BroadcastReceiver;
Erik954c8712010-08-06 10:12:34 -070041import android.content.ContentResolver;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070042import android.content.ContentUris;
Erikdd95df52010-08-27 09:31:18 -070043import android.content.Intent;
Mason Tang8e3d4302010-07-12 17:39:30 -070044import android.content.SharedPreferences;
45import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -070046import android.content.res.Configuration;
Erikeaafa2b2010-12-23 14:30:37 -080047import android.content.res.Resources;
Erik954c8712010-08-06 10:12:34 -070048import android.database.ContentObserver;
RoboErik6c892a22011-09-08 16:54:04 -070049import android.database.Cursor;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070050import android.graphics.drawable.LayerDrawable;
Erikdd95df52010-08-27 09:31:18 -070051import android.net.Uri;
Michael Chan693ca602012-05-31 12:24:11 -070052import android.os.Build;
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;
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -070056import android.provider.CalendarContract.Attendees;
RoboErik6c892a22011-09-08 16:54:04 -070057import android.provider.CalendarContract.Calendars;
RoboErika7c03902011-06-14 11:06:44 -070058import android.provider.CalendarContract.Events;
Erik6c255102010-09-29 14:43:00 -070059import android.text.TextUtils;
60import android.text.format.DateFormat;
Michael Chan3458a172010-07-13 17:58:21 -070061import android.text.format.DateUtils;
Michael Chan83b0fe32010-07-08 16:46:26 -070062import android.text.format.Time;
Erik954c8712010-08-06 10:12:34 -070063import android.util.Log;
Erik2051f122010-07-02 13:45:45 -070064import android.view.Menu;
Michael Chan3458a172010-07-13 17:58:21 -070065import android.view.MenuItem;
Michael Chanab29d9e2010-07-21 06:08:47 -070066import android.view.View;
Erik259b8f92011-01-12 14:01:12 -080067import android.view.accessibility.AccessibilityEvent;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -070068import android.widget.LinearLayout;
RoboErikde20d762011-02-08 17:52:25 -080069import android.widget.RelativeLayout;
70import android.widget.RelativeLayout.LayoutParams;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -070071import android.widget.SearchView;
RoboErik17664072011-08-16 16:22:39 -070072import android.widget.SearchView.OnSuggestionListener;
Erik6c255102010-09-29 14:43:00 -070073import android.widget.TextView;
74
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -070075import com.android.calendar.CalendarController.EventHandler;
76import com.android.calendar.CalendarController.EventInfo;
77import com.android.calendar.CalendarController.EventType;
78import com.android.calendar.CalendarController.ViewType;
79import com.android.calendar.agenda.AgendaFragment;
80import com.android.calendar.month.MonthByWeekFragment;
81import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
82
RoboErik6c892a22011-09-08 16:54:04 -070083import java.io.IOException;
Michael Chan2c7c8512010-12-10 14:12:57 -080084import java.util.List;
Erik6c255102010-09-29 14:43:00 -070085import java.util.Locale;
86import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070087
Michael Chanab29d9e2010-07-21 06:08:47 -070088public class AllInOneActivity extends Activity implements EventHandler,
RoboErike635aec2011-07-15 11:22:13 -070089 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener,
RoboErik17664072011-08-16 16:22:39 -070090 ActionBar.OnNavigationListener, OnSuggestionListener {
Michael Chand6734db2010-07-22 00:48:08 -070091 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070092 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080093 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070094 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070095 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080096 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
RoboErik6c892a22011-09-08 16:54:04 -070097 private static final String BUNDLE_KEY_CHECK_ACCOUNTS = "key_check_for_accounts";
Erik3f348f32010-08-10 13:17:19 -070098 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080099 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -0800100
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700101 // Indices of buttons for the drop down menu (tabs replacement)
102 // Must match the strings in the array buttons_list in arrays.xml and the
103 // OnNavigationListener
104 private static final int BUTTON_DAY_INDEX = 0;
105 private static final int BUTTON_WEEK_INDEX = 1;
106 private static final int BUTTON_MONTH_INDEX = 2;
107 private static final int BUTTON_AGENDA_INDEX = 3;
108
RoboErikd69ccdf2011-08-05 14:50:27 -0700109 private CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -0700110 private static boolean mIsMultipane;
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700111 private static boolean mIsTabletConfig;
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700112 private static boolean mShowAgendaWithMonth;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700113 private static boolean mShowEventDetailsWithAgenda;
Michael Chan6191c122010-11-02 16:23:47 -0700114 private boolean mOnSaveInstanceStateCalled = false;
Michael Chanfb0ec222011-08-12 17:39:30 -0700115 private boolean mBackToPreviousView = false;
Erik954c8712010-08-06 10:12:34 -0700116 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700117 private int mPreviousView;
118 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700119 private boolean mPaused = true;
120 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800121 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800122 private boolean mShowSideViews = true;
RoboErik14e82b42011-07-19 09:46:39 -0700123 private boolean mShowWeekNum = false;
Erik6c255102010-09-29 14:43:00 -0700124 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800125 private TextView mDateRange;
RoboErik14e82b42011-07-19 09:46:39 -0700126 private TextView mWeekTextView;
RoboErikde20d762011-02-08 17:52:25 -0800127 private View mMiniMonth;
128 private View mCalendarsList;
129 private View mMiniMonthContainer;
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700130 private View mSecondaryPane;
Erikc5f92d72010-11-11 16:18:34 -0800131 private String mTimeZone;
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700132 private boolean mShowCalendarControls;
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700133 private boolean mShowEventInfoFullScreenAgenda;
Isaac Katzenelson998e66e2011-11-08 11:25:55 -0800134 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700135 private int mWeekNum;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700136 private int mCalendarControlsAnimationTime;
137 private int mControlsAnimateWidth;
138 private int mControlsAnimateHeight;
Erik6c255102010-09-29 14:43:00 -0700139
Michael Chan2c7c8512010-12-10 14:12:57 -0800140 private long mViewEventId = -1;
141 private long mIntentEventStartMillis = -1;
142 private long mIntentEventEndMillis = -1;
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -0700143 private int mIntentAttendeeResponse = Attendees.ATTENDEE_STATUS_NONE;
144 private boolean mIntentAllDay = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800145
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700146 // Action bar and Navigation bar (left side of Action bar)
147 private ActionBar mActionBar;
148 private ActionBar.Tab mDayTab;
149 private ActionBar.Tab mWeekTab;
150 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700151 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800152 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700153 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800154 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700155 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700156 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErik6c892a22011-09-08 16:54:04 -0700157 private QueryHandler mHandler;
158 private boolean mCheckForAccounts = true;
RoboErikde20d762011-02-08 17:52:25 -0800159
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700160 private String mHideString;
161 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800162
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700163 DayOfMonthDrawable mDayOfMonthIcon;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700164
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700165 int mOrientation;
Michael Chan5756bbc2011-03-02 18:22:07 -0800166
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700167 // Params for animating the controls on the right
168 private LayoutParams mControlsParams;
169 private LinearLayout.LayoutParams mVerticalControlsParams;
170
171 private final AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
Michael Chan5756bbc2011-03-02 18:22:07 -0800172
173 @Override
174 public void onAnimationCancel(Animator animation) {
175 }
176
177 @Override
178 public void onAnimationEnd(android.animation.Animator animation) {
179 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
180 mMiniMonth.setVisibility(visibility);
181 mCalendarsList.setVisibility(visibility);
182 mMiniMonthContainer.setVisibility(visibility);
183 }
184
185 @Override
186 public void onAnimationRepeat(android.animation.Animator animation) {
187 }
188
189 @Override
190 public void onAnimationStart(android.animation.Animator animation) {
191 }
192 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700193
RoboErik6c892a22011-09-08 16:54:04 -0700194 private class QueryHandler extends AsyncQueryHandler {
195 public QueryHandler(ContentResolver cr) {
196 super(cr);
197 }
198
199 @Override
200 protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
201 mCheckForAccounts = false;
Sara Ting343fb832012-05-21 16:45:22 -0700202 try {
203 // If the query didn't return a cursor for some reason return
204 if (cursor == null || cursor.getCount() > 0 || isFinishing()) {
205 return;
206 }
207 } finally {
208 if (cursor != null) {
209 cursor.close();
210 }
RoboErik6c892a22011-09-08 16:54:04 -0700211 }
Sara Ting343fb832012-05-21 16:45:22 -0700212
RoboErik6c892a22011-09-08 16:54:04 -0700213 Bundle options = new Bundle();
214 options.putCharSequence("introMessage",
215 getResources().getString(R.string.create_an_account_desc));
216 options.putBoolean("allowSkip", true);
217
218 AccountManager am = AccountManager.get(AllInOneActivity.this);
219 am.addAccount("com.google", CalendarContract.AUTHORITY, null, options,
220 AllInOneActivity.this,
221 new AccountManagerCallback<Bundle>() {
222 @Override
223 public void run(AccountManagerFuture<Bundle> future) {
224 if (future.isCancelled()) {
225 return;
226 }
227 try {
228 Bundle result = future.getResult();
229 boolean setupSkipped = result.getBoolean("setupSkipped");
230
231 if (setupSkipped) {
232 Utils.setSharedPreference(AllInOneActivity.this,
233 GeneralPreferences.KEY_SKIP_SETUP, true);
234 }
235
236 } catch (OperationCanceledException ignore) {
237 // The account creation process was canceled
238 } catch (IOException ignore) {
239 } catch (AuthenticatorException ignore) {
240 }
241 }
242 }, null);
243 }
244 }
245
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700246 private final Runnable mHomeTimeUpdater = new Runnable() {
Erik6c255102010-09-29 14:43:00 -0700247 @Override
248 public void run() {
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700249 mTimeZone = Utils.getTimeZone(AllInOneActivity.this, mHomeTimeUpdater);
RoboErik4eb34322011-08-19 15:47:51 -0700250 updateSecondaryTitleFields(-1);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700251 AllInOneActivity.this.invalidateOptionsMenu();
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700252 Utils.setMidnightUpdater(mHandler, mTimeChangesUpdater, mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700253 }
254 };
Erik954c8712010-08-06 10:12:34 -0700255
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700256 // runs every midnight/time changes and refreshes the today icon
257 private final Runnable mTimeChangesUpdater = new Runnable() {
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700258 @Override
259 public void run() {
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700260 mTimeZone = Utils.getTimeZone(AllInOneActivity.this, mHomeTimeUpdater);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700261 AllInOneActivity.this.invalidateOptionsMenu();
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700262 Utils.setMidnightUpdater(mHandler, mTimeChangesUpdater, mTimeZone);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700263 }
264 };
265
266
Erik954c8712010-08-06 10:12:34 -0700267 // Create an observer so that we can update the views whenever a
268 // Calendar event changes.
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700269 private final ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700270 @Override
271 public boolean deliverSelfNotifications() {
272 return true;
273 }
274
275 @Override
276 public void onChange(boolean selfChange) {
277 eventsChanged();
278 }
279 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700280
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700281 BroadcastReceiver mCalIntentReceiver;
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700282
Michael Chan49701592010-06-30 11:04:03 -0700283 @Override
Erik63cd0532011-01-26 14:16:03 -0800284 protected void onNewIntent(Intent intent) {
285 String action = intent.getAction();
RoboErik4ba19df2011-09-22 11:31:21 -0700286 if (DEBUG)
287 Log.d(TAG, "New intent received " + intent.toString());
288 // Don't change the date if we're just returning to the app's home
289 if (Intent.ACTION_VIEW.equals(action)
290 && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
RoboErik2c2dab42011-09-09 15:50:26 -0700291 long millis = parseViewAction(intent);
292 if (millis == -1) {
293 millis = Utils.timeFromIntentInMillis(intent);
294 }
295 if (millis != -1 && mViewEventId == -1 && mController != null) {
296 Time time = new Time(mTimeZone);
297 time.set(millis);
298 time.normalize(true);
299 mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
300 }
Erik63cd0532011-01-26 14:16:03 -0800301 }
302 }
303
304 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700305 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800306 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
307 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
308 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700309 super.onCreate(icicle);
310
RoboErik6c892a22011-09-08 16:54:04 -0700311 if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
312 mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
313 }
314 // Launch add google account if this is first time and there are no
315 // accounts yet
316 if (mCheckForAccounts
317 && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) {
318
319 mHandler = new QueryHandler(this.getContentResolver());
320 mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] {
321 Calendars._ID
322 }, null, null /* selection args */, null /* sort order */);
323 }
324
Michael Chan83b0fe32010-07-08 16:46:26 -0700325 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700326 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700327
328
Erik954c8712010-08-06 10:12:34 -0700329 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800330 long timeMillis = -1;
331 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800332 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700333 if (icicle != null) {
334 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800335 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700336 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800337 String action = intent.getAction();
338 if (Intent.ACTION_VIEW.equals(action)) {
339 // Open EventInfo later
340 timeMillis = parseViewAction(intent);
341 }
342
343 if (timeMillis == -1) {
344 timeMillis = Utils.timeFromIntentInMillis(intent);
345 }
346 }
347
RoboErik277eb972011-02-24 16:05:04 -0800348 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700349 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
350 }
Erikc5f92d72010-11-11 16:18:34 -0800351 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
352 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700353 t.set(timeMillis);
354
RoboErik8e62ac32011-09-09 10:13:07 -0700355 if (DEBUG) {
356 if (icicle != null && intent != null) {
357 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
358 } else {
359 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
360 }
Erik7b92da22010-09-23 14:55:22 -0700361 }
362
Erikeaafa2b2010-12-23 14:30:37 -0800363 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800364 mHideString = res.getString(R.string.hide_controls);
365 mShowString = res.getString(R.string.show_controls);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700366 mOrientation = res.getConfiguration().orientation;
367 if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
Isaac Katzenelsone0b4b272012-04-12 16:00:53 -0700368 mControlsAnimateWidth = (int)res.getDimension(R.dimen.calendar_controls_width);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700369 if (mControlsParams == null) {
370 mControlsParams = new LayoutParams(mControlsAnimateWidth, 0);
371 }
372 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Isaac Katzenelsone0b4b272012-04-12 16:00:53 -0700373 } else {
374 // Make sure width is in between allowed min and max width values
375 mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100,
376 (int)res.getDimension(R.dimen.min_portrait_calendar_controls_width));
377 mControlsAnimateWidth = Math.min(mControlsAnimateWidth,
378 (int)res.getDimension(R.dimen.max_portrait_calendar_controls_width));
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700379 }
380
381 mControlsAnimateHeight = (int)res.getDimension(R.dimen.calendar_controls_height);
RoboErikb8549562011-02-15 14:25:23 -0800382
Isaac Katzenelson31489e92012-05-14 11:25:58 -0700383 mHideControls = !Utils.getSharedPreference(
384 this, GeneralPreferences.KEY_SHOW_CONTROLS, true);
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700385 mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700386 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700387 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson31489e92012-05-14 11:25:58 -0700388 mShowCalendarControls =
389 Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700390 mShowEventDetailsWithAgenda =
391 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700392 mShowEventInfoFullScreenAgenda =
393 Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen);
Isaac Katzenelson998e66e2011-11-08 11:25:55 -0800394 mShowEventInfoFullScreen =
395 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700396 mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time);
Erik63cd0532011-01-26 14:16:03 -0800397 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800398
Erikbe8191c2010-10-26 16:50:08 -0700399 // setContentView must be called before configureActionBar
400 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700401
402 if (mIsTabletConfig) {
403 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700404 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700405 } else {
406 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
407 }
408
Erikbe8191c2010-10-26 16:50:08 -0700409 // configureActionBar auto-selects the first tab you add, so we need to
410 // call it before we set up our own fragments to make sure it doesn't
411 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700412 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700413
Erik6c255102010-09-29 14:43:00 -0700414 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800415 mMiniMonth = findViewById(R.id.mini_month);
Isaac Katzenelsona1542512012-04-20 16:44:05 -0700416 if (mIsTabletConfig && mOrientation == Configuration.ORIENTATION_PORTRAIT) {
Isaac Katzenelsone0b4b272012-04-12 16:00:53 -0700417 mMiniMonth.setLayoutParams(new LinearLayout.LayoutParams(mControlsAnimateWidth,
418 mControlsAnimateHeight));
419 }
RoboErikde20d762011-02-08 17:52:25 -0800420 mCalendarsList = findViewById(R.id.calendar_list);
421 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700422 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700423
RoboErik3864be02011-07-25 15:56:50 -0700424 // Must register as the first activity because this activity can modify
425 // the list of event handlers in it's handle method. This affects who
426 // the rest of the handlers the controller dispatches to are.
427 mController.registerFirstEventHandler(HANDLER_KEY, this);
428
Erik7b92da22010-09-23 14:55:22 -0700429 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700430
431 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700432 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700433 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700434
Erik954c8712010-08-06 10:12:34 -0700435 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700436 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700437
Michael Chan2c7c8512010-12-10 14:12:57 -0800438 private long parseViewAction(final Intent intent) {
439 long timeMillis = -1;
440 Uri data = intent.getData();
441 if (data != null && data.isHierarchical()) {
442 List<String> path = data.getPathSegments();
443 if (path.size() == 2 && path.get(0).equals("events")) {
444 try {
445 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700446 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700447 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
448 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800449 mIntentAttendeeResponse = intent.getIntExtra(
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -0700450 ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE);
451 mIntentAllDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false);
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 Katzenelson5925a272012-05-08 16:23:07 -0700463 createButtonsSpinner(viewType, mIsTabletConfig);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700464 if (mIsMultipane) {
465 mActionBar.setDisplayOptions(
466 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
467 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700468 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700469 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700470 }
471
472 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700473 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700474 if (mActionBar == null) {
475 Log.w(TAG, "ActionBar is null.");
476 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700477 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700478 mDayTab = mActionBar.newTab();
479 mDayTab.setText(getString(R.string.day_view));
480 mDayTab.setTabListener(this);
481 mActionBar.addTab(mDayTab);
482 mWeekTab = mActionBar.newTab();
483 mWeekTab.setText(getString(R.string.week_view));
484 mWeekTab.setTabListener(this);
485 mActionBar.addTab(mWeekTab);
486 mMonthTab = mActionBar.newTab();
487 mMonthTab.setText(getString(R.string.month_view));
488 mMonthTab.setTabListener(this);
489 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700490 mAgendaTab = mActionBar.newTab();
491 mAgendaTab.setText(getString(R.string.agenda_view));
492 mAgendaTab.setTabListener(this);
493 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700494 }
Erik954c8712010-08-06 10:12:34 -0700495 }
496
Isaac Katzenelson5925a272012-05-08 16:23:07 -0700497 private void createButtonsSpinner(int viewType, boolean tabletConfig) {
498 // If tablet configuration , show spinner with no dates
499 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType, !tabletConfig);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700500 mActionBar = getActionBar();
501 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700502 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700503 switch (viewType) {
504 case ViewType.AGENDA:
505 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
506 break;
507 case ViewType.DAY:
508 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
509 break;
510 case ViewType.WEEK:
511 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
512 break;
513 case ViewType.MONTH:
514 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
515 break;
516 default:
517 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
518 break;
519 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700520 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700521 // Clear buttons used in the agenda view
522 private void clearOptionsMenu() {
523 if (mOptionsMenu == null) {
524 return;
525 }
526 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700527 if (cancelItem != null) {
528 cancelItem.setVisible(false);
529 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700530 }
531
Erik954c8712010-08-06 10:12:34 -0700532 @Override
533 protected void onResume() {
534 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700535
536 // Must register as the first activity because this activity can modify
537 // the list of event handlers in it's handle method. This affects who
538 // the rest of the handlers the controller dispatches to are.
539 mController.registerFirstEventHandler(HANDLER_KEY, this);
540
Michael Chanf2cfa202011-08-19 17:58:16 -0700541 mOnSaveInstanceStateCalled = false;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700542 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
543 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700544 if (mUpdateOnResume) {
545 initFragments(mController.getTime(), mController.getViewType(), null);
546 mUpdateOnResume = false;
547 }
RoboErikc8e0f212011-10-13 17:57:39 -0700548 Time t = new Time(mTimeZone);
549 t.set(mController.getTime());
550 mController.sendEvent(this, EventType.UPDATE_TITLE, t, t, -1, ViewType.CURRENT,
551 mController.getDateFlags(), null, null);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700552 // Make sure the drop-down menu will get its date updated at midnight
553 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700554 mActionBarMenuSpinnerAdapter.refresh(this);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700555 }
556
RoboErik3b3af612011-02-24 13:42:57 -0800557 if (mControlsMenu != null) {
558 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
559 }
Erikcb811892010-09-28 13:44:19 -0700560 mPaused = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800561
562 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800563 long currentMillis = System.currentTimeMillis();
564 long selectedTime = -1;
565 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
566 selectedTime = currentMillis;
567 }
Michael Chanedecd9a2011-08-24 23:58:48 -0700568 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700569 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -0700570 EventInfo.buildViewExtraLong(mIntentAttendeeResponse,mIntentAllDay),
571 selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800572 mViewEventId = -1;
573 mIntentEventStartMillis = -1;
574 mIntentEventEndMillis = -1;
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -0700575 mIntentAllDay = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800576 }
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700577 Utils.setMidnightUpdater(mHandler, mTimeChangesUpdater, mTimeZone);
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700578 // Make sure the today icon is up to date
579 invalidateOptionsMenu();
580
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700581 mCalIntentReceiver = Utils.setTimeChangesReceiver(this, mTimeChangesUpdater);
Mason Tang8e3d4302010-07-12 17:39:30 -0700582 }
583
584 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700585 protected void onPause() {
586 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700587
588 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700589 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700590 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700591 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700592 mActionBarMenuSpinnerAdapter.onPause();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700593 }
Erik954c8712010-08-06 10:12:34 -0700594 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700595 if (isFinishing()) {
596 // Stop listening for changes that would require this to be refreshed
597 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
598 prefs.unregisterOnSharedPreferenceChangeListener(this);
599 }
Erik7b92da22010-09-23 14:55:22 -0700600 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700601 if (mController.getViewType() != ViewType.EDIT) {
602 Utils.setDefaultView(this, mController.getViewType());
603 }
Isaac Katzenelsonc9993162012-05-08 19:15:12 -0700604 Utils.resetMidnightUpdater(mHandler, mTimeChangesUpdater);
605 Utils.clearTimeChangesReceiver(this, mCalIntentReceiver);
Michael Chand6734db2010-07-22 00:48:08 -0700606 }
607
608 @Override
Erik7b92da22010-09-23 14:55:22 -0700609 protected void onUserLeaveHint() {
610 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
611 super.onUserLeaveHint();
612 }
613
614 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700615 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700616 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700617 super.onSaveInstanceState(outState);
Michael Chand6734db2010-07-22 00:48:08 -0700618 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
RoboErik24c479e2011-11-14 10:32:58 -0800619 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700620 if (mCurrentView == ViewType.EDIT) {
Erik7b92da22010-09-23 14:55:22 -0700621 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
Isaac Katzenelson4b468392012-05-22 10:27:32 -0700622 } else if (mCurrentView == ViewType.AGENDA) {
623 FragmentManager fm = getFragmentManager();
624 Fragment f = fm.findFragmentById(R.id.main_pane);
625 if (f instanceof AgendaFragment) {
626 outState.putLong(BUNDLE_KEY_EVENT_ID, ((AgendaFragment)f).getLastShowEventId());
627 }
Erik7b92da22010-09-23 14:55:22 -0700628 }
RoboErik6c892a22011-09-08 16:54:04 -0700629 outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts);
Michael Chand6734db2010-07-22 00:48:08 -0700630 }
631
632 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700633 protected void onDestroy() {
634 super.onDestroy();
635
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700636 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700637 prefs.unregisterOnSharedPreferenceChangeListener(this);
Paul Westbrook89af1892011-10-05 18:15:00 -0700638
Paul Westbrook61310b72011-10-07 15:43:00 -0700639 mController.deregisterAllEventHandlers();
Paul Westbrook89af1892011-10-05 18:15:00 -0700640
Eriked61b482010-08-13 13:59:50 -0700641 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700642 }
643
Erik7b92da22010-09-23 14:55:22 -0700644 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700645 if (DEBUG) {
646 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
647 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800648 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700649
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700650 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800651 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700652 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700653 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700654
Michael Chan2aeb8d92011-07-10 13:32:09 -0700655 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700656 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800657 mController.registerEventHandler(
658 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700659 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700660 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800661 mMiniMonth.setVisibility(View.GONE);
662 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700663 }
Michael Chan3458a172010-07-13 17:58:21 -0700664
Erikdd95df52010-08-27 09:31:18 -0700665 EventInfo info = null;
666 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700667 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700668 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700669
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700670 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700671 Intent intent = getIntent();
672 Uri data = intent.getData();
673 if (data != null) {
674 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700675 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700676 } catch (NumberFormatException e) {
677 if (DEBUG) {
678 Log.d(TAG, "Create new event");
679 }
680 }
Erik7b92da22010-09-23 14:55:22 -0700681 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
682 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700683 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700684
RoboErika27a8862011-06-23 15:26:23 -0700685 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
686 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700687 info = new EventInfo();
688 if (end != -1) {
689 info.endTime = new Time();
690 info.endTime.set(end);
691 }
692 if (begin != -1) {
693 info.startTime = new Time();
694 info.startTime.set(begin);
695 }
696 info.id = eventId;
697 // We set the viewtype so if the user presses back when they are
698 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700699 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700700 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700701 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700702 } else {
703 mPreviousView = viewType;
704 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700705
Erik63cd0532011-01-26 14:16:03 -0800706 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700707 ft.commit(); // this needs to be after setMainPane()
708
Erikc5f92d72010-11-11 16:18:34 -0800709 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700710 t.set(timeMillis);
Isaac Katzenelson4b468392012-05-22 10:27:32 -0700711 if (viewType == ViewType.AGENDA && icicle != null) {
712 mController.sendEvent(this, EventType.GO_TO, t, null,
713 icicle.getLong(BUNDLE_KEY_EVENT_ID, -1), viewType);
714 } else if (viewType != ViewType.EDIT) {
Erikdd95df52010-08-27 09:31:18 -0700715 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
716 }
Michael Chan49701592010-06-30 11:04:03 -0700717 }
Erik2051f122010-07-02 13:45:45 -0700718
719 @Override
Erik648c59c2010-08-13 12:49:26 -0700720 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700721 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700722 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700723 } else {
724 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700725 }
726 }
727
728 @Override
Erik2051f122010-07-02 13:45:45 -0700729 public boolean onCreateOptionsMenu(Menu menu) {
730 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700731 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700732 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700733
RoboErike635aec2011-07-15 11:22:13 -0700734 mSearchMenu = menu.findItem(R.id.action_search);
735 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800736 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700737 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800738 mSearchView.setOnQueryTextListener(this);
RoboErik17664072011-08-16 16:22:39 -0700739 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700740 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700741
742 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700743 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700744
RoboErikde20d762011-02-08 17:52:25 -0800745 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700746 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700747 if (mControlsMenu != null) {
748 mControlsMenu.setVisible(false);
749 mControlsMenu.setEnabled(false);
750 }
751 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700752 && (mController.getViewType() == ViewType.MONTH ||
753 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800754 mControlsMenu.setVisible(false);
755 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700756 } else if (mControlsMenu != null){
757 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800758 }
Isaac Katzenelson4bd4a5c2012-03-20 11:02:03 -0700759
Michael Chan693ca602012-05-31 12:24:11 -0700760 MenuItem menuItem = menu.findItem(R.id.action_today);
761 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
762 menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light);
763 } else {
764 // replace the default top layer drawable of the today icon with a
765 // custom drawable that shows the day of the month of today
766 LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
767 Utils.setTodayIcon(icon, this, mTimeZone);
768 }
Erik2051f122010-07-02 13:45:45 -0700769 return true;
770 }
Michael Chan3458a172010-07-13 17:58:21 -0700771
772 @Override
773 public boolean onOptionsItemSelected(MenuItem item) {
774 Time t = null;
775 int viewType = ViewType.CURRENT;
RoboErik5b872522011-10-03 17:24:50 -0700776 long extras = CalendarController.EXTRA_GOTO_TIME;
Michael Chan3458a172010-07-13 17:58:21 -0700777 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700778 case R.id.action_refresh:
779 mController.refreshCalendars();
780 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700781 case R.id.action_today:
782 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800783 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700784 t.setToNow();
RoboErik5b872522011-10-03 17:24:50 -0700785 extras |= CalendarController.EXTRA_GOTO_TODAY;
Michael Chan3458a172010-07-13 17:58:21 -0700786 break;
787 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800788 t = new Time();
789 t.set(mController.getTime());
Isaac Katzenelson576521e2011-10-12 16:19:40 -0700790 if (t.minute > 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800791 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800792 t.minute = 0;
Isaac Katzenelson576521e2011-10-12 16:19:40 -0700793 } else if (t.minute > 0 && t.minute < 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800794 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800795 }
796 mController.sendEventRelatedEvent(
797 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700798 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700799 case R.id.action_select_visible_calendars:
800 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
801 0, 0);
802 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700803 case R.id.action_settings:
804 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
805 return true;
RoboErikde20d762011-02-08 17:52:25 -0800806 case R.id.action_hide_controls:
807 mHideControls = !mHideControls;
Isaac Katzenelson31489e92012-05-14 11:25:58 -0700808 Utils.setSharedPreference(
809 this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls);
RoboErikde20d762011-02-08 17:52:25 -0800810 item.setTitle(mHideControls ? mShowString : mHideString);
Isaac Katzenelson31489e92012-05-14 11:25:58 -0700811 if (!mHideControls) {
812 mMiniMonth.setVisibility(View.VISIBLE);
813 mCalendarsList.setVisibility(View.VISIBLE);
814 mMiniMonthContainer.setVisibility(View.VISIBLE);
815 }
RoboErikb8549562011-02-15 14:25:23 -0800816 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700817 mHideControls ? 0 : mControlsAnimateWidth,
818 mHideControls ? mControlsAnimateWidth : 0);
819 slideAnimation.setDuration(mCalendarControlsAnimationTime);
RoboErikb8549562011-02-15 14:25:23 -0800820 ObjectAnimator.setFrameDelay(0);
821 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800822 return true;
RoboErike635aec2011-07-15 11:22:13 -0700823 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700824 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700825 default:
826 return false;
827 }
RoboErik5b872522011-10-03 17:24:50 -0700828 mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
Michael Chan3458a172010-07-13 17:58:21 -0700829 return true;
830 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700831
RoboErikb8549562011-02-15 14:25:23 -0800832 /**
833 * Sets the offset of the controls on the right for animating them off/on
834 * screen. ProGuard strips this if it's not in proguard.flags
835 *
836 * @param controlsOffset The current offset in pixels
837 */
838 public void setControlsOffset(int controlsOffset) {
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -0700839 if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
840 mMiniMonth.setTranslationX(controlsOffset);
841 mCalendarsList.setTranslationX(controlsOffset);
842 mControlsParams.width = Math.max(0, mControlsAnimateWidth - controlsOffset);
843 mMiniMonthContainer.setLayoutParams(mControlsParams);
844 } else {
845 mMiniMonth.setTranslationY(controlsOffset);
846 mCalendarsList.setTranslationY(controlsOffset);
847 if (mVerticalControlsParams == null) {
848 mVerticalControlsParams = new LinearLayout.LayoutParams(
849 LinearLayout.LayoutParams.MATCH_PARENT, mControlsAnimateHeight);
850 }
851 mVerticalControlsParams.height = Math.max(0, mControlsAnimateHeight - controlsOffset);
852 mMiniMonthContainer.setLayoutParams(mVerticalControlsParams);
853 }
RoboErikb8549562011-02-15 14:25:23 -0800854 }
RoboErikde20d762011-02-08 17:52:25 -0800855
Mason Tang8e3d4302010-07-12 17:39:30 -0700856 @Override
857 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700858 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700859 if (mPaused) {
860 mUpdateOnResume = true;
861 } else {
862 initFragments(mController.getTime(), mController.getViewType(), null);
863 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700864 }
865 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700866
Erik63cd0532011-01-26 14:16:03 -0800867 private void setMainPane(
868 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700869 if (mOnSaveInstanceStateCalled) {
870 return;
871 }
Erik7b92da22010-09-23 14:55:22 -0700872 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700873 return;
874 }
875
Michael Chan5756bbc2011-03-02 18:22:07 -0800876 // Remove this when transition to and from month view looks fine.
877 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700878 FragmentManager fragmentManager = getFragmentManager();
879 // Check if our previous view was an Agenda view
880 // TODO remove this if framework ever supports nested fragments
881 if (mCurrentView == ViewType.AGENDA) {
882 // If it was, we need to do some cleanup on it to prevent the
883 // edit/delete buttons from coming back on a rotation.
884 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
885 if (oldFrag instanceof AgendaFragment) {
886 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
887 }
888 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800889
Erik648c59c2010-08-13 12:49:26 -0700890 if (viewType != mCurrentView) {
891 // The rules for this previous view are different than the
892 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700893 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
894 mPreviousView = mCurrentView;
895 }
Erik648c59c2010-08-13 12:49:26 -0700896 mCurrentView = viewType;
897 }
Erik3f348f32010-08-10 13:17:19 -0700898 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700899 Fragment frag = null;
900 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700901 switch (viewType) {
902 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700903 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
904 mActionBar.selectTab(mAgendaTab);
905 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700906 if (mActionBarMenuSpinnerAdapter != null) {
907 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
908 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700909 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700910 break;
911 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700912 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
913 mActionBar.selectTab(mDayTab);
914 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700915 if (mActionBarMenuSpinnerAdapter != null) {
916 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
917 }
Michael Chan75d9b562010-07-26 16:54:25 -0700918 frag = new DayFragment(timeMillis, 1);
919 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700920 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700921 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
922 mActionBar.selectTab(mWeekTab);
923 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700924 if (mActionBarMenuSpinnerAdapter != null) {
925 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
926 }
Michael Chan75d9b562010-07-26 16:54:25 -0700927 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700928 break;
929 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700930 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
931 mActionBar.selectTab(mMonthTab);
932 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700933 if (mActionBarMenuSpinnerAdapter != null) {
934 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
935 }
Erik40bcd102010-11-16 15:46:40 -0800936 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700937 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700938 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700939 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700940 break;
941 default:
Michael Chand6734db2010-07-22 00:48:08 -0700942 throw new IllegalArgumentException(
943 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700944 }
945
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700946 // Update the current view so that the menu can update its look according to the
947 // current view.
Isaac Katzenelson5925a272012-05-08 16:23:07 -0700948 if (mActionBarMenuSpinnerAdapter != null) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700949 mActionBarMenuSpinnerAdapter.setMainView(viewType);
Isaac Katzenelson5925a272012-05-08 16:23:07 -0700950 if (!mIsTabletConfig) {
951 mActionBarMenuSpinnerAdapter.setTime(timeMillis);
952 }
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700953 }
954
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700955
956 // Show date only on tablet configurations in views different than Agenda
957 if (!mIsTabletConfig) {
958 mDateRange.setVisibility(View.GONE);
959 } else if (viewType != ViewType.AGENDA) {
960 mDateRange.setVisibility(View.VISIBLE);
961 } else {
962 mDateRange.setVisibility(View.GONE);
963 }
964
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700965 // Clear unnecessary buttons from the option menu when switching from the agenda view
966 if (viewType != ViewType.AGENDA) {
967 clearOptionsMenu();
968 }
969
Michael Chanab29d9e2010-07-21 06:08:47 -0700970 boolean doCommit = false;
971 if (ft == null) {
972 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700973 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700974 }
975
Michael Chan5756bbc2011-03-02 18:22:07 -0800976 if (doTransition) {
977 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
978 }
979
Michael Chanab29d9e2010-07-21 06:08:47 -0700980 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700981 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700982
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700983 // Show/hide secondary fragment
984
985 if (secFrag != null) {
986 ft.replace(R.id.secondary_pane, secFrag);
987 mSecondaryPane.setVisibility(View.VISIBLE);
988 } else {
989 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700990 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700991 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700992 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700993 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700994 mController.deregisterEventHandler(R.id.secondary_pane);
995 }
996 }
Erik954c8712010-08-06 10:12:34 -0700997 if (DEBUG) {
998 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
999 }
Erik3f348f32010-08-10 13:17:19 -07001000 // If the key is already registered this will replace it
1001 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -07001002 if (secFrag != null) {
1003 mController.registerEventHandler(viewId, (EventHandler) secFrag);
1004 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001005
1006 if (doCommit) {
RoboErik8e62ac32011-09-09 10:13:07 -07001007 if (DEBUG) {
1008 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
1009 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001010 ft.commit();
1011 }
1012 }
1013
1014 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -08001015 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -07001016 return;
1017 }
1018
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001019 final long start = event.startTime.toMillis(false /* use isDst */);
1020 final long end;
Michael Chand6734db2010-07-22 00:48:08 -07001021 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -07001022 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001023 } else {
1024 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -07001025 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001026
Erikeaafa2b2010-12-23 14:30:37 -08001027 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -08001028 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -08001029 mDateRange.setText(msg);
RoboErik8e62ac32011-09-09 10:13:07 -07001030 updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true)
1031 : start);
Erik259b8f92011-01-12 14:01:12 -08001032 if (!TextUtils.equals(oldDate, msg)) {
1033 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -07001034 if (mShowWeekNum && mWeekTextView != null) {
1035 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
1036 }
Erik259b8f92011-01-12 14:01:12 -08001037 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001038 }
1039
RoboErik4eb34322011-08-19 15:47:51 -07001040 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
RoboErik14e82b42011-07-19 09:46:39 -07001041 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -08001042 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -07001043 if (visibleMillisSinceEpoch != -1) {
1044 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
1045 mWeekNum = weekNum;
1046 }
1047
1048 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
1049 && mWeekTextView != null) {
1050 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
1051 mWeekNum);
1052 mWeekTextView.setText(weekString);
1053 mWeekTextView.setVisibility(View.VISIBLE);
RoboErik4eb34322011-08-19 15:47:51 -07001054 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null
1055 && mCurrentView == ViewType.DAY && mIsTabletConfig) {
1056 Time time = new Time(mTimeZone);
1057 time.set(visibleMillisSinceEpoch);
1058 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
1059 time.setToNow();
1060 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
1061 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay,
1062 visibleMillisSinceEpoch, this);
1063 mWeekTextView.setText(dayString);
1064 mWeekTextView.setVisibility(View.VISIBLE);
1065 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
RoboErik14e82b42011-07-19 09:46:39 -07001066 mWeekTextView.setVisibility(View.GONE);
1067 }
Michael Chanbe686752011-08-23 15:53:35 -07001068
RoboErik14e82b42011-07-19 09:46:39 -07001069 if (mHomeTime != null
1070 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
1071 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -08001072 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
1073 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -07001074 time.setToNow();
1075 long millis = time.toMillis(true);
1076 boolean isDST = time.isDst != 0;
1077 int flags = DateUtils.FORMAT_SHOW_TIME;
1078 if (DateFormat.is24HourFormat(this)) {
1079 flags |= DateUtils.FORMAT_24HOUR;
1080 }
1081 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -08001082 String timeString = (new StringBuilder(
1083 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
1084 TimeZone.getTimeZone(mTimeZone).getDisplayName(
1085 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -07001086 mHomeTime.setText(timeString);
1087 mHomeTime.setVisibility(View.VISIBLE);
1088 // Update when the minute changes
Michael Chan5d740e12011-11-16 16:51:10 -08001089 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Erik6c255102010-09-29 14:43:00 -07001090 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -07001091 mHomeTimeUpdater,
1092 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -07001093 } else if (mHomeTime != null) {
1094 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -07001095 }
1096 }
1097
Erik3f348f32010-08-10 13:17:19 -07001098 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001099 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -08001100 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -07001101 }
1102
Erik3f348f32010-08-10 13:17:19 -07001103 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001104 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -07001105 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -07001106 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -07001107 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
1108 mBackToPreviousView = true;
1109 } else if (event.viewType != mController.getPreviousViewType()
1110 && event.viewType != ViewType.EDIT) {
1111 // Clear the flag is change to a different view type
1112 mBackToPreviousView = false;
1113 }
1114
Erik63cd0532011-01-26 14:16:03 -08001115 setMainPane(
1116 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -08001117 if (mSearchView != null) {
1118 mSearchView.clearFocus();
1119 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001120 if (mShowCalendarControls) {
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001121 int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ?
1122 mControlsAnimateWidth : mControlsAnimateHeight;
Isaac Katzenelson31489e92012-05-14 11:25:58 -07001123 boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA;
1124 if (mControlsMenu != null) {
1125 mControlsMenu.setVisible(!noControlsView);
1126 mControlsMenu.setEnabled(!noControlsView);
1127 }
1128 if (noControlsView || mHideControls) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001129 // hide minimonth and calendar frag
1130 mShowSideViews = false;
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001131 if (!mHideControls) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001132 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001133 "controlsOffset", 0, animationSize);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001134 slideAnimation.addListener(mSlideAnimationDoneListener);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001135 slideAnimation.setDuration(mCalendarControlsAnimationTime);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001136 ObjectAnimator.setFrameDelay(0);
1137 slideAnimation.start();
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001138 } else {
1139 mMiniMonth.setVisibility(View.GONE);
1140 mCalendarsList.setVisibility(View.GONE);
1141 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -08001142 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001143 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001144 // show minimonth and calendar frag
1145 mShowSideViews = true;
1146 mMiniMonth.setVisibility(View.VISIBLE);
1147 mCalendarsList.setVisibility(View.VISIBLE);
1148 mMiniMonthContainer.setVisibility(View.VISIBLE);
Isaac Katzenelson4d2f0352012-03-26 17:37:24 -07001149 if (!mHideControls &&
1150 (mController.getPreviousViewType() == ViewType.MONTH ||
1151 mController.getPreviousViewType() == ViewType.AGENDA)) {
1152 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1153 "controlsOffset", animationSize, 0);
1154 slideAnimation.setDuration(mCalendarControlsAnimationTime);
1155 ObjectAnimator.setFrameDelay(0);
1156 slideAnimation.start();
Michael Chan5756bbc2011-03-02 18:22:07 -08001157 }
RoboErikde20d762011-02-08 17:52:25 -08001158 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001159 }
RoboErik8e62ac32011-09-09 10:13:07 -07001160 displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
1161 : event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -07001162 if (!mIsTabletConfig) {
1163 mActionBarMenuSpinnerAdapter.setTime(displayTime);
1164 }
Michael Chan71d08832010-08-25 18:28:59 -07001165 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001166
1167 // If in Agenda view and "show_event_details_with_agenda" is "true",
1168 // do not create the event info fragment here, it will be created by the Agenda
1169 // fragment
1170
RoboErikd6c93ce2011-07-22 17:54:40 -07001171 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -07001172 if (event.startTime != null && event.endTime != null) {
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -07001173 // Event is all day , adjust the goto time to local time
1174 if (event.isAllDay()) {
1175 Utils.convertAlldayUtcToLocal(
1176 event.startTime, event.startTime.toMillis(false), mTimeZone);
1177 Utils.convertAlldayUtcToLocal(
1178 event.endTime, event.endTime.toMillis(false), mTimeZone);
1179 }
RoboErikf836d4a2011-07-22 17:01:27 -07001180 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
Isaac Katzenelson4b468392012-05-22 10:27:32 -07001181 event.selectedTime, event.id, ViewType.AGENDA,
1182 CalendarController.EXTRA_GOTO_TIME, null, null);
RoboErikf836d4a2011-07-22 17:01:27 -07001183 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001184 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1185 event.selectedTime, event.id, ViewType.AGENDA);
1186 }
1187 } else {
RoboErik796db762011-09-12 14:56:23 -07001188 // TODO Fix the temp hack below: && mCurrentView !=
1189 // ViewType.AGENDA
1190 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
1191 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
RoboErik20911fa2011-09-13 17:07:47 -07001192 event.selectedTime, -1, ViewType.CURRENT);
RoboErik796db762011-09-12 14:56:23 -07001193 }
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -07001194 int response = event.getResponse();
Isaac Katzenelson7ef29812011-10-25 18:00:50 -07001195 if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda) ||
Isaac Katzenelson998e66e2011-11-08 11:25:55 -08001196 ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK) ||
1197 mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)){
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001198 // start event info as activity
1199 Intent intent = new Intent(Intent.ACTION_VIEW);
1200 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
1201 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -07001202 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001203 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
1204 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -07001205 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
1206 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -07001207 intent.putExtra(EVENT_ATTENDEE_RESPONSE, response);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001208 startActivity(intent);
1209 } else {
1210 // start event info as a dialog
1211 EventInfoFragment fragment = new EventInfoFragment(this,
1212 event.id, event.startTime.toMillis(false),
Isaac Katzenelson6bcafcf2012-05-02 18:25:36 -07001213 event.endTime.toMillis(false), response, true,
Isaac Katzenelson7ef29812011-10-25 18:00:50 -07001214 EventInfoFragment.DIALOG_WINDOW_STYLE);
Isaac Katzenelson0aa0c612011-10-03 16:46:10 -07001215 fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001216 FragmentManager fm = getFragmentManager();
1217 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -07001218 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001219 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson80985d92011-11-11 14:09:04 -08001220 if (fOld != null && fOld.isAdded()) {
1221 ft.remove(fOld);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001222 }
Isaac Katzenelson80985d92011-11-11 14:09:04 -08001223 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001224 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001225 }
Erik63cd0532011-01-26 14:16:03 -08001226 }
RoboErik14e82b42011-07-19 09:46:39 -07001227 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001228 } else if (event.eventType == EventType.UPDATE_TITLE) {
1229 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001230 if (!mIsTabletConfig) {
RoboErike11975f2011-09-02 14:00:39 -07001231 mActionBarMenuSpinnerAdapter.setTime(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001232 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001233 }
RoboErik4eb34322011-08-19 15:47:51 -07001234 updateSecondaryTitleFields(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001235 }
1236
Michael Chan2aeb8d92011-07-10 13:32:09 -07001237 // Needs to be in proguard whitelist
1238 // Specified as listener via android:onClick in a layout xml
1239 public void handleSelectSyncedCalendarsClicked(View v) {
1240 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1241 CalendarController.EXTRA_GOTO_TIME, null,
1242 null);
1243 }
1244
Erik3f348f32010-08-10 13:17:19 -07001245 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001246 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001247 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001248 }
1249
Erik3f348f32010-08-10 13:17:19 -07001250 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001251 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001252 return false;
1253 }
1254
1255 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001256 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001257 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001258 Utils.tardis();
1259 }
RoboErika0954942011-07-27 17:43:14 -07001260 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001261 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001262 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001263 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001264 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001265
1266 @Override
1267 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001268 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001269 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001270 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001271 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001272 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001273 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001274 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001275 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1276 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001277 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001278 Log.w(TAG, "TabSelected event from unknown tab: "
1279 + (tab == null ? "null" : tab.getText()));
1280 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001281 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001282 }
1283 }
1284
1285 @Override
1286 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1287 }
1288
1289 @Override
1290 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1291 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001292
1293
1294 @Override
1295 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1296 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001297 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001298 if (mCurrentView != ViewType.DAY) {
1299 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1300 }
1301 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001302 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001303 if (mCurrentView != ViewType.WEEK) {
1304 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1305 }
1306 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001307 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001308 if (mCurrentView != ViewType.MONTH) {
1309 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1310 }
1311 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001312 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001313 if (mCurrentView != ViewType.AGENDA) {
1314 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1315 }
1316 break;
1317 default:
1318 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1319 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1320 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1321 " Agenda:" + mAgendaTab);
1322 break;
1323 }
1324 return false;
1325 }
RoboErik17664072011-08-16 16:22:39 -07001326
1327 @Override
1328 public boolean onSuggestionSelect(int position) {
1329 return false;
1330 }
1331
1332 @Override
1333 public boolean onSuggestionClick(int position) {
1334 mSearchMenu.collapseActionView();
1335 return false;
1336 }
RoboErikc6e314f2011-08-17 10:55:03 -07001337
1338 @Override
1339 public boolean onSearchRequested() {
1340 if (mSearchMenu != null) {
1341 mSearchMenu.expandActionView();
1342 }
1343 return false;
1344 }
Michael Chan49701592010-06-30 11:04:03 -07001345}