blob: a86c1b20b0015144f52cece00f75589816bba082 [file] [log] [blame]
Michael Chan49701592010-06-30 11:04:03 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.calendar;
18
RoboErika27a8862011-06-23 15:26:23 -070019import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
20import static android.provider.CalendarContract.EXTRA_EVENT_END_TIME;
RoboErika7c03902011-06-14 11:06:44 -070021import static android.provider.CalendarContract.Attendees.ATTENDEE_STATUS;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070022import static com.android.calendar.CalendarController.EVENT_ATTENDEE_RESPONSE;
Erikdd95df52010-08-27 09:31:18 -070023
Michael Chan83b0fe32010-07-08 16:46:26 -070024import com.android.calendar.CalendarController.EventHandler;
Michael Chanab29d9e2010-07-21 06:08:47 -070025import com.android.calendar.CalendarController.EventInfo;
Michael Chan83b0fe32010-07-08 16:46:26 -070026import com.android.calendar.CalendarController.EventType;
Michael Chan3458a172010-07-13 17:58:21 -070027import com.android.calendar.CalendarController.ViewType;
Mason Tang00b8c1a2010-08-23 12:02:00 -070028import com.android.calendar.agenda.AgendaFragment;
Erik981874e2010-10-05 16:52:52 -070029import com.android.calendar.month.MonthByWeekFragment;
Michael Chan2aeb8d92011-07-10 13:32:09 -070030import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;
Michael Chan83b0fe32010-07-08 16:46:26 -070031
RoboErik6c892a22011-09-08 16:54:04 -070032import android.accounts.AccountManager;
33import android.accounts.AccountManagerCallback;
34import android.accounts.AccountManagerFuture;
35import android.accounts.AuthenticatorException;
36import android.accounts.OperationCanceledException;
Michael Chan5756bbc2011-03-02 18:22:07 -080037import android.animation.Animator;
38import android.animation.Animator.AnimatorListener;
RoboErikd97f7982011-03-02 15:13:05 -080039import android.animation.ObjectAnimator;
Michael Chanab29d9e2010-07-21 06:08:47 -070040import android.app.ActionBar;
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -070041import android.app.ActionBar.Tab;
Michael Chan49701592010-06-30 11:04:03 -070042import android.app.Activity;
Michael Chan83b0fe32010-07-08 16:46:26 -070043import android.app.Fragment;
Erik63cd0532011-01-26 14:16:03 -080044import android.app.FragmentManager;
Michael Chan3458a172010-07-13 17:58:21 -070045import android.app.FragmentTransaction;
RoboErik6c892a22011-09-08 16:54:04 -070046import android.content.AsyncQueryHandler;
Erik954c8712010-08-06 10:12:34 -070047import android.content.ContentResolver;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -070048import android.content.ContentUris;
Erikdd95df52010-08-27 09:31:18 -070049import android.content.Intent;
Mason Tang8e3d4302010-07-12 17:39:30 -070050import android.content.SharedPreferences;
51import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Erikeaafa2b2010-12-23 14:30:37 -080052import android.content.res.Resources;
Erik954c8712010-08-06 10:12:34 -070053import android.database.ContentObserver;
RoboErik6c892a22011-09-08 16:54:04 -070054import android.database.Cursor;
Erikdd95df52010-08-27 09:31:18 -070055import android.net.Uri;
Michael Chan49701592010-06-30 11:04:03 -070056import android.os.Bundle;
Erik954c8712010-08-06 10:12:34 -070057import android.os.Handler;
RoboErika7c03902011-06-14 11:06:44 -070058import android.provider.CalendarContract;
RoboErik6c892a22011-09-08 16:54:04 -070059import android.provider.CalendarContract.Calendars;
RoboErika7c03902011-06-14 11:06:44 -070060import android.provider.CalendarContract.Events;
Erik6c255102010-09-29 14:43:00 -070061import android.text.TextUtils;
62import android.text.format.DateFormat;
Michael Chan3458a172010-07-13 17:58:21 -070063import android.text.format.DateUtils;
Michael Chan83b0fe32010-07-08 16:46:26 -070064import android.text.format.Time;
Erik954c8712010-08-06 10:12:34 -070065import android.util.Log;
Erik2051f122010-07-02 13:45:45 -070066import android.view.Menu;
Michael Chan3458a172010-07-13 17:58:21 -070067import android.view.MenuItem;
Michael Chanab29d9e2010-07-21 06:08:47 -070068import android.view.View;
Erik259b8f92011-01-12 14:01:12 -080069import android.view.accessibility.AccessibilityEvent;
RoboErikde20d762011-02-08 17:52:25 -080070import android.widget.RelativeLayout;
71import android.widget.RelativeLayout.LayoutParams;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -070072import android.widget.SearchView;
RoboErik17664072011-08-16 16:22:39 -070073import android.widget.SearchView.OnSuggestionListener;
Erik6c255102010-09-29 14:43:00 -070074import android.widget.TextView;
75
RoboErik6c892a22011-09-08 16:54:04 -070076import java.io.IOException;
Michael Chan2c7c8512010-12-10 14:12:57 -080077import java.util.List;
Erik6c255102010-09-29 14:43:00 -070078import java.util.Locale;
79import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070080
Michael Chanab29d9e2010-07-21 06:08:47 -070081public class AllInOneActivity extends Activity implements EventHandler,
RoboErike635aec2011-07-15 11:22:13 -070082 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener, ActionBar.TabListener,
RoboErik17664072011-08-16 16:22:39 -070083 ActionBar.OnNavigationListener, OnSuggestionListener {
Michael Chand6734db2010-07-22 00:48:08 -070084 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070085 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080086 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070087 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070088 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080089 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
RoboErik6c892a22011-09-08 16:54:04 -070090 private static final String BUNDLE_KEY_CHECK_ACCOUNTS = "key_check_for_accounts";
Erik3f348f32010-08-10 13:17:19 -070091 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080092 private static final long CONTROLS_ANIMATE_DURATION = 400;
RoboErike9cd8f42011-07-01 16:36:11 -070093 private static int CONTROLS_ANIMATE_WIDTH = 280;
RoboErikde20d762011-02-08 17:52:25 -080094 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -080095
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -070096 // Indices of buttons for the drop down menu (tabs replacement)
97 // Must match the strings in the array buttons_list in arrays.xml and the
98 // OnNavigationListener
99 private static final int BUTTON_DAY_INDEX = 0;
100 private static final int BUTTON_WEEK_INDEX = 1;
101 private static final int BUTTON_MONTH_INDEX = 2;
102 private static final int BUTTON_AGENDA_INDEX = 3;
103
RoboErikd69ccdf2011-08-05 14:50:27 -0700104 private CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -0700105 private static boolean mIsMultipane;
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700106 private static boolean mIsTabletConfig;
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700107 private static boolean mShowAgendaWithMonth;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700108 private static boolean mShowEventDetailsWithAgenda;
Michael Chan6191c122010-11-02 16:23:47 -0700109 private boolean mOnSaveInstanceStateCalled = false;
Michael Chanfb0ec222011-08-12 17:39:30 -0700110 private boolean mBackToPreviousView = false;
Erik954c8712010-08-06 10:12:34 -0700111 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -0700112 private int mPreviousView;
113 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -0700114 private boolean mPaused = true;
115 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -0800116 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -0800117 private boolean mShowSideViews = true;
RoboErik14e82b42011-07-19 09:46:39 -0700118 private boolean mShowWeekNum = false;
Erik6c255102010-09-29 14:43:00 -0700119 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -0800120 private TextView mDateRange;
RoboErik14e82b42011-07-19 09:46:39 -0700121 private TextView mWeekTextView;
RoboErikde20d762011-02-08 17:52:25 -0800122 private View mMiniMonth;
123 private View mCalendarsList;
124 private View mMiniMonthContainer;
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700125 private View mSecondaryPane;
Erikc5f92d72010-11-11 16:18:34 -0800126 private String mTimeZone;
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700127 private boolean mShowCalendarControls;
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700128 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700129 private int mWeekNum;
Erik6c255102010-09-29 14:43:00 -0700130
Michael Chan2c7c8512010-12-10 14:12:57 -0800131 private long mViewEventId = -1;
132 private long mIntentEventStartMillis = -1;
133 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800134 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800135
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700136 // Action bar and Navigation bar (left side of Action bar)
137 private ActionBar mActionBar;
138 private ActionBar.Tab mDayTab;
139 private ActionBar.Tab mWeekTab;
140 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700141 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800142 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700143 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800144 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700145 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700146 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErik6c892a22011-09-08 16:54:04 -0700147 private QueryHandler mHandler;
148 private boolean mCheckForAccounts = true;
RoboErikde20d762011-02-08 17:52:25 -0800149
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700150 private String mHideString;
151 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800152
RoboErikb8549562011-02-15 14:25:23 -0800153 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800154 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
155
156 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
157
158 @Override
159 public void onAnimationCancel(Animator animation) {
160 }
161
162 @Override
163 public void onAnimationEnd(android.animation.Animator animation) {
164 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
165 mMiniMonth.setVisibility(visibility);
166 mCalendarsList.setVisibility(visibility);
167 mMiniMonthContainer.setVisibility(visibility);
168 }
169
170 @Override
171 public void onAnimationRepeat(android.animation.Animator animation) {
172 }
173
174 @Override
175 public void onAnimationStart(android.animation.Animator animation) {
176 }
177 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700178
RoboErik6c892a22011-09-08 16:54:04 -0700179 private class QueryHandler extends AsyncQueryHandler {
180 public QueryHandler(ContentResolver cr) {
181 super(cr);
182 }
183
184 @Override
185 protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
186 mCheckForAccounts = false;
187 // If the query didn't return a cursor for some reason return
188 if (cursor == null || cursor.getCount() > 0 || isFinishing()) {
189 return;
190 }
191 Bundle options = new Bundle();
192 options.putCharSequence("introMessage",
193 getResources().getString(R.string.create_an_account_desc));
194 options.putBoolean("allowSkip", true);
195
196 AccountManager am = AccountManager.get(AllInOneActivity.this);
197 am.addAccount("com.google", CalendarContract.AUTHORITY, null, options,
198 AllInOneActivity.this,
199 new AccountManagerCallback<Bundle>() {
200 @Override
201 public void run(AccountManagerFuture<Bundle> future) {
202 if (future.isCancelled()) {
203 return;
204 }
205 try {
206 Bundle result = future.getResult();
207 boolean setupSkipped = result.getBoolean("setupSkipped");
208
209 if (setupSkipped) {
210 Utils.setSharedPreference(AllInOneActivity.this,
211 GeneralPreferences.KEY_SKIP_SETUP, true);
212 }
213
214 } catch (OperationCanceledException ignore) {
215 // The account creation process was canceled
216 } catch (IOException ignore) {
217 } catch (AuthenticatorException ignore) {
218 }
219 }
220 }, null);
221 }
222 }
223
Erik6c255102010-09-29 14:43:00 -0700224 private Runnable mHomeTimeUpdater = new Runnable() {
225 @Override
226 public void run() {
RoboErik4eb34322011-08-19 15:47:51 -0700227 updateSecondaryTitleFields(-1);
Erik6c255102010-09-29 14:43:00 -0700228 }
229 };
Erik954c8712010-08-06 10:12:34 -0700230
231 // Create an observer so that we can update the views whenever a
232 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700233 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700234 @Override
235 public boolean deliverSelfNotifications() {
236 return true;
237 }
238
239 @Override
240 public void onChange(boolean selfChange) {
241 eventsChanged();
242 }
243 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700244
Michael Chan49701592010-06-30 11:04:03 -0700245 @Override
Erik63cd0532011-01-26 14:16:03 -0800246 protected void onNewIntent(Intent intent) {
247 String action = intent.getAction();
RoboErik4ba19df2011-09-22 11:31:21 -0700248 if (DEBUG)
249 Log.d(TAG, "New intent received " + intent.toString());
250 // Don't change the date if we're just returning to the app's home
251 if (Intent.ACTION_VIEW.equals(action)
252 && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
RoboErik2c2dab42011-09-09 15:50:26 -0700253 long millis = parseViewAction(intent);
254 if (millis == -1) {
255 millis = Utils.timeFromIntentInMillis(intent);
256 }
257 if (millis != -1 && mViewEventId == -1 && mController != null) {
258 Time time = new Time(mTimeZone);
259 time.set(millis);
260 time.normalize(true);
261 mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
262 }
Erik63cd0532011-01-26 14:16:03 -0800263 }
264 }
265
266 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700267 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800268 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
269 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
270 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700271 super.onCreate(icicle);
272
RoboErik6c892a22011-09-08 16:54:04 -0700273 if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
274 mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
275 }
276 // Launch add google account if this is first time and there are no
277 // accounts yet
278 if (mCheckForAccounts
279 && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) {
280
281 mHandler = new QueryHandler(this.getContentResolver());
282 mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] {
283 Calendars._ID
284 }, null, null /* selection args */, null /* sort order */);
285 }
286
Michael Chan83b0fe32010-07-08 16:46:26 -0700287 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700288 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700289
290
Erik954c8712010-08-06 10:12:34 -0700291 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800292 long timeMillis = -1;
293 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800294 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700295 if (icicle != null) {
296 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800297 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700298 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800299 String action = intent.getAction();
300 if (Intent.ACTION_VIEW.equals(action)) {
301 // Open EventInfo later
302 timeMillis = parseViewAction(intent);
303 }
304
305 if (timeMillis == -1) {
306 timeMillis = Utils.timeFromIntentInMillis(intent);
307 }
308 }
309
RoboErik277eb972011-02-24 16:05:04 -0800310 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700311 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
312 }
Erikc5f92d72010-11-11 16:18:34 -0800313 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
314 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700315 t.set(timeMillis);
316
RoboErik8e62ac32011-09-09 10:13:07 -0700317 if (DEBUG) {
318 if (icicle != null && intent != null) {
319 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
320 } else {
321 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
322 }
Erik7b92da22010-09-23 14:55:22 -0700323 }
324
Erikeaafa2b2010-12-23 14:30:37 -0800325 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800326 if (mScale == 0) {
327 mScale = res.getDisplayMetrics().density;
328 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800329 }
330 mHideString = res.getString(R.string.hide_controls);
331 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800332 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800333
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700334 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700335 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700336 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700337 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700338 mShowEventDetailsWithAgenda =
339 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700340 mShowEventInfoFullScreen =
341 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700342
Erik63cd0532011-01-26 14:16:03 -0800343 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800344
Erikbe8191c2010-10-26 16:50:08 -0700345 // setContentView must be called before configureActionBar
346 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700347
348 if (mIsTabletConfig) {
349 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700350 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700351 } else {
352 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
353 }
354
Erikbe8191c2010-10-26 16:50:08 -0700355 // configureActionBar auto-selects the first tab you add, so we need to
356 // call it before we set up our own fragments to make sure it doesn't
357 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700358 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700359
Erik6c255102010-09-29 14:43:00 -0700360 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800361 mMiniMonth = findViewById(R.id.mini_month);
362 mCalendarsList = findViewById(R.id.calendar_list);
363 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700364 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700365
RoboErik3864be02011-07-25 15:56:50 -0700366 // Must register as the first activity because this activity can modify
367 // the list of event handlers in it's handle method. This affects who
368 // the rest of the handlers the controller dispatches to are.
369 mController.registerFirstEventHandler(HANDLER_KEY, this);
370
Erik7b92da22010-09-23 14:55:22 -0700371 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700372
373 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700374 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700375 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700376
Erik954c8712010-08-06 10:12:34 -0700377 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700378 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700379
Michael Chan2c7c8512010-12-10 14:12:57 -0800380 private long parseViewAction(final Intent intent) {
381 long timeMillis = -1;
382 Uri data = intent.getData();
383 if (data != null && data.isHierarchical()) {
384 List<String> path = data.getPathSegments();
385 if (path.size() == 2 && path.get(0).equals("events")) {
386 try {
387 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700388 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700389 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
390 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800391 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800392 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800393 timeMillis = mIntentEventStartMillis;
394 }
395 } catch (NumberFormatException e) {
396 // Ignore if mViewEventId can't be parsed
397 }
398 }
399 }
400 return timeMillis;
401 }
402
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700403 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700404 if (mIsTabletConfig) {
405 createTabs();
406 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700407 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700408 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700409 if (mIsMultipane) {
410 mActionBar.setDisplayOptions(
411 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
412 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700413 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700414 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700415 }
416
417 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700418 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700419 if (mActionBar == null) {
420 Log.w(TAG, "ActionBar is null.");
421 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700422 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700423 mDayTab = mActionBar.newTab();
424 mDayTab.setText(getString(R.string.day_view));
425 mDayTab.setTabListener(this);
426 mActionBar.addTab(mDayTab);
427 mWeekTab = mActionBar.newTab();
428 mWeekTab.setText(getString(R.string.week_view));
429 mWeekTab.setTabListener(this);
430 mActionBar.addTab(mWeekTab);
431 mMonthTab = mActionBar.newTab();
432 mMonthTab.setText(getString(R.string.month_view));
433 mMonthTab.setTabListener(this);
434 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700435 mAgendaTab = mActionBar.newTab();
436 mAgendaTab.setText(getString(R.string.agenda_view));
437 mAgendaTab.setTabListener(this);
438 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700439 }
Erik954c8712010-08-06 10:12:34 -0700440 }
441
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700442 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700443 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700444 mActionBar = getActionBar();
445 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700446 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700447 switch (viewType) {
448 case ViewType.AGENDA:
449 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
450 break;
451 case ViewType.DAY:
452 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
453 break;
454 case ViewType.WEEK:
455 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
456 break;
457 case ViewType.MONTH:
458 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
459 break;
460 default:
461 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
462 break;
463 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700464 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700465 // Clear buttons used in the agenda view
466 private void clearOptionsMenu() {
467 if (mOptionsMenu == null) {
468 return;
469 }
470 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700471 if (cancelItem != null) {
472 cancelItem.setVisible(false);
473 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700474 }
475
Erik954c8712010-08-06 10:12:34 -0700476 @Override
477 protected void onResume() {
478 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700479
480 // Must register as the first activity because this activity can modify
481 // the list of event handlers in it's handle method. This affects who
482 // the rest of the handlers the controller dispatches to are.
483 mController.registerFirstEventHandler(HANDLER_KEY, this);
484
Michael Chanf2cfa202011-08-19 17:58:16 -0700485 mOnSaveInstanceStateCalled = false;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700486 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
487 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700488 if (mUpdateOnResume) {
489 initFragments(mController.getTime(), mController.getViewType(), null);
490 mUpdateOnResume = false;
491 }
RoboErik4eb34322011-08-19 15:47:51 -0700492 updateSecondaryTitleFields(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700493 // Make sure the drop-down menu will get its date updated at midnight
494 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700495 mActionBarMenuSpinnerAdapter.refresh(this);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700496 }
497
RoboErik3b3af612011-02-24 13:42:57 -0800498 if (mControlsMenu != null) {
499 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
500 }
Erikcb811892010-09-28 13:44:19 -0700501 mPaused = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800502
503 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800504 long currentMillis = System.currentTimeMillis();
505 long selectedTime = -1;
506 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
507 selectedTime = currentMillis;
508 }
Michael Chanedecd9a2011-08-24 23:58:48 -0700509 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700510 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
511 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800512 mViewEventId = -1;
513 mIntentEventStartMillis = -1;
514 mIntentEventEndMillis = -1;
515 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700516 }
517
518 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700519 protected void onPause() {
520 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700521
522 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700523 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700524 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700525 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700526 mActionBarMenuSpinnerAdapter.onPause();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700527 }
Erik954c8712010-08-06 10:12:34 -0700528 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700529 if (isFinishing()) {
530 // Stop listening for changes that would require this to be refreshed
531 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
532 prefs.unregisterOnSharedPreferenceChangeListener(this);
533 }
Erik7b92da22010-09-23 14:55:22 -0700534 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700535 if (mController.getViewType() != ViewType.EDIT) {
536 Utils.setDefaultView(this, mController.getViewType());
537 }
Michael Chand6734db2010-07-22 00:48:08 -0700538 }
539
540 @Override
Erik7b92da22010-09-23 14:55:22 -0700541 protected void onUserLeaveHint() {
542 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
543 super.onUserLeaveHint();
544 }
545
546 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700547 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700548 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700549 super.onSaveInstanceState(outState);
550
551 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700552 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800553 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700554 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
555 }
RoboErik6c892a22011-09-08 16:54:04 -0700556 outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts);
Michael Chand6734db2010-07-22 00:48:08 -0700557 }
558
559 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700560 protected void onDestroy() {
561 super.onDestroy();
562
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700563 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700564 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700565 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700566 }
567
Erik7b92da22010-09-23 14:55:22 -0700568 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700569 if (DEBUG) {
570 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
571 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800572 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700573
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700574 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800575 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700576 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700577 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700578
Michael Chan2aeb8d92011-07-10 13:32:09 -0700579 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700580 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800581 mController.registerEventHandler(
582 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700583 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700584 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800585 mMiniMonth.setVisibility(View.GONE);
586 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700587 }
Michael Chan3458a172010-07-13 17:58:21 -0700588
Erikdd95df52010-08-27 09:31:18 -0700589 EventInfo info = null;
590 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700591 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700592 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700593
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700594 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700595 Intent intent = getIntent();
596 Uri data = intent.getData();
597 if (data != null) {
598 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700599 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700600 } catch (NumberFormatException e) {
601 if (DEBUG) {
602 Log.d(TAG, "Create new event");
603 }
604 }
Erik7b92da22010-09-23 14:55:22 -0700605 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
606 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700607 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700608
RoboErika27a8862011-06-23 15:26:23 -0700609 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
610 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700611 info = new EventInfo();
612 if (end != -1) {
613 info.endTime = new Time();
614 info.endTime.set(end);
615 }
616 if (begin != -1) {
617 info.startTime = new Time();
618 info.startTime.set(begin);
619 }
620 info.id = eventId;
621 // We set the viewtype so if the user presses back when they are
622 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700623 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700624 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700625 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700626 } else {
627 mPreviousView = viewType;
628 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700629
Erik63cd0532011-01-26 14:16:03 -0800630 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700631 ft.commit(); // this needs to be after setMainPane()
632
Erikc5f92d72010-11-11 16:18:34 -0800633 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700634 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700635 if (viewType != ViewType.EDIT) {
636 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
637 }
Michael Chan49701592010-06-30 11:04:03 -0700638 }
Erik2051f122010-07-02 13:45:45 -0700639
640 @Override
Erik648c59c2010-08-13 12:49:26 -0700641 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700642 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700643 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700644 } else {
645 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700646 }
647 }
648
649 @Override
Erik2051f122010-07-02 13:45:45 -0700650 public boolean onCreateOptionsMenu(Menu menu) {
651 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700652 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700653 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700654
RoboErike635aec2011-07-15 11:22:13 -0700655 mSearchMenu = menu.findItem(R.id.action_search);
656 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800657 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700658 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800659 mSearchView.setOnQueryTextListener(this);
RoboErik17664072011-08-16 16:22:39 -0700660 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700661 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700662
663 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700664 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700665
RoboErikde20d762011-02-08 17:52:25 -0800666 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700667 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700668 if (mControlsMenu != null) {
669 mControlsMenu.setVisible(false);
670 mControlsMenu.setEnabled(false);
671 }
672 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700673 && (mController.getViewType() == ViewType.MONTH ||
674 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800675 mControlsMenu.setVisible(false);
676 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700677 } else if (mControlsMenu != null){
678 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800679 }
Erik2051f122010-07-02 13:45:45 -0700680 return true;
681 }
Michael Chan3458a172010-07-13 17:58:21 -0700682
683 @Override
684 public boolean onOptionsItemSelected(MenuItem item) {
685 Time t = null;
686 int viewType = ViewType.CURRENT;
687 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700688 case R.id.action_refresh:
689 mController.refreshCalendars();
690 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700691 case R.id.action_today:
692 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800693 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700694 t.setToNow();
695 break;
696 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800697 t = new Time();
698 t.set(mController.getTime());
699 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800700 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800701 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800702 } else {
703 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800704 }
705 mController.sendEventRelatedEvent(
706 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700707 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700708 case R.id.action_select_visible_calendars:
709 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
710 0, 0);
711 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700712 case R.id.action_settings:
713 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
714 return true;
RoboErikde20d762011-02-08 17:52:25 -0800715 case R.id.action_hide_controls:
716 mHideControls = !mHideControls;
717 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800718 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
719 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
720 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
721 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
722 ObjectAnimator.setFrameDelay(0);
723 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800724 return true;
RoboErike635aec2011-07-15 11:22:13 -0700725 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700726 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700727 default:
728 return false;
729 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700730 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700731 return true;
732 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700733
RoboErikb8549562011-02-15 14:25:23 -0800734 /**
735 * Sets the offset of the controls on the right for animating them off/on
736 * screen. ProGuard strips this if it's not in proguard.flags
737 *
738 * @param controlsOffset The current offset in pixels
739 */
740 public void setControlsOffset(int controlsOffset) {
741 mMiniMonth.setTranslationX(controlsOffset);
742 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800743 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800744 mMiniMonthContainer.setLayoutParams(mControlsParams);
745 }
RoboErikde20d762011-02-08 17:52:25 -0800746
Mason Tang8e3d4302010-07-12 17:39:30 -0700747 @Override
748 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700749 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700750 if (mPaused) {
751 mUpdateOnResume = true;
752 } else {
753 initFragments(mController.getTime(), mController.getViewType(), null);
754 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700755 }
756 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700757
Erik63cd0532011-01-26 14:16:03 -0800758 private void setMainPane(
759 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700760 if (mOnSaveInstanceStateCalled) {
761 return;
762 }
Erik7b92da22010-09-23 14:55:22 -0700763 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700764 return;
765 }
766
Michael Chan5756bbc2011-03-02 18:22:07 -0800767 // Remove this when transition to and from month view looks fine.
768 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700769 FragmentManager fragmentManager = getFragmentManager();
770 // Check if our previous view was an Agenda view
771 // TODO remove this if framework ever supports nested fragments
772 if (mCurrentView == ViewType.AGENDA) {
773 // If it was, we need to do some cleanup on it to prevent the
774 // edit/delete buttons from coming back on a rotation.
775 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
776 if (oldFrag instanceof AgendaFragment) {
777 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
778 }
779 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800780
Erik648c59c2010-08-13 12:49:26 -0700781 if (viewType != mCurrentView) {
782 // The rules for this previous view are different than the
783 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700784 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
785 mPreviousView = mCurrentView;
786 }
Erik648c59c2010-08-13 12:49:26 -0700787 mCurrentView = viewType;
788 }
Erik3f348f32010-08-10 13:17:19 -0700789 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700790 Fragment frag = null;
791 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700792 switch (viewType) {
793 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700794 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
795 mActionBar.selectTab(mAgendaTab);
796 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700797 if (mActionBarMenuSpinnerAdapter != null) {
798 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
799 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700800 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700801 break;
802 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700803 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
804 mActionBar.selectTab(mDayTab);
805 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700806 if (mActionBarMenuSpinnerAdapter != null) {
807 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
808 }
Michael Chan75d9b562010-07-26 16:54:25 -0700809 frag = new DayFragment(timeMillis, 1);
810 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700811 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700812 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
813 mActionBar.selectTab(mWeekTab);
814 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700815 if (mActionBarMenuSpinnerAdapter != null) {
816 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
817 }
Michael Chan75d9b562010-07-26 16:54:25 -0700818 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700819 break;
820 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700821 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
822 mActionBar.selectTab(mMonthTab);
823 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700824 if (mActionBarMenuSpinnerAdapter != null) {
825 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
826 }
Erik40bcd102010-11-16 15:46:40 -0800827 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700828 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700829 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700830 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700831 break;
832 default:
Michael Chand6734db2010-07-22 00:48:08 -0700833 throw new IllegalArgumentException(
834 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700835 }
836
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700837 // Update the current view so that the menu can update its look according to the
838 // current view.
839 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
RoboErike11975f2011-09-02 14:00:39 -0700840 mActionBarMenuSpinnerAdapter.setTime(timeMillis);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700841 mActionBarMenuSpinnerAdapter.setMainView(viewType);
842 }
843
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700844
845 // Show date only on tablet configurations in views different than Agenda
846 if (!mIsTabletConfig) {
847 mDateRange.setVisibility(View.GONE);
848 } else if (viewType != ViewType.AGENDA) {
849 mDateRange.setVisibility(View.VISIBLE);
850 } else {
851 mDateRange.setVisibility(View.GONE);
852 }
853
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700854 // Clear unnecessary buttons from the option menu when switching from the agenda view
855 if (viewType != ViewType.AGENDA) {
856 clearOptionsMenu();
857 }
858
Michael Chanab29d9e2010-07-21 06:08:47 -0700859 boolean doCommit = false;
860 if (ft == null) {
861 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700862 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700863 }
864
Michael Chan5756bbc2011-03-02 18:22:07 -0800865 if (doTransition) {
866 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
867 }
868
Michael Chanab29d9e2010-07-21 06:08:47 -0700869 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700870 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700871
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700872 // Show/hide secondary fragment
873
874 if (secFrag != null) {
875 ft.replace(R.id.secondary_pane, secFrag);
876 mSecondaryPane.setVisibility(View.VISIBLE);
877 } else {
878 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700879 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700880 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700881 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700882 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700883 mController.deregisterEventHandler(R.id.secondary_pane);
884 }
885 }
Erik954c8712010-08-06 10:12:34 -0700886 if (DEBUG) {
887 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
888 }
Erik3f348f32010-08-10 13:17:19 -0700889 // If the key is already registered this will replace it
890 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700891 if (secFrag != null) {
892 mController.registerEventHandler(viewId, (EventHandler) secFrag);
893 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700894
895 if (doCommit) {
RoboErik8e62ac32011-09-09 10:13:07 -0700896 if (DEBUG) {
897 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
898 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700899 ft.commit();
900 }
901 }
902
903 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800904 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700905 return;
906 }
907
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700908 final long start = event.startTime.toMillis(false /* use isDst */);
909 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700910 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700911 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700912 } else {
913 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700914 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700915
Erikeaafa2b2010-12-23 14:30:37 -0800916 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800917 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800918 mDateRange.setText(msg);
RoboErik8e62ac32011-09-09 10:13:07 -0700919 updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true)
920 : start);
Erik259b8f92011-01-12 14:01:12 -0800921 if (!TextUtils.equals(oldDate, msg)) {
922 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700923 if (mShowWeekNum && mWeekTextView != null) {
924 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
925 }
Erik259b8f92011-01-12 14:01:12 -0800926 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700927 }
928
RoboErik4eb34322011-08-19 15:47:51 -0700929 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
RoboErik14e82b42011-07-19 09:46:39 -0700930 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800931 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700932 if (visibleMillisSinceEpoch != -1) {
933 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
934 mWeekNum = weekNum;
935 }
936
937 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
938 && mWeekTextView != null) {
939 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
940 mWeekNum);
941 mWeekTextView.setText(weekString);
942 mWeekTextView.setVisibility(View.VISIBLE);
RoboErik4eb34322011-08-19 15:47:51 -0700943 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null
944 && mCurrentView == ViewType.DAY && mIsTabletConfig) {
945 Time time = new Time(mTimeZone);
946 time.set(visibleMillisSinceEpoch);
947 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
948 time.setToNow();
949 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
950 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay,
951 visibleMillisSinceEpoch, this);
952 mWeekTextView.setText(dayString);
953 mWeekTextView.setVisibility(View.VISIBLE);
954 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
RoboErik14e82b42011-07-19 09:46:39 -0700955 mWeekTextView.setVisibility(View.GONE);
956 }
Michael Chanbe686752011-08-23 15:53:35 -0700957
RoboErik14e82b42011-07-19 09:46:39 -0700958 if (mHomeTime != null
959 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
960 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800961 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
962 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700963 time.setToNow();
964 long millis = time.toMillis(true);
965 boolean isDST = time.isDst != 0;
966 int flags = DateUtils.FORMAT_SHOW_TIME;
967 if (DateFormat.is24HourFormat(this)) {
968 flags |= DateUtils.FORMAT_24HOUR;
969 }
970 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800971 String timeString = (new StringBuilder(
972 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
973 TimeZone.getTimeZone(mTimeZone).getDisplayName(
974 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700975 mHomeTime.setText(timeString);
976 mHomeTime.setVisibility(View.VISIBLE);
977 // Update when the minute changes
978 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700979 mHomeTimeUpdater,
980 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700981 } else if (mHomeTime != null) {
982 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700983 }
984 }
985
Erik3f348f32010-08-10 13:17:19 -0700986 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700987 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800988 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700989 }
990
Erik3f348f32010-08-10 13:17:19 -0700991 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700992 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700993 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700994 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -0700995 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
996 mBackToPreviousView = true;
997 } else if (event.viewType != mController.getPreviousViewType()
998 && event.viewType != ViewType.EDIT) {
999 // Clear the flag is change to a different view type
1000 mBackToPreviousView = false;
1001 }
1002
Erik63cd0532011-01-26 14:16:03 -08001003 setMainPane(
1004 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -08001005 if (mSearchView != null) {
1006 mSearchView.clearFocus();
1007 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001008
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001009 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001010 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001011 // hide minimonth and calendar frag
1012 mShowSideViews = false;
1013 if (mControlsMenu != null) {
1014 mControlsMenu.setVisible(false);
1015 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -08001016
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001017 if (!mHideControls) {
1018 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1019 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
1020 slideAnimation.addListener(mSlideAnimationDoneListener);
1021 slideAnimation.setDuration(220);
1022 ObjectAnimator.setFrameDelay(0);
1023 slideAnimation.start();
1024 }
1025 } else {
1026 mMiniMonth.setVisibility(View.GONE);
1027 mCalendarsList.setVisibility(View.GONE);
1028 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -08001029 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001030 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001031 // show minimonth and calendar frag
1032 mShowSideViews = true;
1033 mMiniMonth.setVisibility(View.VISIBLE);
1034 mCalendarsList.setVisibility(View.VISIBLE);
1035 mMiniMonthContainer.setVisibility(View.VISIBLE);
1036 if (mControlsMenu != null) {
1037 mControlsMenu.setVisible(true);
1038 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001039 if (!mHideControls &&
1040 (mController.getPreviousViewType() == ViewType.MONTH ||
1041 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001042 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1043 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
1044 slideAnimation.setDuration(220);
1045 ObjectAnimator.setFrameDelay(0);
1046 slideAnimation.start();
1047 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001048 }
RoboErikde20d762011-02-08 17:52:25 -08001049 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001050 }
RoboErik8e62ac32011-09-09 10:13:07 -07001051 displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
1052 : event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -07001053 if (!mIsTabletConfig) {
1054 mActionBarMenuSpinnerAdapter.setTime(displayTime);
1055 }
Michael Chan71d08832010-08-25 18:28:59 -07001056 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001057
1058 // If in Agenda view and "show_event_details_with_agenda" is "true",
1059 // do not create the event info fragment here, it will be created by the Agenda
1060 // fragment
1061
RoboErikd6c93ce2011-07-22 17:54:40 -07001062 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -07001063 if (event.startTime != null && event.endTime != null) {
1064 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
1065 event.id, ViewType.AGENDA);
1066 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001067 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1068 event.selectedTime, event.id, ViewType.AGENDA);
1069 }
1070 } else {
RoboErik796db762011-09-12 14:56:23 -07001071 // TODO Fix the temp hack below: && mCurrentView !=
1072 // ViewType.AGENDA
1073 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
1074 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
RoboErik20911fa2011-09-13 17:07:47 -07001075 event.selectedTime, -1, ViewType.CURRENT);
RoboErik796db762011-09-12 14:56:23 -07001076 }
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001077 if (mShowEventInfoFullScreen) {
1078 // start event info as activity
1079 Intent intent = new Intent(Intent.ACTION_VIEW);
1080 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
1081 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -07001082 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001083 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
1084 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -07001085 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
1086 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001087 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
1088 startActivity(intent);
1089 } else {
1090 // start event info as a dialog
1091 EventInfoFragment fragment = new EventInfoFragment(this,
1092 event.id, event.startTime.toMillis(false),
1093 event.endTime.toMillis(false), (int) event.extraLong, true);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001094 fragment.setDialogParams(event.x, event.y);
1095 FragmentManager fm = getFragmentManager();
1096 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -07001097 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001098 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
RoboErika459d0b2011-08-15 13:46:36 -07001099 int oldId;
1100 if (fOld != null && fOld.isAdded() && (oldId = fOld.getId()) != 0) {
1101 ft.replace(oldId, fragment, EVENT_INFO_FRAGMENT_TAG);
1102 } else {
1103 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001104 }
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001105 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001106 }
Erik63cd0532011-01-26 14:16:03 -08001107 }
RoboErik14e82b42011-07-19 09:46:39 -07001108 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001109 } else if (event.eventType == EventType.UPDATE_TITLE) {
1110 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001111 if (!mIsTabletConfig) {
RoboErike11975f2011-09-02 14:00:39 -07001112 mActionBarMenuSpinnerAdapter.setTime(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001113 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001114 }
RoboErik4eb34322011-08-19 15:47:51 -07001115 updateSecondaryTitleFields(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001116 }
1117
Michael Chan2aeb8d92011-07-10 13:32:09 -07001118 // Needs to be in proguard whitelist
1119 // Specified as listener via android:onClick in a layout xml
1120 public void handleSelectSyncedCalendarsClicked(View v) {
1121 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1122 CalendarController.EXTRA_GOTO_TIME, null,
1123 null);
1124 }
1125
Erik3f348f32010-08-10 13:17:19 -07001126 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001127 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001128 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001129 }
1130
Erik3f348f32010-08-10 13:17:19 -07001131 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001132 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001133 return false;
1134 }
1135
1136 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001137 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001138 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001139 Utils.tardis();
1140 }
RoboErika0954942011-07-27 17:43:14 -07001141 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001142 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001143 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001144 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001145 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001146
1147 @Override
1148 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001149 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001150 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001151 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001152 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001153 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001154 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001155 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001156 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1157 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001158 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001159 Log.w(TAG, "TabSelected event from unknown tab: "
1160 + (tab == null ? "null" : tab.getText()));
1161 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001162 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001163 }
1164 }
1165
1166 @Override
1167 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1168 }
1169
1170 @Override
1171 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1172 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001173
1174
1175 @Override
1176 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1177 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001178 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001179 if (mCurrentView != ViewType.DAY) {
1180 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1181 }
1182 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001183 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001184 if (mCurrentView != ViewType.WEEK) {
1185 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1186 }
1187 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001188 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001189 if (mCurrentView != ViewType.MONTH) {
1190 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1191 }
1192 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001193 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001194 if (mCurrentView != ViewType.AGENDA) {
1195 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1196 }
1197 break;
1198 default:
1199 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1200 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1201 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1202 " Agenda:" + mAgendaTab);
1203 break;
1204 }
1205 return false;
1206 }
RoboErik17664072011-08-16 16:22:39 -07001207
1208 @Override
1209 public boolean onSuggestionSelect(int position) {
1210 return false;
1211 }
1212
1213 @Override
1214 public boolean onSuggestionClick(int position) {
1215 mSearchMenu.collapseActionView();
1216 return false;
1217 }
RoboErikc6e314f2011-08-17 10:55:03 -07001218
1219 @Override
1220 public boolean onSearchRequested() {
1221 if (mSearchMenu != null) {
1222 mSearchMenu.expandActionView();
1223 }
1224 return false;
1225 }
Michael Chan49701592010-06-30 11:04:03 -07001226}