AllInOneActivity.java revision 0558defd2215696cee0768ce2bf2cb4da56efc42
14970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan/* 24970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * Copyright (C) 2010 The Android Open Source Project 34970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * 44970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * Licensed under the Apache License, Version 2.0 (the "License"); 54970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * you may not use this file except in compliance with the License. 64970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * You may obtain a copy of the License at 74970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * 84970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * http://www.apache.org/licenses/LICENSE-2.0 94970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * 104970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * Unless required by applicable law or agreed to in writing, software 114970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * distributed under the License is distributed on an "AS IS" BASIS, 124970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * See the License for the specific language governing permissions and 144970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan * limitations under the License. 154970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan */ 164970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan 174970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chanpackage com.android.calendar; 184970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan 1983b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chanimport com.android.calendar.CalendarController.EventHandler; 20ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chanimport com.android.calendar.CalendarController.EventInfo; 2183b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chanimport com.android.calendar.CalendarController.EventType; 223458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chanimport com.android.calendar.CalendarController.ViewType; 233458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chanimport com.android.calendar.SelectCalendars.SelectCalendarsFragment; 2483b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan 25ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chanimport android.app.ActionBar; 264970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chanimport android.app.Activity; 2783b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chanimport android.app.Fragment; 283458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chanimport android.app.FragmentTransaction; 298e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tangimport android.content.SharedPreferences; 308e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tangimport android.content.SharedPreferences.OnSharedPreferenceChangeListener; 31ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chanimport android.content.res.Configuration; 324970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chanimport android.os.Bundle; 333458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chanimport android.text.format.DateUtils; 3483b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chanimport android.text.format.Time; 352051f1275ec5e5eeffe5bbf5773860b855316d95Erikimport android.view.Menu; 363458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chanimport android.view.MenuItem; 37ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chanimport android.view.View; 384970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan 39ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chanpublic class AllInOneActivity extends Activity implements EventHandler, 40ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan OnSharedPreferenceChangeListener { 41d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan private static final String TAG = "AllInOneActivity"; 42d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan private static final String BUNDLE_KEY_RESTORE_TIME = "key_restore_time"; 430558defd2215696cee0768ce2bf2cb4da56efc42Michael Chan private static CalendarController mController; 4483b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan 454970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan @Override 4683b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan protected void onCreate(Bundle icicle) { 4783b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan super.onCreate(icicle); 4883b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan 4983b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan // This needs to be created before setContentView 500558defd2215696cee0768ce2bf2cb4da56efc42Michael Chan mController = CalendarController.getInstance(this); 51d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan 52d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan // Must be the first to register so that this activity can modify the 53d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan // list the event handlers during dispatching. 54ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan mController.registerEventHandler(this); 5583b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan 564970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan setContentView(R.layout.all_in_one); 5783b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan 583458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan // Get time from intent or icicle 5983b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan long timeMillis; 6083b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan if (icicle != null) { 61d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); 6283b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan } else { 6383b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan timeMillis = Utils.timeFromIntentInMillis(getIntent()); 6483b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan } 6583b0fe36b523192a504a1d2baf2f36676a80b9d5Michael Chan 66d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan initFragments(timeMillis, Utils.getViewTypeFromIntentAndSharedPref(this)); 678e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang 688e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang // Listen for changes that would require this to be refreshed 698e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this); 708e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang prefs.registerOnSharedPreferenceChangeListener(this); 718e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang } 728e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang 738e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang @Override 74d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan protected void onPause() { 75d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan super.onPause(); 76d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan //FRAG_TODO save highlighted days of the week; 77d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan Utils.setDefaultView(this, mController.getViewType()); 78d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan } 79d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan 80d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan @Override 81d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan public void onSaveInstanceState(Bundle outState) { 82d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan super.onSaveInstanceState(outState); 83d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan 84d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan outState.putLong(BUNDLE_KEY_RESTORE_TIME, mController.getTime()); 85d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan } 86d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan 87d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan @Override 888e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang protected void onDestroy() { 898e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang super.onDestroy(); 908e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang 918e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this); 928e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang prefs.unregisterOnSharedPreferenceChangeListener(this); 938e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang } 948e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang 95d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan private void initFragments(long timeMillis, int viewType) { 963458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan FragmentTransaction ft = openFragmentTransaction(); 973458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan 98ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan boolean multipane = (getResources().getConfiguration().screenLayout & 99ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan Configuration.SCREENLAYOUT_SIZE_XLARGE) != 0; 1003458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan 101ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (multipane) { 102ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan Fragment miniMonthFrag = new MonthFragment(false, timeMillis); 103ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ft.replace(R.id.mini_month, miniMonthFrag); 104ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan mController.registerEventHandler((EventHandler) miniMonthFrag); 105ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 106ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan Fragment selectCalendarsFrag = new SelectCalendarsFragment(); 107ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ft.replace(R.id.calendar_list, selectCalendarsFrag); 108ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } else { 109ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan findViewById(R.id.mini_month).setVisibility(View.GONE); 110ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan findViewById(R.id.calendar_list).setVisibility(View.GONE); 111ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 1123458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan 113d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan setMainPane(ft, R.id.main_pane, viewType, timeMillis, true); 1143458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan 1153458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan ft.commit(); // this needs to be after setMainPane() 1163458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan 117d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan Time t = new Time(); 118d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan t.set(timeMillis); 119d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType); 1204970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan } 1212051f1275ec5e5eeffe5bbf5773860b855316d95Erik 1222051f1275ec5e5eeffe5bbf5773860b855316d95Erik @Override 1232051f1275ec5e5eeffe5bbf5773860b855316d95Erik public boolean onCreateOptionsMenu(Menu menu) { 1242051f1275ec5e5eeffe5bbf5773860b855316d95Erik super.onCreateOptionsMenu(menu); 1252051f1275ec5e5eeffe5bbf5773860b855316d95Erik 1262051f1275ec5e5eeffe5bbf5773860b855316d95Erik getMenuInflater().inflate(R.menu.all_in_one_title_bar, menu); 1272051f1275ec5e5eeffe5bbf5773860b855316d95Erik return true; 1282051f1275ec5e5eeffe5bbf5773860b855316d95Erik } 1293458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan 1303458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan @Override 1313458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan public boolean onOptionsItemSelected(MenuItem item) { 1323458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan Time t = null; 1333458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan int viewType = ViewType.CURRENT; 1343458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan switch (item.getItemId()) { 135ba1b94afd187279623a57417da1ef78efa1217e2Erik case R.id.action_refresh: 136ba1b94afd187279623a57417da1ef78efa1217e2Erik mController.refreshCalendars(); 137ba1b94afd187279623a57417da1ef78efa1217e2Erik return true; 1383458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan case R.id.action_day: 1393458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan viewType = ViewType.DAY; 1403458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan break; 1413458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan case R.id.action_week: 1423458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan viewType = ViewType.WEEK; 1433458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan break; 1443458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan case R.id.action_month: 1453458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan viewType = ViewType.MONTH; 1463458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan break; 147ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan case R.id.action_agenda: 148ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan viewType = ViewType.AGENDA; 149ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan break; 1503458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan case R.id.action_today: 1513458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan viewType = ViewType.CURRENT; 1523458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan t = new Time(); 1533458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan t.setToNow(); 1543458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan break; 1553458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan case R.id.action_create_event: 1563458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan mController.sendEventRelatedEvent(this, EventType.CREATE_EVENT, -1, 0, 0, 0, 0); 1573458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan return true; 1582c477fc6410f4da175d8a9856561aab230ff1c19Michael Chan case R.id.action_manage_calendars: 1592c477fc6410f4da175d8a9856561aab230ff1c19Michael Chan mController.sendEvent(this, EventType.LAUNCH_MANAGE_CALENDARS, null, null, 0, 0); 1602c477fc6410f4da175d8a9856561aab230ff1c19Michael Chan return true; 161ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan case R.id.action_settings: 162ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0); 163ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan return true; 1643458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan default: 1653458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan return false; 1663458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan } 167ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType); 1683458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan return true; 1693458a1775920dda53099b7f1913cd4ec4c8b4095Michael Chan } 1708e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang 1718e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang @Override 1728e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { 1738e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang if (key.equals(CalendarPreferenceActivity.KEY_WEEK_START_DAY)) { 174d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan initFragments(mController.getTime(), mController.getViewType()); 1758e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang } 1768e3d430a020744faa21bf4ca24f1a99c36ec5c4fMason Tang } 177ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 178ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan private void setMainPane(FragmentTransaction ft, int viewId, int viewType, 179ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan long timeMillis, boolean force) { 180ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if(!force && mController.getPreviousViewType() == viewType) { 181ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan return; 182ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 183ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 184ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // Deregister old view 185ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan Fragment frag = findFragmentById(viewId); 186ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (frag != null) { 187ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan mController.deregisterEventHandler((EventHandler) frag); 188ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 189ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 190ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // Create new one 191ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan switch (viewType) { 192ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan case ViewType.AGENDA: 19331df4265e34c36df56e8b49de5cd0b24c02701e6Mason Tang frag = new AgendaFragment(timeMillis); 194ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan break; 195ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan case ViewType.DAY: 196ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan case ViewType.WEEK: 197ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan frag = new DayFragment(timeMillis); 198ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan break; 199ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan case ViewType.MONTH: 200ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan frag = new MonthFragment(false, timeMillis); 201ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan break; 202ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan default: 203d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan throw new IllegalArgumentException( 204d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan "Must be Agenda, Day, Week, or Month ViewType, not " + viewType); 205ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 206ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 207ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan boolean doCommit = false; 208ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (ft == null) { 209ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan doCommit = true; 210ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ft = openFragmentTransaction(); 211ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 212ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 213ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ft.replace(viewId, frag); 214ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan mController.registerEventHandler((EventHandler) frag); 215ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 216ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (doCommit) { 217ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ft.commit(); 218ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 219ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 220ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 221ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan private void setTitleInActionBar(EventInfo event) { 222ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (event.eventType != EventType.GO_TO) { 223ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan return; 224ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 225ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 226ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan long start = event.startTime.toMillis(false /* use isDst */); 227ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan long end = start; 228ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 229d6734dbbd704cdb1bc331d1bd74b7a3be58f69ffMichael Chan if (event.endTime != null) { 230ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan end = event.endTime.toMillis(false /* use isDst */); 231ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 232ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan String msg = DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_DATE); 233ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 234ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ActionBar ab = getActionBar(); 235ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (ab != null) { 236ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan ab.setTitle(msg); 237ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 238ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 239ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 240ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 241ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public long getSupportedEventTypes() { 242ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan return EventType.GO_TO; 243ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 244ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 245ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 246ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public void handleEvent(EventInfo event) { 247ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (event.eventType == EventType.GO_TO) { 248ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // Set title bar 249ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan setTitleInActionBar(event); 250ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 251ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan setMainPane(null, R.id.main_pane, event.viewType, 252ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan event.startTime.toMillis(false), false); 253ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 254ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // FRAG_TODO only for XL screen 255ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan if (event.viewType == ViewType.MONTH) { 256ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // hide minimonth and calendar frag 257ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // show agenda view 258ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } else { 259ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // show minimonth and calendar frag 260ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 261ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 262ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 263ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 264ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 265ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public void eventsChanged() { 266ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 267ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 268ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 269ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public boolean getAllDay() { 270ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan return false; 271ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 272ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 273ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 274ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public long getSelectedTime() { 275ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan return 0; 276ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 277ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 278ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 279ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public void goTo(Time time, boolean animate) { 280ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 281ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan 282ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan // EventHandler Interface 283ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan public void goToToday() { 284ab29d9ea9a4fe6b835c7f484a2273e92e8bc323dMichael Chan } 2854970159b2e6674fc5d61425aa0fcff8e5fc15bdbMichael Chan} 286