Java Code Examples for android.graphics.drawable.Drawable#canApplyTheme()

The following examples show how to use android.graphics.drawable.Drawable#canApplyTheme() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawableContainerCompat.java    From MaterialProgressBar with Apache License 2.0 6 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean canApplyTheme() {
    final int count = mNumChildren;
    final Drawable[] drawables = mDrawables;
    for (int i = 0; i < count; i++) {
        final Drawable d = drawables[i];
        if (d != null) {
            if (d.canApplyTheme()) {
                return true;
            }
        } else {
            final ConstantState future = mDrawableFutures.get(i);
            if (future != null && future.canApplyTheme()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: LollipopDrawablesCompat.java    From Carbon with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canApplyTheme(Drawable drawable) {
    return drawable.canApplyTheme();
}
 
Example 3
Source File: LollipopDrawablesCompat.java    From RippleDrawable with MIT License 4 votes vote down vote up
@Override
public boolean canApplyTheme(Drawable drawable) {
    return drawable.canApplyTheme();
}
 
Example 4
Source File: Resources.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Return a drawable object associated with a particular resource ID.
 * Various types of objects will be returned depending on the underlying
 * resource -- for example, a solid color, PNG image, scalable image, etc.
 * The Drawable API hides these implementation details.
 *
 * <p class="note"><strong>Note:</strong> Prior to
 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, this function
 * would not correctly retrieve the final configuration density when
 * the resource ID passed here is an alias to another Drawable resource.
 * This means that if the density configuration of the alias resource
 * is different than the actual resource, the density of the returned
 * Drawable would be incorrect, resulting in bad scaling. To work
 * around this, you can instead manually resolve the aliased reference
 * by using {@link #getValue(int, TypedValue, boolean)} and passing
 * {@code true} for {@code resolveRefs}. The resulting
 * {@link TypedValue#resourceId} value may be passed to this method.</p>
 *
 * <p class="note"><strong>Note:</strong> To obtain a themed drawable, use
 * {@link android.content.Context#getDrawable(int) Context.getDrawable(int)}
 * or {@link #getDrawable(int, Theme)} passing the desired theme.</p>
 *
 * @param id The desired resource identifier, as generated by the aapt
 *           tool. This integer encodes the package, type, and resource
 *           entry. The value 0 is an invalid identifier.
 * @return Drawable An object that can be used to draw this resource.
 * @throws NotFoundException Throws NotFoundException if the given ID does
 *         not exist.
 * @see #getDrawable(int, Theme)
 * @deprecated Use {@link #getDrawable(int, Theme)} instead.
 */
@Deprecated
public Drawable getDrawable(@DrawableRes int id) throws NotFoundException {
    final Drawable d = getDrawable(id, null);
    if (d != null && d.canApplyTheme()) {
        Log.w(TAG, "Drawable " + getResourceName(id) + " has unresolved theme "
                + "attributes! Consider using Resources.getDrawable(int, Theme) or "
                + "Context.getDrawable(int).", new RuntimeException());
    }
    return d;
}