Search in sources :

Example 16 with Resources

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);
}
Also used : Resources(android.content.res.Resources)

Example 17 with Resources

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)));
    }
}
Also used : ColorInt(android.support.annotation.ColorInt) Resources(android.content.res.Resources) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 18 with Resources

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);
}
Also used : Resources(android.content.res.Resources) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 19 with Resources

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();
}
Also used : TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) Resources(android.content.res.Resources) SuppressLint(android.annotation.SuppressLint)

Example 20 with Resources

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);
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Aggregations

Resources (android.content.res.Resources)3195 Context (android.content.Context)292 Intent (android.content.Intent)280 View (android.view.View)236 TextView (android.widget.TextView)214 IOException (java.io.IOException)209 PackageManager (android.content.pm.PackageManager)206 Drawable (android.graphics.drawable.Drawable)197 Paint (android.graphics.Paint)178 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)176 Bitmap (android.graphics.Bitmap)174 DisplayMetrics (android.util.DisplayMetrics)165 Configuration (android.content.res.Configuration)151 Point (android.graphics.Point)151 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)137 ArrayList (java.util.ArrayList)134 XmlResourceParser (android.content.res.XmlResourceParser)132 TypedArray (android.content.res.TypedArray)129 Test (org.junit.Test)126 PendingIntent (android.app.PendingIntent)122