PhoneStatusBarView.java revision 1e8feef1faca7d2f14bf459691dbe724c8cf5c88
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 PanelView mFadingPanel = null; 47 PanelView mNotificationPanel, mSettingsPanel; 48 49 public PhoneStatusBarView(Context context, AttributeSet attrs) { 50 super(context, attrs); 51 } 52 53 public void setBar(PhoneStatusBar bar) { 54 mBar = bar; 55 } 56 57 @Override 58 public void onAttachedToWindow() { 59 Resources res = getContext().getResources(); 60 mScrimColor = res.getColor(R.color.notification_panel_scrim_color); 61 } 62 63 @Override 64 public void addPanel(PanelView pv) { 65 super.addPanel(pv); 66 if (pv.getId() == R.id.notification_panel) { 67 mNotificationPanel = pv; 68 } else if (pv.getId() == R.id.settings_panel){ 69 mSettingsPanel = pv; 70 } 71 } 72 73 @Override 74 public boolean isEnabled() { 75 return ((mBar.mDisabled & StatusBarManager.DISABLE_EXPAND) == 0); 76 } 77 78 @Override 79 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { 80 if (super.onRequestSendAccessibilityEvent(child, event)) { 81 // The status bar is very small so augment the view that the user is touching 82 // with the content of the status bar a whole. This way an accessibility service 83 // may announce the current item as well as the entire content if appropriate. 84 AccessibilityEvent record = AccessibilityEvent.obtain(); 85 onInitializeAccessibilityEvent(record); 86 dispatchPopulateAccessibilityEvent(record); 87 event.appendRecord(record); 88 return true; 89 } 90 return false; 91 } 92 93 @Override 94 public PanelView selectPanelForTouchX(float x) { 95 // We split the status bar into thirds: the left 2/3 are for notifications, and the 96 // right 1/3 for quick settings. If you pull the status bar down a second time you'll 97 // toggle panels no matter where you pull it down. 98 final float w = (float) getMeasuredWidth(); 99 final float f = x / w; 100 if (f > 0.67f && mSettingsPanel.getExpandedFraction() != 1.0f 101 || mNotificationPanel.getExpandedFraction() == 1.0f) { 102 return mSettingsPanel; 103 } 104 return mNotificationPanel; 105 } 106 107 @Override 108 public void onPanelPeeked() { 109 super.onPanelPeeked(); 110 mBar.makeExpandedVisible(true); 111 if (mFadingPanel == null) { 112 mFadingPanel = mTouchingPanel; 113 } 114 } 115 116 @Override 117 public void onAllPanelsCollapsed() { 118 super.onAllPanelsCollapsed(); 119 mBar.makeExpandedInvisible(); 120 mFadingPanel = null; 121 } 122 123 @Override 124 public void onPanelFullyOpened(PanelView openPanel) { 125 mFadingPanel = openPanel; 126 } 127 128 @Override 129 public boolean onTouchEvent(MotionEvent event) { 130 return mBar.interceptTouchEvent(event) || super.onTouchEvent(event); 131 } 132 133 @Override 134 public boolean onInterceptTouchEvent(MotionEvent event) { 135 return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event); 136 } 137 138 @Override 139 public void panelExpansionChanged(PanelView pv, float frac) { 140 super.panelExpansionChanged(pv, frac); 141 142 if (mFadingPanel == pv 143 && mScrimColor != 0 && ActivityManager.isHighEndGfx(mBar.mDisplay)) { 144 // woo, special effects 145 final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2.2f)))); 146 // attenuate background color alpha by k 147 final int color = (int) ((float)(mScrimColor >>> 24) * k) << 24 | (mScrimColor & 0xFFFFFF); 148 mBar.mStatusBarWindow.setBackgroundColor(color); 149 } 150 151 mBar.updateCarrierLabelVisibility(false); 152 } 153 154 155} 156