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