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