Search in sources :

Example 21 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project WordPress-Android by wordpress-mobile.

the class StatsWidgetProvider method showMessage.

private static void showMessage(Context context, int[] allWidgets, String message, SiteStore siteStore) {
    if (allWidgets.length == 0) {
        return;
    }
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (int widgetId : allWidgets) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.stats_widget_layout);
        int remoteBlogID = getRemoteBlogIDFromWidgetID(widgetId);
        SiteModel site = siteStore.getSiteBySiteId(remoteBlogID);
        String name;
        if (site != null) {
            name = context.getString(R.string.stats_widget_name_for_blog);
            name = String.format(name, StringEscapeUtils.unescapeHtml(SiteUtils.getSiteNameOrHomeURL(site)));
        } else {
            name = context.getString(R.string.stats_widget_name);
        }
        remoteViews.setTextViewText(R.id.blog_title, name);
        remoteViews.setViewVisibility(R.id.stats_widget_error_container, View.VISIBLE);
        remoteViews.setViewVisibility(R.id.stats_widget_values_container, View.GONE);
        remoteViews.setTextViewText(R.id.stats_widget_error_text, message);
        Intent intent = new Intent(context, WPMainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.setAction("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.LAUNCHER");
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        remoteViews.setOnClickPendingIntent(R.id.stats_widget_outer_container, pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 22 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project WordPress-Android by wordpress-mobile.

the class StatsWidgetProvider method showStatsData.

private static void showStatsData(Context context, int[] allWidgets, SiteModel site, JSONObject data) {
    if (allWidgets.length == 0) {
        return;
    }
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    String name = context.getString(R.string.stats_widget_name_for_blog);
    name = String.format(name, StringEscapeUtils.unescapeHtml(SiteUtils.getSiteNameOrHomeURL(site)));
    for (int widgetId : allWidgets) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.stats_widget_layout);
        remoteViews.setTextViewText(R.id.blog_title, name);
        remoteViews.setViewVisibility(R.id.stats_widget_error_container, View.GONE);
        remoteViews.setViewVisibility(R.id.stats_widget_values_container, View.VISIBLE);
        // Update Views
        updateTabValue(context, remoteViews, R.id.stats_widget_views, data.optString("views", " 0"));
        // Update Visitors
        updateTabValue(context, remoteViews, R.id.stats_widget_visitors, data.optString("visitors", " 0"));
        // Update Comments
        updateTabValue(context, remoteViews, R.id.stats_widget_comments, data.optString("comments", " 0"));
        // Update Likes
        updateTabValue(context, remoteViews, R.id.stats_widget_likes, data.optString("likes", " 0"));
        Intent intent = new Intent(context, StatsActivity.class);
        intent.putExtra(WordPress.SITE, site);
        intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsActivity.StatsLaunchedFrom.STATS_WIDGET);
        intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, StatsTimeframe.DAY);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, site.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.stats_widget_outer_container, pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 23 with AppWidgetManager

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

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 24 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project NetGuard by M66B.

the class WidgetLockdown method updateWidgets.

public static void updateWidgets(Context context) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WidgetLockdown.class));
    update(appWidgetIds, appWidgetManager, context);
}
Also used : AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 25 with AppWidgetManager

use of android.appwidget.AppWidgetManager in project NetGuard by M66B.

the class WidgetMain method updateWidgets.

public static void updateWidgets(Context context) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WidgetMain.class));
    update(appWidgetIds, appWidgetManager, context);
}
Also used : 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