StatusBarWindowView.java revision df993513fbfe0e952175c1c5384458deaa1ff01a
1/* 2 * Copyright (C) 2012 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.StatusBarManager; 20import android.content.Context; 21import android.graphics.Canvas; 22import android.graphics.Paint; 23import android.graphics.Rect; 24import android.util.AttributeSet; 25import android.view.KeyEvent; 26import android.view.MotionEvent; 27import android.view.View; 28import android.view.ViewRootImpl; 29import android.widget.FrameLayout; 30 31import com.android.systemui.ExpandHelper; 32import com.android.systemui.R; 33import com.android.systemui.statusbar.BaseStatusBar; 34import com.android.systemui.statusbar.DragDownHelper; 35import com.android.systemui.statusbar.StatusBarState; 36import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; 37 38 39public class StatusBarWindowView extends FrameLayout { 40 public static final String TAG = "StatusBarWindowView"; 41 public static final boolean DEBUG = BaseStatusBar.DEBUG; 42 43 private ExpandHelper mExpandHelper; 44 private DragDownHelper mDragDownHelper; 45 private NotificationStackScrollLayout mStackScrollLayout; 46 private NotificationPanelView mNotificationPanel; 47 48 PhoneStatusBar mService; 49 50 public StatusBarWindowView(Context context, AttributeSet attrs) { 51 super(context, attrs); 52 setMotionEventSplittingEnabled(false); 53 setWillNotDraw(!DEBUG); 54 } 55 56 @Override 57 protected boolean fitSystemWindows(Rect insets) { 58 if (getFitsSystemWindows()) { 59 setPadding(insets.left, insets.top, insets.right, 0); 60 insets.left = 0; 61 insets.top = 0; 62 insets.right = 0; 63 } else { 64 setPadding(0, 0, 0, 0); 65 } 66 return false; 67 } 68 69 @Override 70 protected void onAttachedToWindow () { 71 super.onAttachedToWindow(); 72 73 mStackScrollLayout = (NotificationStackScrollLayout) findViewById( 74 R.id.notification_stack_scroller); 75 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); 76 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height); 77 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height); 78 mExpandHelper = new ExpandHelper(getContext(), mStackScrollLayout, 79 minHeight, maxHeight); 80 mExpandHelper.setEventSource(this); 81 mExpandHelper.setScrollAdapter(mStackScrollLayout); 82 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); 83 84 // We really need to be able to animate while window animations are going on 85 // so that activities may be started asynchronously from panel animations 86 final ViewRootImpl root = getViewRootImpl(); 87 if (root != null) { 88 root.setDrawDuringWindowsAnimating(true); 89 } 90 } 91 92 @Override 93 public boolean dispatchKeyEvent(KeyEvent event) { 94 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 95 switch (event.getKeyCode()) { 96 case KeyEvent.KEYCODE_BACK: 97 if (!down) { 98 mService.onBackPressed(); 99 } 100 return true; 101 case KeyEvent.KEYCODE_MENU: 102 if (!down) { 103 return mService.onMenuPressed(); 104 } 105 } 106 if (mService.interceptMediaKey(event)) { 107 return true; 108 } 109 return super.dispatchKeyEvent(event); 110 } 111 112 @Override 113 public boolean onInterceptTouchEvent(MotionEvent ev) { 114 boolean intercept = false; 115 if (mNotificationPanel.isFullyExpanded() 116 && mStackScrollLayout.getVisibility() == View.VISIBLE 117 && (mService.getBarState() == StatusBarState.SHADE 118 || (mService.getBarState() == StatusBarState.SHADE_LOCKED 119 && !mService.isBouncerShowing()))) { 120 intercept = mExpandHelper.onInterceptTouchEvent(ev); 121 } else if (mNotificationPanel.isFullyExpanded() 122 && mStackScrollLayout.getVisibility() == View.VISIBLE 123 && mService.getBarState() == StatusBarState.KEYGUARD 124 && !mService.isBouncerShowing()) { 125 intercept = mDragDownHelper.onInterceptTouchEvent(ev); 126 } 127 if (!intercept) { 128 super.onInterceptTouchEvent(ev); 129 } 130 if (intercept) { 131 MotionEvent cancellation = MotionEvent.obtain(ev); 132 cancellation.setAction(MotionEvent.ACTION_CANCEL); 133 mStackScrollLayout.onInterceptTouchEvent(cancellation); 134 cancellation.recycle(); 135 } 136 return intercept; 137 } 138 139 @Override 140 public boolean onTouchEvent(MotionEvent ev) { 141 boolean handled = false; 142 if (mNotificationPanel.isFullyExpanded() 143 && mService.getBarState() != StatusBarState.KEYGUARD) { 144 handled = mExpandHelper.onTouchEvent(ev); 145 } else if (mService.getBarState() == StatusBarState.KEYGUARD) { 146 handled = mDragDownHelper.onTouchEvent(ev); 147 } 148 if (!handled) { 149 handled = super.onTouchEvent(ev); 150 } 151 final int action = ev.getAction(); 152 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { 153 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); 154 } 155 return handled; 156 } 157 158 @Override 159 public void onDraw(Canvas canvas) { 160 super.onDraw(canvas); 161 if (DEBUG) { 162 Paint pt = new Paint(); 163 pt.setColor(0x80FFFF00); 164 pt.setStrokeWidth(12.0f); 165 pt.setStyle(Paint.Style.STROKE); 166 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); 167 } 168 } 169 170 public void cancelExpandHelper() { 171 if (mExpandHelper != null) { 172 mExpandHelper.cancel(); 173 } 174 } 175} 176 177