PhoneStatusBarView.java revision b8ea2f59e2727020ac211d5b6f6d421314546439
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.app.StatusBarManager; 21import android.content.Context; 22import android.content.res.Configuration; 23import android.content.res.Resources; 24import android.graphics.Canvas; 25import android.graphics.Color; 26import android.graphics.Rect; 27import android.os.SystemClock; 28import android.util.AttributeSet; 29import android.util.Log; 30import android.view.KeyEvent; 31import android.view.MotionEvent; 32import android.view.View; 33import android.view.ViewGroup; 34import android.view.ViewParent; 35import android.view.accessibility.AccessibilityEvent; 36import android.widget.FrameLayout; 37 38import com.android.systemui.R; 39import com.android.systemui.statusbar.BaseStatusBar; 40import com.android.systemui.statusbar.policy.FixedSizeDrawable; 41 42public class PhoneStatusBarView extends PanelBar { 43 private static final String TAG = "PhoneStatusBarView"; 44 PhoneStatusBar mBar; 45 int mScrimColor; 46 float mMinFlingGutter; 47 float mNotificationWidth; 48 boolean mFullWidthNotifications; 49 PanelView mFadingPanel = null; 50 PanelView mNotificationPanel, mSettingsPanel; 51 52 public PhoneStatusBarView(Context context, AttributeSet attrs) { 53 super(context, attrs); 54 } 55 56 public void setBar(PhoneStatusBar bar) { 57 mBar = bar; 58 } 59 60 @Override 61 public void onAttachedToWindow() { 62 Resources res = getContext().getResources(); 63 mScrimColor = res.getColor(R.color.notification_panel_scrim_color); 64 mMinFlingGutter = res.getDimension(R.dimen.settings_panel_fling_gutter); 65 mFullWidthNotifications = false; 66 try { 67 mNotificationWidth = res.getDimension(R.dimen.notification_panel_width); 68 } catch (Resources.NotFoundException ex) { 69 mFullWidthNotifications = true; 70 } 71 } 72 73 @Override 74 public void addPanel(PanelView pv) { 75 super.addPanel(pv); 76 if (pv.getId() == R.id.notification_panel) { 77 mNotificationPanel = pv; 78 } else if (pv.getId() == R.id.settings_panel){ 79 mSettingsPanel = pv; 80 } 81 } 82 83 @Override 84 public boolean panelsEnabled() { 85 return ((mBar.mDisabled & StatusBarManager.DISABLE_EXPAND) == 0); 86 } 87 88 @Override 89 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { 90 if (super.onRequestSendAccessibilityEvent(child, event)) { 91 // The status bar is very small so augment the view that the user is touching 92 // with the content of the status bar a whole. This way an accessibility service 93 // may announce the current item as well as the entire content if appropriate. 94 AccessibilityEvent record = AccessibilityEvent.obtain(); 95 onInitializeAccessibilityEvent(record); 96 dispatchPopulateAccessibilityEvent(record); 97 event.appendRecord(record); 98 return true; 99 } 100 return false; 101 } 102 103 @Override 104 public PanelView selectPanelForTouchX(float x) { 105 // We split the status bar into thirds: the left 2/3 are for notifications, and the 106 // right 1/3 for quick settings. If you pull the status bar down a second time you'll 107 // toggle panels no matter where you pull it down. 108 final float w = (float) getMeasuredWidth(); 109 final float gutter = w - mNotificationWidth; 110 final boolean useGutter = !mFullWidthNotifications && gutter > mMinFlingGutter; 111 final float threshold = 1.0f - (gutter / w); 112 final float f = x / w; 113 if ((useGutter && f > threshold && mSettingsPanel.getExpandedFraction() != 1.0f) || 114 mNotificationPanel.getExpandedFraction() == 1.0f) { 115 return mSettingsPanel; 116 } 117 return mNotificationPanel; 118 } 119 120 @Override 121 public void onPanelPeeked() { 122 super.onPanelPeeked(); 123 mBar.makeExpandedVisible(true); 124 if (mFadingPanel == null) { 125 mFadingPanel = mTouchingPanel; 126 } 127 } 128 129 @Override 130 public void onAllPanelsCollapsed() { 131 super.onAllPanelsCollapsed(); 132 mBar.makeExpandedInvisible(); 133 mFadingPanel = null; 134 } 135 136 @Override 137 public void onPanelFullyOpened(PanelView openPanel) { 138 mFadingPanel = openPanel; 139 } 140 141 @Override 142 public boolean onTouchEvent(MotionEvent event) { 143 return mBar.interceptTouchEvent(event) || super.onTouchEvent(event); 144 } 145 146 @Override 147 public boolean onInterceptTouchEvent(MotionEvent event) { 148 return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event); 149 } 150 151 @Override 152 public void panelExpansionChanged(PanelView pv, float frac) { 153 super.panelExpansionChanged(pv, frac); 154 155 if (mFadingPanel == pv 156 && mScrimColor != 0 && ActivityManager.isHighEndGfx()) { 157 // woo, special effects 158 final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2.2f)))); 159 // attenuate background color alpha by k 160 final int color = (int) ((float)(mScrimColor >>> 24) * k) << 24 | (mScrimColor & 0xFFFFFF); 161 mBar.mStatusBarWindow.setBackgroundColor(color); 162 } 163 164 mBar.updateCarrierLabelVisibility(false); 165 } 166 167 168} 169