• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package com.android.systemui.statusbar;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.content.res.Resources;
21 import android.graphics.Canvas;
22 import android.graphics.Rect;
23 import android.graphics.drawable.Drawable;
24 import android.graphics.drawable.DrawableWrapper;
25 import android.util.AttributeSet;
26 
27 import com.android.systemui.R;
28 
29 import org.xmlpull.v1.XmlPullParser;
30 import org.xmlpull.v1.XmlPullParserException;
31 
32 import java.io.IOException;
33 
34 /**
35  * The status bar cast drawable draws ic_cast and ic_cast_connected_fill to indicate that the
36  * screen is being recorded. A simple layer-list drawable isn't used here because the record fill
37  * must not be tinted by the caller.
38  */
39 public class CastDrawable extends DrawableWrapper {
40     private Drawable mFillDrawable;
41     private int mHorizontalPadding;
42 
43     /** No-arg constructor used by drawable inflation. */
CastDrawable()44     public CastDrawable() {
45         super(null);
46     }
47 
48     @Override
inflate(@onNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Resources.Theme theme)49     public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser,
50             @NonNull AttributeSet attrs, @Nullable Resources.Theme theme)
51             throws XmlPullParserException, IOException {
52         super.inflate(r, parser, attrs, theme);
53         setDrawable(r.getDrawable(R.drawable.ic_cast, theme).mutate());
54         mFillDrawable = r.getDrawable(R.drawable.ic_cast_connected_fill, theme).mutate();
55         mHorizontalPadding = r.getDimensionPixelSize(R.dimen.status_bar_horizontal_padding);
56     }
57 
58     @Override
canApplyTheme()59     public boolean canApplyTheme() {
60         return mFillDrawable.canApplyTheme() || super.canApplyTheme();
61     }
62 
63     @Override
applyTheme(Resources.Theme t)64     public void applyTheme(Resources.Theme t) {
65         super.applyTheme(t);
66         mFillDrawable.applyTheme(t);
67     }
68 
69     @Override
onBoundsChange(Rect bounds)70     protected void onBoundsChange(Rect bounds) {
71         super.onBoundsChange(bounds);
72         mFillDrawable.setBounds(bounds);
73     }
74 
75     @Override
onLayoutDirectionChanged(int layoutDirection)76     public boolean onLayoutDirectionChanged(int layoutDirection) {
77         mFillDrawable.setLayoutDirection(layoutDirection);
78         return super.onLayoutDirectionChanged(layoutDirection);
79     }
80 
81     @Override
draw(Canvas canvas)82     public void draw(Canvas canvas) {
83         super.draw(canvas);
84         mFillDrawable.draw(canvas);
85     }
86 
87     @Override
getPadding(Rect padding)88     public boolean getPadding(Rect padding) {
89         padding.left += mHorizontalPadding;
90         padding.right += mHorizontalPadding;
91         return true;
92     }
93 
94     @Override
setAlpha(int alpha)95     public void setAlpha(int alpha) {
96         super.setAlpha(alpha);
97         mFillDrawable.setAlpha(alpha);
98     }
99 
100     @Override
setVisible(boolean visible, boolean restart)101     public boolean setVisible(boolean visible, boolean restart) {
102         mFillDrawable.setVisible(visible, restart);
103         return super.setVisible(visible, restart);
104     }
105 
106     @Override
mutate()107     public Drawable mutate() {
108         mFillDrawable.mutate();
109         return super.mutate();
110     }
111 }
112