diff options
author | Erik <roboerik@android.com> | 2010-09-10 13:13:04 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-10 13:13:04 -0700 |
commit | 44cb3f08563dfe3cd3c04930e209f9571df73268 (patch) | |
tree | c67361e1d0a95127e2de2e356f777e2dccdfdea6 /src/com | |
parent | 7befe8d6f9a6e1e47749c97ed2f14e6e60f8067e (diff) | |
parent | e0f6a5cb8640e2d5da914da8d12bd0a5bd852e30 (diff) | |
download | android_packages_apps_Calendar-44cb3f08563dfe3cd3c04930e209f9571df73268.tar.gz android_packages_apps_Calendar-44cb3f08563dfe3cd3c04930e209f9571df73268.tar.bz2 android_packages_apps_Calendar-44cb3f08563dfe3cd3c04930e209f9571df73268.zip |
am e0f6a5cb: **DO NOT MERGE**Updates day/week/month view to use home tz
Merge commit 'e0f6a5cb8640e2d5da914da8d12bd0a5bd852e30' into gingerbread-plus-aosp
* commit 'e0f6a5cb8640e2d5da914da8d12bd0a5bd852e30':
**DO NOT MERGE**Updates day/week/month view to use home tz
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/calendar/CalendarActivity.java | 24 | ||||
-rw-r--r-- | src/com/android/calendar/CalendarView.java | 75 | ||||
-rw-r--r-- | src/com/android/calendar/MonthActivity.java | 51 | ||||
-rw-r--r-- | src/com/android/calendar/MonthView.java | 54 | ||||
-rw-r--r-- | src/com/android/calendar/WeekActivity.java | 2 |
5 files changed, 162 insertions, 44 deletions
diff --git a/src/com/android/calendar/CalendarActivity.java b/src/com/android/calendar/CalendarActivity.java index 982268d6..c261f661 100644 --- a/src/com/android/calendar/CalendarActivity.java +++ b/src/com/android/calendar/CalendarActivity.java @@ -16,6 +16,8 @@ package com.android.calendar; +import dalvik.system.VMRuntime; + import android.app.Activity; import android.content.BroadcastReceiver; import android.content.ContentResolver; @@ -38,8 +40,6 @@ import android.view.animation.TranslateAnimation; import android.widget.ProgressBar; import android.widget.ViewSwitcher; -import dalvik.system.VMRuntime; - /** * This is the base class for Day and Week Activities. */ @@ -60,7 +60,17 @@ public class CalendarActivity extends Activity implements Navigator { protected Animation mOutAnimationBackward; EventLoader mEventLoader; - Time mSelectedDay = new Time(); + Time mSelectedDay; + + // This gets run if the time zone is updated in the db + private Runnable mUpdateTZ = new Runnable() { + @Override + public void run() { + // We want this to keep the same day so we swap the tz + mSelectedDay.timezone = Utils.getTimeZone(CalendarActivity.this, this); + mSelectedDay.normalize(true); + } + }; /* package */ GestureDetector mGestureDetector; @@ -98,6 +108,8 @@ public class CalendarActivity extends Activity implements Navigator { protected void onCreate(Bundle icicle) { super.onCreate(icicle); + mSelectedDay = new Time(Utils.getTimeZone(this, mUpdateTZ)); + // 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 VMRuntime.getRuntime().setMinimumHeapSize(INITIAL_HEAP_SIZE); @@ -119,7 +131,7 @@ public class CalendarActivity extends Activity implements Navigator { super.onRestoreInstanceState(savedInstanceState); CalendarView view = (CalendarView) mViewSwitcher.getCurrentView(); - Time time = new Time(); + Time time = new Time(Utils.getTimeZone(this, mUpdateTZ)); time.set(savedInstanceState.getLong(BUNDLE_KEY_RESTORE_TIME)); view.setSelectedDay(time); } @@ -128,7 +140,7 @@ public class CalendarActivity extends Activity implements Navigator { protected void onNewIntent(Intent intent) { long timeMillis = Utils.timeFromIntentInMillis(intent); if (timeMillis > 0) { - Time time = new Time(); + Time time = new Time(Utils.getTimeZone(this, mUpdateTZ)); time.set(timeMillis); goTo(time, false); } @@ -141,7 +153,7 @@ public class CalendarActivity extends Activity implements Navigator { eventsChanged(); CalendarView view = (CalendarView) mViewSwitcher.getCurrentView(); view.updateIs24HourFormat(); - view.restartCurrentTimeUpdates(); + view.updateView(); view = (CalendarView) mViewSwitcher.getNextView(); view.updateIs24HourFormat(); diff --git a/src/com/android/calendar/CalendarView.java b/src/com/android/calendar/CalendarView.java index a3296cab..e012d890 100644 --- a/src/com/android/calendar/CalendarView.java +++ b/src/com/android/calendar/CalendarView.java @@ -30,13 +30,13 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Paint.Style; import android.graphics.Path; +import android.graphics.Path.Direction; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; -import android.graphics.Paint.Style; -import android.graphics.Path.Direction; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -49,6 +49,7 @@ import android.text.format.DateUtils; import android.text.format.Time; import android.util.Log; import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -58,7 +59,6 @@ import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.WindowManager; -import android.view.ContextMenu.ContextMenuInfo; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.widget.ImageView; @@ -67,6 +67,8 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Calendar; +import java.util.Locale; +import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -94,6 +96,24 @@ public class CalendarView extends View protected CalendarApplication mCalendarApp; protected CalendarActivity mParentActivity; + // This runs when we need to update the tz + private Runnable mUpdateTZ = new Runnable() { + @Override + public void run() { + String tz = Utils.getTimeZone(mContext, this); + // BaseDate we want to keep on the same day, so we swap tz + mBaseDate.timezone = tz; + mBaseDate.normalize(true); + // CurrentTime we want to keep at the same absolute time, so we + // call switch tz + mCurrentTime.switchTimezone(tz); + mTimeZone = TimeZone.getTimeZone(tz); + recalc(); + mTitleTextView.setText(mDateRange); + } + }; + private Context mContext; + private static final String[] CALENDARS_PROJECTION = new String[] { Calendars._ID, // 0 Calendars.ACCESS_LEVEL, // 1 @@ -341,6 +361,7 @@ public class CalendarView extends View private boolean mScrolling = false; + private TimeZone mTimeZone; private String mDateRange; private TextView mTitleTextView; @@ -405,7 +426,10 @@ public class CalendarView extends View mStartDay = Utils.getFirstDayOfWeek(); - mCurrentTime = new Time(); + mTimeZone = TimeZone.getTimeZone(Utils.getTimeZone(context, mUpdateTZ)); + + mContext = context; + mCurrentTime = new Time(Utils.getTimeZone(context, mUpdateTZ)); long currentTime = System.currentTimeMillis(); mCurrentTime.set(currentTime); //The % makes it go off at the next increment of 5 minutes. @@ -514,7 +538,7 @@ public class CalendarView extends View // Enable touching the popup window mPopupView.setOnClickListener(this); - mBaseDate = new Time(); + mBaseDate = new Time(Utils.getTimeZone(context, mUpdateTZ)); long millis = System.currentTimeMillis(); mBaseDate.set(millis); @@ -627,7 +651,7 @@ public class CalendarView extends View } } - final long start = mBaseDate.toMillis(false /* use isDst */); + long start = mBaseDate.normalize(true /* use isDst */); long end = start; mFirstJulianDay = Time.getJulianDay(start, mBaseDate.gmtoff); mLastJulianDay = mFirstJulianDay + mNumDays - 1; @@ -649,7 +673,24 @@ public class CalendarView extends View | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH; } - mDateRange = DateUtils.formatDateRange(mParentActivity, start, end, flags); + mDateRange = Utils.formatDateRange(mParentActivity, start, end, flags); + + if (!TextUtils.equals(Utils.getTimeZone(mContext, mUpdateTZ), Time.getCurrentTimezone())) { + flags = DateUtils.FORMAT_SHOW_TIME; + if (DateFormat.is24HourFormat(mParentActivity)) { + flags |= DateUtils.FORMAT_24HOUR; + } + start = System.currentTimeMillis(); + + String tz = Utils.getTimeZone(mContext, mUpdateTZ); + boolean isDST = mBaseDate.isDst != 0; + StringBuilder title = new StringBuilder(mDateRange); + title.append(" (").append(Utils.formatDateRange(mContext, start, start, flags)) + .append(" ") + .append(mTimeZone.getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault())) + .append(")"); + mDateRange = title.toString(); + } // Do not set the title here because this is called when executing // initNextView() to prepare the Day view when sliding the finger // horizontally but we don't always want to change the title. And @@ -1226,7 +1267,7 @@ public class CalendarView extends View mSelectedEvents.clear(); // The start date is the beginning of the week at 12am - Time weekStart = new Time(); + Time weekStart = new Time(Utils.getTimeZone(mContext, mUpdateTZ)); weekStart.set(mBaseDate); weekStart.hour = 0; weekStart.minute = 0; @@ -1439,7 +1480,7 @@ public class CalendarView extends View r.bottom = top + CURRENT_TIME_LINE_HEIGHT / 2; r.left = 0; r.right = mHoursWidth; - + p.setColor(mCurrentTimeMarkerColor); canvas.drawRect(r, p); } @@ -1605,7 +1646,7 @@ public class CalendarView extends View time.setJulianDay(firstJulianDay + mNumDays); long endTime = time.normalize(true); - String timeRange = DateUtils.formatDateRange(mParentActivity, startTime, endTime, + String timeRange = Utils.formatDateRange(mParentActivity, startTime, endTime, flags); event.getText().add(timeRange); } @@ -1624,7 +1665,7 @@ public class CalendarView extends View if (DateFormat.is24HourFormat(mParentActivity)) { flags |= DateUtils.FORMAT_24HOUR; } - String timeRange = DateUtils.formatDateRange(mParentActivity, startTime, endTime, + String timeRange = Utils.formatDateRange(mParentActivity, startTime, endTime, flags); event.getText().add(timeRange); @@ -2165,7 +2206,7 @@ public class CalendarView extends View if (DateFormat.is24HourFormat(mParentActivity)) { flags |= DateUtils.FORMAT_24HOUR; } - String timeRange = DateUtils.formatDateRange(mParentActivity, + String timeRange = Utils.formatDateRange(mParentActivity, ev.startMillis, ev.endMillis, flags); Log.i("Cal", "left: " + left + " right: " + right + " top: " + top + " bottom: " + bottom + " ev: " + timeRange + " " + ev.title); @@ -2547,7 +2588,7 @@ public class CalendarView extends View if (DateFormat.is24HourFormat(mParentActivity)) { flags |= DateUtils.FORMAT_24HOUR; } - String timeRange = DateUtils.formatDateRange(mParentActivity, + String timeRange = Utils.formatDateRange(mParentActivity, event.startMillis, event.endMillis, flags); TextView timeView = (TextView) mPopupView.findViewById(R.id.time); timeView.setText(timeRange); @@ -2825,7 +2866,8 @@ public class CalendarView extends View int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_WEEKDAY; - final String title = DateUtils.formatDateTime(mParentActivity, startMillis, flags); + final String title = Utils.formatDateRange(mParentActivity, startMillis, startMillis, + flags); menu.setHeaderTitle(title); int numSelectedEvents = mSelectedEvents.size(); @@ -3085,7 +3127,7 @@ public class CalendarView extends View // for (Event ev : mSelectedEvents) { // int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL // | DateUtils.FORMAT_CAP_NOON_MIDNIGHT; -// String timeRange = formatDateRange(mParentActivity, +// String timeRange = Utils.formatDateRange(mParentActivity, // ev.startMillis, ev.endMillis, flags); // // Log.i("Cal", " " + timeRange + " " + ev.title); @@ -3328,7 +3370,8 @@ public class CalendarView extends View /** * Restart the update timer */ - public void restartCurrentTimeUpdates() { + public void updateView() { + mUpdateTZ.run(); post(mUpdateCurrentTime); } diff --git a/src/com/android/calendar/MonthActivity.java b/src/com/android/calendar/MonthActivity.java index ec7c670f..03fb7e1e 100644 --- a/src/com/android/calendar/MonthActivity.java +++ b/src/com/android/calendar/MonthActivity.java @@ -29,22 +29,25 @@ import android.content.SharedPreferences; import android.database.ContentObserver; import android.os.Bundle; import android.os.Handler; -import android.preference.PreferenceManager; import android.provider.Calendar.Events; +import android.text.TextUtils; +import android.text.format.DateFormat; import android.text.format.DateUtils; import android.text.format.Time; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.view.animation.Animation.AnimationListener; +import android.view.animation.AnimationUtils; +import android.widget.Gallery.LayoutParams; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ViewSwitcher; -import android.widget.Gallery.LayoutParams; import java.util.Calendar; +import java.util.Locale; +import java.util.TimeZone; public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, Navigator, AnimationListener { @@ -62,6 +65,17 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, private ProgressBar mProgressBar; + // This gets run if the time zone is updated in the db + private Runnable mUpdateTZ = new Runnable() { + @Override + public void run() { + // We want mTime to stay on the same day, so we swap the tz + mTime.timezone = Utils.getTimeZone(MonthActivity.this, this); + mTime.normalize(true); + updateTitle(mTime); + } + }; + private static final int DAY_OF_WEEK_LABEL_IDS[] = { R.id.day0, R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5, R.id.day6 }; @@ -89,10 +103,28 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, return mv; } + public void updateTitle(Time time) { + TextView title = (TextView) findViewById(R.id.title); + StringBuffer date = new StringBuffer(Utils.formatMonthYear(this, time)); + if (!TextUtils.equals(Utils.getTimeZone(this, mUpdateTZ), Time.getCurrentTimezone())) { + int flags = DateUtils.FORMAT_SHOW_TIME; + if (DateFormat.is24HourFormat(this)) { + flags |= DateUtils.FORMAT_24HOUR; + } + long start = System.currentTimeMillis(); + String tz = Utils.getTimeZone(this, mUpdateTZ); + boolean isDST = time.isDst != 0; + TimeZone timeZone = TimeZone.getTimeZone(tz); + date.append(" (").append(Utils.formatDateRange(this, start, start, flags)).append(" ") + .append(timeZone.getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault())) + .append(")"); + } + title.setText(date.toString()); + } + /* Navigator interface methods */ public void goTo(Time time, boolean animate) { - TextView title = (TextView) findViewById(R.id.title); - title.setText(Utils.formatMonthYear(this, time)); + updateTitle(time); MonthView current = (MonthView) mSwitcher.getCurrentView(); current.dismissPopup(); @@ -126,7 +158,7 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, } public void goToToday() { - Time now = new Time(); + Time now = new Time(Utils.getTimeZone(this, mUpdateTZ)); now.set(System.currentTimeMillis()); now.minute = 0; now.second = 0; @@ -219,7 +251,7 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, time = Utils.timeFromIntentInMillis(getIntent()); } - mTime = new Time(); + mTime = new Time(Utils.getTimeZone(this, mUpdateTZ)); mTime.set(time); mTime.normalize(true); @@ -266,7 +298,7 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, protected void onNewIntent(Intent intent) { long timeMillis = Utils.timeFromIntentInMillis(intent); if (timeMillis > 0) { - Time time = new Time(); + Time time = new Time(Utils.getTimeZone(this, mUpdateTZ)); time.set(timeMillis); goTo(time, false); } @@ -294,6 +326,7 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, @Override protected void onResume() { super.onResume(); + mUpdateTZ.run(); mEventLoader.startBackgroundThread(); eventsChanged(); @@ -302,6 +335,8 @@ public class MonthActivity extends Activity implements ViewSwitcher.ViewFactory, SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(this); String str = prefs.getString(CalendarPreferenceActivity.KEY_DETAILED_VIEW, CalendarPreferenceActivity.DEFAULT_DETAILED_VIEW); + view1.updateView(); + view2.updateView(); view1.setDetailedView(str); view2.setDetailedView(str); diff --git a/src/com/android/calendar/MonthView.java b/src/com/android/calendar/MonthView.java index 531dc1da..e07f87c1 100644 --- a/src/com/android/calendar/MonthView.java +++ b/src/com/android/calendar/MonthView.java @@ -27,10 +27,10 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Paint.Style; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.RectF; -import android.graphics.Paint.Style; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.SystemClock; @@ -39,6 +39,7 @@ import android.text.format.DateUtils; import android.text.format.Time; import android.util.SparseArray; import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector; import android.view.Gravity; import android.view.KeyEvent; @@ -47,7 +48,6 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; -import android.view.ContextMenu.ContextMenuInfo; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.widget.PopupWindow; @@ -90,14 +90,14 @@ public class MonthView extends View implements View.OnCreateContextMenuListener private Time mToday; private Time mViewCalendar; - private Time mSavedTime = new Time(); // the time when we entered this view + private Time mSavedTime; // the time when we entered this view // This Time object is used to set the time for the other Month view. - private Time mOtherViewCalendar = new Time(); + private Time mOtherViewCalendar; // This Time object is used for temporary calculations and is allocated // once to avoid extra garbage collection - private Time mTempTime = new Time(); + private Time mTempTime; private DayOfMonthCursor mCursor; @@ -182,6 +182,24 @@ public class MonthView extends View implements View.OnCreateContextMenuListener private int mPrevSelectedMonth; private CharSequence mPrevTitleTextViewText; + // This gets run if the time zone is updated in the db + private Runnable mUpdateTZ = new Runnable() { + @Override + public void run() { + String tz = Utils.getTimeZone(mContext, this); + // These fields we want to keep the same time represented + mSavedTime.switchTimezone(tz); + mToday.switchTimezone(tz); + mTempTime.switchTimezone(tz); + + // These fields we want to keep the same day represented + mViewCalendar.timezone = tz; + mViewCalendar.normalize(true); + mOtherViewCalendar.timezone = tz; + mOtherViewCalendar.normalize(true); + } + }; + public MonthView(MonthActivity activity, Navigator navigator) { super(activity); if (mScale == 0) { @@ -207,20 +225,25 @@ public class MonthView extends View implements View.OnCreateContextMenuListener } } + String tz = Utils.getTimeZone(mContext, mUpdateTZ); + mSavedTime = new Time(tz); + mOtherViewCalendar = new Time(tz); + mTempTime = new Time(tz); + mEventLoader = activity.mEventLoader; mNavigator = navigator; mEventGeometry = new EventGeometry(); mEventGeometry.setMinEventHeight(MIN_EVENT_HEIGHT); mEventGeometry.setHourGap(HOUR_GAP); - init(activity); + init(activity, tz); } - private void init(MonthActivity activity) { + private void init(MonthActivity activity, String timeZone) { setFocusable(true); setClickable(true); setOnCreateContextMenuListener(this); mParentActivity = activity; - mViewCalendar = new Time(); + mViewCalendar = new Time(timeZone); long now = System.currentTimeMillis(); mViewCalendar.set(now); mViewCalendar.monthDay = 1; @@ -231,7 +254,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener mCursor = new DayOfMonthCursor(mViewCalendar.year, mViewCalendar.month, mViewCalendar.monthDay, mParentActivity.getStartDay()); - mToday = new Time(); + mToday = new Time(timeZone); mToday.set(System.currentTimeMillis()); mResources = activity.getResources(); @@ -384,7 +407,8 @@ public class MonthView extends View implements View.OnCreateContextMenuListener final int flags = DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH; - final String title = DateUtils.formatDateTime(mParentActivity, startMillis, flags); + final String title = Utils.formatDateRange(mParentActivity, startMillis, startMillis, + flags); menu.setHeaderTitle(title); item = menu.add(0, MenuHelper.MENU_DAY, 0, R.string.show_day_view); @@ -642,7 +666,7 @@ public class MonthView extends View implements View.OnCreateContextMenuListener long startMillis = getSelectedTimeInMillis(); int flags = DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH; - String text = DateUtils.formatDateTime(mParentActivity, startMillis, flags); + String text = Utils.formatDateRange(mParentActivity, startMillis, startMillis, flags); event.getText().add(text); // add event count @@ -1120,10 +1144,10 @@ public class MonthView extends View implements View.OnCreateContextMenuListener String timeRange; if (showEndTime) { - timeRange = DateUtils.formatDateRange(mParentActivity, + timeRange = Utils.formatDateRange(mParentActivity, event.startMillis, event.endMillis, flags); } else { - timeRange = DateUtils.formatDateRange(mParentActivity, + timeRange = Utils.formatDateRange(mParentActivity, event.startMillis, event.startMillis, flags); } @@ -1384,4 +1408,8 @@ public class MonthView extends View implements View.OnCreateContextMenuListener handler.removeCallbacks(mDismissPopup); } } + + public void updateView() { + mUpdateTZ.run(); + } } diff --git a/src/com/android/calendar/WeekActivity.java b/src/com/android/calendar/WeekActivity.java index 5bfdd3a2..bfda3e0c 100644 --- a/src/com/android/calendar/WeekActivity.java +++ b/src/com/android/calendar/WeekActivity.java @@ -60,7 +60,7 @@ public class WeekActivity extends CalendarActivity implements ViewSwitcher.ViewF protected void onNewIntent(Intent intent) { long timeMillis = Utils.timeFromIntentInMillis(intent); if (timeMillis > 0) { - Time time = new Time(); + Time time = new Time(Utils.getTimeZone(this, null)); time.set(timeMillis); goTo(time, false); } |