List of usage examples for android.appwidget AppWidgetManager getInstance
public static AppWidgetManager getInstance(Context context)
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
/** * Updates all app widgets./* ww w . ja v a2 s. co m*/ * * @param context the context * @param trackId track id */ private static void updateAllAppWidgets(Context context, long trackId) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class)); for (int appWidgetId : appWidgetIds) { updateAppWidget(context, appWidgetManager, appWidgetId, trackId); } }
From source file:com.brewcrewfoo.performance.util.Helpers.java
public static void updateAppWidget(Context context) { AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); ComponentName widgetComponent = new ComponentName(context, PCWidget.class); int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent); Intent update = new Intent(); update.setAction("com.brewcrewfoo.performance.ACTION_FREQS_CHANGED"); update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds); context.sendBroadcast(update);// w w w . j a va 2 s .c o m }
From source file:com.meiste.greg.ptw.WidgetProvider.java
private int[] getInstalledWidgets(final Context context) { final ComponentName thisWidget = new ComponentName(context, WidgetProvider.class); final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); return appWidgetManager.getAppWidgetIds(thisWidget); }
From source file:com.sudhirkhanger.andpress.ui.MainActivity.java
private void updateWidgets() { ComponentName name = new ComponentName(this, AndPressWidgetProvider.class); int[] ids = AppWidgetManager.getInstance(this).getAppWidgetIds(name); Intent intent = new Intent(this, AndPressWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); sendBroadcast(intent);//from w w w .j a v a2s .co m }
From source file:at.wada811.dayscounter.view.activity.SettingsActivity.java
private void submit() { LogUtils.d();/* w w w . ja v a 2s . co m*/ viewModel.save(); // updateAppWidget CounterAppWidgetProvider.updateAppWidget(this, AppWidgetManager.getInstance(this), appWidgetId); // setResult Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_OK, resultValue); finish(); }
From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java
/** * Updates the widget./*ww w . ja va 2 s . com*/ * * @param action the action */ private void updateTrack(String action) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.track_widget); if (action != null) { updateButton(remoteViews, action); } updateView(remoteViews); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class)); for (int appWidgetId : appWidgetIds) { appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { mComtext = context;// w w w . j av a 2 s.com String action = intent.getAction(); Log.i("sai", "onReceive: " + action); super.onReceive(context, intent); if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId); // SPRD for bug421127 add am/pm for widget WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size), R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); //refreshAlarm(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } if (!ACTION_ON_QUARTER_HOUR.equals(action)) { cancelAlarmOnQuarterHour(context); } startAlarmOnQuarterHour(context); } // cg sai.pan begin else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); refreshBtStatus(context, widget); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0); Log.e("sai", "wifiStatus" + wifiStatus); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); if (WifiManager.WIFI_STATE_ENABLED == wifiStatus || WifiManager.WIFI_STATE_ENABLING == wifiStatus) { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on); } else { widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off); } appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context)); for (int appWidgetId : appWidgetIds) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); refreshWifiStatus(context, widget); } } } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) { if (isNetworkConnected(context)) { Log.e("sai", "isNetworkConnected true"); requestLocation(context); } else { Log.e("sai", "isNetworkConnected false"); } } }
From source file:mx.klozz.xperience.tweaker.helpers.Helpers.java
public static void updateAppWidget(Context context) { AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); ComponentName widgetComponent = new ComponentName(context, Widget.class); int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent); Intent update = new Intent(); update.setAction("mx.klozz.xperience.tweaker.ACTION_FREQS_CHANGED"); update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds); context.sendBroadcast(update);/*from w ww .ja v a 2 s . c o m*/ }
From source file:com.miz.functions.TheMovieDb.java
private void updateWidgets() { AppWidgetManager awm = AppWidgetManager.getInstance(context); awm.notifyAppWidgetViewDataChanged(/*from ww w .j a va 2s . c om*/ awm.getAppWidgetIds(new ComponentName(context, MovieStackWidgetProvider.class)), R.id.stack_view); // Update stack view widget awm.notifyAppWidgetViewDataChanged( awm.getAppWidgetIds(new ComponentName(context, MovieCoverWidgetProvider.class)), R.id.widget_grid); // Update grid view widget awm.notifyAppWidgetViewDataChanged( awm.getAppWidgetIds(new ComponentName(context, MovieBackdropWidgetProvider.class)), R.id.widget_grid); // Update grid view widget }
From source file:ru.kaefik.isaifutdinov.an_weather_widget.AnWeatherWidget.java
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG_SERVICE, " onReceive " + intent.getAction()); super.onReceive(context, intent); if (FORCE_WIDGET_UPDATE.equals(intent.getAction())) { String nameCity = intent.getStringExtra(PARAM_CITY); String tempCity = intent.getStringExtra(PARAM_TEMP); String windCity = intent.getStringExtra(PARAM_WIND); String timeRefreshCity = intent.getStringExtra(PARAM_TIMEREFRESH); String weatherImageCity = intent.getStringExtra(PARAM_WEATHERIMAGE); String descriptionWeather = intent.getStringExtra(PARAM_DESCWEATHER); int WidgetId = intent.getIntExtra(PARAM_WIDGETID, 0); //TODO: ? , ?. ? ? GetWeatherCityService Log.i(TAG_SERVICE, "onReceive " + nameCity + " -> " + tempCity); // /* w w w . j ava 2 s .c o m*/ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "onReceive -> appWidgetId = " + String.valueOf(appWidgetId[i])); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); if (WidgetId == appWidgetId[i]) { views.setTextViewText(R.id.cityNameText, nameCity); views.setTextViewText(R.id.tempCityText, tempCity); views.setTextViewText(R.id.windText, windCity); views.setTextViewText(R.id.timeRefreshText, timeRefreshCity); views.setTextViewText(R.id.descriptionWeatherText, descriptionWeather); views.setImageViewUri(R.id.weatherImageView, Uri.parse("android.resource://ru.kaefik.isaifutdinov.an_weather_widget/mipmap/" + "weather" + weatherImageCity)); // ? CLICK_WIDGET_BUTTON onReceive // Intent ? Broadcast Intent active = new Intent(context, AnWeatherWidget.class); active.setAction(CLICK_WIDGET_BUTTON); //? ? PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); //? ? views.setOnClickPendingIntent(R.id.refreshButton, actionPendingIntent); //? // END - ? CLICK_WIDGET_BUTTON onReceive appWidgetManager.updateAppWidget(appWidgetId[i], views); break; } appWidgetManager.updateAppWidget(appWidgetId[i], views); } } if (CLICK_WIDGET_BUTTON.equals(intent.getAction())) { Log.i(TAG_SERVICE, " "); // AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName thisWidget = new ComponentName(context, AnWeatherWidget.class); int[] appWidgetId = appWidgetManager.getAppWidgetIds(thisWidget); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.an_weather_widget); // ? for (int i = 0; i < appWidgetId.length; i++) { Log.i(TAG_SERVICE, "id -> " + String.valueOf(appWidgetId[i])); String nameCity = ConfigActivity.loadStringParametersFromFile(context, String.valueOf(appWidgetId[i])); startGetWeatherCityService(context, appWidgetId[i], new CityModel(nameCity)); } } }