blob: 2936c3b2ed6a7d51a135cf4cf7ddfa8185efe1dc [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();
248 if (Intent.ACTION_VIEW.equals(action)) {
249 parseViewAction(intent);
250 }
251 }
252
253 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700254 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800255 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
256 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
257 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700258 super.onCreate(icicle);
259
RoboErik6c892a22011-09-08 16:54:04 -0700260 if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
261 mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
262 }
263 // Launch add google account if this is first time and there are no
264 // accounts yet
265 if (mCheckForAccounts
266 && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) {
267
268 mHandler = new QueryHandler(this.getContentResolver());
269 mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] {
270 Calendars._ID
271 }, null, null /* selection args */, null /* sort order */);
272 }
273
Michael Chan83b0fe32010-07-08 16:46:26 -0700274 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700275 mController = CalendarController.getInstance(this);
RoboErik3864be02011-07-25 15:56:50 -0700276
277
Erik954c8712010-08-06 10:12:34 -0700278 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800279 long timeMillis = -1;
280 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800281 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700282 if (icicle != null) {
283 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800284 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700285 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800286 String action = intent.getAction();
287 if (Intent.ACTION_VIEW.equals(action)) {
288 // Open EventInfo later
289 timeMillis = parseViewAction(intent);
290 }
291
292 if (timeMillis == -1) {
293 timeMillis = Utils.timeFromIntentInMillis(intent);
294 }
295 }
296
RoboErik277eb972011-02-24 16:05:04 -0800297 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700298 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
299 }
Erikc5f92d72010-11-11 16:18:34 -0800300 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
301 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700302 t.set(timeMillis);
303
Michael Chan2c7c8512010-12-10 14:12:57 -0800304 if (icicle != null && intent != null) {
305 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700306 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800307 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700308 }
309
Erikeaafa2b2010-12-23 14:30:37 -0800310 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800311 if (mScale == 0) {
312 mScale = res.getDisplayMetrics().density;
313 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800314 }
315 mHideString = res.getString(R.string.hide_controls);
316 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800317 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800318
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700319 mIsMultipane = Utils.isMultiPaneConfiguration(this);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700320 mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700321 mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700322 mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700323 mShowEventDetailsWithAgenda =
324 Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -0700325 mShowEventInfoFullScreen =
326 Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
Erik9fc409f2010-07-28 11:40:47 -0700327
Erik63cd0532011-01-26 14:16:03 -0800328 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800329
Erikbe8191c2010-10-26 16:50:08 -0700330 // setContentView must be called before configureActionBar
331 setContentView(R.layout.all_in_one);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700332
333 if (mIsTabletConfig) {
334 mDateRange = (TextView) findViewById(R.id.date_bar);
RoboErik14e82b42011-07-19 09:46:39 -0700335 mWeekTextView = (TextView) findViewById(R.id.week_num);
Isaac Katzenelson62967cb2011-06-14 13:27:20 -0700336 } else {
337 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
338 }
339
Erikbe8191c2010-10-26 16:50:08 -0700340 // configureActionBar auto-selects the first tab you add, so we need to
341 // call it before we set up our own fragments to make sure it doesn't
342 // overwrite us
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700343 configureActionBar(viewType);
Erikbe8191c2010-10-26 16:50:08 -0700344
Erik6c255102010-09-29 14:43:00 -0700345 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800346 mMiniMonth = findViewById(R.id.mini_month);
347 mCalendarsList = findViewById(R.id.calendar_list);
348 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700349 mSecondaryPane = findViewById(R.id.secondary_pane);
Michael Chan83b0fe32010-07-08 16:46:26 -0700350
RoboErik3864be02011-07-25 15:56:50 -0700351 // Must register as the first activity because this activity can modify
352 // the list of event handlers in it's handle method. This affects who
353 // the rest of the handlers the controller dispatches to are.
354 mController.registerFirstEventHandler(HANDLER_KEY, this);
355
Erik7b92da22010-09-23 14:55:22 -0700356 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700357
358 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700359 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700360 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700361
Erik954c8712010-08-06 10:12:34 -0700362 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700363 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700364
Michael Chan2c7c8512010-12-10 14:12:57 -0800365 private long parseViewAction(final Intent intent) {
366 long timeMillis = -1;
367 Uri data = intent.getData();
368 if (data != null && data.isHierarchical()) {
369 List<String> path = data.getPathSegments();
370 if (path.size() == 2 && path.get(0).equals("events")) {
371 try {
372 mViewEventId = Long.valueOf(data.getLastPathSegment());
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700373 if (mViewEventId != -1) {
RoboErika27a8862011-06-23 15:26:23 -0700374 mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
375 mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
Michael Chan2c7c8512010-12-10 14:12:57 -0800376 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800377 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800378 timeMillis = mIntentEventStartMillis;
379 }
380 } catch (NumberFormatException e) {
381 // Ignore if mViewEventId can't be parsed
382 }
383 }
384 }
385 return timeMillis;
386 }
387
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700388 private void configureActionBar(int viewType) {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700389 if (mIsTabletConfig) {
390 createTabs();
391 } else {
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700392 createButtonsSpinner(viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700393 }
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700394 if (mIsMultipane) {
395 mActionBar.setDisplayOptions(
396 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
397 } else {
RoboErik0d865f32011-08-09 10:17:25 -0700398 mActionBar.setDisplayOptions(0);
Isaac Katzenelson53aad912011-07-01 12:15:09 -0700399 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700400 }
401
402 private void createTabs() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700403 mActionBar = getActionBar();
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700404 if (mActionBar == null) {
405 Log.w(TAG, "ActionBar is null.");
406 } else {
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700407 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700408 mDayTab = mActionBar.newTab();
409 mDayTab.setText(getString(R.string.day_view));
410 mDayTab.setTabListener(this);
411 mActionBar.addTab(mDayTab);
412 mWeekTab = mActionBar.newTab();
413 mWeekTab.setText(getString(R.string.week_view));
414 mWeekTab.setTabListener(this);
415 mActionBar.addTab(mWeekTab);
416 mMonthTab = mActionBar.newTab();
417 mMonthTab.setText(getString(R.string.month_view));
418 mMonthTab.setTabListener(this);
419 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700420 mAgendaTab = mActionBar.newTab();
421 mAgendaTab.setText(getString(R.string.agenda_view));
422 mAgendaTab.setTabListener(this);
423 mActionBar.addTab(mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700424 }
Erik954c8712010-08-06 10:12:34 -0700425 }
426
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700427 private void createButtonsSpinner(int viewType) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700428 mActionBarMenuSpinnerAdapter = new CalendarViewAdapter (this, viewType);
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700429 mActionBar = getActionBar();
430 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700431 mActionBar.setListNavigationCallbacks(mActionBarMenuSpinnerAdapter, this);
Isaac Katzenelsona457a1b2011-06-21 15:13:57 -0700432 switch (viewType) {
433 case ViewType.AGENDA:
434 mActionBar.setSelectedNavigationItem(BUTTON_AGENDA_INDEX);
435 break;
436 case ViewType.DAY:
437 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
438 break;
439 case ViewType.WEEK:
440 mActionBar.setSelectedNavigationItem(BUTTON_WEEK_INDEX);
441 break;
442 case ViewType.MONTH:
443 mActionBar.setSelectedNavigationItem(BUTTON_MONTH_INDEX);
444 break;
445 default:
446 mActionBar.setSelectedNavigationItem(BUTTON_DAY_INDEX);
447 break;
448 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -0700449 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700450 // Clear buttons used in the agenda view
451 private void clearOptionsMenu() {
452 if (mOptionsMenu == null) {
453 return;
454 }
455 MenuItem cancelItem = mOptionsMenu.findItem(R.id.action_cancel);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700456 if (cancelItem != null) {
457 cancelItem.setVisible(false);
458 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700459 }
460
Erik954c8712010-08-06 10:12:34 -0700461 @Override
462 protected void onResume() {
463 super.onResume();
RoboErik3864be02011-07-25 15:56:50 -0700464
465 // Must register as the first activity because this activity can modify
466 // the list of event handlers in it's handle method. This affects who
467 // the rest of the handlers the controller dispatches to are.
468 mController.registerFirstEventHandler(HANDLER_KEY, this);
469
Michael Chanf2cfa202011-08-19 17:58:16 -0700470 mOnSaveInstanceStateCalled = false;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700471 mContentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI,
472 true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700473 if (mUpdateOnResume) {
474 initFragments(mController.getTime(), mController.getViewType(), null);
475 mUpdateOnResume = false;
476 }
RoboErik4eb34322011-08-19 15:47:51 -0700477 updateSecondaryTitleFields(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700478 // Make sure the drop-down menu will get its date updated at midnight
479 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700480 mActionBarMenuSpinnerAdapter.refresh(this);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700481 }
482
RoboErik3b3af612011-02-24 13:42:57 -0800483 if (mControlsMenu != null) {
484 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
485 }
Erikcb811892010-09-28 13:44:19 -0700486 mPaused = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800487
488 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800489 long currentMillis = System.currentTimeMillis();
490 long selectedTime = -1;
491 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
492 selectedTime = currentMillis;
493 }
Michael Chanedecd9a2011-08-24 23:58:48 -0700494 mController.sendEventRelatedEventWithExtra(this, EventType.VIEW_EVENT, mViewEventId,
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700495 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1,
496 mIntentAttendeeResponse, selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800497 mViewEventId = -1;
498 mIntentEventStartMillis = -1;
499 mIntentEventEndMillis = -1;
500 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700501 }
502
503 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700504 protected void onPause() {
505 super.onPause();
RoboErik3864be02011-07-25 15:56:50 -0700506
507 mController.deregisterEventHandler(HANDLER_KEY);
Erikcb811892010-09-28 13:44:19 -0700508 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700509 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700510 if (mActionBarMenuSpinnerAdapter != null) {
Michael Chanbe686752011-08-23 15:53:35 -0700511 mActionBarMenuSpinnerAdapter.onPause();
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700512 }
Erik954c8712010-08-06 10:12:34 -0700513 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700514 if (isFinishing()) {
515 // Stop listening for changes that would require this to be refreshed
516 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
517 prefs.unregisterOnSharedPreferenceChangeListener(this);
518 }
Erik7b92da22010-09-23 14:55:22 -0700519 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700520 if (mController.getViewType() != ViewType.EDIT) {
521 Utils.setDefaultView(this, mController.getViewType());
522 }
Michael Chand6734db2010-07-22 00:48:08 -0700523 }
524
525 @Override
Erik7b92da22010-09-23 14:55:22 -0700526 protected void onUserLeaveHint() {
527 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
528 super.onUserLeaveHint();
529 }
530
531 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700532 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700533 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700534 super.onSaveInstanceState(outState);
535
536 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700537 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800538 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700539 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
540 }
RoboErik6c892a22011-09-08 16:54:04 -0700541 outState.putBoolean(BUNDLE_KEY_CHECK_ACCOUNTS, mCheckForAccounts);
Michael Chand6734db2010-07-22 00:48:08 -0700542 }
543
544 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700545 protected void onDestroy() {
546 super.onDestroy();
547
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700548 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700549 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700550 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700551 }
552
Erik7b92da22010-09-23 14:55:22 -0700553 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
RoboErikf836d4a2011-07-22 17:01:27 -0700554 if (DEBUG) {
555 Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
556 }
Dianne Hackborn12b33302011-01-17 12:30:13 -0800557 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700558
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700559 if (mShowCalendarControls) {
Erik40bcd102010-11-16 15:46:40 -0800560 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700561 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700562 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700563
Michael Chan2aeb8d92011-07-10 13:32:09 -0700564 Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
Michael Chanab29d9e2010-07-21 06:08:47 -0700565 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800566 mController.registerEventHandler(
567 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700568 }
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700569 if (!mShowCalendarControls || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800570 mMiniMonth.setVisibility(View.GONE);
571 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700572 }
Michael Chan3458a172010-07-13 17:58:21 -0700573
Erikdd95df52010-08-27 09:31:18 -0700574 EventInfo info = null;
575 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700576 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700577 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700578
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700579 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700580 Intent intent = getIntent();
581 Uri data = intent.getData();
582 if (data != null) {
583 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700584 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700585 } catch (NumberFormatException e) {
586 if (DEBUG) {
587 Log.d(TAG, "Create new event");
588 }
589 }
Erik7b92da22010-09-23 14:55:22 -0700590 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
591 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700592 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700593
RoboErika27a8862011-06-23 15:26:23 -0700594 long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
595 long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
Erikdd95df52010-08-27 09:31:18 -0700596 info = new EventInfo();
597 if (end != -1) {
598 info.endTime = new Time();
599 info.endTime.set(end);
600 }
601 if (begin != -1) {
602 info.startTime = new Time();
603 info.startTime.set(begin);
604 }
605 info.id = eventId;
606 // We set the viewtype so if the user presses back when they are
607 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700608 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700609 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700610 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700611 } else {
612 mPreviousView = viewType;
613 }
Isaac Katzenelson96a0b542011-04-13 13:43:20 -0700614
Erik63cd0532011-01-26 14:16:03 -0800615 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700616 ft.commit(); // this needs to be after setMainPane()
617
Erikc5f92d72010-11-11 16:18:34 -0800618 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700619 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700620 if (viewType != ViewType.EDIT) {
621 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
622 }
Michael Chan49701592010-06-30 11:04:03 -0700623 }
Erik2051f122010-07-02 13:45:45 -0700624
625 @Override
Erik648c59c2010-08-13 12:49:26 -0700626 public void onBackPressed() {
Michael Chanfb0ec222011-08-12 17:39:30 -0700627 if (mCurrentView == ViewType.EDIT || mBackToPreviousView) {
Erikdd95df52010-08-27 09:31:18 -0700628 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700629 } else {
630 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700631 }
632 }
633
634 @Override
Erik2051f122010-07-02 13:45:45 -0700635 public boolean onCreateOptionsMenu(Menu menu) {
636 super.onCreateOptionsMenu(menu);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700637 mOptionsMenu = menu;
Erik2051f122010-07-02 13:45:45 -0700638 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700639
RoboErike635aec2011-07-15 11:22:13 -0700640 mSearchMenu = menu.findItem(R.id.action_search);
641 mSearchView = (SearchView) mSearchMenu.getActionView();
Erikcb830312011-01-19 14:41:41 -0800642 if (mSearchView != null) {
RoboErik50f10942011-07-26 14:30:25 -0700643 Utils.setUpSearchView(mSearchView, this);
Adam Powell28f9b352011-01-20 18:36:10 -0800644 mSearchView.setOnQueryTextListener(this);
RoboErik17664072011-08-16 16:22:39 -0700645 mSearchView.setOnSuggestionListener(this);
Michael Chan71b221a2010-10-25 17:55:44 -0700646 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700647
648 // Hide the "show/hide controls" button if this is a phone
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700649 // or the view type is "Month" or "Agenda".
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700650
RoboErikde20d762011-02-08 17:52:25 -0800651 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700652 if (!mShowCalendarControls) {
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700653 if (mControlsMenu != null) {
654 mControlsMenu.setVisible(false);
655 mControlsMenu.setEnabled(false);
656 }
657 } else if (mControlsMenu != null && mController != null
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700658 && (mController.getViewType() == ViewType.MONTH ||
659 mController.getViewType() == ViewType.AGENDA)) {
RoboErikde20d762011-02-08 17:52:25 -0800660 mControlsMenu.setVisible(false);
661 mControlsMenu.setEnabled(false);
Isaac Katzenelson9c163922011-07-07 11:19:19 -0700662 } else if (mControlsMenu != null){
663 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
RoboErikde20d762011-02-08 17:52:25 -0800664 }
Erik2051f122010-07-02 13:45:45 -0700665 return true;
666 }
Michael Chan3458a172010-07-13 17:58:21 -0700667
668 @Override
669 public boolean onOptionsItemSelected(MenuItem item) {
670 Time t = null;
671 int viewType = ViewType.CURRENT;
672 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700673 case R.id.action_refresh:
674 mController.refreshCalendars();
675 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700676 case R.id.action_today:
677 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800678 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700679 t.setToNow();
680 break;
681 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800682 t = new Time();
683 t.set(mController.getTime());
684 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800685 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800686 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800687 } else {
688 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800689 }
690 mController.sendEventRelatedEvent(
691 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700692 return true;
Michael Chan2aeb8d92011-07-10 13:32:09 -0700693 case R.id.action_select_visible_calendars:
694 mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null,
695 0, 0);
696 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700697 case R.id.action_settings:
698 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
699 return true;
RoboErikde20d762011-02-08 17:52:25 -0800700 case R.id.action_hide_controls:
701 mHideControls = !mHideControls;
702 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800703 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
704 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
705 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
706 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
707 ObjectAnimator.setFrameDelay(0);
708 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800709 return true;
RoboErike635aec2011-07-15 11:22:13 -0700710 case R.id.action_search:
RoboErik50f10942011-07-26 14:30:25 -0700711 return false;
Michael Chan3458a172010-07-13 17:58:21 -0700712 default:
713 return false;
714 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700715 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700716 return true;
717 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700718
RoboErikb8549562011-02-15 14:25:23 -0800719 /**
720 * Sets the offset of the controls on the right for animating them off/on
721 * screen. ProGuard strips this if it's not in proguard.flags
722 *
723 * @param controlsOffset The current offset in pixels
724 */
725 public void setControlsOffset(int controlsOffset) {
726 mMiniMonth.setTranslationX(controlsOffset);
727 mCalendarsList.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800728 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800729 mMiniMonthContainer.setLayoutParams(mControlsParams);
730 }
RoboErikde20d762011-02-08 17:52:25 -0800731
Mason Tang8e3d4302010-07-12 17:39:30 -0700732 @Override
733 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700734 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700735 if (mPaused) {
736 mUpdateOnResume = true;
737 } else {
738 initFragments(mController.getTime(), mController.getViewType(), null);
739 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700740 }
741 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700742
Erik63cd0532011-01-26 14:16:03 -0800743 private void setMainPane(
744 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700745 if (mOnSaveInstanceStateCalled) {
746 return;
747 }
Erik7b92da22010-09-23 14:55:22 -0700748 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700749 return;
750 }
751
Michael Chan5756bbc2011-03-02 18:22:07 -0800752 // Remove this when transition to and from month view looks fine.
753 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
RoboErikd725bfc2011-06-20 14:09:09 -0700754 FragmentManager fragmentManager = getFragmentManager();
755 // Check if our previous view was an Agenda view
756 // TODO remove this if framework ever supports nested fragments
757 if (mCurrentView == ViewType.AGENDA) {
758 // If it was, we need to do some cleanup on it to prevent the
759 // edit/delete buttons from coming back on a rotation.
760 Fragment oldFrag = fragmentManager.findFragmentById(viewId);
761 if (oldFrag instanceof AgendaFragment) {
762 ((AgendaFragment) oldFrag).removeFragments(fragmentManager);
763 }
764 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800765
Erik648c59c2010-08-13 12:49:26 -0700766 if (viewType != mCurrentView) {
767 // The rules for this previous view are different than the
768 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700769 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
770 mPreviousView = mCurrentView;
771 }
Erik648c59c2010-08-13 12:49:26 -0700772 mCurrentView = viewType;
773 }
Erik3f348f32010-08-10 13:17:19 -0700774 // Create new fragment
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700775 Fragment frag = null;
776 Fragment secFrag = null;
Michael Chanab29d9e2010-07-21 06:08:47 -0700777 switch (viewType) {
778 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700779 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
780 mActionBar.selectTab(mAgendaTab);
781 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700782 if (mActionBarMenuSpinnerAdapter != null) {
783 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.AGENDA_BUTTON_INDEX);
784 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700785 frag = new AgendaFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700786 break;
787 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700788 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
789 mActionBar.selectTab(mDayTab);
790 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700791 if (mActionBarMenuSpinnerAdapter != null) {
792 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.DAY_BUTTON_INDEX);
793 }
Michael Chan75d9b562010-07-26 16:54:25 -0700794 frag = new DayFragment(timeMillis, 1);
795 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700796 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700797 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
798 mActionBar.selectTab(mWeekTab);
799 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700800 if (mActionBarMenuSpinnerAdapter != null) {
801 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.WEEK_BUTTON_INDEX);
802 }
Michael Chan75d9b562010-07-26 16:54:25 -0700803 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700804 break;
805 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700806 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
807 mActionBar.selectTab(mMonthTab);
808 }
Isaac Katzenelson01d36972011-06-29 11:29:35 -0700809 if (mActionBarMenuSpinnerAdapter != null) {
810 mActionBar.setSelectedNavigationItem(CalendarViewAdapter.MONTH_BUTTON_INDEX);
811 }
Erik40bcd102010-11-16 15:46:40 -0800812 frag = new MonthByWeekFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700813 if (mShowAgendaWithMonth) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700814 secFrag = new AgendaFragment(timeMillis, false);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700815 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700816 break;
817 default:
Michael Chand6734db2010-07-22 00:48:08 -0700818 throw new IllegalArgumentException(
819 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700820 }
821
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700822 // Update the current view so that the menu can update its look according to the
823 // current view.
824 if (!mIsTabletConfig && mActionBarMenuSpinnerAdapter != null) {
RoboErike11975f2011-09-02 14:00:39 -0700825 mActionBarMenuSpinnerAdapter.setTime(timeMillis);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -0700826 mActionBarMenuSpinnerAdapter.setMainView(viewType);
827 }
828
Isaac Katzenelson672ecfd2011-07-01 16:11:32 -0700829
830 // Show date only on tablet configurations in views different than Agenda
831 if (!mIsTabletConfig) {
832 mDateRange.setVisibility(View.GONE);
833 } else if (viewType != ViewType.AGENDA) {
834 mDateRange.setVisibility(View.VISIBLE);
835 } else {
836 mDateRange.setVisibility(View.GONE);
837 }
838
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700839 // Clear unnecessary buttons from the option menu when switching from the agenda view
840 if (viewType != ViewType.AGENDA) {
841 clearOptionsMenu();
842 }
843
Michael Chanab29d9e2010-07-21 06:08:47 -0700844 boolean doCommit = false;
845 if (ft == null) {
846 doCommit = true;
RoboErikd725bfc2011-06-20 14:09:09 -0700847 ft = fragmentManager.beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700848 }
849
Michael Chan5756bbc2011-03-02 18:22:07 -0800850 if (doTransition) {
851 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
852 }
853
Michael Chanab29d9e2010-07-21 06:08:47 -0700854 ft.replace(viewId, frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700855 if (mShowAgendaWithMonth) {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700856
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700857 // Show/hide secondary fragment
858
859 if (secFrag != null) {
860 ft.replace(R.id.secondary_pane, secFrag);
861 mSecondaryPane.setVisibility(View.VISIBLE);
862 } else {
863 mSecondaryPane.setVisibility(View.GONE);
RoboErikd725bfc2011-06-20 14:09:09 -0700864 Fragment f = fragmentManager.findFragmentById(R.id.secondary_pane);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700865 if (f != null) {
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700866 ft.remove(f);
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700867 }
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700868 mController.deregisterEventHandler(R.id.secondary_pane);
869 }
870 }
Erik954c8712010-08-06 10:12:34 -0700871 if (DEBUG) {
872 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
873 }
Erik3f348f32010-08-10 13:17:19 -0700874 // If the key is already registered this will replace it
875 mController.registerEventHandler(viewId, (EventHandler) frag);
Isaac Katzenelson6a182582011-04-21 15:46:33 -0700876 if (secFrag != null) {
877 mController.registerEventHandler(viewId, (EventHandler) secFrag);
878 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700879
880 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800881 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700882 ft.commit();
883 }
884 }
885
886 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800887 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700888 return;
889 }
890
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700891 final long start = event.startTime.toMillis(false /* use isDst */);
892 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700893 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700894 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700895 } else {
896 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700897 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700898
Erikeaafa2b2010-12-23 14:30:37 -0800899 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800900 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800901 mDateRange.setText(msg);
RoboErik4eb34322011-08-19 15:47:51 -0700902 updateSecondaryTitleFields(start);
Erik259b8f92011-01-12 14:01:12 -0800903 if (!TextUtils.equals(oldDate, msg)) {
904 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
RoboErik14e82b42011-07-19 09:46:39 -0700905 if (mShowWeekNum && mWeekTextView != null) {
906 mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
907 }
Erik259b8f92011-01-12 14:01:12 -0800908 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700909 }
910
RoboErik4eb34322011-08-19 15:47:51 -0700911 private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
RoboErik14e82b42011-07-19 09:46:39 -0700912 mShowWeekNum = Utils.getShowWeekNumber(this);
Erikc5f92d72010-11-11 16:18:34 -0800913 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
RoboErik14e82b42011-07-19 09:46:39 -0700914 if (visibleMillisSinceEpoch != -1) {
915 int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
916 mWeekNum = weekNum;
917 }
918
919 if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig
920 && mWeekTextView != null) {
921 String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum,
922 mWeekNum);
923 mWeekTextView.setText(weekString);
924 mWeekTextView.setVisibility(View.VISIBLE);
RoboErik4eb34322011-08-19 15:47:51 -0700925 } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null
926 && mCurrentView == ViewType.DAY && mIsTabletConfig) {
927 Time time = new Time(mTimeZone);
928 time.set(visibleMillisSinceEpoch);
929 int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
930 time.setToNow();
931 int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
932 String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay,
933 visibleMillisSinceEpoch, this);
934 mWeekTextView.setText(dayString);
935 mWeekTextView.setVisibility(View.VISIBLE);
936 } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
RoboErik14e82b42011-07-19 09:46:39 -0700937 mWeekTextView.setVisibility(View.GONE);
938 }
Michael Chanbe686752011-08-23 15:53:35 -0700939
RoboErik14e82b42011-07-19 09:46:39 -0700940 if (mHomeTime != null
941 && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
942 || mCurrentView == ViewType.AGENDA)
Erikc5f92d72010-11-11 16:18:34 -0800943 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
944 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700945 time.setToNow();
946 long millis = time.toMillis(true);
947 boolean isDST = time.isDst != 0;
948 int flags = DateUtils.FORMAT_SHOW_TIME;
949 if (DateFormat.is24HourFormat(this)) {
950 flags |= DateUtils.FORMAT_24HOUR;
951 }
952 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800953 String timeString = (new StringBuilder(
954 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
955 TimeZone.getTimeZone(mTimeZone).getDisplayName(
956 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700957 mHomeTime.setText(timeString);
958 mHomeTime.setVisibility(View.VISIBLE);
959 // Update when the minute changes
960 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700961 mHomeTimeUpdater,
962 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
RoboErik14e82b42011-07-19 09:46:39 -0700963 } else if (mHomeTime != null) {
964 mHomeTime.setVisibility(View.GONE);
Erik6c255102010-09-29 14:43:00 -0700965 }
966 }
967
Erik3f348f32010-08-10 13:17:19 -0700968 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700969 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800970 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700971 }
972
Erik3f348f32010-08-10 13:17:19 -0700973 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700974 public void handleEvent(EventInfo event) {
RoboErik14e82b42011-07-19 09:46:39 -0700975 long displayTime = -1;
Michael Chanab29d9e2010-07-21 06:08:47 -0700976 if (event.eventType == EventType.GO_TO) {
Michael Chanfb0ec222011-08-12 17:39:30 -0700977 if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
978 mBackToPreviousView = true;
979 } else if (event.viewType != mController.getPreviousViewType()
980 && event.viewType != ViewType.EDIT) {
981 // Clear the flag is change to a different view type
982 mBackToPreviousView = false;
983 }
984
Erik63cd0532011-01-26 14:16:03 -0800985 setMainPane(
986 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800987 if (mSearchView != null) {
988 mSearchView.clearFocus();
989 }
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700990
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700991 if (mShowCalendarControls) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -0700992 if (event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700993 // hide minimonth and calendar frag
994 mShowSideViews = false;
995 if (mControlsMenu != null) {
996 mControlsMenu.setVisible(false);
997 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800998
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -0700999 if (!mHideControls) {
1000 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1001 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
1002 slideAnimation.addListener(mSlideAnimationDoneListener);
1003 slideAnimation.setDuration(220);
1004 ObjectAnimator.setFrameDelay(0);
1005 slideAnimation.start();
1006 }
1007 } else {
1008 mMiniMonth.setVisibility(View.GONE);
1009 mCalendarsList.setVisibility(View.GONE);
1010 mMiniMonthContainer.setVisibility(View.GONE);
Michael Chan100bdbe2011-03-04 22:30:10 -08001011 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001012 } else {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001013 // show minimonth and calendar frag
1014 mShowSideViews = true;
1015 mMiniMonth.setVisibility(View.VISIBLE);
1016 mCalendarsList.setVisibility(View.VISIBLE);
1017 mMiniMonthContainer.setVisibility(View.VISIBLE);
1018 if (mControlsMenu != null) {
1019 mControlsMenu.setVisible(true);
1020 mControlsMenu.setEnabled(true);
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001021 if (!mHideControls &&
1022 (mController.getPreviousViewType() == ViewType.MONTH ||
1023 mController.getPreviousViewType() == ViewType.AGENDA)) {
Isaac Katzenelson5ab87e32011-04-21 17:19:25 -07001024 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
1025 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
1026 slideAnimation.setDuration(220);
1027 ObjectAnimator.setFrameDelay(0);
1028 slideAnimation.start();
1029 }
Michael Chan5756bbc2011-03-02 18:22:07 -08001030 }
RoboErikde20d762011-02-08 17:52:25 -08001031 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001032 }
RoboErik14e82b42011-07-19 09:46:39 -07001033 displayTime = event.startTime.toMillis(true);
RoboErik57df20b2011-08-09 17:44:18 -07001034 if (!mIsTabletConfig) {
1035 mActionBarMenuSpinnerAdapter.setTime(displayTime);
1036 }
Michael Chan71d08832010-08-25 18:28:59 -07001037 } else if (event.eventType == EventType.VIEW_EVENT) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001038
1039 // If in Agenda view and "show_event_details_with_agenda" is "true",
1040 // do not create the event info fragment here, it will be created by the Agenda
1041 // fragment
1042
RoboErikd6c93ce2011-07-22 17:54:40 -07001043 if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
RoboErikf836d4a2011-07-22 17:01:27 -07001044 if (event.startTime != null && event.endTime != null) {
1045 mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime,
1046 event.id, ViewType.AGENDA);
1047 } else if (event.selectedTime != null) {
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001048 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1049 event.selectedTime, event.id, ViewType.AGENDA);
1050 }
1051 } else {
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001052 if (mShowEventInfoFullScreen) {
1053 // start event info as activity
1054 Intent intent = new Intent(Intent.ACTION_VIEW);
1055 Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
1056 intent.setData(eventUri);
Michael Chan07d9fee2011-07-25 09:41:21 -07001057 intent.setClass(this, EventInfoActivity.class);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001058 intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
1059 Intent.FLAG_ACTIVITY_SINGLE_TOP);
RoboErika27a8862011-06-23 15:26:23 -07001060 intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
1061 intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001062 intent.putExtra(EVENT_ATTENDEE_RESPONSE, (int)event.extraLong);
1063 startActivity(intent);
1064 } else {
1065 // start event info as a dialog
1066 EventInfoFragment fragment = new EventInfoFragment(this,
1067 event.id, event.startTime.toMillis(false),
1068 event.endTime.toMillis(false), (int) event.extraLong, true);
1069 // TODO Fix the temp hack below: && mCurrentView !=
1070 // ViewType.AGENDA
1071 if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
1072 mController.sendEvent(this, EventType.GO_TO, event.selectedTime,
1073 event.selectedTime, -1, ViewType.DETAIL);
1074 }
1075 fragment.setDialogParams(event.x, event.y);
1076 FragmentManager fm = getFragmentManager();
1077 FragmentTransaction ft = fm.beginTransaction();
RoboErika459d0b2011-08-15 13:46:36 -07001078 // if we have an old popup replace it
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001079 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
RoboErika459d0b2011-08-15 13:46:36 -07001080 int oldId;
1081 if (fOld != null && fOld.isAdded() && (oldId = fOld.getId()) != 0) {
1082 ft.replace(oldId, fragment, EVENT_INFO_FRAGMENT_TAG);
1083 } else {
1084 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001085 }
Isaac Katzenelson60f01c22011-06-03 15:42:01 -07001086 ft.commit();
Isaac Katzenelsonccf565b2011-04-27 14:40:08 -07001087 }
Erik63cd0532011-01-26 14:16:03 -08001088 }
RoboErik14e82b42011-07-19 09:46:39 -07001089 displayTime = event.startTime.toMillis(true);
Erikeaafa2b2010-12-23 14:30:37 -08001090 } else if (event.eventType == EventType.UPDATE_TITLE) {
1091 setTitleInActionBar(event);
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001092 if (!mIsTabletConfig) {
RoboErike11975f2011-09-02 14:00:39 -07001093 mActionBarMenuSpinnerAdapter.setTime(mController.getTime());
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001094 }
Michael Chanab29d9e2010-07-21 06:08:47 -07001095 }
RoboErik4eb34322011-08-19 15:47:51 -07001096 updateSecondaryTitleFields(displayTime);
Michael Chanab29d9e2010-07-21 06:08:47 -07001097 }
1098
Michael Chan2aeb8d92011-07-10 13:32:09 -07001099 // Needs to be in proguard whitelist
1100 // Specified as listener via android:onClick in a layout xml
1101 public void handleSelectSyncedCalendarsClicked(View v) {
1102 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, null, 0, 0,
1103 CalendarController.EXTRA_GOTO_TIME, null,
1104 null);
1105 }
1106
Erik3f348f32010-08-10 13:17:19 -07001107 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -07001108 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -07001109 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -07001110 }
1111
Erik3f348f32010-08-10 13:17:19 -07001112 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001113 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001114 return false;
1115 }
1116
1117 @Override
Adam Powell28f9b352011-01-20 18:36:10 -08001118 public boolean onQueryTextSubmit(String query) {
Michael Chanc03aab42011-04-21 15:59:29 -07001119 if ("TARDIS".equalsIgnoreCase(query)) {
Erikca478672011-01-19 20:02:47 -08001120 Utils.tardis();
1121 }
RoboErika0954942011-07-27 17:43:14 -07001122 mSearchMenu.collapseActionView();
Michael Chanfb0ec222011-08-12 17:39:30 -07001123 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, 0, query,
Erik7b92da22010-09-23 14:55:22 -07001124 getComponentName());
RoboErik17664072011-08-16 16:22:39 -07001125 return true;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -07001126 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001127
1128 @Override
1129 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -08001130 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001131 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001132 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001133 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001134 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -07001135 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001136 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001137 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
1138 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001139 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -08001140 Log.w(TAG, "TabSelected event from unknown tab: "
1141 + (tab == null ? "null" : tab.getText()));
1142 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -07001143 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -07001144 }
1145 }
1146
1147 @Override
1148 public void onTabReselected(Tab tab, FragmentTransaction ft) {
1149 }
1150
1151 @Override
1152 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
1153 }
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001154
1155
1156 @Override
1157 public boolean onNavigationItemSelected(int itemPosition, long itemId) {
1158 switch (itemPosition) {
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001159 case CalendarViewAdapter.DAY_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001160 if (mCurrentView != ViewType.DAY) {
1161 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
1162 }
1163 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001164 case CalendarViewAdapter.WEEK_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001165 if (mCurrentView != ViewType.WEEK) {
1166 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
1167 }
1168 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001169 case CalendarViewAdapter.MONTH_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001170 if (mCurrentView != ViewType.MONTH) {
1171 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
1172 }
1173 break;
Isaac Katzenelson9a39bdd2011-06-23 16:52:08 -07001174 case CalendarViewAdapter.AGENDA_BUTTON_INDEX:
Isaac Katzenelson2c5dd7c2011-06-16 17:56:06 -07001175 if (mCurrentView != ViewType.AGENDA) {
1176 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
1177 }
1178 break;
1179 default:
1180 Log.w(TAG, "ItemSelected event from unknown button: " + itemPosition);
1181 Log.w(TAG, "CurrentView:" + mCurrentView + " Button:" + itemPosition +
1182 " Day:" + mDayTab + " Week:" + mWeekTab + " Month:" + mMonthTab +
1183 " Agenda:" + mAgendaTab);
1184 break;
1185 }
1186 return false;
1187 }
RoboErik17664072011-08-16 16:22:39 -07001188
1189 @Override
1190 public boolean onSuggestionSelect(int position) {
1191 return false;
1192 }
1193
1194 @Override
1195 public boolean onSuggestionClick(int position) {
1196 mSearchMenu.collapseActionView();
1197 return false;
1198 }
RoboErikc6e314f2011-08-17 10:55:03 -07001199
1200 @Override
1201 public boolean onSearchRequested() {
1202 if (mSearchMenu != null) {
1203 mSearchMenu.expandActionView();
1204 }
1205 return false;
1206 }
Michael Chan49701592010-06-30 11:04:03 -07001207}