17e82b99953680915596eaf0eb35927388e574ca8Chris Banes/*
27e82b99953680915596eaf0eb35927388e574ca8Chris Banes * Copyright (C) 2014 The Android Open Source Project
37e82b99953680915596eaf0eb35927388e574ca8Chris Banes *
47e82b99953680915596eaf0eb35927388e574ca8Chris Banes * Licensed under the Apache License, Version 2.0 (the "License");
57e82b99953680915596eaf0eb35927388e574ca8Chris Banes * you may not use this file except in compliance with the License.
67e82b99953680915596eaf0eb35927388e574ca8Chris Banes * You may obtain a copy of the License at
77e82b99953680915596eaf0eb35927388e574ca8Chris Banes *
87e82b99953680915596eaf0eb35927388e574ca8Chris Banes *      http://www.apache.org/licenses/LICENSE-2.0
97e82b99953680915596eaf0eb35927388e574ca8Chris Banes *
107e82b99953680915596eaf0eb35927388e574ca8Chris Banes * Unless required by applicable law or agreed to in writing, software
117e82b99953680915596eaf0eb35927388e574ca8Chris Banes * distributed under the License is distributed on an "AS IS" BASIS,
127e82b99953680915596eaf0eb35927388e574ca8Chris Banes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137e82b99953680915596eaf0eb35927388e574ca8Chris Banes * See the License for the specific language governing permissions and
147e82b99953680915596eaf0eb35927388e574ca8Chris Banes * limitations under the License.
157e82b99953680915596eaf0eb35927388e574ca8Chris Banes */
167e82b99953680915596eaf0eb35927388e574ca8Chris Banes
177e82b99953680915596eaf0eb35927388e574ca8Chris Banespackage android.support.v4.graphics.drawable;
187e82b99953680915596eaf0eb35927388e574ca8Chris Banes
197e82b99953680915596eaf0eb35927388e574ca8Chris Banesimport android.content.res.ColorStateList;
20ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhuimport android.content.res.Resources;
21ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhuimport android.graphics.ColorFilter;
227e82b99953680915596eaf0eb35927388e574ca8Chris Banesimport android.graphics.PorterDuff;
237e82b99953680915596eaf0eb35927388e574ca8Chris Banesimport android.graphics.drawable.Drawable;
24ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhuimport android.util.AttributeSet;
25ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhuimport org.xmlpull.v1.XmlPullParser;
26ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhuimport org.xmlpull.v1.XmlPullParserException;
27ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu
28ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhuimport java.io.IOException;
297e82b99953680915596eaf0eb35927388e574ca8Chris Banes
307e82b99953680915596eaf0eb35927388e574ca8Chris Banes/**
317e82b99953680915596eaf0eb35927388e574ca8Chris Banes * Implementation of drawable compatibility that can call L APIs.
327e82b99953680915596eaf0eb35927388e574ca8Chris Banes */
337e82b99953680915596eaf0eb35927388e574ca8Chris Banesclass DrawableCompatLollipop {
347e82b99953680915596eaf0eb35927388e574ca8Chris Banes
357e82b99953680915596eaf0eb35927388e574ca8Chris Banes    public static void setHotspot(Drawable drawable, float x, float y) {
367e82b99953680915596eaf0eb35927388e574ca8Chris Banes        drawable.setHotspot(x, y);
377e82b99953680915596eaf0eb35927388e574ca8Chris Banes    }
387e82b99953680915596eaf0eb35927388e574ca8Chris Banes
397e82b99953680915596eaf0eb35927388e574ca8Chris Banes    public static void setHotspotBounds(Drawable drawable, int left, int top,
407e82b99953680915596eaf0eb35927388e574ca8Chris Banes            int right, int bottom) {
417e82b99953680915596eaf0eb35927388e574ca8Chris Banes        drawable.setHotspotBounds( left, top, right, bottom);
427e82b99953680915596eaf0eb35927388e574ca8Chris Banes    }
437e82b99953680915596eaf0eb35927388e574ca8Chris Banes
447e82b99953680915596eaf0eb35927388e574ca8Chris Banes    public static void setTint(Drawable drawable, int tint) {
457797b9f22c8c404309b778a0966266d2b1a84915Chris Banes        drawable.setTint(tint);
467e82b99953680915596eaf0eb35927388e574ca8Chris Banes    }
477e82b99953680915596eaf0eb35927388e574ca8Chris Banes
487e82b99953680915596eaf0eb35927388e574ca8Chris Banes    public static void setTintList(Drawable drawable, ColorStateList tint) {
497797b9f22c8c404309b778a0966266d2b1a84915Chris Banes        drawable.setTintList(tint);
507e82b99953680915596eaf0eb35927388e574ca8Chris Banes    }
517e82b99953680915596eaf0eb35927388e574ca8Chris Banes
527e82b99953680915596eaf0eb35927388e574ca8Chris Banes    public static void setTintMode(Drawable drawable, PorterDuff.Mode tintMode) {
537797b9f22c8c404309b778a0966266d2b1a84915Chris Banes        drawable.setTintMode(tintMode);
547e82b99953680915596eaf0eb35927388e574ca8Chris Banes    }
557e82b99953680915596eaf0eb35927388e574ca8Chris Banes
56ac54e3ed316c378f9f339b88811613feb176e75dChris Banes    public static Drawable wrapForTinting(final Drawable drawable) {
57be678137d44778590a6220ae0ef13649e83363a9Chris Banes        if (!(drawable instanceof TintAwareDrawable)) {
589925d4a53e0dbaacf07901fb48907fe1aff9bbbdChris Banes            return new DrawableWrapperLollipop(drawable);
59ac54e3ed316c378f9f339b88811613feb176e75dChris Banes        }
60ac54e3ed316c378f9f339b88811613feb176e75dChris Banes        return drawable;
617e82b99953680915596eaf0eb35927388e574ca8Chris Banes    }
62ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu
63ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    public static void applyTheme(Drawable drawable, Resources.Theme t) {
64ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu        drawable.applyTheme(t);
65ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    }
66ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu
67ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    public static boolean canApplyTheme(Drawable drawable) {
68ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu        return drawable.canApplyTheme();
69ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    }
70ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu
71ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    public static ColorFilter getColorFilter(Drawable drawable) {
72ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu        return drawable.getColorFilter();
73ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    }
74ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu
75ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    public static void inflate(Drawable drawable, Resources res, XmlPullParser parser,
76ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu                               AttributeSet attrs, Resources.Theme t)
77ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu            throws IOException, XmlPullParserException {
78ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu        drawable.inflate(res, parser, attrs, t);
79ebbed34a78fa6519de6c2848e68b97f9d3b98e08Tenghui Zhu    }
807e82b99953680915596eaf0eb35927388e574ca8Chris Banes}
81