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