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; |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 26 | import com.android.systemui.statusbar.GestureRecorder; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 27 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 28 | |
| 29 | public class NotificationPanelView extends PanelView { |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 30 | public static final boolean DEBUG_GESTURES = true; |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 31 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 32 | PhoneStatusBar mStatusBar; |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 33 | private View mHeader; |
| 34 | private View mKeyguardStatusView; |
| 35 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 36 | private NotificationStackScrollLayout mNotificationStackScroller; |
| 37 | private int[] mTempLocation = new int[2]; |
| 38 | private int[] mTempChildLocation = new int[2]; |
| 39 | private View mNotificationParent; |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 40 | private boolean mTrackingSettings; |
John Spurlock | f0b06c7 | 2014-04-18 15:04:11 -0400 | [diff] [blame] | 41 | private float mExpandedHeight = -1; |
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); |
| 70 | mNotificationParent = findViewById(R.id.notification_container_parent); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 73 | @Override |
| 74 | public void fling(float vel, boolean always) { |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 75 | GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder(); |
| 76 | if (gr != null) { |
| 77 | gr.tag( |
| 78 | "fling " + ((vel > 0) ? "open" : "closed"), |
| 79 | "notifications,v=" + vel); |
| 80 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 81 | super.fling(vel, always); |
| 82 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 83 | |
Casey Burkhardt | 23b0a4e | 2013-04-29 12:18:32 -0700 | [diff] [blame] | 84 | @Override |
| 85 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 86 | if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 87 | event.getText() |
| 88 | .add(getContext().getString(R.string.accessibility_desc_notification_shade)); |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | return super.dispatchPopulateAccessibilityEvent(event); |
| 93 | } |
| 94 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 95 | /** |
| 96 | * Gets the relative position of a view on the screen in regard to this view. |
| 97 | * |
| 98 | * @param requestedView the view we want to find the relative position for |
| 99 | * @return |
| 100 | */ |
| 101 | private int getRelativeTop(View requestedView) { |
| 102 | getLocationOnScreen(mTempLocation); |
| 103 | requestedView.getLocationOnScreen(mTempChildLocation); |
| 104 | return mTempChildLocation[1] - mTempLocation[1]; |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 105 | } |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 106 | |
| 107 | @Override |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 108 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 109 | // intercept for quick settings |
| 110 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 111 | final View target = mStatusBar.isOnKeyguard() ? mKeyguardStatusView : mHeader; |
| 112 | final boolean inTarget = PhoneStatusBar.inBounds(target, event, true); |
| 113 | if (inTarget && !isInSettings()) { |
| 114 | mTrackingSettings = true; |
| 115 | return true; |
| 116 | } |
| 117 | if (!inTarget && isInSettings()) { |
| 118 | mTrackingSettings = true; |
| 119 | return true; |
| 120 | } |
| 121 | } |
| 122 | return super.onInterceptTouchEvent(event); |
| 123 | } |
| 124 | |
| 125 | @Override |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 126 | public boolean onTouchEvent(MotionEvent event) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 127 | // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference |
| 128 | // implementation. |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 129 | if (mTrackingSettings) { |
| 130 | mStatusBar.onSettingsEvent(event); |
| 131 | if (event.getAction() == MotionEvent.ACTION_UP |
| 132 | || event.getAction() == MotionEvent.ACTION_CANCEL) { |
| 133 | mTrackingSettings = false; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | if (isInSettings()) { |
| 138 | return true; |
| 139 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 140 | return super.onTouchEvent(event); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | protected boolean isScrolledToBottom() { |
| 145 | if (!isInSettings()) { |
| 146 | return mNotificationStackScroller.isScrolledToBottom(); |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 147 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 148 | return super.isScrolledToBottom(); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | protected int getMaxPanelHeight() { |
| 153 | if (!isInSettings()) { |
| 154 | int maxPanelHeight = super.getMaxPanelHeight(); |
| 155 | int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin(); |
| 156 | return maxPanelHeight - emptyBottomMargin; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 157 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 158 | return super.getMaxPanelHeight(); |
| 159 | } |
| 160 | |
| 161 | private boolean isInSettings() { |
| 162 | return mStatusBar != null && mStatusBar.isFlippedToSettings(); |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | protected void onHeightUpdated(float expandedHeight) { |
| 167 | updateNotificationStackHeight(expandedHeight); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Update the height of the {@link #mNotificationStackScroller} to the new expanded height. |
| 172 | * This is much more efficient than doing it over the layout pass. |
| 173 | * |
| 174 | * @param expandedHeight the new expanded height |
| 175 | */ |
| 176 | private void updateNotificationStackHeight(float expandedHeight) { |
John Spurlock | f0b06c7 | 2014-04-18 15:04:11 -0400 | [diff] [blame] | 177 | if (mExpandedHeight == expandedHeight) return; |
| 178 | mExpandedHeight = expandedHeight; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 179 | mNotificationStackScroller.setIsExpanded(expandedHeight > 0.0f); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 180 | float childOffset = getRelativeTop(mNotificationStackScroller) |
| 181 | - mNotificationParent.getTranslationY(); |
| 182 | int newStackHeight = (int) (expandedHeight - childOffset); |
| 183 | int itemHeight = mNotificationStackScroller.getItemHeight(); |
| 184 | int bottomStackPeekSize = mNotificationStackScroller.getBottomStackPeekSize(); |
| 185 | int minStackHeight = itemHeight + bottomStackPeekSize; |
| 186 | if (newStackHeight >= minStackHeight) { |
| 187 | mNotificationParent.setTranslationY(0); |
| 188 | mNotificationStackScroller.setCurrentStackHeight(newStackHeight); |
| 189 | } else { |
| 190 | |
| 191 | // We did not reach the position yet where we actually start growing, |
| 192 | // so we translate the stack upwards. |
| 193 | int translationY = (newStackHeight - minStackHeight); |
| 194 | // A slight parallax effect is introduced in order for the stack to catch up with |
| 195 | // the top card. |
| 196 | float partiallyThere = (float) newStackHeight / minStackHeight; |
| 197 | partiallyThere = Math.max(0, partiallyThere); |
| 198 | translationY += (1 - partiallyThere) * bottomStackPeekSize; |
| 199 | mNotificationParent.setTranslationY(translationY); |
| 200 | mNotificationStackScroller.setCurrentStackHeight( |
| 201 | (int) (expandedHeight - (childOffset + translationY))); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | protected int getDesiredMeasureHeight() { |
| 207 | return mMaxPanelHeight; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 208 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 209 | |
| 210 | @Override |
| 211 | protected void onExpandingStarted() { |
| 212 | super.onExpandingStarted(); |
| 213 | mNotificationStackScroller.onExpansionStarted(); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | protected void onExpandingFinished() { |
| 218 | super.onExpandingFinished(); |
| 219 | mNotificationStackScroller.onExpansionStopped(); |
| 220 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 221 | } |