1 /*
2  * Copyright (C) 2012 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.shade;
18 
19 import android.content.Context;
20 import android.content.res.Configuration;
21 import android.graphics.Canvas;
22 import android.graphics.Color;
23 import android.graphics.Paint;
24 import android.graphics.PorterDuff;
25 import android.graphics.PorterDuffXfermode;
26 import android.util.AttributeSet;
27 import android.view.MotionEvent;
28 import android.widget.FrameLayout;
29 
30 /** The shade view. */
31 public final class NotificationPanelView extends FrameLayout {
32     static final boolean DEBUG = false;
33 
34     private final Paint mAlphaPaint = new Paint();
35 
36     private int mCurrentPanelAlpha;
37     private boolean mDozing;
38     private RtlChangeListener mRtlChangeListener;
39     private NotificationPanelViewController.TouchHandler mTouchHandler;
40     private OnConfigurationChangedListener mOnConfigurationChangedListener;
41 
NotificationPanelView(Context context, AttributeSet attrs)42     public NotificationPanelView(Context context, AttributeSet attrs) {
43         super(context, attrs);
44         setWillNotDraw(!DEBUG);
45         mAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
46 
47         setBackgroundColor(Color.TRANSPARENT);
48     }
49 
50     @Override
onRtlPropertiesChanged(int layoutDirection)51     public void onRtlPropertiesChanged(int layoutDirection) {
52         if (mRtlChangeListener != null) {
53             mRtlChangeListener.onRtlPropertielsChanged(layoutDirection);
54         }
55     }
56 
57     @Override
shouldDelayChildPressedState()58     public boolean shouldDelayChildPressedState() {
59         return true;
60     }
61 
62     @Override
dispatchDraw(Canvas canvas)63     protected void dispatchDraw(Canvas canvas) {
64         super.dispatchDraw(canvas);
65         if (mCurrentPanelAlpha != 255) {
66             canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mAlphaPaint);
67         }
68     }
69 
getCurrentPanelAlpha()70     float getCurrentPanelAlpha() {
71         return mCurrentPanelAlpha;
72     }
73 
setPanelAlphaInternal(float alpha)74     void setPanelAlphaInternal(float alpha) {
75         mCurrentPanelAlpha = (int) alpha;
76         mAlphaPaint.setARGB(mCurrentPanelAlpha, 255, 255, 255);
77         invalidate();
78     }
79 
setDozing(boolean dozing)80     public void setDozing(boolean dozing) {
81         mDozing = dozing;
82     }
83 
84     @Override
hasOverlappingRendering()85     public boolean hasOverlappingRendering() {
86         return !mDozing;
87     }
88 
setRtlChangeListener(RtlChangeListener listener)89     void setRtlChangeListener(RtlChangeListener listener) {
90         mRtlChangeListener = listener;
91     }
92 
93     /** Sets the touch handler for this view. */
setOnTouchListener(NotificationPanelViewController.TouchHandler touchHandler)94     public void setOnTouchListener(NotificationPanelViewController.TouchHandler touchHandler) {
95         super.setOnTouchListener(touchHandler);
96         mTouchHandler = touchHandler;
97     }
98 
setOnConfigurationChangedListener(OnConfigurationChangedListener listener)99     void setOnConfigurationChangedListener(OnConfigurationChangedListener listener) {
100         mOnConfigurationChangedListener = listener;
101     }
102 
103     @Override
onInterceptTouchEvent(MotionEvent event)104     public boolean onInterceptTouchEvent(MotionEvent event) {
105         return mTouchHandler.onInterceptTouchEvent(event);
106     }
107 
108     @Override
dispatchTouchEvent(MotionEvent ev)109     public boolean dispatchTouchEvent(MotionEvent ev) {
110         return TouchLogger.logDispatchTouch("NPV", ev, super.dispatchTouchEvent(ev));
111     }
112 
113     @Override
dispatchConfigurationChanged(Configuration newConfig)114     public void dispatchConfigurationChanged(Configuration newConfig) {
115         super.dispatchConfigurationChanged(newConfig);
116         mOnConfigurationChangedListener.onConfigurationChanged(newConfig);
117     }
118 
119     /** Callback for right-to-left setting changes. */
120     interface RtlChangeListener {
121         /** Called when right-to-left setting changes. */
onRtlPropertielsChanged(int layoutDirection)122         void onRtlPropertielsChanged(int layoutDirection);
123     }
124 
125     /** Callback for config changes. */
126     interface OnConfigurationChangedListener {
127         /** Called when configuration changes. */
onConfigurationChanged(Configuration newConfig)128         void onConfigurationChanged(Configuration newConfig);
129     }
130 }
131