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