1 /*
2  * Copyright (C) 2014 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.statusbar;
18 
19 import android.content.Context;
20 import android.graphics.Canvas;
21 import android.graphics.drawable.Drawable;
22 import android.util.AttributeSet;
23 import android.widget.FrameLayout;
24 import com.android.systemui.R;
25 
26 /**
27  * The guts of a notification revealed when performing a long press.
28  */
29 public class NotificationGuts extends FrameLayout {
30 
31     private Drawable mBackground;
32     private int mClipTopAmount;
33     private int mActualHeight;
34 
NotificationGuts(Context context, AttributeSet attrs)35     public NotificationGuts(Context context, AttributeSet attrs) {
36         super(context, attrs);
37         setWillNotDraw(false);
38     }
39 
40     @Override
onDraw(Canvas canvas)41     protected void onDraw(Canvas canvas) {
42         draw(canvas, mBackground);
43     }
44 
draw(Canvas canvas, Drawable drawable)45     private void draw(Canvas canvas, Drawable drawable) {
46         if (drawable != null) {
47             drawable.setBounds(0, mClipTopAmount, getWidth(), mActualHeight);
48             drawable.draw(canvas);
49         }
50     }
51 
52     @Override
onFinishInflate()53     protected void onFinishInflate() {
54         super.onFinishInflate();
55         mBackground = mContext.getDrawable(R.drawable.notification_guts_bg);
56         if (mBackground != null) {
57             mBackground.setCallback(this);
58         }
59     }
60 
61     @Override
verifyDrawable(Drawable who)62     protected boolean verifyDrawable(Drawable who) {
63         return super.verifyDrawable(who) || who == mBackground;
64     }
65 
66     @Override
drawableStateChanged()67     protected void drawableStateChanged() {
68         drawableStateChanged(mBackground);
69     }
70 
drawableStateChanged(Drawable d)71     private void drawableStateChanged(Drawable d) {
72         if (d != null && d.isStateful()) {
73             d.setState(getDrawableState());
74         }
75     }
76 
77     @Override
drawableHotspotChanged(float x, float y)78     public void drawableHotspotChanged(float x, float y) {
79         if (mBackground != null) {
80             mBackground.setHotspot(x, y);
81         }
82     }
83 
setActualHeight(int actualHeight)84     public void setActualHeight(int actualHeight) {
85         mActualHeight = actualHeight;
86         invalidate();
87     }
88 
getActualHeight()89     public int getActualHeight() {
90         return mActualHeight;
91     }
92 
setClipTopAmount(int clipTopAmount)93     public void setClipTopAmount(int clipTopAmount) {
94         mClipTopAmount = clipTopAmount;
95         invalidate();
96     }
97 
98     @Override
hasOverlappingRendering()99     public boolean hasOverlappingRendering() {
100 
101         // Prevents this view from creating a layer when alpha is animating.
102         return false;
103     }
104 }
105