Skip to content

Instantly share code, notes, and snippets.

Andrew Konecki

Contact

Email

Phone

  • 210.264.4675

Location

  • Santa Clara, CA 95051
@RunWith(AndroidJUnit4.class)
public class BakingActivityTest {
@Rule public ActivityTestRule<BakingActivity> mActivityTestRule =
new ActivityTestRule<BakingActivity>(BakingActivity.class);
private IdlingResource mIdlingResource;
@Before
public void registerIdlingResource() {
mIdlingResource = mActivityTestRule.getActivity().getIdlingDBResource();
public static void sendRefreshBoardcast(Context context) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.setComponent(new ComponentName(context, BakingWidgetProvider.class));
context.sendBroadcast(intent);
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
// An intent can send anything in a boardcast only want to perform an action if
// it meets the correct action.
if (intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)) {
// intent is an update intent for the appwidget manager.
int [] widgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(
new ComponentName(context, BakingWidgetProvider.class));
public class ListViewFactory implements RemoteViewsService.RemoteViewsFactory {
private Context mContext = null;
private Cursor mCursor = null;
public ListViewFactory(Context context, Intent intent) {
mContext = context;
}
@Override
public void onCreate() {}
public class ListViewWidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new ListViewFactory(this.getApplicationContext(), intent);
}
}
static void updateAppWidget(Context context,
AppWidgetManager appWidgetManager,
String recipeName,
int appWidgetId)
{
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.baking_widget);
views.setTextViewText(R.id.tv_widget_recipe_name, recipeName);
Intent onClickIntent = new Intent(context, BakingActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
public class RecipeTask extends AsyncTaskLoader<Cursor> {
private final Bundle mArgs;
private NetworkIdlingResource mIdlingResource;
public RecipeTask(Context context,
@Nullable Bundle args,
@Nullable NetworkIdlingResource resource) {
super(context);
this.mArgs = args;
@Override
public void onResponse(Call<ArrayList<Recipe>> call, Response<ArrayList<Recipe>> response) {
if (response != null && response.body() != null) {
Bundle fragmentArgs = new Bundle();
fragmentArgs.putParcelableArrayList(getString(R.string.key_recipes), response.body());
FragmentManager fragmentManager = getSupportFragmentManager();
RecipesFragment recipesFragment = new RecipesFragment();
recipesFragment.setArguments(fragmentArgs);
@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {
if (data != null) {
if (data.getCount() > 0) {
data.moveToFirst();
do {
mSupportedRecipes.add(
data.getString(
data.getColumnIndex(