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