blob: c1f9e88b0379b004a2939c01e2523cbee894d3c5 [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
Erikdd95df52010-08-27 09:31:18 -070019import static android.provider.Calendar.EVENT_BEGIN_TIME;
20import static android.provider.Calendar.EVENT_END_TIME;
Michael Chan2c7c8512010-12-10 14:12:57 -080021import static android.provider.Calendar.AttendeesColumns.ATTENDEE_STATUS;
Erikdd95df52010-08-27 09:31:18 -070022
Michael Chan83b0fe32010-07-08 16:46:26 -070023import com.android.calendar.CalendarController.EventHandler;
Michael Chanab29d9e2010-07-21 06:08:47 -070024import com.android.calendar.CalendarController.EventInfo;
Michael Chan83b0fe32010-07-08 16:46:26 -070025import com.android.calendar.CalendarController.EventType;
Michael Chan3458a172010-07-13 17:58:21 -070026import com.android.calendar.CalendarController.ViewType;
Mason Tang00b8c1a2010-08-23 12:02:00 -070027import com.android.calendar.agenda.AgendaFragment;
Erik981874e2010-10-05 16:52:52 -070028import com.android.calendar.month.MonthByWeekFragment;
Mason Tang9a3cb142010-07-27 12:16:41 -070029import com.android.calendar.selectcalendars.SelectCalendarsFragment;
Michael Chan83b0fe32010-07-08 16:46:26 -070030
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -070031
Michael Chan5756bbc2011-03-02 18:22:07 -080032import android.animation.Animator;
33import android.animation.Animator.AnimatorListener;
RoboErikd97f7982011-03-02 15:13:05 -080034import android.animation.ObjectAnimator;
Michael Chanab29d9e2010-07-21 06:08:47 -070035import android.app.ActionBar;
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -070036import android.app.ActionBar.Tab;
Michael Chan49701592010-06-30 11:04:03 -070037import android.app.Activity;
Michael Chan83b0fe32010-07-08 16:46:26 -070038import android.app.Fragment;
Erik63cd0532011-01-26 14:16:03 -080039import android.app.FragmentManager;
Michael Chan3458a172010-07-13 17:58:21 -070040import android.app.FragmentTransaction;
Erik954c8712010-08-06 10:12:34 -070041import android.content.ContentResolver;
Erikdd95df52010-08-27 09:31:18 -070042import android.content.Intent;
Mason Tang8e3d4302010-07-12 17:39:30 -070043import android.content.SharedPreferences;
44import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
Michael Chanab29d9e2010-07-21 06:08:47 -070045import android.content.res.Configuration;
Erikeaafa2b2010-12-23 14:30:37 -080046import android.content.res.Resources;
Erik954c8712010-08-06 10:12:34 -070047import android.database.ContentObserver;
Erikdd95df52010-08-27 09:31:18 -070048import android.net.Uri;
Michael Chan49701592010-06-30 11:04:03 -070049import android.os.Bundle;
Erik954c8712010-08-06 10:12:34 -070050import android.os.Handler;
51import android.provider.Calendar;
Erik6c255102010-09-29 14:43:00 -070052import android.text.TextUtils;
53import android.text.format.DateFormat;
Michael Chan3458a172010-07-13 17:58:21 -070054import android.text.format.DateUtils;
Michael Chan83b0fe32010-07-08 16:46:26 -070055import android.text.format.Time;
Erik954c8712010-08-06 10:12:34 -070056import android.util.Log;
Erik2051f122010-07-02 13:45:45 -070057import android.view.Menu;
Michael Chan3458a172010-07-13 17:58:21 -070058import android.view.MenuItem;
Michael Chanab29d9e2010-07-21 06:08:47 -070059import android.view.View;
Erik259b8f92011-01-12 14:01:12 -080060import android.view.accessibility.AccessibilityEvent;
RoboErikde20d762011-02-08 17:52:25 -080061import android.widget.RelativeLayout;
62import android.widget.RelativeLayout.LayoutParams;
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -070063import android.widget.SearchView;
Erik6c255102010-09-29 14:43:00 -070064import android.widget.TextView;
65
Michael Chan2c7c8512010-12-10 14:12:57 -080066import java.util.List;
Erik6c255102010-09-29 14:43:00 -070067import java.util.Locale;
68import java.util.TimeZone;
Michael Chan49701592010-06-30 11:04:03 -070069
Michael Chanab29d9e2010-07-21 06:08:47 -070070public class AllInOneActivity extends Activity implements EventHandler,
Adam Powell28f9b352011-01-20 18:36:10 -080071 OnSharedPreferenceChangeListener, SearchView.OnQueryTextListener,
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -070072 ActionBar.TabListener {
Michael Chand6734db2010-07-22 00:48:08 -070073 private static final String TAG = "AllInOneActivity";
Erik954c8712010-08-06 10:12:34 -070074 private static final boolean DEBUG = false;
Erik63cd0532011-01-26 14:16:03 -080075 private static final String EVENT_INFO_FRAGMENT_TAG = "EventInfoFragment";
Michael Chand6734db2010-07-22 00:48:08 -070076 private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time";
Erik7b92da22010-09-23 14:55:22 -070077 private static final String BUNDLE_KEY_EVENT_ID = "key_event_id";
RoboErik277eb972011-02-24 16:05:04 -080078 private static final String BUNDLE_KEY_RESTORE_VIEW = "key_restore_view";
Erik3f348f32010-08-10 13:17:19 -070079 private static final int HANDLER_KEY = 0;
RoboErikde20d762011-02-08 17:52:25 -080080 private static final long CONTROLS_ANIMATE_DURATION = 400;
Michael Chan5756bbc2011-03-02 18:22:07 -080081 private static int CONTROLS_ANIMATE_WIDTH = 267;
RoboErikde20d762011-02-08 17:52:25 -080082 private static float mScale = 0;
Erikeaafa2b2010-12-23 14:30:37 -080083
Michael Chan0558def2010-07-22 21:30:32 -070084 private static CalendarController mController;
Erik9fc409f2010-07-28 11:40:47 -070085 private static boolean mIsMultipane;
Michael Chan6191c122010-11-02 16:23:47 -070086 private boolean mOnSaveInstanceStateCalled = false;
Erik954c8712010-08-06 10:12:34 -070087 private ContentResolver mContentResolver;
Erik648c59c2010-08-13 12:49:26 -070088 private int mPreviousView;
89 private int mCurrentView;
Erikcb811892010-09-28 13:44:19 -070090 private boolean mPaused = true;
91 private boolean mUpdateOnResume = false;
RoboErikde20d762011-02-08 17:52:25 -080092 private boolean mHideControls = false;
Michael Chan5756bbc2011-03-02 18:22:07 -080093 private boolean mShowSideViews = true;
Erik6c255102010-09-29 14:43:00 -070094 private TextView mHomeTime;
Erikeaafa2b2010-12-23 14:30:37 -080095 private TextView mDateRange;
RoboErikde20d762011-02-08 17:52:25 -080096 private View mMiniMonth;
97 private View mCalendarsList;
98 private View mMiniMonthContainer;
Erikc5f92d72010-11-11 16:18:34 -080099 private String mTimeZone;
Erik6c255102010-09-29 14:43:00 -0700100
Michael Chan2c7c8512010-12-10 14:12:57 -0800101 private long mViewEventId = -1;
102 private long mIntentEventStartMillis = -1;
103 private long mIntentEventEndMillis = -1;
Michael Chandeced892010-12-10 15:59:35 -0800104 private int mIntentAttendeeResponse = CalendarController.ATTENDEE_NO_RESPONSE;
Michael Chan2c7c8512010-12-10 14:12:57 -0800105
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700106 // Action bar and Navigation bar (left side of Action bar)
107 private ActionBar mActionBar;
108 private ActionBar.Tab mDayTab;
109 private ActionBar.Tab mWeekTab;
110 private ActionBar.Tab mMonthTab;
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700111 private ActionBar.Tab mAgendaTab;
Erikcb830312011-01-19 14:41:41 -0800112 private SearchView mSearchView;
RoboErikde20d762011-02-08 17:52:25 -0800113 private MenuItem mControlsMenu;
114
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700115 private String mHideString;
116 private String mShowString;
RoboErikde20d762011-02-08 17:52:25 -0800117
RoboErikb8549562011-02-15 14:25:23 -0800118 // Params for animating the controls on the right
Michael Chan5756bbc2011-03-02 18:22:07 -0800119 private LayoutParams mControlsParams = new LayoutParams(CONTROLS_ANIMATE_WIDTH, 0);
120
121 private AnimatorListener mSlideAnimationDoneListener = new AnimatorListener() {
122
123 @Override
124 public void onAnimationCancel(Animator animation) {
125 }
126
127 @Override
128 public void onAnimationEnd(android.animation.Animator animation) {
129 int visibility = mShowSideViews ? View.VISIBLE : View.GONE;
130 mMiniMonth.setVisibility(visibility);
131 mCalendarsList.setVisibility(visibility);
132 mMiniMonthContainer.setVisibility(visibility);
133 }
134
135 @Override
136 public void onAnimationRepeat(android.animation.Animator animation) {
137 }
138
139 @Override
140 public void onAnimationStart(android.animation.Animator animation) {
141 }
142 };
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700143
Erik6c255102010-09-29 14:43:00 -0700144 private Runnable mHomeTimeUpdater = new Runnable() {
145 @Override
146 public void run() {
147 updateHomeClock();
148 }
149 };
Erik954c8712010-08-06 10:12:34 -0700150
151 // Create an observer so that we can update the views whenever a
152 // Calendar event changes.
Erik7b92da22010-09-23 14:55:22 -0700153 private ContentObserver mObserver = new ContentObserver(new Handler()) {
Erik954c8712010-08-06 10:12:34 -0700154 @Override
155 public boolean deliverSelfNotifications() {
156 return true;
157 }
158
159 @Override
160 public void onChange(boolean selfChange) {
161 eventsChanged();
162 }
163 };
Michael Chan83b0fe32010-07-08 16:46:26 -0700164
Michael Chan49701592010-06-30 11:04:03 -0700165 @Override
Erik63cd0532011-01-26 14:16:03 -0800166 protected void onNewIntent(Intent intent) {
167 String action = intent.getAction();
168 if (Intent.ACTION_VIEW.equals(action)) {
169 parseViewAction(intent);
170 }
171 }
172
173 @Override
Michael Chan83b0fe32010-07-08 16:46:26 -0700174 protected void onCreate(Bundle icicle) {
Erikca478672011-01-19 20:02:47 -0800175 if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
176 setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
177 }
Michael Chan83b0fe32010-07-08 16:46:26 -0700178 super.onCreate(icicle);
179
180 // This needs to be created before setContentView
Michael Chan0558def2010-07-22 21:30:32 -0700181 mController = CalendarController.getInstance(this);
Erik954c8712010-08-06 10:12:34 -0700182 // Get time from intent or icicle
Michael Chan2c7c8512010-12-10 14:12:57 -0800183 long timeMillis = -1;
184 int viewType = -1;
Michael Chan2c7c8512010-12-10 14:12:57 -0800185 final Intent intent = getIntent();
Erik954c8712010-08-06 10:12:34 -0700186 if (icicle != null) {
187 timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
RoboErik277eb972011-02-24 16:05:04 -0800188 viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
Erik7b92da22010-09-23 14:55:22 -0700189 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800190 String action = intent.getAction();
191 if (Intent.ACTION_VIEW.equals(action)) {
192 // Open EventInfo later
193 timeMillis = parseViewAction(intent);
194 }
195
196 if (timeMillis == -1) {
197 timeMillis = Utils.timeFromIntentInMillis(intent);
198 }
199 }
200
RoboErik277eb972011-02-24 16:05:04 -0800201 if (viewType == -1) {
Erik7b92da22010-09-23 14:55:22 -0700202 viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
203 }
Erikc5f92d72010-11-11 16:18:34 -0800204 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
205 Time t = new Time(mTimeZone);
Erik954c8712010-08-06 10:12:34 -0700206 t.set(timeMillis);
207
Michael Chan2c7c8512010-12-10 14:12:57 -0800208 if (icicle != null && intent != null) {
209 Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString());
Erik7b92da22010-09-23 14:55:22 -0700210 } else {
Michael Chan2c7c8512010-12-10 14:12:57 -0800211 Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
Erik7b92da22010-09-23 14:55:22 -0700212 }
213
Erikeaafa2b2010-12-23 14:30:37 -0800214 Resources res = getResources();
RoboErikde20d762011-02-08 17:52:25 -0800215 if (mScale == 0) {
216 mScale = res.getDisplayMetrics().density;
217 CONTROLS_ANIMATE_WIDTH *= mScale;
RoboErikde20d762011-02-08 17:52:25 -0800218 }
219 mHideString = res.getString(R.string.hide_controls);
220 mShowString = res.getString(R.string.show_controls);
RoboErikb8549562011-02-15 14:25:23 -0800221 mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
RoboErikb8549562011-02-15 14:25:23 -0800222
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700223 mIsMultipane = Utils.isMultiPaneConfiguration (this);
Erik9fc409f2010-07-28 11:40:47 -0700224
Erik63cd0532011-01-26 14:16:03 -0800225 Utils.setAllowWeekForDetailView(mIsMultipane);
Michael Chanb60218a2010-12-14 16:34:39 -0800226
Erikeaafa2b2010-12-23 14:30:37 -0800227 mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
228
Erikbe8191c2010-10-26 16:50:08 -0700229 // setContentView must be called before configureActionBar
230 setContentView(R.layout.all_in_one);
231 // configureActionBar auto-selects the first tab you add, so we need to
232 // call it before we set up our own fragments to make sure it doesn't
233 // overwrite us
234 configureActionBar();
235
Erik3f348f32010-08-10 13:17:19 -0700236 // Must be the first to register because this activity can modify the
237 // list of event handlers in it's handle method. This affects who the
238 // rest of the handlers the controller dispatches to are.
239 mController.registerEventHandler(HANDLER_KEY, this);
Michael Chan83b0fe32010-07-08 16:46:26 -0700240
Erik6c255102010-09-29 14:43:00 -0700241 mHomeTime = (TextView) findViewById(R.id.home_time);
RoboErikde20d762011-02-08 17:52:25 -0800242 mMiniMonth = findViewById(R.id.mini_month);
243 mCalendarsList = findViewById(R.id.calendar_list);
244 mMiniMonthContainer = findViewById(R.id.mini_month_container);
Michael Chan83b0fe32010-07-08 16:46:26 -0700245
Erik7b92da22010-09-23 14:55:22 -0700246 initFragments(timeMillis, viewType, icicle);
Mason Tang8e3d4302010-07-12 17:39:30 -0700247
Erik6c255102010-09-29 14:43:00 -0700248
Mason Tang8e3d4302010-07-12 17:39:30 -0700249 // Listen for changes that would require this to be refreshed
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700250 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700251 prefs.registerOnSharedPreferenceChangeListener(this);
Erikcb811892010-09-28 13:44:19 -0700252
Erik954c8712010-08-06 10:12:34 -0700253 mContentResolver = getContentResolver();
Erikbe8191c2010-10-26 16:50:08 -0700254 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700255
Michael Chan2c7c8512010-12-10 14:12:57 -0800256 private long parseViewAction(final Intent intent) {
257 long timeMillis = -1;
258 Uri data = intent.getData();
259 if (data != null && data.isHierarchical()) {
260 List<String> path = data.getPathSegments();
261 if (path.size() == 2 && path.get(0).equals("events")) {
262 try {
263 mViewEventId = Long.valueOf(data.getLastPathSegment());
264 if(mViewEventId != -1) {
265 mIntentEventStartMillis = intent.getLongExtra(EVENT_BEGIN_TIME, 0);
266 mIntentEventEndMillis = intent.getLongExtra(EVENT_END_TIME, 0);
267 mIntentAttendeeResponse = intent.getIntExtra(
Michael Chandeced892010-12-10 15:59:35 -0800268 ATTENDEE_STATUS, CalendarController.ATTENDEE_NO_RESPONSE);
Michael Chan2c7c8512010-12-10 14:12:57 -0800269 timeMillis = mIntentEventStartMillis;
270 }
271 } catch (NumberFormatException e) {
272 // Ignore if mViewEventId can't be parsed
273 }
274 }
275 }
276 return timeMillis;
277 }
278
Erikbe8191c2010-10-26 16:50:08 -0700279 private void configureActionBar() {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700280 mActionBar = getActionBar();
Michael Chandeced892010-12-10 15:59:35 -0800281 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700282 if (mActionBar == null) {
283 Log.w(TAG, "ActionBar is null.");
284 } else {
285 mDayTab = mActionBar.newTab();
286 mDayTab.setText(getString(R.string.day_view));
287 mDayTab.setTabListener(this);
288 mActionBar.addTab(mDayTab);
289 mWeekTab = mActionBar.newTab();
290 mWeekTab.setText(getString(R.string.week_view));
291 mWeekTab.setTabListener(this);
292 mActionBar.addTab(mWeekTab);
293 mMonthTab = mActionBar.newTab();
294 mMonthTab.setText(getString(R.string.month_view));
295 mMonthTab.setTabListener(this);
296 mActionBar.addTab(mMonthTab);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700297 mAgendaTab = mActionBar.newTab();
298 mAgendaTab.setText(getString(R.string.agenda_view));
299 mAgendaTab.setTabListener(this);
300 mActionBar.addTab(mAgendaTab);
Erikeaafa2b2010-12-23 14:30:37 -0800301 mActionBar.setCustomView(mDateRange);
Isaac Katzenelson0b1bd102011-04-07 14:26:29 -0700302 if (mIsMultipane) {
303 mActionBar.setDisplayOptions(
304 ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700305 } else {
306 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
307 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700308 }
Erik954c8712010-08-06 10:12:34 -0700309 }
310
311 @Override
312 protected void onResume() {
313 super.onResume();
314 mContentResolver.registerContentObserver(Calendar.Events.CONTENT_URI, true, mObserver);
Erikcb811892010-09-28 13:44:19 -0700315 if (mUpdateOnResume) {
316 initFragments(mController.getTime(), mController.getViewType(), null);
317 mUpdateOnResume = false;
318 }
Erik6c255102010-09-29 14:43:00 -0700319 updateHomeClock();
RoboErik3b3af612011-02-24 13:42:57 -0800320 if (mControlsMenu != null) {
321 mControlsMenu.setTitle(mHideControls ? mShowString : mHideString);
322 }
Erikcb811892010-09-28 13:44:19 -0700323 mPaused = false;
Michael Chan6191c122010-11-02 16:23:47 -0700324 mOnSaveInstanceStateCalled = false;
Michael Chan2c7c8512010-12-10 14:12:57 -0800325
326 if (mViewEventId != -1 && mIntentEventStartMillis != -1 && mIntentEventEndMillis != -1) {
RoboErikf6b58a92011-02-24 14:22:11 -0800327 long currentMillis = System.currentTimeMillis();
328 long selectedTime = -1;
329 if (currentMillis > mIntentEventStartMillis && currentMillis < mIntentEventEndMillis) {
330 selectedTime = currentMillis;
331 }
Michael Chanf0868f62011-01-11 19:37:35 -0800332 mController.sendEventRelatedEventWithResponse(this, EventType.VIEW_EVENT, mViewEventId,
RoboErikf6b58a92011-02-24 14:22:11 -0800333 mIntentEventStartMillis, mIntentEventEndMillis, -1, -1, mIntentAttendeeResponse,
334 selectedTime);
Michael Chan2c7c8512010-12-10 14:12:57 -0800335 mViewEventId = -1;
336 mIntentEventStartMillis = -1;
337 mIntentEventEndMillis = -1;
338 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700339 }
340
341 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700342 protected void onPause() {
343 super.onPause();
Erikcb811892010-09-28 13:44:19 -0700344 mPaused = true;
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700345 mHomeTime.removeCallbacks(mHomeTimeUpdater);
Erik954c8712010-08-06 10:12:34 -0700346 mContentResolver.unregisterContentObserver(mObserver);
Erikcb811892010-09-28 13:44:19 -0700347 if (isFinishing()) {
348 // Stop listening for changes that would require this to be refreshed
349 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
350 prefs.unregisterOnSharedPreferenceChangeListener(this);
351 }
Erik7b92da22010-09-23 14:55:22 -0700352 // FRAG_TODO save highlighted days of the week;
Erikdd95df52010-08-27 09:31:18 -0700353 if (mController.getViewType() != ViewType.EDIT) {
354 Utils.setDefaultView(this, mController.getViewType());
355 }
Michael Chand6734db2010-07-22 00:48:08 -0700356 }
357
358 @Override
Erik7b92da22010-09-23 14:55:22 -0700359 protected void onUserLeaveHint() {
360 mController.sendEvent(this, EventType.USER_HOME, null, null, -1, ViewType.CURRENT);
361 super.onUserLeaveHint();
362 }
363
364 @Override
Michael Chand6734db2010-07-22 00:48:08 -0700365 public void onSaveInstanceState(Bundle outState) {
Michael Chan6191c122010-11-02 16:23:47 -0700366 mOnSaveInstanceStateCalled = true;
Michael Chand6734db2010-07-22 00:48:08 -0700367 super.onSaveInstanceState(outState);
368
369 outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime());
Erik7b92da22010-09-23 14:55:22 -0700370 if (mCurrentView == ViewType.EDIT) {
RoboErik277eb972011-02-24 16:05:04 -0800371 outState.putInt(BUNDLE_KEY_RESTORE_VIEW, mCurrentView);
Erik7b92da22010-09-23 14:55:22 -0700372 outState.putLong(BUNDLE_KEY_EVENT_ID, mController.getEventId());
373 }
Michael Chand6734db2010-07-22 00:48:08 -0700374 }
375
376 @Override
Mason Tang8e3d4302010-07-12 17:39:30 -0700377 protected void onDestroy() {
378 super.onDestroy();
379
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700380 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700381 prefs.unregisterOnSharedPreferenceChangeListener(this);
Eriked61b482010-08-13 13:59:50 -0700382 CalendarController.removeInstance(this);
Mason Tang8e3d4302010-07-12 17:39:30 -0700383 }
384
Erik7b92da22010-09-23 14:55:22 -0700385 private void initFragments(long timeMillis, int viewType, Bundle icicle) {
Dianne Hackborn12b33302011-01-17 12:30:13 -0800386 FragmentTransaction ft = getFragmentManager().beginTransaction();
Michael Chan3458a172010-07-13 17:58:21 -0700387
Erik9fc409f2010-07-28 11:40:47 -0700388 if (mIsMultipane) {
Erik40bcd102010-11-16 15:46:40 -0800389 Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
Michael Chanab29d9e2010-07-21 06:08:47 -0700390 ft.replace(R.id.mini_month, miniMonthFrag);
Erik3f348f32010-08-10 13:17:19 -0700391 mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700392
393 Fragment selectCalendarsFrag = new SelectCalendarsFragment();
394 ft.replace(R.id.calendar_list, selectCalendarsFrag);
RoboErik8d1b2fd2011-02-25 10:24:43 -0800395 mController.registerEventHandler(
396 R.id.calendar_list, (EventHandler) selectCalendarsFrag);
Erikdd95df52010-08-27 09:31:18 -0700397 }
Erik7b92da22010-09-23 14:55:22 -0700398 if (!mIsMultipane || viewType == ViewType.EDIT) {
RoboErikde20d762011-02-08 17:52:25 -0800399 mMiniMonth.setVisibility(View.GONE);
400 mCalendarsList.setVisibility(View.GONE);
Michael Chanab29d9e2010-07-21 06:08:47 -0700401 }
Michael Chan3458a172010-07-13 17:58:21 -0700402
Erikdd95df52010-08-27 09:31:18 -0700403 EventInfo info = null;
404 if (viewType == ViewType.EDIT) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700405 mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(
Erik7b92da22010-09-23 14:55:22 -0700406 GeneralPreferences.KEY_START_VIEW, GeneralPreferences.DEFAULT_START_VIEW);
Erikdd95df52010-08-27 09:31:18 -0700407
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700408 long eventId = -1;
Erikdd95df52010-08-27 09:31:18 -0700409 Intent intent = getIntent();
410 Uri data = intent.getData();
411 if (data != null) {
412 try {
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700413 eventId = Long.parseLong(data.getLastPathSegment());
Erikdd95df52010-08-27 09:31:18 -0700414 } catch (NumberFormatException e) {
415 if (DEBUG) {
416 Log.d(TAG, "Create new event");
417 }
418 }
Erik7b92da22010-09-23 14:55:22 -0700419 } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
420 eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
Erikdd95df52010-08-27 09:31:18 -0700421 }
Daisuke Miyakawa4143cfa2010-09-17 19:55:04 -0700422
Erikdd95df52010-08-27 09:31:18 -0700423 long begin = intent.getLongExtra(EVENT_BEGIN_TIME, -1);
424 long end = intent.getLongExtra(EVENT_END_TIME, -1);
425 info = new EventInfo();
426 if (end != -1) {
427 info.endTime = new Time();
428 info.endTime.set(end);
429 }
430 if (begin != -1) {
431 info.startTime = new Time();
432 info.startTime.set(begin);
433 }
434 info.id = eventId;
435 // We set the viewtype so if the user presses back when they are
436 // done editing the controller knows we were in the Edit Event
Erik7b92da22010-09-23 14:55:22 -0700437 // screen. Likewise for eventId
Erikdd95df52010-08-27 09:31:18 -0700438 mController.setViewType(viewType);
Erik7b92da22010-09-23 14:55:22 -0700439 mController.setEventId(eventId);
Erikdd95df52010-08-27 09:31:18 -0700440 } else {
441 mPreviousView = viewType;
442 }
Erik63cd0532011-01-26 14:16:03 -0800443 setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
Michael Chan3458a172010-07-13 17:58:21 -0700444
445 ft.commit(); // this needs to be after setMainPane()
446
Erikc5f92d72010-11-11 16:18:34 -0800447 Time t = new Time(mTimeZone);
Michael Chand6734db2010-07-22 00:48:08 -0700448 t.set(timeMillis);
Erikdd95df52010-08-27 09:31:18 -0700449 if (viewType != ViewType.EDIT) {
450 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
451 }
Michael Chan49701592010-06-30 11:04:03 -0700452 }
Erik2051f122010-07-02 13:45:45 -0700453
454 @Override
Erik648c59c2010-08-13 12:49:26 -0700455 public void onBackPressed() {
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700456 if (mCurrentView == ViewType.EDIT || mCurrentView == ViewType.DETAIL) {
Erikdd95df52010-08-27 09:31:18 -0700457 mController.sendEvent(this, EventType.GO_TO, null, null, -1, mPreviousView);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700458 } else {
459 super.onBackPressed();
Erik648c59c2010-08-13 12:49:26 -0700460 }
461 }
462
463 @Override
Erik2051f122010-07-02 13:45:45 -0700464 public boolean onCreateOptionsMenu(Menu menu) {
465 super.onCreateOptionsMenu(menu);
466
Erik2051f122010-07-02 13:45:45 -0700467 getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu);
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700468
Erikcb830312011-01-19 14:41:41 -0800469 mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
470 if (mSearchView != null) {
471 mSearchView.setIconifiedByDefault(true);
Adam Powell28f9b352011-01-20 18:36:10 -0800472 mSearchView.setOnQueryTextListener(this);
Erikcb830312011-01-19 14:41:41 -0800473 mSearchView.setSubmitButtonEnabled(true);
Michael Chan09b1b2e2011-04-05 11:24:32 -0700474 if (!mIsMultipane)
475 mSearchView.setVisibility(View.GONE);
Michael Chan71b221a2010-10-25 17:55:44 -0700476 }
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700477
478 // Hide the "show/hide controls" button if this is a phone
479 // or the view type is "Month".
480
RoboErikde20d762011-02-08 17:52:25 -0800481 mControlsMenu = menu.findItem(R.id.action_hide_controls);
Isaac Katzenelson5b2a9072011-04-08 15:23:57 -0700482 if (!mIsMultipane) {
483 if (mControlsMenu != null) {
484 mControlsMenu.setVisible(false);
485 mControlsMenu.setEnabled(false);
486 }
487 } else if (mControlsMenu != null && mController != null
488 && mController.getViewType() == ViewType.MONTH) {
RoboErikde20d762011-02-08 17:52:25 -0800489 mControlsMenu.setVisible(false);
490 mControlsMenu.setEnabled(false);
491 }
Erik2051f122010-07-02 13:45:45 -0700492 return true;
493 }
Michael Chan3458a172010-07-13 17:58:21 -0700494
495 @Override
496 public boolean onOptionsItemSelected(MenuItem item) {
497 Time t = null;
498 int viewType = ViewType.CURRENT;
499 switch (item.getItemId()) {
Erikba1b94a2010-07-20 17:50:50 -0700500 case R.id.action_refresh:
501 mController.refreshCalendars();
502 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700503 case R.id.action_today:
504 viewType = ViewType.CURRENT;
Erikc5f92d72010-11-11 16:18:34 -0800505 t = new Time(mTimeZone);
Michael Chan3458a172010-07-13 17:58:21 -0700506 t.setToNow();
507 break;
508 case R.id.action_create_event:
RoboErik0271b412011-03-01 15:34:53 -0800509 t = new Time();
510 t.set(mController.getTime());
511 if (t.minute >= 30) {
RoboErikd97f7982011-03-02 15:13:05 -0800512 t.hour++;
RoboErik0271b412011-03-01 15:34:53 -0800513 t.minute = 0;
RoboErikd97f7982011-03-02 15:13:05 -0800514 } else {
515 t.minute = 30;
RoboErik0271b412011-03-01 15:34:53 -0800516 }
517 mController.sendEventRelatedEvent(
518 this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
Michael Chan3458a172010-07-13 17:58:21 -0700519 return true;
Michael Chanab29d9e2010-07-21 06:08:47 -0700520 case R.id.action_settings:
521 mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
522 return true;
RoboErikde20d762011-02-08 17:52:25 -0800523 case R.id.action_hide_controls:
524 mHideControls = !mHideControls;
525 item.setTitle(mHideControls ? mShowString : mHideString);
RoboErikb8549562011-02-15 14:25:23 -0800526 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
527 mHideControls ? 0 : CONTROLS_ANIMATE_WIDTH,
528 mHideControls ? CONTROLS_ANIMATE_WIDTH : 0);
529 slideAnimation.setDuration(CONTROLS_ANIMATE_DURATION);
530 ObjectAnimator.setFrameDelay(0);
531 slideAnimation.start();
RoboErikde20d762011-02-08 17:52:25 -0800532 return true;
Michael Chan3458a172010-07-13 17:58:21 -0700533 default:
534 return false;
535 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700536 mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
Michael Chan3458a172010-07-13 17:58:21 -0700537 return true;
538 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700539
RoboErikb8549562011-02-15 14:25:23 -0800540 /**
541 * Sets the offset of the controls on the right for animating them off/on
542 * screen. ProGuard strips this if it's not in proguard.flags
543 *
544 * @param controlsOffset The current offset in pixels
545 */
546 public void setControlsOffset(int controlsOffset) {
547 mMiniMonth.setTranslationX(controlsOffset);
548 mCalendarsList.setTranslationX(controlsOffset);
549 mHomeTime.setTranslationX(controlsOffset);
Michael Chan5756bbc2011-03-02 18:22:07 -0800550 mControlsParams.width = Math.max(0, CONTROLS_ANIMATE_WIDTH - controlsOffset);
RoboErikb8549562011-02-15 14:25:23 -0800551 mMiniMonthContainer.setLayoutParams(mControlsParams);
552 }
RoboErikde20d762011-02-08 17:52:25 -0800553
Mason Tang8e3d4302010-07-12 17:39:30 -0700554 @Override
555 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Daisuke Miyakawa4b441bd2010-09-16 14:55:36 -0700556 if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
Erikcb811892010-09-28 13:44:19 -0700557 if (mPaused) {
558 mUpdateOnResume = true;
559 } else {
560 initFragments(mController.getTime(), mController.getViewType(), null);
561 }
Mason Tang8e3d4302010-07-12 17:39:30 -0700562 }
563 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700564
Erik63cd0532011-01-26 14:16:03 -0800565 private void setMainPane(
566 FragmentTransaction ft, int viewId, int viewType, long timeMillis, boolean force) {
Michael Chan6191c122010-11-02 16:23:47 -0700567 if (mOnSaveInstanceStateCalled) {
568 return;
569 }
Erik7b92da22010-09-23 14:55:22 -0700570 if (!force && mCurrentView == viewType) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700571 return;
572 }
573
Michael Chan5756bbc2011-03-02 18:22:07 -0800574 // Remove this when transition to and from month view looks fine.
575 boolean doTransition = viewType != ViewType.MONTH && mCurrentView != ViewType.MONTH;
576
Erik648c59c2010-08-13 12:49:26 -0700577 if (viewType != mCurrentView) {
578 // The rules for this previous view are different than the
579 // controller's and are used for intercepting the back button.
Erikdd95df52010-08-27 09:31:18 -0700580 if (mCurrentView != ViewType.EDIT && mCurrentView > 0) {
581 mPreviousView = mCurrentView;
582 }
Erik648c59c2010-08-13 12:49:26 -0700583 mCurrentView = viewType;
584 }
Erik3f348f32010-08-10 13:17:19 -0700585 // Create new fragment
586 Fragment frag;
Michael Chanab29d9e2010-07-21 06:08:47 -0700587 switch (viewType) {
588 case ViewType.AGENDA:
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700589 if (mActionBar != null && (mActionBar.getSelectedTab() != mAgendaTab)) {
590 mActionBar.selectTab(mAgendaTab);
591 }
Mason Tang31df4262010-07-19 17:51:46 -0700592 frag = new AgendaFragment(timeMillis);
Michael Chanab29d9e2010-07-21 06:08:47 -0700593 break;
594 case ViewType.DAY:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700595 if (mActionBar != null && (mActionBar.getSelectedTab() != mDayTab)) {
596 mActionBar.selectTab(mDayTab);
597 }
Michael Chan75d9b562010-07-26 16:54:25 -0700598 frag = new DayFragment(timeMillis, 1);
599 break;
Michael Chanab29d9e2010-07-21 06:08:47 -0700600 case ViewType.WEEK:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700601 if (mActionBar != null && (mActionBar.getSelectedTab() != mWeekTab)) {
602 mActionBar.selectTab(mWeekTab);
603 }
Michael Chan75d9b562010-07-26 16:54:25 -0700604 frag = new DayFragment(timeMillis, 7);
Michael Chanab29d9e2010-07-21 06:08:47 -0700605 break;
606 case ViewType.MONTH:
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700607 if (mActionBar != null && (mActionBar.getSelectedTab() != mMonthTab)) {
608 mActionBar.selectTab(mMonthTab);
609 }
Erik40bcd102010-11-16 15:46:40 -0800610 frag = new MonthByWeekFragment(timeMillis, false);
Michael Chanab29d9e2010-07-21 06:08:47 -0700611 break;
612 default:
Michael Chand6734db2010-07-22 00:48:08 -0700613 throw new IllegalArgumentException(
614 "Must be Agenda, Day, Week, or Month ViewType, not " + viewType);
Michael Chanab29d9e2010-07-21 06:08:47 -0700615 }
616
617 boolean doCommit = false;
618 if (ft == null) {
619 doCommit = true;
Dianne Hackborn12b33302011-01-17 12:30:13 -0800620 ft = getFragmentManager().beginTransaction();
Michael Chanab29d9e2010-07-21 06:08:47 -0700621 }
622
Michael Chan5756bbc2011-03-02 18:22:07 -0800623 if (doTransition) {
624 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
625 }
626
Michael Chanab29d9e2010-07-21 06:08:47 -0700627 ft.replace(viewId, frag);
Daisuke Miyakawa93e69eb2010-10-22 18:54:38 -0700628
Erik954c8712010-08-06 10:12:34 -0700629 if (DEBUG) {
630 Log.d(TAG, "Adding handler with viewId " + viewId + " and type " + viewType);
631 }
Erik3f348f32010-08-10 13:17:19 -0700632 // If the key is already registered this will replace it
633 mController.registerEventHandler(viewId, (EventHandler) frag);
Michael Chanab29d9e2010-07-21 06:08:47 -0700634
635 if (doCommit) {
Michael Chane8f45c62011-03-01 14:41:03 -0800636 Log.d(TAG, "setMainPane AllInOne=" + this + " finishing:" + this.isFinishing());
Michael Chanab29d9e2010-07-21 06:08:47 -0700637 ft.commit();
638 }
639 }
640
641 private void setTitleInActionBar(EventInfo event) {
Erikeaafa2b2010-12-23 14:30:37 -0800642 if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700643 return;
644 }
645
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700646 final long start = event.startTime.toMillis(false /* use isDst */);
647 final long end;
Michael Chand6734db2010-07-22 00:48:08 -0700648 if (event.endTime != null) {
Michael Chanab29d9e2010-07-21 06:08:47 -0700649 end = event.endTime.toMillis(false /* use isDst */);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700650 } else {
651 end = start;
Michael Chanab29d9e2010-07-21 06:08:47 -0700652 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700653
Erikeaafa2b2010-12-23 14:30:37 -0800654 final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
Erik259b8f92011-01-12 14:01:12 -0800655 CharSequence oldDate = mDateRange.getText();
Erikeaafa2b2010-12-23 14:30:37 -0800656 mDateRange.setText(msg);
Erik259b8f92011-01-12 14:01:12 -0800657 if (!TextUtils.equals(oldDate, msg)) {
658 mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
659 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700660 }
661
Erik6c255102010-09-29 14:43:00 -0700662 private void updateHomeClock() {
Erikc5f92d72010-11-11 16:18:34 -0800663 mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
Erik6c255102010-09-29 14:43:00 -0700664 if (mIsMultipane && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK)
Erikc5f92d72010-11-11 16:18:34 -0800665 && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
666 Time time = new Time(mTimeZone);
Erik6c255102010-09-29 14:43:00 -0700667 time.setToNow();
668 long millis = time.toMillis(true);
669 boolean isDST = time.isDst != 0;
670 int flags = DateUtils.FORMAT_SHOW_TIME;
671 if (DateFormat.is24HourFormat(this)) {
672 flags |= DateUtils.FORMAT_24HOUR;
673 }
674 // Formats the time as
Erikc5f92d72010-11-11 16:18:34 -0800675 String timeString = (new StringBuilder(
676 Utils.formatDateRange(this, millis, millis, flags))).append(" ").append(
677 TimeZone.getTimeZone(mTimeZone).getDisplayName(
678 isDST, TimeZone.SHORT, Locale.getDefault())).toString();
Erik6c255102010-09-29 14:43:00 -0700679 mHomeTime.setText(timeString);
680 mHomeTime.setVisibility(View.VISIBLE);
681 // Update when the minute changes
682 mHomeTime.postDelayed(
Daisuke Miyakawac9e53072010-10-14 12:18:49 -0700683 mHomeTimeUpdater,
684 DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
Erik6c255102010-09-29 14:43:00 -0700685 } else {
686 mHomeTime.setVisibility(View.GONE);
687 }
688 }
689
Erik3f348f32010-08-10 13:17:19 -0700690 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700691 public long getSupportedEventTypes() {
Erikeaafa2b2010-12-23 14:30:37 -0800692 return EventType.GO_TO | EventType.VIEW_EVENT | EventType.UPDATE_TITLE;
Michael Chanab29d9e2010-07-21 06:08:47 -0700693 }
694
Erik3f348f32010-08-10 13:17:19 -0700695 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700696 public void handleEvent(EventInfo event) {
Michael Chane8f45c62011-03-01 14:41:03 -0800697 Log.d(TAG, "handleEvent AllInOne=" + this);
Michael Chanab29d9e2010-07-21 06:08:47 -0700698 if (event.eventType == EventType.GO_TO) {
Erik63cd0532011-01-26 14:16:03 -0800699 setMainPane(
700 null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
Erikaa3dde12011-02-03 11:16:23 -0800701 if (mSearchView != null) {
702 mSearchView.clearFocus();
703 }
Erik9fc409f2010-07-28 11:40:47 -0700704 if (!mIsMultipane) {
705 return;
706 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700707 if (event.viewType == ViewType.MONTH) {
708 // hide minimonth and calendar frag
Michael Chan5756bbc2011-03-02 18:22:07 -0800709 mShowSideViews = false;
RoboErikde20d762011-02-08 17:52:25 -0800710 if (mControlsMenu != null) {
711 mControlsMenu.setVisible(false);
712 mControlsMenu.setEnabled(false);
Michael Chan5756bbc2011-03-02 18:22:07 -0800713
Michael Chan100bdbe2011-03-04 22:30:10 -0800714 if (!mHideControls) {
715 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
716 "controlsOffset", 0, CONTROLS_ANIMATE_WIDTH);
717 slideAnimation.addListener(mSlideAnimationDoneListener);
718 slideAnimation.setDuration(220);
719 ObjectAnimator.setFrameDelay(0);
720 slideAnimation.start();
721 }
Michael Chan5756bbc2011-03-02 18:22:07 -0800722 } else {
723 mMiniMonth.setVisibility(View.GONE);
724 mCalendarsList.setVisibility(View.GONE);
725 mMiniMonthContainer.setVisibility(View.GONE);
RoboErikde20d762011-02-08 17:52:25 -0800726 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700727 } else {
728 // show minimonth and calendar frag
Michael Chan5756bbc2011-03-02 18:22:07 -0800729 mShowSideViews = true;
RoboErikde20d762011-02-08 17:52:25 -0800730 mMiniMonth.setVisibility(View.VISIBLE);
731 mCalendarsList.setVisibility(View.VISIBLE);
732 mMiniMonthContainer.setVisibility(View.VISIBLE);
733 if (mControlsMenu != null) {
734 mControlsMenu.setVisible(true);
735 mControlsMenu.setEnabled(true);
Michael Chan100bdbe2011-03-04 22:30:10 -0800736 if (!mHideControls && mController.getPreviousViewType() == ViewType.MONTH) {
Michael Chan5756bbc2011-03-02 18:22:07 -0800737 final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this,
738 "controlsOffset", CONTROLS_ANIMATE_WIDTH, 0);
739 slideAnimation.setDuration(220);
740 ObjectAnimator.setFrameDelay(0);
741 slideAnimation.start();
742 }
RoboErikde20d762011-02-08 17:52:25 -0800743 }
Michael Chanab29d9e2010-07-21 06:08:47 -0700744 }
Michael Chan71d08832010-08-25 18:28:59 -0700745 } else if (event.eventType == EventType.VIEW_EVENT) {
Michael Chan0a01fd32011-01-23 15:13:28 -0800746 EventInfoFragment fragment = new EventInfoFragment(this,
Michael Chandeced892010-12-10 15:59:35 -0800747 event.id, event.startTime.toMillis(false), event.endTime.toMillis(false),
748 (int) event.extraLong);
RoboErik87f993f2011-02-03 17:47:20 -0800749 if (event.selectedTime != null) {
750 mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime,
751 -1, ViewType.DETAIL);
Erik63cd0532011-01-26 14:16:03 -0800752 }
Isaac Katzenelson0b1bd102011-04-07 14:26:29 -0700753 fragment.setDialogParams(event.x, event.y, !mIsMultipane);
Erik63cd0532011-01-26 14:16:03 -0800754 FragmentManager fm = getFragmentManager();
755 FragmentTransaction ft = fm.beginTransaction();
756 // if we have an old popup close it
757 Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
Michael Chane8f45c62011-03-01 14:41:03 -0800758 if (fOld != null && fOld.isAdded()) {
Erik63cd0532011-01-26 14:16:03 -0800759 ft.remove(fOld);
760 }
761 ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
762 ft.commit();
Erikeaafa2b2010-12-23 14:30:37 -0800763 } else if (event.eventType == EventType.UPDATE_TITLE) {
764 setTitleInActionBar(event);
Michael Chanab29d9e2010-07-21 06:08:47 -0700765 }
Erik6c255102010-09-29 14:43:00 -0700766 updateHomeClock();
Michael Chanab29d9e2010-07-21 06:08:47 -0700767 }
768
Erik3f348f32010-08-10 13:17:19 -0700769 @Override
Michael Chanab29d9e2010-07-21 06:08:47 -0700770 public void eventsChanged() {
Erik954c8712010-08-06 10:12:34 -0700771 mController.sendEvent(this, EventType.EVENTS_CHANGED, null, null, -1, ViewType.CURRENT);
Michael Chanab29d9e2010-07-21 06:08:47 -0700772 }
773
Erik3f348f32010-08-10 13:17:19 -0700774 @Override
Adam Powell28f9b352011-01-20 18:36:10 -0800775 public boolean onQueryTextChange(String newText) {
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700776 return false;
777 }
778
779 @Override
Adam Powell28f9b352011-01-20 18:36:10 -0800780 public boolean onQueryTextSubmit(String query) {
Erikca478672011-01-19 20:02:47 -0800781 if (TextUtils.equals(query, "TARDIS")) {
782 Utils.tardis();
783 }
Erikcb830312011-01-19 14:41:41 -0800784 mSearchView.clearFocus();
Michael Chan46a8b112010-12-14 16:36:27 -0800785 mController.sendEvent(this, EventType.SEARCH, null, null, -1, ViewType.CURRENT, -1, query,
Erik7b92da22010-09-23 14:55:22 -0700786 getComponentName());
Daisuke Miyakawa6d2e6f72010-09-17 10:30:54 -0700787 return false;
788 }
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700789
790 @Override
791 public void onTabSelected(Tab tab, FragmentTransaction ft) {
Michael Chane8f45c62011-03-01 14:41:03 -0800792 Log.w(TAG, "TabSelected AllInOne=" + this + " finishing:" + this.isFinishing());
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700793 if (tab == mDayTab && mCurrentView != ViewType.DAY) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700794 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.DAY);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700795 } else if (tab == mWeekTab && mCurrentView != ViewType.WEEK) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700796 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.WEEK);
Daisuke Miyakawa40474a82010-10-25 17:07:34 -0700797 } else if (tab == mMonthTab && mCurrentView != ViewType.MONTH) {
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700798 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.MONTH);
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700799 } else if (tab == mAgendaTab && mCurrentView != ViewType.AGENDA) {
800 mController.sendEvent(this, EventType.GO_TO, null, null, -1, ViewType.AGENDA);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700801 } else {
Michael Chanece2fbd2011-01-19 14:49:37 -0800802 Log.w(TAG, "TabSelected event from unknown tab: "
803 + (tab == null ? "null" : tab.getText()));
804 Log.w(TAG, "CurrentView:" + mCurrentView + " Tab:" + tab.toString() + " Day:" + mDayTab
Isaac Katzenelsonae7c1c62011-04-11 18:30:26 -0700805 + " Week:" + mWeekTab + " Month:" + mMonthTab + " Agenda:" + mAgendaTab);
Daisuke Miyakawa04ae7682010-10-19 14:15:39 -0700806 }
807 }
808
809 @Override
810 public void onTabReselected(Tab tab, FragmentTransaction ft) {
811 }
812
813 @Override
814 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
815 }
Michael Chan49701592010-06-30 11:04:03 -0700816}