1 /*
2  * Copyright (C) 2008 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.phone;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.util.AttributeSet;
22 import android.util.EventLog;
23 import android.view.MotionEvent;
24 import android.view.View;
25 import android.view.accessibility.AccessibilityEvent;
26 
27 import com.android.systemui.EventLogTags;
28 import com.android.systemui.R;
29 
30 public class PhoneStatusBarView extends PanelBar {
31     private static final String TAG = "PhoneStatusBarView";
32     private static final boolean DEBUG = PhoneStatusBar.DEBUG;
33     private static final boolean DEBUG_GESTURES = false;
34 
35     PhoneStatusBar mBar;
36 
37     PanelView mLastFullyOpenedPanel = null;
38     PanelView mNotificationPanel;
39     private final PhoneStatusBarTransitions mBarTransitions;
40     private ScrimController mScrimController;
41 
PhoneStatusBarView(Context context, AttributeSet attrs)42     public PhoneStatusBarView(Context context, AttributeSet attrs) {
43         super(context, attrs);
44 
45         Resources res = getContext().getResources();
46         mBarTransitions = new PhoneStatusBarTransitions(this);
47     }
48 
getBarTransitions()49     public BarTransitions getBarTransitions() {
50         return mBarTransitions;
51     }
52 
setBar(PhoneStatusBar bar)53     public void setBar(PhoneStatusBar bar) {
54         mBar = bar;
55     }
56 
setScrimController(ScrimController scrimController)57     public void setScrimController(ScrimController scrimController) {
58         mScrimController = scrimController;
59     }
60 
61     @Override
onFinishInflate()62     public void onFinishInflate() {
63         mBarTransitions.init();
64     }
65 
66     @Override
addPanel(PanelView pv)67     public void addPanel(PanelView pv) {
68         super.addPanel(pv);
69         if (pv.getId() == R.id.notification_panel) {
70             mNotificationPanel = pv;
71         }
72     }
73 
74     @Override
panelsEnabled()75     public boolean panelsEnabled() {
76         return mBar.panelsEnabled();
77     }
78 
79     @Override
onRequestSendAccessibilityEvent(View child, AccessibilityEvent event)80     public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
81         if (super.onRequestSendAccessibilityEvent(child, event)) {
82             // The status bar is very small so augment the view that the user is touching
83             // with the content of the status bar a whole. This way an accessibility service
84             // may announce the current item as well as the entire content if appropriate.
85             AccessibilityEvent record = AccessibilityEvent.obtain();
86             onInitializeAccessibilityEvent(record);
87             dispatchPopulateAccessibilityEvent(record);
88             event.appendRecord(record);
89             return true;
90         }
91         return false;
92     }
93 
94     @Override
selectPanelForTouch(MotionEvent touch)95     public PanelView selectPanelForTouch(MotionEvent touch) {
96         // No double swiping. If either panel is open, nothing else can be pulled down.
97         return mNotificationPanel.getExpandedHeight() > 0
98                 ? null
99                 : mNotificationPanel;
100     }
101 
102     @Override
onPanelPeeked()103     public void onPanelPeeked() {
104         super.onPanelPeeked();
105         mBar.makeExpandedVisible(false);
106     }
107 
108     @Override
onAllPanelsCollapsed()109     public void onAllPanelsCollapsed() {
110         super.onAllPanelsCollapsed();
111 
112         // Close the status bar in the next frame so we can show the end of the animation.
113         postOnAnimation(new Runnable() {
114             @Override
115             public void run() {
116                 mBar.makeExpandedInvisible();
117             }
118         });
119         mLastFullyOpenedPanel = null;
120     }
121 
122     @Override
onPanelFullyOpened(PanelView openPanel)123     public void onPanelFullyOpened(PanelView openPanel) {
124         super.onPanelFullyOpened(openPanel);
125         if (openPanel != mLastFullyOpenedPanel) {
126             openPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
127         }
128         mLastFullyOpenedPanel = openPanel;
129     }
130 
131     @Override
onTouchEvent(MotionEvent event)132     public boolean onTouchEvent(MotionEvent event) {
133         boolean barConsumedEvent = mBar.interceptTouchEvent(event);
134 
135         if (DEBUG_GESTURES) {
136             if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
137                 EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
138                         event.getActionMasked(), (int) event.getX(), (int) event.getY(),
139                         barConsumedEvent ? 1 : 0);
140             }
141         }
142 
143         return barConsumedEvent || super.onTouchEvent(event);
144     }
145 
146     @Override
onTrackingStarted(PanelView panel)147     public void onTrackingStarted(PanelView panel) {
148         super.onTrackingStarted(panel);
149         mBar.onTrackingStarted();
150         mScrimController.onTrackingStarted();
151     }
152 
153     @Override
onClosingFinished()154     public void onClosingFinished() {
155         super.onClosingFinished();
156         mBar.onClosingFinished();
157     }
158 
159     @Override
onTrackingStopped(PanelView panel, boolean expand)160     public void onTrackingStopped(PanelView panel, boolean expand) {
161         super.onTrackingStopped(panel, expand);
162         mBar.onTrackingStopped(expand);
163     }
164 
165     @Override
onExpandingFinished()166     public void onExpandingFinished() {
167         super.onExpandingFinished();
168         mScrimController.onExpandingFinished();
169     }
170 
171     @Override
onInterceptTouchEvent(MotionEvent event)172     public boolean onInterceptTouchEvent(MotionEvent event) {
173         return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event);
174     }
175 
176     @Override
panelExpansionChanged(PanelView panel, float frac, boolean expanded)177     public void panelExpansionChanged(PanelView panel, float frac, boolean expanded) {
178         super.panelExpansionChanged(panel, frac, expanded);
179         mScrimController.setPanelExpansion(frac);
180         mBar.updateCarrierLabelVisibility(false);
181     }
182 }
183