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