summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar/Utils.java
diff options
context:
space:
mode:
authorErik <roboerik@android.com>2010-09-02 16:29:59 -0700
committerErik <roboerik@android.com>2010-09-02 16:34:06 -0700
commit235d59cf61769ec8ab777d81cd1ceb2e7530f439 (patch)
tree8ca714ebac6925b620e81b68b873eadf02b5237c /src/com/android/calendar/Utils.java
parent7b7844c30fdf716a1e5663d6d4ce88bf1c857f2d (diff)
downloadandroid_packages_apps_Calendar-235d59cf61769ec8ab777d81cd1ceb2e7530f439.tar.gz
android_packages_apps_Calendar-235d59cf61769ec8ab777d81cd1ceb2e7530f439.tar.bz2
android_packages_apps_Calendar-235d59cf61769ec8ab777d81cd1ceb2e7530f439.zip
Adds a getTimeZone helper function to utils
getTimeZone allows Calendar to get the correct timezone to display in. An asynchronous query still needs to be added once the provider supports the new tz feature. Change-Id: I3fcb67067d9f8bace8420574fd57cab7bd3bf154
Diffstat (limited to 'src/com/android/calendar/Utils.java')
-rw-r--r--src/com/android/calendar/Utils.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index 9a201aeb..6a9e2913 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -33,6 +33,7 @@ import android.view.animation.AlphaAnimation;
import android.widget.ViewFlipper;
import java.util.Calendar;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -48,6 +49,13 @@ public class Utils {
/* The corner should be rounded on the top right and bottom right */
private static final float[] CORNERS = new float[] {0, 0, 5, 5, 5, 5, 0, 0};
+ private volatile static boolean mFirstTZRequest = true;
+ private volatile static boolean mTZQueryInProgress = false;
+
+ private volatile static boolean mUseHomeTZ = false;
+ private volatile static String mHomeTZ = Time.getCurrentTimezone();
+
+ private static HashSet<Runnable> mTZCallbacks = new HashSet<Runnable>();
public static void startActivity(Context context, String className, long time) {
Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -64,6 +72,46 @@ public class Utils {
return prefs.getString(key, defaultValue);
}
+ /**
+ * Gets the time zone that Calendar should be displayed in
+ *
+ * This is a helper method to get the appropriate time zone for Calendar. If this
+ * is the first time this method has been called it will initiate an asynchronous
+ * query to verify that the data in preferences is correct. The callback supplied
+ * will only be called if this query returns a value other than what is stored in
+ * preferences and should cause the calling activity to refresh anything that
+ * depends on calling this method.
+ *
+ * @param context The calling activity
+ * @param callback The runnable that should execute if a query returns new values
+ * @return The string value representing the time zone Calendar should display
+ */
+ public static String getTimeZone(Context context, Runnable callback) {
+ synchronized (mTZCallbacks){
+ if (mFirstTZRequest) {
+ mTZQueryInProgress = true;
+ mFirstTZRequest = false;
+
+ SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
+ mUseHomeTZ = prefs.getBoolean(
+ CalendarPreferenceActivity.KEY_HOME_TZ_ENABLED, false);
+ mHomeTZ = prefs.getString(
+ CalendarPreferenceActivity.KEY_HOME_TZ, Time.getCurrentTimezone());
+ // TODO kick off async query
+ // When the async query returns it should synchronize on
+ // mTZCallbacks, update mUseHomeTZ, mHomeTZ, and the
+ // preferences, set mTZQueryInProgress to false, and call all
+ // the runnables in mTZCallbacks.
+ // TODO remove this line when we have a query
+ mTZQueryInProgress = false;
+ }
+ if (mTZQueryInProgress) {
+ mTZCallbacks.add(callback);
+ }
+ }
+ return mUseHomeTZ ? mHomeTZ : Time.getCurrentTimezone();
+ }
+
static void setSharedPreference(Context context, String key, String value) {
SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();