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; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 33 | private NotificationStackScrollLayout mNotificationStackScroller; |
| 34 | private int[] mTempLocation = new int[2]; |
| 35 | private int[] mTempChildLocation = new int[2]; |
| 36 | private View mNotificationParent; |
| 37 | |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 38 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 39 | public NotificationPanelView(Context context, AttributeSet attrs) { |
| 40 | super(context, attrs); |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 41 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 42 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 43 | public void setStatusBar(PhoneStatusBar bar) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 44 | if (mStatusBar != null) { |
| 45 | mStatusBar.setOnFlipRunnable(null); |
| 46 | } |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 47 | mStatusBar = bar; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 48 | if (bar != null) { |
| 49 | mStatusBar.setOnFlipRunnable(new Runnable() { |
| 50 | @Override |
| 51 | public void run() { |
| 52 | requestPanelHeightUpdate(); |
| 53 | } |
| 54 | }); |
| 55 | } |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 58 | @Override |
| 59 | protected void onFinishInflate() { |
| 60 | super.onFinishInflate(); |
| 61 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 62 | mNotificationStackScroller = (NotificationStackScrollLayout) |
| 63 | findViewById(R.id.notification_stack_scroller); |
| 64 | mNotificationParent = findViewById(R.id.notification_container_parent); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 67 | @Override |
| 68 | public void fling(float vel, boolean always) { |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 69 | GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder(); |
| 70 | if (gr != null) { |
| 71 | gr.tag( |
| 72 | "fling " + ((vel > 0) ? "open" : "closed"), |
| 73 | "notifications,v=" + vel); |
| 74 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 75 | super.fling(vel, always); |
| 76 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 77 | |
Casey Burkhardt | 23b0a4e | 2013-04-29 12:18:32 -0700 | [diff] [blame] | 78 | @Override |
| 79 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 80 | if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 81 | event.getText() |
| 82 | .add(getContext().getString(R.string.accessibility_desc_notification_shade)); |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | return super.dispatchPopulateAccessibilityEvent(event); |
| 87 | } |
| 88 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 89 | /** |
| 90 | * Gets the relative position of a view on the screen in regard to this view. |
| 91 | * |
| 92 | * @param requestedView the view we want to find the relative position for |
| 93 | * @return |
| 94 | */ |
| 95 | private int getRelativeTop(View requestedView) { |
| 96 | getLocationOnScreen(mTempLocation); |
| 97 | requestedView.getLocationOnScreen(mTempChildLocation); |
| 98 | return mTempChildLocation[1] - mTempLocation[1]; |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 99 | } |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 100 | |
| 101 | @Override |
| 102 | public boolean onTouchEvent(MotionEvent event) { |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 103 | // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference |
| 104 | // implementation. |
| 105 | return super.onTouchEvent(event); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | protected boolean isScrolledToBottom() { |
| 110 | if (!isInSettings()) { |
| 111 | return mNotificationStackScroller.isScrolledToBottom(); |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 112 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 113 | return super.isScrolledToBottom(); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | protected int getMaxPanelHeight() { |
| 118 | if (!isInSettings()) { |
| 119 | int maxPanelHeight = super.getMaxPanelHeight(); |
| 120 | int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin(); |
| 121 | return maxPanelHeight - emptyBottomMargin; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 122 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame^] | 123 | return super.getMaxPanelHeight(); |
| 124 | } |
| 125 | |
| 126 | private boolean isInSettings() { |
| 127 | return mStatusBar != null && mStatusBar.isFlippedToSettings(); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | protected void onHeightUpdated(float expandedHeight) { |
| 132 | updateNotificationStackHeight(expandedHeight); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Update the height of the {@link #mNotificationStackScroller} to the new expanded height. |
| 137 | * This is much more efficient than doing it over the layout pass. |
| 138 | * |
| 139 | * @param expandedHeight the new expanded height |
| 140 | */ |
| 141 | private void updateNotificationStackHeight(float expandedHeight) { |
| 142 | float childOffset = getRelativeTop(mNotificationStackScroller) |
| 143 | - mNotificationParent.getTranslationY(); |
| 144 | int newStackHeight = (int) (expandedHeight - childOffset); |
| 145 | int itemHeight = mNotificationStackScroller.getItemHeight(); |
| 146 | int bottomStackPeekSize = mNotificationStackScroller.getBottomStackPeekSize(); |
| 147 | int minStackHeight = itemHeight + bottomStackPeekSize; |
| 148 | if (newStackHeight >= minStackHeight) { |
| 149 | mNotificationParent.setTranslationY(0); |
| 150 | mNotificationStackScroller.setCurrentStackHeight(newStackHeight); |
| 151 | } else { |
| 152 | |
| 153 | // We did not reach the position yet where we actually start growing, |
| 154 | // so we translate the stack upwards. |
| 155 | int translationY = (newStackHeight - minStackHeight); |
| 156 | // A slight parallax effect is introduced in order for the stack to catch up with |
| 157 | // the top card. |
| 158 | float partiallyThere = (float) newStackHeight / minStackHeight; |
| 159 | partiallyThere = Math.max(0, partiallyThere); |
| 160 | translationY += (1 - partiallyThere) * bottomStackPeekSize; |
| 161 | mNotificationParent.setTranslationY(translationY); |
| 162 | mNotificationStackScroller.setCurrentStackHeight( |
| 163 | (int) (expandedHeight - (childOffset + translationY))); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | protected int getDesiredMeasureHeight() { |
| 169 | return mMaxPanelHeight; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 170 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 171 | } |