StatusBarWindowView.java revision a4b70aff3419b61d2395589b393251da9ddcba3f
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 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 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems); 58 mScrollView = (ScrollView) findViewById(R.id.scroll); 59 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); 60 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height); 61 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height); 62 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight); 63 mExpandHelper.setEventSource(this); 64 mExpandHelper.setScrollView(mScrollView); 65 66 // We really need to be able to animate while window animations are going on 67 // so that activities may be started asynchronously from panel animations 68 final ViewRootImpl root = getViewRootImpl(); 69 if (root != null) { 70 root.setDrawDuringWindowsAnimating(true); 71 } 72 } 73 74 @Override 75 public boolean dispatchKeyEvent(KeyEvent event) { 76 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 77 switch (event.getKeyCode()) { 78 case KeyEvent.KEYCODE_BACK: 79 if (!down) { 80 mService.animateCollapsePanels(); 81 } 82 return true; 83 } 84 return super.dispatchKeyEvent(event); 85 } 86 87 @Override 88 public boolean onInterceptTouchEvent(MotionEvent ev) { 89 boolean intercept = false; 90 if (mNotificationPanel.isFullyExpanded() && mScrollView.getVisibility() == View.VISIBLE) { 91 intercept = mExpandHelper.onInterceptTouchEvent(ev); 92 } 93 if (!intercept) { 94 super.onInterceptTouchEvent(ev); 95 } 96 if (intercept) { 97 MotionEvent cancellation = MotionEvent.obtain(ev); 98 cancellation.setAction(MotionEvent.ACTION_CANCEL); 99 latestItems.onInterceptTouchEvent(cancellation); 100 cancellation.recycle(); 101 } 102 return intercept; 103 } 104 105 @Override 106 public boolean onTouchEvent(MotionEvent ev) { 107 boolean handled = false; 108 if (mNotificationPanel.isFullyExpanded()) { 109 handled = mExpandHelper.onTouchEvent(ev); 110 } 111 if (!handled) { 112 handled = super.onTouchEvent(ev); 113 } 114 return handled; 115 } 116 117 @Override 118 public void onDraw(Canvas canvas) { 119 super.onDraw(canvas); 120 if (DEBUG) { 121 Paint pt = new Paint(); 122 pt.setColor(0x80FFFF00); 123 pt.setStrokeWidth(12.0f); 124 pt.setStyle(Paint.Style.STROKE); 125 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); 126 } 127 } 128 129 public void cancelExpandHelper() { 130 if (mExpandHelper != null) { 131 mExpandHelper.cancel(); 132 } 133 } 134} 135 136