StatusBarWindowView.java revision 4222d9a7fb87d73e1443ec1a2de9782b05741af6
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, insets.bottom); 60 } else { 61 setPadding(0, 0, 0, 0); 62 } 63 return true; 64 } 65 66 @Override 67 protected void onAttachedToWindow () { 68 super.onAttachedToWindow(); 69 70 mStackScrollLayout = (NotificationStackScrollLayout) findViewById( 71 R.id.notification_stack_scroller); 72 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); 73 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height); 74 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_max_height); 75 mExpandHelper = new ExpandHelper(getContext(), mStackScrollLayout, 76 minHeight, maxHeight); 77 mExpandHelper.setEventSource(this); 78 mExpandHelper.setScrollAdapter(mStackScrollLayout); 79 mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); 80 81 // We really need to be able to animate while window animations are going on 82 // so that activities may be started asynchronously from panel animations 83 final ViewRootImpl root = getViewRootImpl(); 84 if (root != null) { 85 root.setDrawDuringWindowsAnimating(true); 86 } 87 } 88 89 @Override 90 public boolean dispatchKeyEvent(KeyEvent event) { 91 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 92 switch (event.getKeyCode()) { 93 case KeyEvent.KEYCODE_BACK: 94 if (!down) { 95 mService.onBackPressed(); 96 } 97 return true; 98 case KeyEvent.KEYCODE_MENU: 99 if (!down) { 100 return mService.onMenuPressed(); 101 } 102 } 103 return super.dispatchKeyEvent(event); 104 } 105 106 @Override 107 public boolean onInterceptTouchEvent(MotionEvent ev) { 108 boolean intercept = false; 109 if (mNotificationPanel.isFullyExpanded() 110 && mStackScrollLayout.getVisibility() == View.VISIBLE 111 && mService.getBarState() != StatusBarState.KEYGUARD) { 112 intercept = mExpandHelper.onInterceptTouchEvent(ev); 113 } else if (mNotificationPanel.isFullyExpanded() 114 && mStackScrollLayout.getVisibility() == View.VISIBLE 115 && mService.getBarState() == StatusBarState.KEYGUARD 116 && !mService.isBouncerShowing()) { 117 intercept = mDragDownHelper.onInterceptTouchEvent(ev); 118 } 119 if (!intercept) { 120 super.onInterceptTouchEvent(ev); 121 } 122 if (intercept) { 123 MotionEvent cancellation = MotionEvent.obtain(ev); 124 cancellation.setAction(MotionEvent.ACTION_CANCEL); 125 mStackScrollLayout.onInterceptTouchEvent(cancellation); 126 cancellation.recycle(); 127 } 128 return intercept; 129 } 130 131 @Override 132 public boolean onTouchEvent(MotionEvent ev) { 133 boolean handled = false; 134 if (mNotificationPanel.isFullyExpanded() 135 && mService.getBarState() != StatusBarState.KEYGUARD) { 136 handled = mExpandHelper.onTouchEvent(ev); 137 } else if (mService.getBarState() == StatusBarState.KEYGUARD) { 138 handled = mDragDownHelper.onTouchEvent(ev); 139 } 140 if (!handled) { 141 handled = super.onTouchEvent(ev); 142 } 143 final int action = ev.getAction(); 144 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { 145 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); 146 } 147 return handled; 148 } 149 150 @Override 151 public void onDraw(Canvas canvas) { 152 super.onDraw(canvas); 153 if (DEBUG) { 154 Paint pt = new Paint(); 155 pt.setColor(0x80FFFF00); 156 pt.setStrokeWidth(12.0f); 157 pt.setStyle(Paint.Style.STROKE); 158 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); 159 } 160 } 161 162 public void cancelExpandHelper() { 163 if (mExpandHelper != null) { 164 mExpandHelper.cancel(); 165 } 166 } 167} 168 169