Fields Summary |
---|
protected static final String | BUNDLE_KEY_RESTORE_TIME |
static final String[] | PROJECTION |
public static final int | INDEX_TITLE |
public static final int | INDEX_EVENT_LOCATION |
public static final int | INDEX_ALL_DAY |
public static final int | INDEX_HAS_ALARM |
public static final int | INDEX_COLOR |
public static final int | INDEX_RRULE |
public static final int | INDEX_BEGIN |
public static final int | INDEX_END |
public static final int | INDEX_EVENT_ID |
public static final int | INDEX_START_DAY |
public static final int | INDEX_END_DAY |
public static final int | INDEX_SELF_ATTENDEE_STATUS |
public static final String | AGENDA_SORT_ORDER |
private static final long | INITIAL_HEAP_SIZE |
private android.content.ContentResolver | mContentResolver |
private android.widget.ViewSwitcher | mViewSwitcher |
private QueryHandler | mQueryHandler |
private DeleteEventHelper | mDeleteEventHelper |
private android.text.format.Time | mTime |
private android.text.format.Time | mLastQueryTimeThis records the start time parameter for the last query sent to the
AsyncQueryHandler so that we don't send it duplicate query requests. |
private android.content.BroadcastReceiver | mIntentReceiver |
private android.database.ContentObserver | mObserver |
Methods Summary |
---|
private void | clearLastQueryTime()Clears the cached value for the last query time so that renewCursor()
will force a requery of the Calendar events.
mLastQueryTime.year = 0;
mLastQueryTime.month = 0;
|
public boolean | getAllDay()
return false;
|
public long | getSelectedTime()
// Update the current time based on the selected event
AgendaListView current = (AgendaListView) mViewSwitcher.getCurrentView();
int position = current.getSelectedItemPosition();
position = current.getDayAdapter().getCursorPosition(position);
Cursor cursor = current.getCursor();
if (position >= 0 && position < cursor.getCount()) {
cursor.moveToPosition(position);
mTime.set(cursor.getLong(INDEX_BEGIN));
}
return mTime.toMillis(true);
|
public void | goTo(android.text.format.Time time)
if (mTime.year == time.year && mTime.month == time.month) {
mTime = time;
selectTime();
} else {
mTime = time;
renewCursor();
}
|
public void | goToToday()
Time now = new Time();
now.set(System.currentTimeMillis());
goTo(now);
|
public android.view.View | makeView()
AgendaListView agendaListView = new AgendaListView(this);
return agendaListView;
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
// Eliminate extra GCs during startup by setting the initial heap size to 4MB.
// TODO: We should restore the old heap size once the activity reaches the idle state
long oldHeapSize = VMRuntime.getRuntime().setMinimumHeapSize(INITIAL_HEAP_SIZE);
setContentView(R.layout.agenda_activity);
mContentResolver = getContentResolver();
mQueryHandler = new QueryHandler(mContentResolver);
// Preserve the same month and event selection if this activity is
// being restored due to an orientation change
mTime = new Time();
if (icicle != null) {
mTime.set(icicle.getLong(BUNDLE_KEY_RESTORE_TIME));
} else {
mTime.set(Utils.timeFromIntent(getIntent()));
}
setTitle(R.string.agenda_view);
mViewSwitcher = (ViewSwitcher) findViewById(R.id.switcher);
mViewSwitcher.setFactory(this);
// Record Agenda View as the (new) default detailed view.
String activityString = CalendarApplication.ACTIVITY_NAMES[CalendarApplication.AGENDA_VIEW_ID];
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(CalendarPreferenceActivity.KEY_DETAILED_VIEW, activityString);
// Record Agenda View as the (new) start view
editor.putString(CalendarPreferenceActivity.KEY_START_VIEW, activityString);
editor.commit();
mDeleteEventHelper = new DeleteEventHelper(this, false /* don't exit when done */);
|
public boolean | onCreateOptionsMenu(android.view.Menu menu)
MenuHelper.onCreateOptionsMenu(menu);
return super.onCreateOptionsMenu(menu);
|
public boolean | onKeyDown(int keyCode, android.view.KeyEvent event)
switch (keyCode) {
case KeyEvent.KEYCODE_DEL: {
// Delete the currently selected event (if any)
AgendaListView current = (AgendaListView) mViewSwitcher.getCurrentView();
Cursor cursor = current.getCursor();
if (cursor != null) {
int position = current.getSelectedItemPosition();
position = current.getDayAdapter().getCursorPosition(position);
if (position >= 0) {
cursor.moveToPosition(position);
long begin = cursor.getLong(INDEX_BEGIN);
long end = cursor.getLong(INDEX_END);
long eventId = cursor.getLong(INDEX_EVENT_ID);
mDeleteEventHelper.delete(begin, end, eventId, -1);
}
}
}
break;
case KeyEvent.KEYCODE_BACK:
finish();
return true;
}
return super.onKeyDown(keyCode, event);
|
public boolean | onOptionsItemSelected(android.view.MenuItem item)
MenuHelper.onOptionsItemSelected(this, item, this);
return super.onOptionsItemSelected(item);
|
protected void | onPause()
super.onPause();
mContentResolver.unregisterContentObserver(mObserver);
unregisterReceiver(mIntentReceiver);
|
public boolean | onPrepareOptionsMenu(android.view.Menu menu)
MenuHelper.onPrepareOptionsMenu(this, menu);
return super.onPrepareOptionsMenu(menu);
|
protected void | onResume()
super.onResume();
clearLastQueryTime();
renewCursor();
// Register for Intent broadcasts
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_DATE_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
registerReceiver(mIntentReceiver, filter);
mContentResolver.registerContentObserver(Events.CONTENT_URI, true, mObserver);
|
protected void | onSaveInstanceState(android.os.Bundle outState)
super.onSaveInstanceState(outState);
outState.putLong(BUNDLE_KEY_RESTORE_TIME, getSelectedTime());
|
private void | renewCursor()
// Avoid batching up repeated queries for the same month. This can
// happen if the user scrolls with the trackball too fast.
if (mLastQueryTime.month == mTime.month && mLastQueryTime.year == mTime.year) {
return;
}
// Query all instances for the current month
Time time = new Time();
time.year = mTime.year;
time.month = mTime.month;
long start = time.normalize(true);
time.month++;
long end = time.normalize(true);
StringBuilder path = new StringBuilder();
path.append(start);
path.append('/");
path.append(end);
// Respect the preference to show/hide declined events
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean hideDeclined = prefs.getBoolean(CalendarPreferenceActivity.KEY_HIDE_DECLINED,
false);
Uri uri = Uri.withAppendedPath(Instances.CONTENT_URI, path.toString());
String selection;
if (hideDeclined) {
selection = Calendars.SELECTED + "=1 AND " +
Instances.SELF_ATTENDEE_STATUS + "!=" + Attendees.ATTENDEE_STATUS_DECLINED;
} else {
selection = Calendars.SELECTED + "=1";
}
// Cancel any previous queries that haven't started yet. This
// isn't likely to happen since we already avoid sending
// a duplicate query for the same month as the previous query.
// But if the user quickly wiggles the trackball back and forth,
// he could generate a stream of queries.
mQueryHandler.cancelOperation(0);
mLastQueryTime.month = mTime.month;
mLastQueryTime.year = mTime.year;
mQueryHandler.startQuery(0, null, uri, PROJECTION, selection, null,
AGENDA_SORT_ORDER);
|
private void | selectTime()
// Selects the first event of the day
AgendaListView current = (AgendaListView) mViewSwitcher.getCurrentView();
if (current.getCursor() == null) {
return;
}
int position = current.getDayAdapter().findDayPositionNearestTime(mTime);
current.setSelection(position);
|