Home | History | Annotate | Download | only in qs
      1 /*
      2  * Copyright (C) 2017 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 com.android.systemui.qs;
     18 
     19 import android.content.Context;
     20 import android.content.res.ColorStateList;
     21 import android.graphics.drawable.Drawable;
     22 
     23 import com.android.systemui.qs.tileimpl.SlashImageView;
     24 
     25 
     26 /**
     27  * Creates AlphaControlledSlashImageView instead of SlashImageView
     28  */
     29 public class AlphaControlledSignalTileView extends SignalTileView {
     30     public AlphaControlledSignalTileView(Context context) {
     31         super(context);
     32     }
     33 
     34     @Override
     35     protected SlashImageView createSlashImageView(Context context) {
     36         return new AlphaControlledSlashImageView(context);
     37     }
     38 
     39     /**
     40      * Creates AlphaControlledSlashDrawable instead of regular SlashDrawables
     41      */
     42     public static class AlphaControlledSlashImageView extends SlashImageView {
     43         public AlphaControlledSlashImageView(Context context) {
     44             super(context);
     45         }
     46 
     47         public void setFinalImageTintList(ColorStateList tint) {
     48             super.setImageTintList(tint);
     49             final SlashDrawable slash = getSlash();
     50             if (slash != null) {
     51                 ((AlphaControlledSlashDrawable)slash).setFinalTintList(tint);
     52             }
     53         }
     54 
     55         @Override
     56         protected void ensureSlashDrawable() {
     57             if (getSlash() == null) {
     58                 final SlashDrawable slash = new AlphaControlledSlashDrawable(getDrawable());
     59                 setSlash(slash);
     60                 slash.setAnimationEnabled(getAnimationEnabled());
     61                 setImageViewDrawable(slash);
     62             }
     63         }
     64     }
     65 
     66     /**
     67      * SlashDrawable that disobeys orders to change its drawable's tint except when you tell
     68      * it not to disobey. The slash still will animate its alpha.
     69      */
     70     public static class AlphaControlledSlashDrawable extends SlashDrawable {
     71         AlphaControlledSlashDrawable(Drawable d) {
     72             super(d);
     73         }
     74 
     75         @Override
     76         protected void setDrawableTintList(ColorStateList tint) {
     77         }
     78 
     79         /**
     80          * Set a target tint list instead of
     81          */
     82         public void setFinalTintList(ColorStateList tint) {
     83             super.setDrawableTintList(tint);
     84         }
     85     }
     86 }
     87 
     88