Search in sources :

Example 31 with Drawable

use of android.graphics.drawable.Drawable in project material-dialogs by afollestad.

the class MDTintHelper method setTint.

public static void setTint(@NonNull RadioButton radioButton, @NonNull ColorStateList colors) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(colors);
    } else {
        Drawable radioDrawable = ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material);
        Drawable d = DrawableCompat.wrap(radioDrawable);
        DrawableCompat.setTintList(d, colors);
        radioButton.setButtonDrawable(d);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable)

Example 32 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class CarbonResources method createFromXmlInner.

/**
     * Create a drawable from inside an XML document using an optional
     * {@link Resources.Theme}. Called on a parser positioned at a tag in an XML
     * document, tries to create a Drawable from that tag. Returns {@code null}
     * if the tag is not a valid drawable.
     */
public Drawable createFromXmlInner(XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException {
    Drawable drawable = null;
    final String name = parser.getName();
    try {
        Class<? extends Drawable> clazz = CLASS_MAP.get(name);
        if (clazz != null) {
            drawable = clazz.newInstance();
        } else if (name.indexOf('.') > 0) {
            drawable = (Drawable) Class.forName(name).newInstance();
        }
    } catch (Exception e) {
        throw new XmlPullParserException("Error while inflating drawable resource", parser, e);
    }
    if (drawable == null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            return Drawable.createFromXmlInner(this, parser, attrs, theme);
        } else {
            return Drawable.createFromXmlInner(this, parser, attrs);
        }
    }
    IMPL.inflate(drawable, this, parser, attrs, theme);
    return drawable;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) VectorDrawable(carbon.drawable.VectorDrawable) LollipopDrawable(carbon.drawable.ripple.LollipopDrawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 33 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class CarbonResources method loadDrawable.

public Drawable loadDrawable(TypedValue value, Resources.Theme theme) throws Resources.NotFoundException {
    if (value == null || value.resourceId == 0) {
        return null;
    }
    final boolean isColorDrawable;
    final LongSparseArray<WeakReference<Drawable.ConstantState>> cache;
    final long key;
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        isColorDrawable = true;
        cache = sColorDrawableCache;
        key = value.data;
    } else {
        isColorDrawable = false;
        cache = sDrawableCache;
        key = (long) value.assetCookie << 32 | value.data;
    }
    Drawable dr = getCachedDrawable(cache, key);
    if (dr != null) {
        return dr;
    }
    Drawable.ConstantState cs = null;
    if (cs != null) {
        final Drawable cloneDr = cs.newDrawable(this);
        if (theme != null) {
            dr = cloneDr.mutate();
            applyTheme(dr, theme);
        } else {
            dr = cloneDr;
        }
    } else if (isColorDrawable) {
        dr = new ColorDrawable(value.data);
    } else {
        dr = loadDrawableForCookie(value, value.resourceId, theme);
    }
    if (dr != null) {
        dr.setChangingConfigurations(value.changingConfigurations);
        cacheDrawable(value, theme, isColorDrawable, key, dr, cache);
    }
    return dr;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) WeakReference(java.lang.ref.WeakReference) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) VectorDrawable(carbon.drawable.VectorDrawable) LollipopDrawable(carbon.drawable.ripple.LollipopDrawable)

Example 34 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class CarbonResources method createFromXml.

/**
     * Create a drawable from an XML document using an optional {@link Resources.Theme}.
     * For more information on how to create resources in XML, see
     * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
     */
public Drawable createFromXml(XmlPullParser parser, Resources.Theme theme) throws XmlPullParserException, IOException {
    AttributeSet attrs = Xml.asAttributeSet(parser);
    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    // Empty loop
    }
    if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("No start tag found");
    }
    Drawable drawable = createFromXmlInner(parser, attrs, theme);
    if (drawable == null) {
        throw new RuntimeException("Unknown initial tag: " + parser.getName());
    }
    return drawable;
}
Also used : AttributeSet(android.util.AttributeSet) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) VectorDrawable(carbon.drawable.VectorDrawable) LollipopDrawable(carbon.drawable.ripple.LollipopDrawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 35 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class ToolbarWidgetWrapper method updateToolbarLogo.

private void updateToolbarLogo() {
    Drawable logo = null;
    if ((mDisplayOpts & ActionBar.DISPLAY_SHOW_HOME) != 0) {
        if ((mDisplayOpts & ActionBar.DISPLAY_USE_LOGO) != 0) {
            logo = mLogo != null ? mLogo : mIcon;
        } else {
            logo = mIcon;
        }
    }
    mToolbar.setLogo(logo);
}
Also used : Drawable(android.graphics.drawable.Drawable)

Aggregations

Drawable (android.graphics.drawable.Drawable)4516 BitmapDrawable (android.graphics.drawable.BitmapDrawable)795 View (android.view.View)579 Bitmap (android.graphics.Bitmap)476 ColorDrawable (android.graphics.drawable.ColorDrawable)473 ImageView (android.widget.ImageView)471 TextView (android.widget.TextView)439 Paint (android.graphics.Paint)322 LayerDrawable (android.graphics.drawable.LayerDrawable)314 Test (org.junit.Test)276 Context (android.content.Context)267 Resources (android.content.res.Resources)252 Rect (android.graphics.Rect)243 PackageManager (android.content.pm.PackageManager)233 StateListDrawable (android.graphics.drawable.StateListDrawable)212 TypedArray (android.content.res.TypedArray)205 Intent (android.content.Intent)155 ViewGroup (android.view.ViewGroup)148 AnimationDrawable (android.graphics.drawable.AnimationDrawable)147 ArrayList (java.util.ArrayList)139