Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -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; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 21 | import android.view.MotionEvent; |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 22 | import android.view.View; |
Casey Burkhardt | 23b0a4e | 2013-04-29 12:18:32 -0700 | [diff] [blame] | 23 | import android.view.accessibility.AccessibilityEvent; |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 24 | |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 25 | import com.android.systemui.R; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 26 | import com.android.systemui.statusbar.ExpandableView; |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 27 | import com.android.systemui.statusbar.GestureRecorder; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 28 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 29 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 30 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 31 | public class NotificationPanelView extends PanelView implements |
| 32 | ExpandableView.OnHeightChangedListener { |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 33 | public static final boolean DEBUG_GESTURES = true; |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 34 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 35 | PhoneStatusBar mStatusBar; |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 36 | private View mHeader; |
| 37 | private View mKeyguardStatusView; |
| 38 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 39 | private NotificationStackScrollLayout mNotificationStackScroller; |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 40 | private boolean mTrackingSettings; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 41 | private int mNotificationTopPadding; |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 42 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 43 | public NotificationPanelView(Context context, AttributeSet attrs) { |
| 44 | super(context, attrs); |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 45 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 46 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 47 | public void setStatusBar(PhoneStatusBar bar) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 48 | if (mStatusBar != null) { |
| 49 | mStatusBar.setOnFlipRunnable(null); |
| 50 | } |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 51 | mStatusBar = bar; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 52 | if (bar != null) { |
| 53 | mStatusBar.setOnFlipRunnable(new Runnable() { |
| 54 | @Override |
| 55 | public void run() { |
| 56 | requestPanelHeightUpdate(); |
| 57 | } |
| 58 | }); |
| 59 | } |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 60 | } |
| 61 | |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 62 | @Override |
| 63 | protected void onFinishInflate() { |
| 64 | super.onFinishInflate(); |
| 65 | |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 66 | mHeader = findViewById(R.id.header); |
| 67 | mKeyguardStatusView = findViewById(R.id.keyguard_status_view); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 68 | mNotificationStackScroller = (NotificationStackScrollLayout) |
| 69 | findViewById(R.id.notification_stack_scroller); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 70 | mNotificationStackScroller.setOnHeightChangedListener(this); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 71 | mNotificationTopPadding = getResources().getDimensionPixelSize( |
| 72 | R.dimen.notifications_top_padding); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 77 | super.onLayout(changed, left, top, right, bottom); |
| 78 | int keyguardBottomMargin = |
| 79 | ((MarginLayoutParams) mKeyguardStatusView.getLayoutParams()).bottomMargin; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 80 | mNotificationStackScroller.setTopPadding(mStatusBar.getBarState() == StatusBarState.KEYGUARD |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 81 | ? mKeyguardStatusView.getBottom() + keyguardBottomMargin |
Jorim Jaggi | 0dd6881 | 2014-05-01 19:17:37 +0200 | [diff] [blame] | 82 | : mHeader.getBottom() + mNotificationTopPadding, |
| 83 | mStatusBar.isScreenTurnedOn() && mStatusBar.isExpandedVisible()); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 86 | @Override |
| 87 | public void fling(float vel, boolean always) { |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 88 | GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder(); |
| 89 | if (gr != null) { |
| 90 | gr.tag( |
| 91 | "fling " + ((vel > 0) ? "open" : "closed"), |
| 92 | "notifications,v=" + vel); |
| 93 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 94 | super.fling(vel, always); |
| 95 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 96 | |
Casey Burkhardt | 23b0a4e | 2013-04-29 12:18:32 -0700 | [diff] [blame] | 97 | @Override |
| 98 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 99 | if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 100 | event.getText() |
| 101 | .add(getContext().getString(R.string.accessibility_desc_notification_shade)); |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | return super.dispatchPopulateAccessibilityEvent(event); |
| 106 | } |
| 107 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 108 | @Override |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 109 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 110 | // intercept for quick settings |
| 111 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 112 | final View target = mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 113 | ? mKeyguardStatusView |
| 114 | : mHeader; |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 115 | final boolean inTarget = PhoneStatusBar.inBounds(target, event, true); |
| 116 | if (inTarget && !isInSettings()) { |
| 117 | mTrackingSettings = true; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 118 | requestDisallowInterceptTouchEvent(true); |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 119 | return true; |
| 120 | } |
| 121 | if (!inTarget && isInSettings()) { |
| 122 | mTrackingSettings = true; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 123 | requestDisallowInterceptTouchEvent(true); |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 124 | return true; |
| 125 | } |
| 126 | } |
| 127 | return super.onInterceptTouchEvent(event); |
| 128 | } |
| 129 | |
| 130 | @Override |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 131 | public boolean onTouchEvent(MotionEvent event) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 132 | // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference |
| 133 | // implementation. |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 134 | if (mTrackingSettings) { |
| 135 | mStatusBar.onSettingsEvent(event); |
| 136 | if (event.getAction() == MotionEvent.ACTION_UP |
| 137 | || event.getAction() == MotionEvent.ACTION_CANCEL) { |
| 138 | mTrackingSettings = false; |
| 139 | } |
| 140 | return true; |
| 141 | } |
| 142 | if (isInSettings()) { |
| 143 | return true; |
| 144 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 145 | return super.onTouchEvent(event); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | protected boolean isScrolledToBottom() { |
| 150 | if (!isInSettings()) { |
| 151 | return mNotificationStackScroller.isScrolledToBottom(); |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 152 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 153 | return super.isScrolledToBottom(); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | protected int getMaxPanelHeight() { |
| 158 | if (!isInSettings()) { |
| 159 | int maxPanelHeight = super.getMaxPanelHeight(); |
| 160 | int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin(); |
| 161 | return maxPanelHeight - emptyBottomMargin; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 162 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 163 | return super.getMaxPanelHeight(); |
| 164 | } |
| 165 | |
| 166 | private boolean isInSettings() { |
| 167 | return mStatusBar != null && mStatusBar.isFlippedToSettings(); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | protected void onHeightUpdated(float expandedHeight) { |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 172 | mNotificationStackScroller.setStackHeight(expandedHeight); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
| 176 | protected int getDesiredMeasureHeight() { |
| 177 | return mMaxPanelHeight; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 178 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 179 | |
| 180 | @Override |
| 181 | protected void onExpandingStarted() { |
| 182 | super.onExpandingStarted(); |
| 183 | mNotificationStackScroller.onExpansionStarted(); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | protected void onExpandingFinished() { |
| 188 | super.onExpandingFinished(); |
| 189 | mNotificationStackScroller.onExpansionStopped(); |
| 190 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 191 | |
| 192 | @Override |
| 193 | public void onHeightChanged(ExpandableView view) { |
| 194 | requestPanelHeightUpdate(); |
| 195 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 196 | } |