@Nullable @Override public Drawable getDrawable(@DrawableRes int resId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return mActivity.getDrawable(resId); } else { //noinspection deprecation return mActivity.getResources().getDrawable(resId); } } }
@Test public void testGetDrawable() { final Drawable resource = mock(Drawable.class); final int resourceId = 64532; final Activity activity = mock(Activity.class); final ActivityResourceFinder resourceFinder = new ActivityResourceFinder(activity); when(activity.getDrawable(resourceId)).thenReturn(resource); assertEquals(resource, resourceFinder.getDrawable(resourceId)); }
Activity activity = startActivity(); // override progress bar infinite animation with a simple image ProgressBar progressBar = (ProgressBar) activity.findViewById(R.id.loading_progressbar); progressBar.setIndeterminateDrawable(activity.getDrawable(android.R.drawable.ic_lock_lock)); // click on the button that triggers the display of the progress bar onView(withId(R.id.login_button)).perform(click());
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) { String title = getString(getArguments().getInt(ARG_TITLE_RES)); String breadcrumb = ""; String description = Html.fromHtml(getString(getArguments().getInt(ARG_DESC_RES))).toString(); Drawable icon = getActivity().getDrawable(getArguments().getInt(ARG_ICON_RES)); return new GuidanceStylist.Guidance(title, description, breadcrumb, icon); }
private void acceptState(Bundle savedInstanceState) { if (savedInstanceState != null) { current = (Book) savedInstanceState.getSerializable("current_details"); if (current != null) { // Picasa needs the placeholder. showDetails(current, getActivity().getDrawable(R.drawable.user_placeholder)); // Try to set the thumb first. Full size image is sometimes not available. setCover(current.getSmallThumbnail()); } } }
@NonNull @Override public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) { String title = getString(R.string.pref_title_account); String breadcrumb = getString(R.string.pref_title_sign_out); String description = getString(R.string.pref_sign_out_desc); Drawable icon = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { icon = getActivity().getDrawable(R.drawable.ic_app_logo_shadowless); } return new GuidanceStylist.Guidance(title, description, breadcrumb, icon); }
return mActivity.getDrawable(iconRes); } else { return null;