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