AI 146481: am: CL 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. Original author: jsharkey Merged from: //branches/cupcake/... Automated import of CL 146481
This commit is contained in:
committed by
The Android Open Source Project
parent
780ba517cf
commit
f7f1c36f61
@@ -1655,6 +1655,12 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".appwidget.ExampleAppWidgetConfigure">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".appwidget.ExampleBroadcastReceiver" android:enabled="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.ACTION_TIMEZONE_CHANGED" />
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user