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