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 17 package com.android.systemui.statusbar.phone; 18 19 import android.content.Context; 20 import android.graphics.Canvas; 21 import android.graphics.Paint; 22 import android.util.AttributeSet; 23 import android.util.Log; 24 import android.view.KeyEvent; 25 import android.view.MotionEvent; 26 import android.view.View; 27 import android.view.ViewRootImpl; 28 import android.widget.FrameLayout; 29 import android.widget.ScrollView; 30 import android.widget.TextSwitcher; 31 32 import com.android.systemui.ExpandHelper; 33 import com.android.systemui.R; 34 import com.android.systemui.statusbar.BaseStatusBar; 35 import com.android.systemui.statusbar.policy.NotificationRowLayout; 36 37 38 public class StatusBarWindowView extends FrameLayout 39 { 40 public static final String TAG = "StatusBarWindowView"; 41 public static final boolean DEBUG = BaseStatusBar.DEBUG; 42 43 private ExpandHelper mExpandHelper; 44 private NotificationRowLayout latestItems; 45 private NotificationPanelView mNotificationPanel; 46 private ScrollView mScrollView; 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 void onAttachedToWindow () { 58 super.onAttachedToWindow(); 59 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems); 60 mScrollView = (ScrollView) findViewById(R.id.scroll); 61 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); 62 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height); 63 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height); 64 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight); 65 mExpandHelper.setEventSource(this); 66 mExpandHelper.setScrollView(mScrollView); 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() && 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 138