FileDocCategorySizeDatePackage
TestAppWidgetProvider.javaAPI DocAndroid 1.5 API2814Wed May 06 22:42:02 BST 2009com.android.tests.appwidgethost

TestAppWidgetProvider

public class TestAppWidgetProvider extends android.content.BroadcastReceiver

Fields Summary
static final String
TAG
static final String
PREFS_NAME
static final String
PREF_PREFIX_KEY
Constructors Summary
Methods Summary
public voidonReceive(android.content.Context context, android.content.Intent intent)


          
        String action = intent.getAction();
        Log.d(TAG, "intent=" + intent);

        if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
            Log.d(TAG, "ENABLED");
        }
        else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
            Log.d(TAG, "DISABLED");
        }
        else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
            Log.d(TAG, "UPDATE");
            // BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
            Bundle extras = intent.getExtras();
            int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
            // END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)

            SharedPreferences prefs = context.getSharedPreferences(
                    TestAppWidgetProvider.PREFS_NAME, 0);
            String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");

            AppWidgetManager gm = AppWidgetManager.getInstance(context);
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
            views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
            if (false) {
                gm.updateAppWidget(appWidgetIds, views);
            } else {
                gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost",
                            "com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
            }
        }