Home | History | Annotate | Download | only in drawable
      1 /*
      2  * Copyright (C) 2015 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 
     23 /**
     24  * Base implementation of drawable compatibility.
     25  */
     26 class DrawableCompatBase {
     27 
     28     public static void setTint(Drawable drawable, int tint) {
     29         if (drawable instanceof DrawableWrapper) {
     30             ((DrawableWrapper) drawable).setTint(tint);
     31         }
     32     }
     33 
     34     public static void setTintList(Drawable drawable, ColorStateList tint) {
     35         if (drawable instanceof DrawableWrapper) {
     36             ((DrawableWrapper) drawable).setTintList(tint);
     37         }
     38     }
     39 
     40     public static void setTintMode(Drawable drawable, PorterDuff.Mode tintMode) {
     41         if (drawable instanceof DrawableWrapper) {
     42             ((DrawableWrapper) drawable).setTintMode(tintMode);
     43         }
     44     }
     45 
     46     public static Drawable wrapForTinting(Drawable drawable) {
     47         if (!(drawable instanceof DrawableWrapperDonut)) {
     48             return new DrawableWrapperDonut(drawable);
     49         }
     50         return drawable;
     51     }
     52 
     53 }
     54