FileDocCategorySizeDatePackage
CalendarActivity.javaAPI DocAndroid 1.5 API12715Wed May 06 22:42:42 BST 2009com.android.calendar

CalendarActivity

public class CalendarActivity extends android.app.Activity implements Navigator
This is the base class for Day and Week Activities.

Fields Summary
private static final long
INITIAL_HEAP_SIZE
private static final long
ANIMATION_DURATION
protected static final String
BUNDLE_KEY_RESTORE_TIME
private android.content.ContentResolver
mContentResolver
private android.accounts.AccountMonitor
mAccountMonitor
protected android.widget.ProgressBar
mProgressBar
protected android.widget.ViewSwitcher
mViewSwitcher
protected android.view.animation.Animation
mInAnimationForward
protected android.view.animation.Animation
mOutAnimationForward
protected android.view.animation.Animation
mInAnimationBackward
protected android.view.animation.Animation
mOutAnimationBackward
EventLoader
mEventLoader
android.text.format.Time
mSelectedDay
android.view.GestureDetector
mGestureDetector
private android.content.BroadcastReceiver
mIntentReceiver
Listens for intent broadcasts
private android.database.ContentObserver
mObserver
Constructors Summary
Methods Summary
voideventsChanged()

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        view.clearCachedEvents();
        view.reloadEvents();
    
public booleangetAllDay()

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        return view.mSelectionAllDay;
    
EventgetNewEvent()

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        return view.getNewEvent();
    
public CalendarViewgetNextView()

        return (CalendarView) mViewSwitcher.getNextView();
    
EventgetSelectedEvent()

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        return view.getSelectedEvent();
    
public longgetSelectedTime()

        return getSelectedTimeInMillis();
    
public longgetSelectedTimeInMillis()
Returns the selected time in milliseconds. The milliseconds are measured in UTC milliseconds from the epoch and uniquely specifies any selectable time.

return
the selected time in milliseconds

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        return view.getSelectedTimeInMillis();
    
public voidgoTo(android.text.format.Time time)

        CalendarView current = (CalendarView) mViewSwitcher.getCurrentView();

        if (current.getSelectedTime().before(time)) {
            mViewSwitcher.setInAnimation(mInAnimationForward);
            mViewSwitcher.setOutAnimation(mOutAnimationForward);
        } else {
            mViewSwitcher.setInAnimation(mInAnimationBackward);
            mViewSwitcher.setOutAnimation(mOutAnimationBackward);
        }

        CalendarView next = (CalendarView) mViewSwitcher.getNextView();
        next.setSelectedDay(time);
        next.reloadEvents();
        mViewSwitcher.showNext();
        next.requestFocus();
    
public voidgoToToday()

        mSelectedDay.set(System.currentTimeMillis());
        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        view.setSelectedDay(mSelectedDay);
        view.reloadEvents();
    
booleanisEventSelected()

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        return view.isEventSelected();
    
protected voidonCreate(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);

        setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
        mContentResolver = getContentResolver();

        mInAnimationForward = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
        mOutAnimationForward = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
        mInAnimationBackward = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
        mOutAnimationBackward = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);

        mGestureDetector = new GestureDetector(this, new CalendarGestureListener());
        mEventLoader = new EventLoader(this);
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        if (! MenuHelper.onCreateOptionsMenu(menu)) {
            return false;
        }
        return super.onCreateOptionsMenu(menu);
    
protected voidonDestroy()

        if (mAccountMonitor != null) {
            mAccountMonitor.close();
        }
        super.onDestroy();
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        if (MenuHelper.onOptionsItemSelected(this, item, this)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    
protected voidonPause()

        super.onPause();
        mContentResolver.unregisterContentObserver(mObserver);
        unregisterReceiver(mIntentReceiver);

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        view.cleanup();
        view = (CalendarView) mViewSwitcher.getNextView();
        view.cleanup();
        mEventLoader.stopBackgroundThread();
    
public booleanonPrepareOptionsMenu(android.view.Menu menu)

        MenuHelper.onPrepareOptionsMenu(this, menu);
        return super.onPrepareOptionsMenu(menu);
    
protected voidonRestoreInstanceState(android.os.Bundle savedInstanceState)

        super.onRestoreInstanceState(savedInstanceState);

        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        Time time = new Time();
        time.set(savedInstanceState.getLong(BUNDLE_KEY_RESTORE_TIME));
        view.setSelectedDay(time);
    
protected voidonResume()

        super.onResume();
        mEventLoader.startBackgroundThread();
        eventsChanged();

        // 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(Calendar.Events.CONTENT_URI,
                true, mObserver);
    
protected voidonSaveInstanceState(android.os.Bundle outState)

        super.onSaveInstanceState(outState);

        outState.putLong(BUNDLE_KEY_RESTORE_TIME, getSelectedTimeInMillis());
    
public booleanonTouchEvent(android.view.MotionEvent ev)

        if (mGestureDetector.onTouchEvent(ev)) {
            return true;
        }
        return super.onTouchEvent(ev);
    
voidstartProgressSpinner()

        // start the progress spinner
        mProgressBar.setVisibility(View.VISIBLE);
    
voidstopProgressSpinner()

        // stop the progress spinner
        mProgressBar.setVisibility(View.GONE);
    
public android.view.ViewswitchViews(boolean forward, float xOffSet, float width)

        float progress = Math.abs(xOffSet) / width;
        if (progress > 1.0f) {
            progress = 1.0f;
        }
        
        float inFromXValue, inToXValue;
        float outFromXValue, outToXValue;
        if (forward) {
            inFromXValue = 1.0f - progress;
            inToXValue = 0.0f;
            outFromXValue = -progress;
            outToXValue = -1.0f;
        } else {
            inFromXValue = progress - 1.0f;
            inToXValue = 0.0f;
            outFromXValue = progress;
            outToXValue = 1.0f;
        }
        
        // We have to allocate these animation objects each time we switch views
        // because that is the only way to set the animation parameters.
        TranslateAnimation inAnimation = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, inFromXValue,
                Animation.RELATIVE_TO_SELF, inToXValue,
                Animation.ABSOLUTE, 0.0f,
                Animation.ABSOLUTE, 0.0f);

        TranslateAnimation outAnimation = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, outFromXValue,
                Animation.RELATIVE_TO_SELF, outToXValue,
                Animation.ABSOLUTE, 0.0f,
                Animation.ABSOLUTE, 0.0f);
        
        // Reduce the animation duration based on how far we have already swiped.
        long duration = (long) (ANIMATION_DURATION * (1.0f - progress));
        inAnimation.setDuration(duration);
        outAnimation.setDuration(duration);
        mViewSwitcher.setInAnimation(inAnimation);
        mViewSwitcher.setOutAnimation(outAnimation);
        
        CalendarView view = (CalendarView) mViewSwitcher.getCurrentView();
        view.cleanup();
        mViewSwitcher.showNext();
        view = (CalendarView) mViewSwitcher.getCurrentView();
        view.requestFocus();
        view.reloadEvents();
        return view;