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