Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "b/5523793 Fix memory leak on rotation for agenda view" into ic…
Browse files Browse the repository at this point in the history
…s-mr1
  • Loading branch information
Michael Chan authored and Android (Google) Code Review committed Nov 17, 2011
2 parents 812da1b + 5d740e1 commit af705e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/com/android/calendar/AllInOneActivity.java
Expand Up @@ -986,6 +986,7 @@ private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
mHomeTime.setText(timeString);
mHomeTime.setVisibility(View.VISIBLE);
// Update when the minute changes
mHomeTime.removeCallbacks(mHomeTimeUpdater);
mHomeTime.postDelayed(
mHomeTimeUpdater,
DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
Expand Down
11 changes: 3 additions & 8 deletions src/com/android/calendar/CalendarViewAdapter.java
Expand Up @@ -85,6 +85,7 @@ public void run() {
public CalendarViewAdapter(Context context, int viewType) {
super();

mMidnightHandler = new Handler();
mCurrentMainView = viewType;
mContext = context;

Expand Down Expand Up @@ -114,11 +115,7 @@ public void refresh(Context context) {
// Sets a thread to run 1 second after midnight and update the current date
// This is used to display correctly the date of yesterday/today/tomorrow
private void setMidnightHandler() {
if (mMidnightHandler == null) {
mMidnightHandler = new Handler();
} else {
mMidnightHandler.removeCallbacks(mTimeUpdater);
}
mMidnightHandler.removeCallbacks(mTimeUpdater);
// Set the time updater to run at 1 second after midnight
long now = System.currentTimeMillis();
Time time = new Time(mTimeZone);
Expand All @@ -130,9 +127,7 @@ private void setMidnightHandler() {

// Stops the midnight update thread, called by the activity when it is paused.
public void onPause() {
if (mMidnightHandler != null) {
mMidnightHandler.removeCallbacks(mTimeUpdater);
}
mMidnightHandler.removeCallbacks(mTimeUpdater);
}

// Returns the amount of buttons in the menu
Expand Down
4 changes: 3 additions & 1 deletion src/com/android/calendar/DayView.java
Expand Up @@ -4600,6 +4600,7 @@ public void cleanup() {
public void restartCurrentTimeUpdates() {
mPaused = false;
if (mHandler != null) {
mHandler.removeCallbacks(mUpdateCurrentTime);
mHandler.post(mUpdateCurrentTime);
}
}
Expand All @@ -4624,9 +4625,10 @@ public void run() {
long currentTime = System.currentTimeMillis();
mCurrentTime.set(currentTime);
//% causes update to occur on 5 minute marks (11:10, 11:15, 11:20, etc.)
if (!DayView.this.mPaused)
if (!DayView.this.mPaused) {
mHandler.postDelayed(mUpdateCurrentTime, UPDATE_CURRENT_TIME_DELAY
- (currentTime % UPDATE_CURRENT_TIME_DELAY));
}
mTodayJulianDay = Time.getJulianDay(currentTime, mCurrentTime.gmtoff);
invalidate();
}
Expand Down
35 changes: 8 additions & 27 deletions src/com/android/calendar/agenda/AgendaListView.java
Expand Up @@ -49,9 +49,7 @@ public class AgendaListView extends ListView implements OnItemClickListener {
private String mTimeZone;
private Time mTime;
private boolean mShowEventDetailsWithAgenda;
// Used to update the past/present separator at midnight
private Handler mMidnightUpdate = null;
private Handler mPastEventUpdate = null;
private Handler mHandler = null;

private Runnable mTZUpdater = new Runnable() {
@Override
Expand Down Expand Up @@ -107,60 +105,43 @@ private void initView(Context context) {
setDivider(null);
setDividerHeight(0);

setMidnightUpdater();
setPastEventsUpdater();
mHandler = new Handler();
}


// Sets a thread to run one second after midnight and refresh the list view
// causing the separator between past/present to be updated.
private void setMidnightUpdater() {

// Create the handler or clear the existing one.
if (mMidnightUpdate == null) {
mMidnightUpdate = new Handler();
} else {
mMidnightUpdate.removeCallbacks(mMidnightUpdater);
}

// Calculate the time until midnight + 1 second and set the handler to
// do a refresh at that time.
long now = System.currentTimeMillis();
Time time = new Time(mTimeZone);
time.set(now);
long runInMillis = (24 * 3600 - time.hour * 3600 - time.minute * 60 -
time.second + 1) * 1000;
mMidnightUpdate.postDelayed(mMidnightUpdater, runInMillis);
mHandler.removeCallbacks(mMidnightUpdater);
mHandler.postDelayed(mMidnightUpdater, runInMillis);
}

// Stop the midnight update thread
private void resetMidnightUpdater() {
if (mMidnightUpdate != null) {
mMidnightUpdate.removeCallbacks(mMidnightUpdater);
}
mHandler.removeCallbacks(mMidnightUpdater);
}

// Sets a thread to run every EVENT_UPDATE_TIME in order to update the list
// with grayed out past events
private void setPastEventsUpdater() {

// Create the handler or clear the existing one.
if (mPastEventUpdate == null) {
mPastEventUpdate = new Handler();
} else {
mPastEventUpdate.removeCallbacks(mPastEventUpdater);
}
// Run the thread in the nearest rounded EVENT_UPDATE_TIME
long now = System.currentTimeMillis();
long roundedTime = (now / EVENT_UPDATE_TIME) * EVENT_UPDATE_TIME;
mPastEventUpdate.postDelayed(mPastEventUpdater, EVENT_UPDATE_TIME - (now - roundedTime));
mHandler.removeCallbacks(mPastEventUpdater);
mHandler.postDelayed(mPastEventUpdater, EVENT_UPDATE_TIME - (now - roundedTime));
}

// Stop the past events thread
private void resetPastEventsUpdater() {
if (mPastEventUpdate != null) {
mPastEventUpdate.removeCallbacks(mPastEventUpdater);
}
mHandler.removeCallbacks(mPastEventUpdater);
}

// Go over all visible views and checks if all past events are grayed out.
Expand Down

0 comments on commit af705e2

Please sign in to comment.