Search in sources :

Example 1 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project android_frameworks_base by ParanoidAndroid.

the class TestAppWidgetProvider method onReceive.

public void onReceive(Context context, 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);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 2 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project android_frameworks_base by ParanoidAndroid.

the class TestAppWidgetProvider method onReceive.

public void onReceive(Context context, 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)) {
        if (true)
            return;
        Log.d(TAG, "UPDATE");
        Bundle extras = intent.getExtras();
        int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        AppWidgetManager gm = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
        views.setTextViewText(R.id.oh_hai_text, "hai: " + SystemClock.elapsedRealtime());
        if (false) {
            gm.updateAppWidget(appWidgetIds, views);
        } else {
            gm.updateAppWidget(new ComponentName("com.android.tests.appwidgetprovider", "com.android.tests.appwidgetprovider.TestAppWidgetProvider"), views);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 3 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project SeriesGuide by UweTrottmann.

the class ListWidgetConfigure method onUpdateWidget.

private void onUpdateWidget() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    RemoteViews views = ListWidgetProvider.buildRemoteViews(this, appWidgetManager, mAppWidgetId);
    appWidgetManager.updateAppWidget(mAppWidgetId, views);
    appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.list_view);
    Intent resultValue = new Intent();
    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
    setResult(RESULT_OK, resultValue);
    finish();
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent)

Example 4 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project SeriesGuide by UweTrottmann.

the class ListWidgetProvider method notifyAllAppWidgetsViewDataChanged.

/**
     * Notifies all list widgets bound to this provider to update their views.
     */
public static void notifyAllAppWidgetsViewDataChanged(@Nullable Context context) {
    if (context == null) {
        return;
    }
    // use app context as this may be called by activities that can be destroyed
    context = context.getApplicationContext();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager == null) {
        return;
    }
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class));
    if (appWidgetIds == null || appWidgetIds.length == 0) {
        return;
    }
    appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_view);
    Timber.d("notifyAllAppWidgetsViewDataChanged: updated list widget contents.");
}
Also used : AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 5 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project Fairphone by Kwamecorp.

the class LauncherTransitionable method updateGoogleAppsIntallerWidgets.

public void updateGoogleAppsIntallerWidgets() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, GoogleAppsInstallerWidget.class));
    if (appWidgetIds.length > 0) {
        new GoogleAppsInstallerWidget().onUpdate(this, appWidgetManager, appWidgetIds);
    }
}
Also used : GoogleAppsInstallerWidget(org.fairphone.widgets.gapps.GoogleAppsInstallerWidget) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Aggregations

AppWidgetManager (android.appwidget.AppWidgetManager)51 ComponentName (android.content.ComponentName)32 RemoteViews (android.widget.RemoteViews)25 Intent (android.content.Intent)20 PendingIntent (android.app.PendingIntent)12 Bundle (android.os.Bundle)12 SharedPreferences (android.content.SharedPreferences)7 Context (android.content.Context)5 View (android.view.View)4 Uri (android.net.Uri)3 AppWidgetProvider (android.appwidget.AppWidgetProvider)2 PackageManager (android.content.pm.PackageManager)2 Cursor (android.database.Cursor)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Account (android.accounts.Account)1 Service (android.app.Service)1 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 ContentResolver (android.content.ContentResolver)1