blob: 35603c3ff48307bfbf7a661b9918b4b53f74687e [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 Katzenelson7ef29812011-10-25 18:00:50 -0700128 private boolean mShowEventInfoFullScreenAgenda;
Isaac Katzenelson998e66e2011-11-08 11:25:55 -0800129 private boolean mShowEventInfoFullScreen;
RoboErik14e82b42011-07-19 09:46:39 -0700130 private int mWeekNum;
Erik6c255102010-09-29 14:43:00 -0700131
Michael Chan2c7c8512010-12-10 14:12:57 -0800132 private long mViewEventId = -1;
133 private long mIntentEventStartMillis = -1;
134 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800135 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800136
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700137 // Action bar and Navigation bar (left side of Action bar)
138 private ActionBar mActionBar;
139 private ActionBar.Tab mDayTab;
140 private ActionBar.Tab mWeekTab;
141 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700142 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800143 private SearchView mSearchView;
RoboErike635aec2011-07-15 11:22:13 -0700144 private MenuItem mSearchMenu;
RoboErikde20d762011-02-08 17:52:25 -0800145 private MenuItem mControlsMenu;
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700146 private Menu mOptionsMenu;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700147 private CalendarViewAdapter mActionBarMenuSpinnerAdapter;
RoboErik6c892a22011-09-08 16:54:04 -0700148 private QueryHandler mHandler;
149 private boolean mCheckForAccounts = true;
RoboErikde20d762011-02-08 17:52:25 -0800150
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700151 private String mHideString;
152 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800153
RoboErikb8549562011-02-15 14:25:23 -0800154 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800155 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
156
157 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
158
159 @Override
160 public void onAnimationCancel(Animator animation) {
161 }
162
163 @Override
164 public void onAnimationEnd(android.animation.Animator animation) {
165 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
166 mMiniMonth.setVisibility(visibility);
167 mCalendarsList.setVisibility(visibility);
168 mMiniMonthContainer.setVisibility(visibility);
169 }
170
171 @Override
172 public void onAnimationRepeat(android.animation.Animator animation) {
173 }
174
175 @Override
176 public void onAnimationStart(android.animation.Animator animation) {
177 }
178 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700179
RoboErik6c892a22011-09-08 16:54:04 -0700180 private class QueryHandler extends AsyncQueryHandler {
181 public QueryHandler(ContentResolver cr) {
182 super(cr);
183 }
184
185 @Override
186 protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
187 mCheckForAccounts = false;
188 // If the query didn't return a cursor for some reason return
189 if (cursor == null || cursor.getCount() > 0 || isFinishing()) {
190 return;
191 }
192 Bundle options = new Bundle();
193 options.putCharSequence("introMessage",
194 getResources().getString(R.string.create_an_account_desc));
195 options.putBoolean("allowSkip", true);
196
197 AccountManager am = AccountManager.get(AllInOneActivity.this);
198 am.addAccount("com.google", CalendarContract.AUTHORITY, null, options,
199 AllInOneActivity.this,
200 new AccountManagerCallback<Bundle>() {
201 @Override
202 public void run(AccountManagerFuture<Bundle> future) {
203 if (future.isCancelled()) {
204 return;
205 }
206 try {
207 Bundle result = future.getResult();
208 boolean setupSkipped = result.getBoolean("setupSkipped");
209
210 if (setupSkipped) {
211 Utils.setSharedPreference(AllInOneActivity.this,
212 GeneralPreferences.KEY_SKIP_SETUP, true);
213 }
214
215 } catch (OperationCanceledException ignore) {
216 // The account creation process was canceled
217 } catch (IOException ignore) {
218 } catch (AuthenticatorException ignore) {
219 }
220 }
221 }, null);
222 }
223 }
224
Erik6c255102010-09-29 14:43:00 -0700225 private Runnable mHomeTimeUpdater = new Runnable() {
226 @Override
227 public void run() {
RoboErik4eb34322011-08-19 15:47:51 -0700228 updateSecondaryTitleFields(-1);
Erik6c255102010-09-29 14:43:00 -0700229 }
230 };
Erik954c8712010-08-06 10:12:34 -0700231
232 // Create an observer so that we can update the views whenever a
233 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700234 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700235 @Override
236 public boolean deliverSelfNotifications() {
237 return true;
238 }
239
240 @Override
241 public void onChange(boolean selfChange) {
242 eventsChanged();
243 }
244 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700245
Michael Chan49701592010-06-30 11:04:03 -0700246 @Override
Erik63cd0532011-01-26 14:16:03 -0800247 protected void onNewIntent(Intent intent) {
248 String action = intent.getAction();
RoboErik4ba19df2011-09-22 11:31:21 -0700249 if (DEBUG)
250 Log.d(TAG, "New intent received " + intent.toString());
251 // Don't change the date if we're just returning to the app's home
252 if (Intent.ACTION_VIEW.equals(action)
253 && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
RoboErik2c2dab42011-09-09 15:50:26 -0700254 long millis = parseViewAction(intent);
255 if (millis == -1) {
256 millis = Utils.timeFromIntentInMillis(intent);
257 }
258 if (millis != -1 && mViewEventId == -1 && mController != null) {
259 Time time = new Time(mTimeZone);
260 time.set(millis);
261 time.normalize(true);
262 mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
263 }
Erik63cd0532011-01-26 14:16:03 -0800264 }
265 }
266
267 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700268 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800269 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
270 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
271 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700272 super.onCreate(icicle);
273
RoboErik6c892a22011-09-08 16:54:04 -0700274 if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
275 mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
276 }
277 // Launch add google account if this is first time and there are no
278 // accounts yet
279 if (mCheckForAccounts
280 && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) {
281
282 mHandler = new QueryHandler(this.getContentResolver());
283 mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] {
284 Calendars._ID
285 }, null, null /* selection args */, null /* sort order */);
286 }
287
Michael Chan83b0fe32010-07-08 16:46:26 -0700288 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700289 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700290
291
Erik954c8712010-08-06 10:12:34 -0700292 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800293 long timeMillis = -1;
294 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800295 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700296 if (icicle != null) {
297 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800298 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700299 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800300 String action = intent.getAction();
301 if (Intent.ACTION_VIEW.equals(action)) {
302 // Open EventInfo later
303 timeMillis = parseViewAction(intent);
304 }
305
306 if (timeMillis == -1) {
307 timeMillis = Utils.timeFromIntentInMillis(intent);
308 }
309 }
310
RoboErik277eb972011-02-24 16:05:04 -0800311 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700312 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
313 }
Erikc5f92d72010-11-11 16:18:34 -0800314 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
315 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700316 t.set(timeMillis);
317
RoboErik8e62ac32011-09-09 10:13:07 -0700318 if (DEBUG) {
319 if (icicle != null && intent != null) {
320 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
321 } else {
322 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
323 }
Erik7b92da22010-09-23 14:55:22 -0700324 }
325
Erikeaafa2b2010-12-23 14:30:37 -0800326 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800327 if (mScale == 0) {
328 mScale = res.getDisplayMetrics().density;
329 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800330 }
331 mHideString = res.getString(R.string.hide_controls);
332 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800333 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800334
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700335 mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700336 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700337 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700338 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700339 mShowEventDetailsWithAgenda =
340 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson7ef29812011-10-25 18:00:50 -0700341 mShowEventInfoFullScreenAgenda =
342 Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen);
Isaac Katzenelson998e66e2011-11-08 11:25:55 -0800343 mShowEventInfoFullScreen =
344 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700345
Erik63cd0532011-01-26 14:16:03 -0800346 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800347
Erikbe8191c2010-10-26 16:50:08 -0700348 // setContentView must be called before configureActionBar
349 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700350
351 if (mIsTabletConfig) {
352 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700353 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700354 } else {
355 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
356 }
357
Erikbe8191c2010-10-26 16:50:08 -0700358 // configureActionBar auto-selects the first tab you add, so we need to
359 // call it before we set up our own fragments to make sure it doesn't
360 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700361 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700362
Erik6c255102010-09-29 14:43:00 -0700363 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800364 mMiniMonth = findViewById(R.id.mini_month);
365 mCalendarsList = findViewById(R.id.calendar_list);
366 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700367 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700368
RoboErik3864be02011-07-25 15:56:50 -0700369 // Must register as the first activity because this activity can modify
370 // the list of event handlers in it's handle method. This affects who
371 // the rest of the handlers the controller dispatches to are.
372 mController.registerFirstEventHandler(HANDLER_KEY, this);
373
Erik7b92da22010-09-23 14:55:22 -0700374 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700375
376 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700377 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700378 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700379
Erik954c8712010-08-06 10:12:34 -0700380 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700381 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700382
Michael Chan2c7c8512010-12-10 14:12:57 -0800383 private long parseViewAction(final Intent intent) {
384 long timeMillis = -1;
385 Uri data = intent.getData();
386 if (data != null && data.isHierarchical()) {
387 List<String> path = data.getPathSegments();
388 if (path.size() == 2 && path.get(0).equals("events")) {
389 try {
390 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700391 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700392 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
393 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800394 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800395 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800396 timeMillis = mIntentEventStartMillis;
397 }
398 } catch (NumberFormatException e) {
399 // Ignore if mViewEventId can't be parsed
400 }
401 }
402 }
403 return timeMillis;
404 }
405
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700406 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700407 if (mIsTabletConfig) {
408 createTabs();
409 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700410 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700411 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700412 if (mIsMultipane) {
413 mActionBar.setDisplayOptions(
414 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
415 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700416 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700417 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700418 }
419
420 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700421 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700422 if (mActionBar == null) {
423 Log.w(TAG, "ActionBar is null.");
424 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700425 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700426 mDayTab = mActionBar.newTab();
427 mDayTab.setText(getString(R.string.day_view));
428 mDayTab.setTabListener(this);
429 mActionBar.addTab(mDayTab);
430 mWeekTab = mActionBar.newTab();
431 mWeekTab.setText(getString(R.string.week_view));
432 mWeekTab.setTabListener(this);
433 mActionBar.addTab(mWeekTab);
434 mMonthTab = mActionBar.newTab();
435 mMonthTab.setText(getString(R.string.month_view));
436 mMonthTab.setTabListener(this);
437 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700438 mAgendaTab = mActionBar.newTab();
439 mAgendaTab.setText(getString(R.string.agenda_view));
440 mAgendaTab.setTabListener(this);
441 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700442 }
Erik954c8712010-08-06 10:12:34 -0700443 }
444
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700445 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700446 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700447 mActionBar = getActionBar();
448 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700449 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700450 switch (viewType) {
451 case ViewType.AGENDA:
452 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
453 break;
454 case ViewType.DAY:
455 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
456 break;
457 case ViewType.WEEK:
458 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
459 break;
460 case ViewType.MONTH:
461 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
462 break;
463 default:
464 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
465 break;
466 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700467 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700468 // Clear buttons used in the agenda view
469 private void clearOptionsMenu() {
470 if (mOptionsMenu == null) {
471 return;
472 }
473 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700474 if (cancelItem != null) {
475 cancelItem.setVisible(false);
476 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700477 }
478
Erik954c8712010-08-06 10:12:34 -0700479 @Override
480 protected void onResume() {
481 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700482
483 // Must register as the first activity because this activity can modify
484 // the list of event handlers in it's handle method. This affects who
485 // the rest of the handlers the controller dispatches to are.
486 mController.registerFirstEventHandler(HANDLER_KEY, this);
487
Michael Chanf2cfa202011-08-19 17:58:16 -0700488 mOnSaveInstanceStateCalled = false;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700489 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
490 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700491 if (mUpdateOnResume) {
492 initFragments(mController.getTime(), mController.getViewType(), null);
493 mUpdateOnResume = false;
494 }
RoboErikc8e0f212011-10-13 17:57:39 -0700495 Time t = new Time(mTimeZone);
496 t.set(mController.getTime());
497 mController.sendEvent(this, EventType.UPDATE_TITLE, t, t, -1, ViewType.CURRENT,
498 mController.getDateFlags(), null, null);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700499 // Make sure the drop-down menu will get its date updated at midnight
500 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700501 mActionBarMenuSpinnerAdapter.refresh(this);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700502 }
503
RoboErik3b3af612011-02-24 13:42:57 -0800504 if (mControlsMenu != null) {
505 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
506 }
Erikcb811892010-09-28 13:44:19 -0700507 mPaused = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800508
509 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800510 long currentMillis = System.currentTimeMillis();
511 long selectedTime = -1;
512 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
513 selectedTime = currentMillis;
514 }
Michael Chanedecd9a2011-08-24 23:58:48 -0700515 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700516 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
517 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800518 mViewEventId = -1;
519 mIntentEventStartMillis = -1;
520 mIntentEventEndMillis = -1;
521 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700522 }
523
524 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700525 protected void onPause() {
526 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700527
528 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700529 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700530 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700531 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700532 mActionBarMenuSpinnerAdapter.onPause();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700533 }
Erik954c8712010-08-06 10:12:34 -0700534 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700535 if (isFinishing()) {
536 // Stop listening for changes that would require this to be refreshed
537 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
538 prefs.unregisterOnSharedPreferenceChangeListener(this);
539 }
Erik7b92da22010-09-23 14:55:22 -0700540 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700541 if (mController.getViewType() != ViewType.EDIT) {
542 Utils.setDefaultView(this, mController.getViewType());
543 }
Michael Chand6734db2010-07-22 00:48:08 -0700544 }
545
546 @Override
Erik7b92da22010-09-23 14:55:22 -0700547 protected void onUserLeaveHint() {
548 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
549 super.onUserLeaveHint();
550 }
551
552 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700553 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700554 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700555 super.onSaveInstanceState(outState);
556
557 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700558 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800559 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700560 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
561 }
RoboErik6c892a22011-09-08 16:54:04 -0700562 outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts);
Michael Chand6734db2010-07-22 00:48:08 -0700563 }
564
565 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700566 protected void onDestroy() {
567 super.onDestroy();
568
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700569 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700570 prefs.unregisterOnSharedPreferenceChangeListener(this);
Paul Westbrook89af1892011-10-05 18:15:00 -0700571
Paul Westbrook61310b72011-10-07 15:43:00 -0700572 mController.deregisterAllEventHandlers();
Paul Westbrook89af1892011-10-05 18:15:00 -0700573
Eriked61b482010-08-13 13:59:50 -0700574 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700575 }
576
Erik7b92da22010-09-23 14:55:22 -0700577 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700578 if (DEBUG) {
579 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
580 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800581 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700582
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700583 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800584 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700585 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700586 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700587
Michael Chan2aeb8d92011-07-10 13:32:09 -0700588 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700589 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800590 mController.registerEventHandler(
591 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700592 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700593 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800594 mMiniMonth.setVisibility(View.GONE);
595 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700596 }
Michael Chan3458a172010-07-13 17:58:21 -0700597
Erikdd95df52010-08-27 09:31:18 -0700598 EventInfo info = null;
599 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700600 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700601 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700602
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700603 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700604 Intent intent = getIntent();
605 Uri data = intent.getData();
606 if (data != null) {
607 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700608 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700609 } catch (NumberFormatException e) {
610 if (DEBUG) {
611 Log.d(TAG, "Create new event");
612 }
613 }
Erik7b92da22010-09-23 14:55:22 -0700614 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
615 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700616 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700617
RoboErika27a8862011-06-23 15:26:23 -0700618 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
619 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700620 info = new EventInfo();
621 if (end != -1) {
622 info.endTime = new Time();
623 info.endTime.set(end);
624 }
625 if (begin != -1) {
626 info.startTime = new Time();
627 info.startTime.set(begin);
628 }
629 info.id = eventId;
630 // We set the viewtype so if the user presses back when they are
631 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700632 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700633 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700634 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700635 } else {
636 mPreviousView = viewType;
637 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700638
Erik63cd0532011-01-26 14:16:03 -0800639 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700640 ft.commit(); // this needs to be after setMainPane()
641
Erikc5f92d72010-11-11 16:18:34 -0800642 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700643 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700644 if (viewType != ViewType.EDIT) {
645 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
646 }
Michael Chan49701592010-06-30 11:04:03 -0700647 }
Erik2051f122010-07-02 13:45:45 -0700648
649 @Override
Erik648c59c2010-08-13 12:49:26 -0700650 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700651 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700652 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700653 } else {
654 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700655 }
656 }
657
658 @Override
Erik2051f122010-07-02 13:45:45 -0700659 public boolean onCreateOptionsMenu(Menu menu) {
660 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700661 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700662 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700663
RoboErike635aec2011-07-15 11:22:13 -0700664 mSearchMenu = menu.findItem(R.id.action_search);
665 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800666 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700667 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800668 mSearchView.setOnQueryTextListener(this);
RoboErik17664072011-08-16 16:22:39 -0700669 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700670 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700671
672 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700673 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700674
RoboErikde20d762011-02-08 17:52:25 -0800675 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700676 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700677 if (mControlsMenu != null) {
678 mControlsMenu.setVisible(false);
679 mControlsMenu.setEnabled(false);
680 }
681 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700682 && (mController.getViewType() == ViewType.MONTH ||
683 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800684 mControlsMenu.setVisible(false);
685 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700686 } else if (mControlsMenu != null){
687 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800688 }
Erik2051f122010-07-02 13:45:45 -0700689 return true;
690 }
Michael Chan3458a172010-07-13 17:58:21 -0700691
692 @Override
693 public boolean onOptionsItemSelected(MenuItem item) {
694 Time t = null;
695 int viewType = ViewType.CURRENT;
RoboErik5b872522011-10-03 17:24:50 -0700696 long extras = CalendarController.EXTRA_GOTO_TIME;
Michael Chan3458a172010-07-13 17:58:21 -0700697 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700698 case R.id.action_refresh:
699 mController.refreshCalendars();
700 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700701 case R.id.action_today:
702 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800703 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700704 t.setToNow();
RoboErik5b872522011-10-03 17:24:50 -0700705 extras |= CalendarController.EXTRA_GOTO_TODAY;
Michael Chan3458a172010-07-13 17:58:21 -0700706 break;
707 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800708 t = new Time();
709 t.set(mController.getTime());
Isaac Katzenelson576521e2011-10-12 16:19:40 -0700710 if (t.minute > 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800711 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800712 t.minute = 0;
Isaac Katzenelson576521e2011-10-12 16:19:40 -0700713 } else if (t.minute > 0 && t.minute < 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800714 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800715 }
716 mController.sendEventRelatedEvent(
717 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700718 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700719 case R.id.action_select_visible_calendars:
720 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
721 0, 0);
722 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700723 case R.id.action_settings:
724 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
725 return true;
RoboErikde20d762011-02-08 17:52:25 -0800726 case R.id.action_hide_controls:
727 mHideControls = !mHideControls;
728 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800729 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
730 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
731 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
732 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
733 ObjectAnimator.setFrameDelay(0);
734 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800735 return true;
RoboErike635aec2011-07-15 11:22:13 -0700736 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700737 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700738 default:
739 return false;
740 }
RoboErik5b872522011-10-03 17:24:50 -0700741 mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
Michael Chan3458a172010-07-13 17:58:21 -0700742 return true;
743 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700744
RoboErikb8549562011-02-15 14:25:23 -0800745 /**
746 * Sets the offset of the controls on the right for animating them off/on
747 * screen. ProGuard strips this if it's not in proguard.flags
748 *
749 * @param controlsOffset The current offset in pixels
750 */
751 public void setControlsOffset(int controlsOffset) {
752 mMiniMonth.setTranslationX(controlsOffset);
753 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800754 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800755 mMiniMonthContainer.setLayoutParams(mControlsParams);
756 }
RoboErikde20d762011-02-08 17:52:25 -0800757
Mason Tang8e3d4302010-07-12 17:39:30 -0700758 @Override
759 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700760 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700761 if (mPaused) {
762 mUpdateOnResume = true;
763 } else {
764 initFragments(mController.getTime(), mController.getViewType(), null);
765 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700766 }
767 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700768
Erik63cd0532011-01-26 14:16:03 -0800769 private void setMainPane(
770 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700771 if (mOnSaveInstanceStateCalled) {
772 return;
773 }
Erik7b92da22010-09-23 14:55:22 -0700774 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700775 return;
776 }
777
Michael Chan5756bbc2011-03-02 18:22:07 -0800778 // Remove this when transition to and from month view looks fine.
779 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700780 FragmentManager fragmentManager = getFragmentManager();
781 // Check if our previous view was an Agenda view
782 // TODO remove this if framework ever supports nested fragments
783 if (mCurrentView == ViewType.AGENDA) {
784 // If it was, we need to do some cleanup on it to prevent the
785 // edit/delete buttons from coming back on a rotation.
786 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
787 if (oldFrag instanceof AgendaFragment) {
788 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
789 }
790 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800791
Erik648c59c2010-08-13 12:49:26 -0700792 if (viewType != mCurrentView) {
793 // The rules for this previous view are different than the
794 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700795 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
796 mPreviousView = mCurrentView;
797 }
Erik648c59c2010-08-13 12:49:26 -0700798 mCurrentView = viewType;
799 }
Erik3f348f32010-08-10 13:17:19 -0700800 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700801 Fragment frag = null;
802 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700803 switch (viewType) {
804 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700805 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
806 mActionBar.selectTab(mAgendaTab);
807 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700808 if (mActionBarMenuSpinnerAdapter != null) {
809 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
810 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700811 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700812 break;
813 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700814 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
815 mActionBar.selectTab(mDayTab);
816 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700817 if (mActionBarMenuSpinnerAdapter != null) {
818 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
819 }
Michael Chan75d9b562010-07-26 16:54:25 -0700820 frag = new DayFragment(timeMillis, 1);
821 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700822 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700823 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
824 mActionBar.selectTab(mWeekTab);
825 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700826 if (mActionBarMenuSpinnerAdapter != null) {
827 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
828 }
Michael Chan75d9b562010-07-26 16:54:25 -0700829 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700830 break;
831 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700832 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
833 mActionBar.selectTab(mMonthTab);
834 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700835 if (mActionBarMenuSpinnerAdapter != null) {
836 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
837 }
Erik40bcd102010-11-16 15:46:40 -0800838 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700839 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700840 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700841 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700842 break;
843 default:
Michael Chand6734db2010-07-22 00:48:08 -0700844 throw new IllegalArgumentException(
845 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700846 }
847
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700848 // Update the current view so that the menu can update its look according to the
849 // current view.
850 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
RoboErike11975f2011-09-02 14:00:39 -0700851 mActionBarMenuSpinnerAdapter.setTime(timeMillis);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700852 mActionBarMenuSpinnerAdapter.setMainView(viewType);
853 }
854
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700855
856 // Show date only on tablet configurations in views different than Agenda
857 if (!mIsTabletConfig) {
858 mDateRange.setVisibility(View.GONE);
859 } else if (viewType != ViewType.AGENDA) {
860 mDateRange.setVisibility(View.VISIBLE);
861 } else {
862 mDateRange.setVisibility(View.GONE);
863 }
864
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700865 // Clear unnecessary buttons from the option menu when switching from the agenda view
866 if (viewType != ViewType.AGENDA) {
867 clearOptionsMenu();
868 }
869
Michael Chanab29d9e2010-07-21 06:08:47 -0700870 boolean doCommit = false;
871 if (ft == null) {
872 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700873 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700874 }
875
Michael Chan5756bbc2011-03-02 18:22:07 -0800876 if (doTransition) {
877 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
878 }
879
Michael Chanab29d9e2010-07-21 06:08:47 -0700880 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700881 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700882
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700883 // Show/hide secondary fragment
884
885 if (secFrag != null) {
886 ft.replace(R.id.secondary_pane, secFrag);
887 mSecondaryPane.setVisibility(View.VISIBLE);
888 } else {
889 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700890 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700891 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700892 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700893 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700894 mController.deregisterEventHandler(R.id.secondary_pane);
895 }
896 }
Erik954c8712010-08-06 10:12:34 -0700897 if (DEBUG) {
898 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
899 }
Erik3f348f32010-08-10 13:17:19 -0700900 // If the key is already registered this will replace it
901 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700902 if (secFrag != null) {
903 mController.registerEventHandler(viewId, (EventHandler) secFrag);
904 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700905
906 if (doCommit) {
RoboErik8e62ac32011-09-09 10:13:07 -0700907 if (DEBUG) {
908 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
909 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700910 ft.commit();
911 }
912 }
913
914 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800915 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700916 return;
917 }
918
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700919 final long start = event.startTime.toMillis(false /* use isDst */);
920 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700921 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700922 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700923 } else {
924 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700925 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700926
Erikeaafa2b2010-12-23 14:30:37 -0800927 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800928 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800929 mDateRange.setText(msg);
RoboErik8e62ac32011-09-09 10:13:07 -0700930 updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true)
931 : start);
Erik259b8f92011-01-12 14:01:12 -0800932 if (!TextUtils.equals(oldDate, msg)) {
933 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700934 if (mShowWeekNum && mWeekTextView != null) {
935 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
936 }
Erik259b8f92011-01-12 14:01:12 -0800937 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700938 }
939
RoboErik4eb34322011-08-19 15:47:51 -0700940 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
RoboErik14e82b42011-07-19 09:46:39 -0700941 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800942 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700943 if (visibleMillisSinceEpoch != -1) {
944 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
945 mWeekNum = weekNum;
946 }
947
948 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
949 && mWeekTextView != null) {
950 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
951 mWeekNum);
952 mWeekTextView.setText(weekString);
953 mWeekTextView.setVisibility(View.VISIBLE);
RoboErik4eb34322011-08-19 15:47:51 -0700954 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null
955 && mCurrentView == ViewType.DAY && mIsTabletConfig) {
956 Time time = new Time(mTimeZone);
957 time.set(visibleMillisSinceEpoch);
958 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
959 time.setToNow();
960 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
961 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay,
962 visibleMillisSinceEpoch, this);
963 mWeekTextView.setText(dayString);
964 mWeekTextView.setVisibility(View.VISIBLE);
965 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
RoboErik14e82b42011-07-19 09:46:39 -0700966 mWeekTextView.setVisibility(View.GONE);
967 }
Michael Chanbe686752011-08-23 15:53:35 -0700968
RoboErik14e82b42011-07-19 09:46:39 -0700969 if (mHomeTime != null
970 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
971 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800972 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
973 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700974 time.setToNow();
975 long millis = time.toMillis(true);
976 boolean isDST = time.isDst != 0;
977 int flags = DateUtils.FORMAT_SHOW_TIME;
978 if (DateFormat.is24HourFormat(this)) {
979 flags |= DateUtils.FORMAT_24HOUR;
980 }
981 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800982 String timeString = (new StringBuilder(
983 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
984 TimeZone.getTimeZone(mTimeZone).getDisplayName(
985 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700986 mHomeTime.setText(timeString);
987 mHomeTime.setVisibility(View.VISIBLE);
988 // Update when the minute changes
989 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700990 mHomeTimeUpdater,
991 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700992 } else if (mHomeTime != null) {
993 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700994 }
995 }
996
Erik3f348f32010-08-10 13:17:19 -0700997 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700998 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800999 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -07001000 }
1001
Erik3f348f32010-08-10 13:17:19 -07001002 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001003 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -07001004 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -07001005 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -07001006 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
1007 mBackToPreviousView = true;
1008 } else if (event.viewType != mController.getPreviousViewType()
1009 && event.viewType != ViewType.EDIT) {
1010 // Clear the flag is change to a different view type
1011 mBackToPreviousView = false;
1012 }
1013
Erik63cd0532011-01-26 14:16:03 -08001014 setMainPane(
1015 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -08001016 if (mSearchView != null) {
1017 mSearchView.clearFocus();
1018 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001019
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001020 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001021 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001022 // hide minimonth and calendar frag
1023 mShowSideViews = false;
1024 if (mControlsMenu != null) {
1025 mControlsMenu.setVisible(false);
1026 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -08001027
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001028 if (!mHideControls) {
1029 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1030 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
1031 slideAnimation.addListener(mSlideAnimationDoneListener);
1032 slideAnimation.setDuration(220);
1033 ObjectAnimator.setFrameDelay(0);
1034 slideAnimation.start();
1035 }
1036 } else {
1037 mMiniMonth.setVisibility(View.GONE);
1038 mCalendarsList.setVisibility(View.GONE);
1039 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -08001040 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001041 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001042 // show minimonth and calendar frag
1043 mShowSideViews = true;
1044 mMiniMonth.setVisibility(View.VISIBLE);
1045 mCalendarsList.setVisibility(View.VISIBLE);
1046 mMiniMonthContainer.setVisibility(View.VISIBLE);
1047 if (mControlsMenu != null) {
1048 mControlsMenu.setVisible(true);
1049 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001050 if (!mHideControls &&
1051 (mController.getPreviousViewType() == ViewType.MONTH ||
1052 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001053 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1054 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
1055 slideAnimation.setDuration(220);
1056 ObjectAnimator.setFrameDelay(0);
1057 slideAnimation.start();
1058 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001059 }
RoboErikde20d762011-02-08 17:52:25 -08001060 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001061 }
RoboErik8e62ac32011-09-09 10:13:07 -07001062 displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
1063 : event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -07001064 if (!mIsTabletConfig) {
1065 mActionBarMenuSpinnerAdapter.setTime(displayTime);
1066 }
Michael Chan71d08832010-08-25 18:28:59 -07001067 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001068
1069 // If in Agenda view and "show_event_details_with_agenda" is "true",
1070 // do not create the event info fragment here, it will be created by the Agenda
1071 // fragment
1072
RoboErikd6c93ce2011-07-22 17:54:40 -07001073 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -07001074 if (event.startTime != null && event.endTime != null) {
1075 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
1076 event.id, ViewType.AGENDA);
1077 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001078 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1079 event.selectedTime, event.id, ViewType.AGENDA);
1080 }
1081 } else {
RoboErik796db762011-09-12 14:56:23 -07001082 // TODO Fix the temp hack below: && mCurrentView !=
1083 // ViewType.AGENDA
1084 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
1085 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
RoboErik20911fa2011-09-13 17:07:47 -07001086 event.selectedTime, -1, ViewType.CURRENT);
RoboErik796db762011-09-12 14:56:23 -07001087 }
Isaac Katzenelson7ef29812011-10-25 18:00:50 -07001088 if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda) ||
Isaac Katzenelson998e66e2011-11-08 11:25:55 -08001089 ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK) ||
1090 mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)){
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001091 // start event info as activity
1092 Intent intent = new Intent(Intent.ACTION_VIEW);
1093 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
1094 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -07001095 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001096 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
1097 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -07001098 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
1099 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001100 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
1101 startActivity(intent);
1102 } else {
1103 // start event info as a dialog
1104 EventInfoFragment fragment = new EventInfoFragment(this,
1105 event.id, event.startTime.toMillis(false),
Isaac Katzenelson7ef29812011-10-25 18:00:50 -07001106 event.endTime.toMillis(false), (int) event.extraLong, true,
1107 EventInfoFragment.DIALOG_WINDOW_STYLE);
Isaac Katzenelson0aa0c612011-10-03 16:46:10 -07001108 fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001109 FragmentManager fm = getFragmentManager();
1110 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -07001111 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001112 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
RoboErika459d0b2011-08-15 13:46:36 -07001113 int oldId;
1114 if (fOld != null && fOld.isAdded() && (oldId = fOld.getId()) != 0) {
1115 ft.replace(oldId, fragment, EVENT_INFO_FRAGMENT_TAG);
1116 } else {
1117 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001118 }
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001119 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001120 }
Erik63cd0532011-01-26 14:16:03 -08001121 }
RoboErik14e82b42011-07-19 09:46:39 -07001122 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001123 } else if (event.eventType == EventType.UPDATE_TITLE) {
1124 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001125 if (!mIsTabletConfig) {
RoboErike11975f2011-09-02 14:00:39 -07001126 mActionBarMenuSpinnerAdapter.setTime(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001127 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001128 }
RoboErik4eb34322011-08-19 15:47:51 -07001129 updateSecondaryTitleFields(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001130 }
1131
Michael Chan2aeb8d92011-07-10 13:32:09 -07001132 // Needs to be in proguard whitelist
1133 // Specified as listener via android:onClick in a layout xml
1134 public void handleSelectSyncedCalendarsClicked(View v) {
1135 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1136 CalendarController.EXTRA_GOTO_TIME, null,
1137 null);
1138 }
1139
Erik3f348f32010-08-10 13:17:19 -07001140 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001141 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001142 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001143 }
1144
Erik3f348f32010-08-10 13:17:19 -07001145 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001146 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001147 return false;
1148 }
1149
1150 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001151 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001152 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001153 Utils.tardis();
1154 }
RoboErika0954942011-07-27 17:43:14 -07001155 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001156 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001157 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001158 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001159 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001160
1161 @Override
1162 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001163 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001164 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001165 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001166 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001167 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001168 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001169 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001170 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1171 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001172 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001173 Log.w(TAG, "TabSelected event from unknown tab: "
1174 + (tab == null ? "null" : tab.getText()));
1175 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001176 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001177 }
1178 }
1179
1180 @Override
1181 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1182 }
1183
1184 @Override
1185 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1186 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001187
1188
1189 @Override
1190 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1191 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001192 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001193 if (mCurrentView != ViewType.DAY) {
1194 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1195 }
1196 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001197 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001198 if (mCurrentView != ViewType.WEEK) {
1199 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1200 }
1201 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001202 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001203 if (mCurrentView != ViewType.MONTH) {
1204 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1205 }
1206 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001207 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001208 if (mCurrentView != ViewType.AGENDA) {
1209 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1210 }
1211 break;
1212 default:
1213 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1214 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1215 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1216 " Agenda:" + mAgendaTab);
1217 break;
1218 }
1219 return false;
1220 }
RoboErik17664072011-08-16 16:22:39 -07001221
1222 @Override
1223 public boolean onSuggestionSelect(int position) {
1224 return false;
1225 }
1226
1227 @Override
1228 public boolean onSuggestionClick(int position) {
1229 mSearchMenu.collapseActionView();
1230 return false;
1231 }
RoboErikc6e314f2011-08-17 10:55:03 -07001232
1233 @Override
1234 public boolean onSearchRequested() {
1235 if (mSearchMenu != null) {
1236 mSearchMenu.expandActionView();
1237 }
1238 return false;
1239 }
Michael Chan49701592010-06-30 11:04:03 -07001240}