@Test public void testUpdateBest() { RuntimeEnvironment.application.getSharedPreferences("WidgetConfiguration_" + appWidgetId, MODE_PRIVATE) .edit() .putString(RuntimeEnvironment.application.getString(R.string.pref_widget_theme), RuntimeEnvironment.application.getString(R.string.pref_widget_theme_value_dark)) .putString(RuntimeEnvironment.application.getString(R.string.pref_widget_section), RuntimeEnvironment.application.getString(R.string.pref_widget_section_value_best)) .apply(); widgetProvider.onReceive(RuntimeEnvironment.application, new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{appWidgetId})); View view = shadowOf(widgetManager).getViewFor(appWidgetId); assertThat((TextView) view.findViewById(R.id.title)) .containsText(R.string.title_activity_best); assertThat((TextView) view.findViewById(R.id.subtitle)) .doesNotContainText(R.string.loading_text); }
@Override public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), ACTION_REFRESH_WIDGET)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); new WidgetHelper(context).refresh(appWidgetId); } else if (TextUtils.equals(intent.getAction(), AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { WidgetHelper widgetHelper = new WidgetHelper(context); for (int appWidgetId : appWidgetIds) { widgetHelper.configure(appWidgetId); } } } else { super.onReceive(context, intent); } }
WidgetProvider extends AppWidgetProvider { @Override public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), ACTION_REFRESH_WIDGET)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); new WidgetHelper(context).refresh(appWidgetId); } else if (TextUtils.equals(intent.getAction(), AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { WidgetHelper widgetHelper = new WidgetHelper(context); for (int appWidgetId : appWidgetIds) { widgetHelper.configure(appWidgetId); } } } else { super.onReceive(context, intent); } } }
WidgetProvider extends AppWidgetProvider { @Override public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), ACTION_REFRESH_WIDGET)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); new WidgetHelper(context).refresh(appWidgetId); } else if (TextUtils.equals(intent.getAction(), AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { WidgetHelper widgetHelper = new WidgetHelper(context); for (int appWidgetId : appWidgetIds) { widgetHelper.configure(appWidgetId); } } } else { super.onReceive(context, intent); } }  }
WidgetProvider extends AppWidgetProvider { @Override public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), ACTION_REFRESH_WIDGET)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); new WidgetHelper(context).refresh(appWidgetId); } else if (TextUtils.equals(intent.getAction(), AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { WidgetHelper widgetHelper = new WidgetHelper(context); for (int appWidgetId : appWidgetIds) { widgetHelper.configure(appWidgetId); } } } else { super.onReceive(context, intent); } }  @Override void onReceive(Context context, Intent intent); @Override void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds); @Override void onDeleted(Context context, int[] appWidgetIds); }
WidgetProvider extends AppWidgetProvider { @Override public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), ACTION_REFRESH_WIDGET)) { int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); new WidgetHelper(context).refresh(appWidgetId); } else if (TextUtils.equals(intent.getAction(), AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); if (appWidgetIds != null) { WidgetHelper widgetHelper = new WidgetHelper(context); for (int appWidgetId : appWidgetIds) { widgetHelper.configure(appWidgetId); } } } else { super.onReceive(context, intent); } }  @Override void onReceive(Context context, Intent intent); @Override void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds); @Override void onDeleted(Context context, int[] appWidgetIds);  }