StatusBarWindowView.java revision b6d85ebfe4f9f5d3b7d7ab7b6123af02a0deb516
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.animateCollapsePanels(); 83 } 84 return true; 85 } 86 return super.dispatchKeyEvent(event); 87 } 88 89 @Override 90 public boolean onInterceptTouchEvent(MotionEvent ev) { 91 boolean intercept = false; 92 if (mNotificationPanel.isFullyExpanded() 93 && mStackScrollLayout.getVisibility() == View.VISIBLE) { 94 intercept = mExpandHelper.onInterceptTouchEvent(ev); 95 } 96 if (!intercept) { 97 super.onInterceptTouchEvent(ev); 98 } 99 if (intercept) { 100 MotionEvent cancellation = MotionEvent.obtain(ev); 101 cancellation.setAction(MotionEvent.ACTION_CANCEL); 102 mStackScrollLayout.onInterceptTouchEvent(cancellation); 103 cancellation.recycle(); 104 } 105 return intercept; 106 } 107 108 @Override 109 public boolean onTouchEvent(MotionEvent ev) { 110 boolean handled = false; 111 if (mNotificationPanel.isFullyExpanded()) { 112 handled = mExpandHelper.onTouchEvent(ev); 113 } 114 if (!handled) { 115 handled = super.onTouchEvent(ev); 116 } 117 final int action = ev.getAction(); 118 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { 119 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); 120 } 121 return handled; 122 } 123 124 @Override 125 public void onDraw(Canvas canvas) { 126 super.onDraw(canvas); 127 if (DEBUG) { 128 Paint pt = new Paint(); 129 pt.setColor(0x80FFFF00); 130 pt.setStrokeWidth(12.0f); 131 pt.setStyle(Paint.Style.STROKE); 132 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); 133 } 134 } 135 136 public void cancelExpandHelper() { 137 if (mExpandHelper != null) { 138 mExpandHelper.cancel(); 139 } 140 } 141} 142 143