StatusBarWindowView.java revision b4e56edde684c2a09cb225c99571fddb39b43b34
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.util.AttributeSet; 21import android.util.Log; 22import android.view.KeyEvent; 23import android.view.MotionEvent; 24import android.view.View; 25import android.widget.FrameLayout; 26import android.widget.ScrollView; 27import android.widget.TextSwitcher; 28 29import com.android.systemui.ExpandHelper; 30import com.android.systemui.R; 31import com.android.systemui.statusbar.policy.NotificationRowLayout; 32 33 34public class StatusBarWindowView extends FrameLayout 35{ 36 private static final String TAG = "StatusBarWindowView"; 37 38 private ExpandHelper mExpandHelper; 39 private NotificationRowLayout latestItems; 40 private NotificationPanelView mNotificationPanel; 41 42 PhoneStatusBar mService; 43 44 public StatusBarWindowView(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 setMotionEventSplittingEnabled(false); 47 } 48 49 @Override 50 protected void onAttachedToWindow () { 51 super.onAttachedToWindow(); 52 latestItems = (NotificationRowLayout) findViewById(R.id.latestItems); 53 ScrollView scroller = (ScrollView) findViewById(R.id.scroll); 54 mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); 55 int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height); 56 int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height); 57 mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight); 58 mExpandHelper.setEventSource(this); 59 mExpandHelper.setScrollView(scroller); 60 } 61 62 @Override 63 public boolean dispatchKeyEvent(KeyEvent event) { 64 boolean down = event.getAction() == KeyEvent.ACTION_DOWN; 65 switch (event.getKeyCode()) { 66 case KeyEvent.KEYCODE_BACK: 67 if (!down) { 68 mService.animateCollapse(); 69 } 70 return true; 71 } 72 return super.dispatchKeyEvent(event); 73 } 74 75 @Override 76 public boolean onInterceptTouchEvent(MotionEvent ev) { 77 boolean intercept = false; 78 if (mNotificationPanel.isFullyExpanded()) { 79 intercept = mExpandHelper.onInterceptTouchEvent(ev); 80 } 81 if (!intercept) { 82 super.onInterceptTouchEvent(ev); 83 } 84 if (intercept) { 85 MotionEvent cancellation = MotionEvent.obtain(ev); 86 cancellation.setAction(MotionEvent.ACTION_CANCEL); 87 latestItems.onInterceptTouchEvent(cancellation); 88 cancellation.recycle(); 89 } 90 return intercept; 91 } 92 93 @Override 94 public boolean onTouchEvent(MotionEvent ev) { 95 boolean handled = false; 96 if (mNotificationPanel.isFullyExpanded()) { 97 handled = mExpandHelper.onTouchEvent(ev); 98 } 99 if (!handled) { 100 handled = super.onTouchEvent(ev); 101 } 102 return handled; 103 } 104} 105 106