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);
}
}
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);
}
}
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);
}
}
}
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);
}
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);
}
Aggregations