summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar/Utils.java
diff options
context:
space:
mode:
authorMason Tang <masontang@google.com>2010-08-23 17:54:08 -0700
committerMason Tang <masontang@google.com>2010-08-23 18:39:15 -0700
commitf4ad4757de32ace6971cf4c3db7c395aa249001a (patch)
tree31cd4166f27fb7f6e20079c5008200f18aa3f95f /src/com/android/calendar/Utils.java
parent1d564f63f731565219aaca9e1b7e5f466b143c71 (diff)
downloadandroid_packages_apps_Calendar-f4ad4757de32ace6971cf4c3db7c395aa249001a.tar.gz
android_packages_apps_Calendar-f4ad4757de32ace6971cf4c3db7c395aa249001a.tar.bz2
android_packages_apps_Calendar-f4ad4757de32ace6971cf4c3db7c395aa249001a.zip
Moved all edits to shared preferences to an asynchronous service
- This addresses b/2942834 - Should improve responsiveness a bit Change-Id: Ief02c66ac4c1a132f1dc23853015b5b286807ce7
Diffstat (limited to 'src/com/android/calendar/Utils.java')
-rw-r--r--src/com/android/calendar/Utils.java38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index 8e1ff040..41b415c2 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -24,11 +24,13 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.format.Time;
@@ -98,11 +100,37 @@ public class Utils {
return prefs.getInt(key, defaultValue);
}
+
+ private static class PreferenceCommitTask extends
+ AsyncTask<SharedPreferences.Editor, Integer, Boolean> {
+ @Override
+ protected Boolean doInBackground(Editor... params) {
+ Editor editor = params[0];
+ return editor.commit();
+ }
+ }
+
+ /**
+ * Commits the given shared preferences editor asynchronously in the
+ * background.
+ *
+ * @param editor the editor to commit
+ */
+ public static void commitSharedPreferencesEditor(Editor editor) {
+ (new PreferenceCommitTask()).execute(editor);
+ }
+
+ /**
+ * Asynchronously sets the preference with the given key to the given value
+ *
+ * @param context the context to use to get preferences from
+ * @param key the key of the preference to set
+ * @param value the value to set
+ */
public static void setSharedPreference(Context context, String key, String value) {
SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(key, value);
- editor.commit();
+ Editor editor = prefs.edit().putString(key, value);
+ commitSharedPreferencesEditor(editor);
}
/**
@@ -114,6 +142,7 @@ public class Utils {
static void setDefaultView(Context context, int viewId) {
SharedPreferences prefs = CalendarPreferenceActivity.getSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
+
if (viewId == CalendarController.ViewType.AGENDA
|| viewId == CalendarController.ViewType.DAY) {
// Record the (new) detail start view only for Agenda and Day
@@ -122,7 +151,8 @@ public class Utils {
// Record the (new) start view
editor.putInt(CalendarPreferenceActivity.KEY_START_VIEW, viewId);
- editor.commit();
+
+ commitSharedPreferencesEditor(editor);
}
public static MatrixCursor matrixCursorFromCursor(Cursor cursor) {