List of usage examples for android.appwidget AppWidgetManager partiallyUpdateAppWidget
public void partiallyUpdateAppWidget(int appWidgetId, RemoteViews views)
From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(REFRESH_ACTION)) { Log.d(TAG, "Widget Refresh button pressed"); Intent i = new Intent(Constants.INTENT_START_SYNC_WITH_REMOTE); context.sendBroadcast(i);/*from ww w . j av a 2 s . c o m*/ Bundle extras = intent.getExtras(); if (extras != null) { int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); RemoteViews rv = buildLayout(context, appWidgetId, true); appWidgetManager.partiallyUpdateAppWidget(appWidgetId, rv); } } else if (action.equals(Constants.INTENT_WIDGET_UPDATE)) { Log.d(TAG, "Update widget intent received "); int[] appWidgetIds = null; AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); Bundle extras = intent.getExtras(); if (extras != null) { appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS); } if (appWidgetIds == null) { appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class.getName())); } if (appWidgetIds != null && appWidgetIds.length > 0) { this.onUpdate(context, appWidgetManager, appWidgetIds); } } super.onReceive(context, intent); }
From source file:de.hero.vertretungsplan.HtmlWork.java
@SuppressLint("NewApi") private void updateWidget(boolean before) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget); AppWidgetManager appManager = AppWidgetManager.getInstance(context); ComponentName name = new ComponentName(context, WidgetProvider.class); if (before) { widget.setImageViewResource(R.id.aktButton, R.drawable.ic_action_aktualisieren_pressed); } else {/*from w w w .j a va2 s .c o m*/ widget.setImageViewResource(R.id.aktButton, R.drawable.aktualisieren_drawable); if (dataChanged) { appManager.notifyAppWidgetViewDataChanged(appManager.getAppWidgetIds(name), R.id.words); } } appManager.partiallyUpdateAppWidget(appManager.getAppWidgetIds(name), widget); } }
From source file:au.com.wallaceit.reddinator.Rservice.java
private void hideWidgetLoader(boolean goToTopOfList, boolean showError) { AppWidgetManager mgr = AppWidgetManager.getInstance(mContext); // get theme layout id int layout = 1; switch (Integer.valueOf(mSharedPreferences.getString("widgetthemepref", "1"))) { case 1:// w ww . j ava 2 s . c o m layout = R.layout.widgetmain; break; case 2: layout = R.layout.widgetdark; break; case 3: layout = R.layout.widgetholo; break; case 4: layout = R.layout.widgetdarkholo; break; case 5: layout = R.layout.widgettrans; break; } RemoteViews views = new RemoteViews(mContext.getPackageName(), layout); views.setViewVisibility(R.id.srloader, View.INVISIBLE); // go to the top of the list view if (goToTopOfList) { views.setScrollPosition(R.id.listview, 0); } if (showError) { views.setViewVisibility(R.id.erroricon, View.VISIBLE); } mgr.partiallyUpdateAppWidget(appWidgetId, views); }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { mComtext = context;//w w w . j a v a2 s . co m 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:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void refreshCityOrWeather(Context context, String what, int which) { 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 (1 == which) { widget.setTextViewText(R.id.city, what); } else if (2 == which) { if (what.equals("")) { //widget.setTextViewText(R.id.temperature, context.getString(R.string.weather_network_error)); } else if (what.contains(",")) { String weather = what.split(",")[0]; String temperature = what.split(",")[1]; String image = what.split(",")[2]; widget.setTextViewText(R.id.temperature, temperature); widget.setImageViewResource(R.id.weather, getWeatherImageId(image)); }// ww w . j a va 2 s . c o m } appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget); } } }
From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java
private void updateWidget(@Nonnull Context context, @Nonnull AppWidgetManager manager, @Nonnull int[] widgetIds, boolean partially) { final EditorState editorState = editor.getState(); final DisplayState displayState = display.getState(); final Resources resources = context.getResources(); final SimpleTheme theme = App.getWidgetTheme().resolveThemeFor(App.getTheme()); for (int widgetId : widgetIds) { final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout(manager, widgetId, resources, theme)); if (!partially || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { for (CppButton button : CppButton.values()) { final PendingIntent intent = intents.get(context, button); if (intent != null) { final int buttonId; if (button == CppButton.settings_widget) { // overriding default settings button behavior buttonId = CppButton.settings.id; } else { buttonId = button.id; }/*from ww w. j a v a2s . c om*/ views.setOnClickPendingIntent(buttonId, intent); } } } updateEditorState(context, views, editorState, theme); updateDisplayState(context, views, displayState, theme); views.setTextViewText(R.id.cpp_button_multiplication, engine.getMultiplicationSign()); if (partially && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { manager.partiallyUpdateAppWidget(widgetId, views); } else { manager.updateAppWidget(widgetId, views); } } }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void updateFeedAndFinish() { if (widgetFirstTimeSetup) { finishWidgetSetup();//from ww w . j a va 2 s. c o m return; } if (mAppWidgetId != 0) { // refresh widget and close activity (NOTE: put in function) AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget); views.setTextViewText(R.id.subreddittxt, global.getSubredditManager().getCurrentFeedName(mAppWidgetId)); views.setViewVisibility(R.id.srloader, View.VISIBLE); views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // bypass cache if service not loaded global.setBypassCache(true); appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views); appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview); } else { Intent intent = new Intent(); intent.putExtra("themeupdate", needsThemeUpdate); setResult(2, intent); // update feed prefs + reload feed } finish(); }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
public void onBackPressed() { if (widgetFirstTimeSetup) { finishWidgetSetup();/* w w w.j av a 2 s . c o m*/ return; } // check if sort has changed if (needsFeedUpdate || needsFeedViewUpdate || needsThemeUpdate) { if (mAppWidgetId != 0) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget); views.setViewVisibility(R.id.srloader, View.VISIBLE); views.setViewVisibility(R.id.erroricon, View.INVISIBLE); // bypass the cached entrys only if the sorting preference has changed if (needsFeedUpdate) { global.setBypassCache(true); } else { global.setRefreshView(); } if (needsThemeUpdate) { WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, new int[] { mAppWidgetId }, false); } else { appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views); } appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview); } else { Intent intent = new Intent(); intent.putExtra("themeupdate", needsThemeUpdate); if (needsFeedUpdate) { setResult(2, intent); // reload feed and prefs } else { setResult(1, intent); // tells main activity to update feed prefs } if (needsThemeUpdate) { global.setRefreshView(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this); int[] widgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(SubredditSelectActivity.this, WidgetProvider.class)); WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, widgetIds, false); appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.listview); } } } else { setResult(0); } finish(); }