use of android.content.res.Resources in project cordova-plugin-local-notifications by katzer.
the class AssetUtil method getIconFromDrawable.
/**
* Convert drawable resource to bitmap.
*
* @param drawable
* Drawable resource name
*/
Bitmap getIconFromDrawable(String drawable) {
Resources res = context.getResources();
int iconId;
iconId = getResIdForDrawable(getPkgName(), drawable);
if (iconId == 0) {
iconId = getResIdForDrawable("android", drawable);
}
if (iconId == 0) {
iconId = android.R.drawable.screen_background_dark_transparent;
}
return BitmapFactory.decodeResource(res, iconId);
}
use of android.content.res.Resources in project material-components-android by material-components.
the class NavigationViewTest method testTextColor.
@Test
public void testTextColor() {
// Open our drawer
onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
final Resources res = activityTestRule.getActivity().getResources();
@ColorInt final int defaultTextColor = ResourcesCompat.getColor(res, R.color.emerald_text, null);
// Check the default text color of the menu items in our NavigationView
for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
onView(allOf(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i])), isDescendantOfA(withId(R.id.start_drawer)))).check(matches(withTextColor(defaultTextColor)));
}
// Set a new text color on our NavigationView
onView(withId(R.id.start_drawer)).perform(setItemTextColor(ResourcesCompat.getColorStateList(res, R.color.color_state_list_lilac, null)));
// And check that all the menu items have the new color
@ColorInt final int newTextColor = ResourcesCompat.getColor(res, R.color.lilac_default, null);
for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
onView(allOf(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i])), isDescendantOfA(withId(R.id.start_drawer)))).check(matches(withTextColor(newTextColor)));
}
}
use of android.content.res.Resources in project material-components-android by material-components.
the class SnackbarTest method testBasicContent.
@Test
public void testBasicContent() throws Throwable {
// Verify different combinations of snackbar content (message and action) and duration
final Resources res = activityTestRule.getActivity().getResources();
final String resolvedMessage = res.getString(MESSAGE_ID);
final String resolvedAction = res.getString(ACTION_ID);
// String message and no action
verifySnackbarContent(Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_SHORT), MESSAGE_TEXT, null);
// Resource message and no action
verifySnackbarContent(Snackbar.make(mCoordinatorLayout, MESSAGE_ID, Snackbar.LENGTH_LONG), resolvedMessage, null);
// String message and string action
verifySnackbarContent(Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_INDEFINITE).setAction(ACTION_TEXT, mock(View.OnClickListener.class)), MESSAGE_TEXT, ACTION_TEXT);
// String message and resource action
verifySnackbarContent(Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_SHORT).setAction(ACTION_ID, mock(View.OnClickListener.class)), MESSAGE_TEXT, resolvedAction);
// Resource message and resource action
verifySnackbarContent(Snackbar.make(mCoordinatorLayout, MESSAGE_ID, Snackbar.LENGTH_LONG).setAction(ACTION_ID, mock(View.OnClickListener.class)), resolvedMessage, resolvedAction);
}
use of android.content.res.Resources in project Signal-Android by WhisperSystems.
the class MultiWaveView method internalSetTargetResources.
private void internalSetTargetResources(int resourceId) {
Resources res = getContext().getResources();
TypedArray array = res.obtainTypedArray(resourceId);
int count = array.length();
ArrayList<TargetDrawable> targetDrawables = new ArrayList<TargetDrawable>(count);
for (int i = 0; i < count; i++) {
Drawable drawable = array.getDrawable(i);
targetDrawables.add(new TargetDrawable(res, drawable));
}
array.recycle();
mTargetResourceId = resourceId;
mTargetDrawables = targetDrawables;
updateTargetPositions();
}
use of android.content.res.Resources in project Signal-Android by WhisperSystems.
the class ColorPreference method setColorViewValue.
private static void setColorViewValue(View view, int color, boolean selected) {
if (view instanceof ImageView) {
ImageView imageView = (ImageView) view;
Resources res = imageView.getContext().getResources();
Drawable currentDrawable = imageView.getDrawable();
GradientDrawable colorChoiceDrawable;
if (currentDrawable instanceof GradientDrawable) {
// Reuse drawable
colorChoiceDrawable = (GradientDrawable) currentDrawable;
} else {
colorChoiceDrawable = new GradientDrawable();
colorChoiceDrawable.setShape(GradientDrawable.OVAL);
}
// Set stroke to dark version of color
// int darkenedColor = Color.rgb(
// Color.red(color) * 192 / 256,
// Color.green(color) * 192 / 256,
// Color.blue(color) * 192 / 256);
colorChoiceDrawable.setColor(color);
// colorChoiceDrawable.setStroke((int) TypedValue.applyDimension(
// TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor);
Drawable drawable = colorChoiceDrawable;
if (selected) {
BitmapDrawable checkmark = (BitmapDrawable) res.getDrawable(R.drawable.check);
checkmark.setGravity(Gravity.CENTER);
drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark });
}
imageView.setImageDrawable(drawable);
} else if (view instanceof TextView) {
((TextView) view).setTextColor(color);
}
}
Aggregations