StatusBarWindowView.java revision 198a0306e5b0ef6b02d61e299a4b4ab4c1c2cdc8
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.util.Log; 24import android.view.KeyEvent; 25import android.view.MotionEvent; 26import android.view.View; 27import android.widget.FrameLayout; 28import android.widget.ScrollView; 29import android.widget.TextSwitcher; 30 31import com.android.systemui.ExpandHelper; 32import com.android.systemui.R; 33import com.android.systemui.statusbar.BaseStatusBar; 34import com.android.systemui.statusbar.policy.NotificationRowLayout; 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 NotificationRowLayout latestItems; 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 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems); 58 ScrollView scroller = (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(scroller); 65 } 66 67 @Override 68 public boolean dispatchKeyEvent(KeyEvent event) { 69 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 70 switch (event.getKeyCode()) { 71 case KeyEvent.KEYCODE_BACK: 72 if (!down) { 73 mService.animateCollapse(); 74 } 75 return true; 76 } 77 return super.dispatchKeyEvent(event); 78 } 79 80 @Override 81 public boolean onInterceptTouchEvent(MotionEvent ev) { 82 boolean intercept = false; 83 if (mNotificationPanel.isFullyExpanded()) { 84 intercept = mExpandHelper.onInterceptTouchEvent(ev); 85 } 86 if (!intercept) { 87 super.onInterceptTouchEvent(ev); 88 } 89 if (intercept) { 90 MotionEvent cancellation = MotionEvent.obtain(ev); 91 cancellation.setAction(MotionEvent.ACTION_CANCEL); 92 latestItems.onInterceptTouchEvent(cancellation); 93 cancellation.recycle(); 94 } 95 return intercept; 96 } 97 98 @Override 99 public boolean onTouchEvent(MotionEvent ev) { 100 boolean handled = false; 101 if (mNotificationPanel.isFullyExpanded()) { 102 handled = mExpandHelper.onTouchEvent(ev); 103 } 104 if (!handled) { 105 handled = super.onTouchEvent(ev); 106 } 107 return handled; 108 } 109 110 @Override 111 public void onDraw(Canvas canvas) { 112 super.onDraw(canvas); 113 if (DEBUG) { 114 Paint pt = new Paint(); 115 pt.setColor(0x80FFFF00); 116 pt.setStrokeWidth(12.0f); 117 pt.setStyle(Paint.Style.STROKE); 118 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); 119 } 120 } 121} 122 123