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