Home | History | Annotate | Download | only in drawable

Lines Matching defs:drawable

17 package androidx.core.graphics.drawable;
23 import android.graphics.drawable.Drawable;
24 import android.graphics.drawable.DrawableContainer;
25 import android.graphics.drawable.InsetDrawable;
42 * Helper for accessing features in {@link android.graphics.drawable.Drawable}.
54 * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()}.
56 * @param drawable The Drawable against which to invoke the method.
58 * @deprecated Use {@link Drawable#jumpToCurrentState()} directly.
61 public static void jumpToCurrentState(@NonNull Drawable drawable) {
62 drawable.jumpToCurrentState();
66 * Set whether this Drawable is automatically mirrored when its layout
73 * @param drawable The Drawable against which to invoke the method.
74 * @param mirrored Set to true if the Drawable should be mirrored, false if
77 public static void setAutoMirrored(@NonNull Drawable drawable, boolean mirrored) {
79 drawable.setAutoMirrored(mirrored);
84 * Tells if this Drawable will be automatically mirrored when its layout
90 * @param drawable The Drawable against which to invoke the method.
91 * @return boolean Returns true if this Drawable will be automatically
94 public static boolean isAutoMirrored(@NonNull Drawable drawable) {
96 return drawable.isAutoMirrored();
103 * Specifies the hotspot's location within the drawable.
105 * @param drawable The Drawable against which to invoke the method.
109 public static void setHotspot(@NonNull Drawable drawable, float x, float y) {
111 drawable.setHotspot(x, y);
117 * different from the drawable bounds.
119 * @param drawable The Drawable against which to invoke the method.
121 public static void setHotspotBounds(@NonNull Drawable drawable, int left, int top,
124 drawable.setHotspotBounds(left, top, right, bottom);
129 * Specifies a tint for {@code drawable}.
131 * @param drawable The Drawable against which to invoke the method.
132 * @param tint Color to use for tinting this drawable
134 public static void setTint(@NonNull Drawable drawable, @ColorInt int tint) {
136 drawable.setTint(tint);
137 } else if (drawable instanceof TintAwareDrawable) {
138 ((TintAwareDrawable) drawable).setTint(tint);
143 * Specifies a tint for {@code drawable} as a color state list.
145 * @param drawable The Drawable against which to invoke the method.
146 * @param tint Color state list to use for tinting this drawable, or null to clear the tint
148 public static void setTintList(@NonNull Drawable drawable, @Nullable ColorStateList tint) {
150 drawable.setTintList(tint);
151 } else if (drawable instanceof TintAwareDrawable) {
152 ((TintAwareDrawable) drawable).setTintList(tint);
157 * Specifies a tint blending mode for {@code drawable}.
159 * @param drawable The Drawable against which to invoke the method.
162 public static void setTintMode(@NonNull Drawable drawable, @NonNull PorterDuff.Mode tintMode) {
164 drawable.setTintMode(tintMode);
165 } else if (drawable instanceof TintAwareDrawable) {
166 ((TintAwareDrawable) drawable).setTintMode(tintMode);
171 * Get the alpha value of the {@code drawable}.
174 * @param drawable The Drawable against which to invoke the method.
176 public static int getAlpha(@NonNull Drawable drawable) {
178 return drawable.getAlpha();
185 * Applies the specified theme to this Drawable and its children.
187 public static void applyTheme(@NonNull Drawable drawable, @NonNull Resources.Theme theme) {
189 drawable.applyTheme(theme);
194 * Whether a theme can be applied to this Drawable and its children.
196 public static boolean canApplyTheme(@NonNull Drawable drawable) {
198 return drawable.canApplyTheme();
209 public static ColorFilter getColorFilter(@NonNull Drawable drawable) {
211 return drawable.getColorFilter();
218 * Removes the color filter from the given drawable.
220 public static void clearColorFilter(@NonNull Drawable drawable) {
223 drawable.clearColorFilter();
225 drawable.clearColorFilter();
228 // will not propagate to all of its children. To workaround this we unwrap the drawable
231 if (drawable instanceof InsetDrawable) {
232 clearColorFilter(((InsetDrawable) drawable).getDrawable());
233 } else if (drawable instanceof WrappedDrawable) {
234 clearColorFilter(((WrappedDrawable) drawable).getWrappedDrawable());
235 } else if (drawable instanceof DrawableContainer) {
236 final DrawableContainer container = (DrawableContainer) drawable;
240 Drawable child;
250 drawable.clearColorFilter();
255 * Inflate this Drawable from an XML resource optionally styled by a theme.
258 * @param parser XML parser from which to inflate this Drawable
264 public static void inflate(@NonNull Drawable drawable, @NonNull Resources res,
269 drawable.inflate(res, parser, attrs, theme);
271 drawable.inflate(res, parser, attrs);
276 * Potentially wrap {@code drawable} so that it may be used for tinting across the
279 * <p>If the given drawable is wrapped, we will copy over certain state over to the wrapped
280 * drawable, such as its bounds, level, visibility and state.</p>
282 * <p>You must use the result of this call. If the given drawable is being used by a view
283 * (as its background for instance), you must replace the original drawable with
287 * Drawable bg = DrawableCompat.wrap(view.getBackground());
288 * // Need to set the background with the wrapped drawable
291 * // You can now tint the drawable
295 * <p>If you need to get hold of the original {@link android.graphics.drawable.Drawable} again,
296 * you can use the value returned from {@link #unwrap(Drawable)}.</p>
298 * @param drawable The Drawable to process
299 * @return A drawable capable of being tinted across all API levels.
301 * @see #setTint(Drawable, int)
302 * @see #setTintList(Drawable, ColorStateList)
303 * @see #setTintMode(Drawable, PorterDuff.Mode)
304 * @see #unwrap(Drawable)
306 public static Drawable wrap(@NonNull Drawable drawable) {
308 return drawable;
310 if (!(drawable instanceof TintAwareDrawable)) {
311 return new WrappedDrawableApi21(drawable);
313 return drawable;
315 if (!(drawable instanceof TintAwareDrawable)) {
316 return new WrappedDrawableApi14(drawable);
318 return drawable;
323 * Unwrap {@code drawable} if it is the result of a call to {@link #wrap(Drawable)}. If
324 * the {@code drawable} is not the result of a call to {@link #wrap(Drawable)} then
325 * {@code drawable} is returned as-is.
327 * @param drawable The drawable to unwrap
328 * @return the unwrapped {@link Drawable} or {@code drawable} if it hasn't been wrapped.
330 * @see #wrap(Drawable)
333 public static <T extends Drawable> T unwrap(@NonNull Drawable drawable) {
334 if (drawable instanceof WrappedDrawable) {
335 return (T) ((WrappedDrawable) drawable).getWrappedDrawable();
337 return (T) drawable;
341 * Set the layout direction for this drawable. Should be a resolved
342 * layout direction, as the Drawable has no capacity to do the resolution on
345 * @param layoutDirection the resolved layout direction for the drawable,
349 * appearance of the drawable to change such that it needs to be
351 * @see #getLayoutDirection(Drawable)
353 public static boolean setLayoutDirection(@NonNull Drawable drawable, int layoutDirection) {
355 return drawable.setLayoutDirection(layoutDirection);
360 Drawable.class.getDeclaredMethod("setLayoutDirection", int.class);
370 sSetLayoutDirectionMethod.invoke(drawable, layoutDirection);
384 * Returns the resolved layout direction for this Drawable.
388 * @see #setLayoutDirection(Drawable, int)
390 public static int getLayoutDirection(@NonNull Drawable drawable) {
392 return drawable.getLayoutDirection();
397 Drawable.class.getDeclaredMethod("getLayoutDirection");
407 return (int) sGetLayoutDirectionMethod.invoke(drawable);