1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.support.v4.graphics.drawable; 18 19 import android.content.res.ColorStateList; 20 import android.graphics.PorterDuff; 21 import android.graphics.drawable.Drawable; 22 import android.graphics.drawable.DrawableContainer; 23 import android.graphics.drawable.GradientDrawable; 24 25 /** 26 * Implementation of drawable compatibility that can call L APIs. 27 */ 28 class DrawableCompatLollipop { 29 30 public static void setHotspot(Drawable drawable, float x, float y) { 31 drawable.setHotspot(x, y); 32 } 33 34 public static void setHotspotBounds(Drawable drawable, int left, int top, 35 int right, int bottom) { 36 drawable.setHotspotBounds( left, top, right, bottom); 37 } 38 39 public static void setTint(Drawable drawable, int tint) { 40 if (drawable instanceof DrawableWrapperLollipop) { 41 // GradientDrawable on Lollipop does not support tinting, so we'll use our compatible 42 // functionality instead 43 DrawableCompatBase.setTint(drawable, tint); 44 } else { 45 // Else, we'll use the framework API 46 drawable.setTint(tint); 47 } 48 } 49 50 public static void setTintList(Drawable drawable, ColorStateList tint) { 51 if (drawable instanceof DrawableWrapperLollipop) { 52 // GradientDrawable on Lollipop does not support tinting, so we'll use our compatible 53 // functionality instead 54 DrawableCompatBase.setTintList(drawable, tint); 55 } else { 56 // Else, we'll use the framework API 57 drawable.setTintList(tint); 58 } 59 } 60 61 public static void setTintMode(Drawable drawable, PorterDuff.Mode tintMode) { 62 if (drawable instanceof DrawableWrapperLollipop) { 63 // GradientDrawable on Lollipop does not support tinting, so we'll use our compatible 64 // functionality instead 65 DrawableCompatBase.setTintMode(drawable, tintMode); 66 } else { 67 // Else, we'll use the framework API 68 drawable.setTintMode(tintMode); 69 } 70 } 71 72 public static Drawable wrapForTinting(Drawable drawable) { 73 if (drawable instanceof GradientDrawable || drawable instanceof DrawableContainer) { 74 // GradientDrawable on Lollipop does not support tinting, so we'll use our compatible 75 // functionality instead. We also do the same for DrawableContainers since they may 76 // contain GradientDrawable instances. 77 return new DrawableWrapperLollipop(drawable); 78 } 79 return drawable; 80 } 81 82 } 83