From 28a20dae3e8139f84cc396082ecb6f298155778f Mon Sep 17 00:00:00 2001 From: Jeffrey Sharkey <> Date: Wed, 15 Apr 2009 17:15:21 -0700 Subject: [PATCH] AI 146394: Add ExampleAppWidgetConfigure to manifest and correct update issues. This adds widget configuration to manifest so we don't crash when trying to insert. We also correctly push a second update once prefix title has been saved; previously we showed a stale title until next widget update. Also return the title prefix correctly for a given appWidgetId. BUG=1792887 Automated import of CL 146394 --- samples/ApiDemos/AndroidManifest.xml | 6 ++++++ .../apis/appwidget/ExampleAppWidgetConfigure.java | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml index 7079e9ecf..a53718ece 100644 --- a/samples/ApiDemos/AndroidManifest.xml +++ b/samples/ApiDemos/AndroidManifest.xml @@ -1648,6 +1648,12 @@ + + + + + + diff --git a/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java index d7ef9d632..5f8874cab 100644 --- a/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java +++ b/samples/ApiDemos/src/com/example/android/apis/appwidget/ExampleAppWidgetConfigure.java @@ -84,10 +84,17 @@ public class ExampleAppWidgetConfigure extends Activity { View.OnClickListener mOnClickListener = new View.OnClickListener() { public void onClick(View v) { + final Context context = ExampleAppWidgetConfigure.this; + // When the button is clicked, save the string in our prefs and return that they // clicked OK. - saveTitlePref(ExampleAppWidgetConfigure.this, mAppWidgetId, - mAppWidgetPrefix.getText().toString()); + String titlePrefix = mAppWidgetPrefix.getText().toString(); + saveTitlePref(context, mAppWidgetId, titlePrefix); + + // Push widget update to surface with newly set prefix + AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); + ExampleAppWidgetProvider.updateAppWidget(context, appWidgetManager, + mAppWidgetId, titlePrefix); // Make sure we pass back the original appWidgetId Intent resultValue = new Intent(); @@ -108,7 +115,7 @@ public class ExampleAppWidgetConfigure extends Activity { // If there is no preference saved, get the default from a resource static String loadTitlePref(Context context, int appWidgetId) { SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0); - String prefix = prefs.getString(PREF_PREFIX_KEY, null); + String prefix = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null); if (prefix != null) { return prefix; } else {