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