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 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 23 | import android.content.Context; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 26 | import android.view.MotionEvent; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 27 | import android.view.VelocityTracker; |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 28 | import android.view.View; |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 29 | import android.view.ViewGroup; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 30 | import android.view.ViewTreeObserver; |
Casey Burkhardt | 23b0a4e | 2013-04-29 12:18:32 -0700 | [diff] [blame] | 31 | import android.view.accessibility.AccessibilityEvent; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 32 | import android.view.animation.AnimationUtils; |
| 33 | import android.view.animation.Interpolator; |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 34 | import android.widget.LinearLayout; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 35 | import android.widget.TextView; |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 36 | |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 37 | import com.android.systemui.R; |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 38 | import com.android.systemui.qs.QSPanel; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 39 | import com.android.systemui.statusbar.ExpandableView; |
Jorim Jaggi | 87cd5e7 | 2014-05-12 23:29:10 +0200 | [diff] [blame] | 40 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.GestureRecorder; |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 42 | import com.android.systemui.statusbar.MirrorView; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 43 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 44 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 45 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 46 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 47 | import java.util.ArrayList; |
| 48 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 49 | public class NotificationPanelView extends PanelView implements |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 50 | ExpandableView.OnHeightChangedListener, ObservableScrollView.Listener, |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 51 | View.OnClickListener, NotificationStackScrollLayout.OnOverscrollTopChangedListener, |
| 52 | KeyguardPageSwipeHelper.Callback { |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 53 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 54 | // Cap and total height of Roboto font. Needs to be adjusted when font for the big clock is |
| 55 | // changed. |
| 56 | private static final int CAP_HEIGHT = 1456; |
| 57 | private static final int FONT_HEIGHT = 2163; |
| 58 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 59 | private static final float HEADER_RUBBERBAND_FACTOR = 2.15f; |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 60 | private static final float LOCK_ICON_ACTIVE_SCALE = 1.2f; |
Selim Cinek | a02fe52 | 2014-05-30 17:01:21 +0200 | [diff] [blame] | 61 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 62 | private KeyguardPageSwipeHelper mPageSwiper; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 63 | private StatusBarHeaderView mHeader; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 64 | private View mQsContainer; |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 65 | private QSPanel mQsPanel; |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 66 | private View mKeyguardStatusView; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 67 | private ObservableScrollView mScrollView; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 68 | private TextView mClockView; |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 69 | private View mReserveNotificationSpace; |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 70 | private MirrorView mSystemIconsCopy; |
| 71 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 72 | private NotificationStackScrollLayout mNotificationStackScroller; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 73 | private int mNotificationTopPadding; |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 74 | private boolean mAnimateNextTopPaddingChange; |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 75 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 76 | private int mTrackingPointer; |
| 77 | private VelocityTracker mVelocityTracker; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 78 | private boolean mQsTracking; |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 79 | |
| 80 | /** |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 81 | * If set, the ongoing touch gesture might both trigger the expansion in {@link PanelView} and |
| 82 | * the expansion for quick settings. |
| 83 | */ |
| 84 | private boolean mConflictingQsExpansionGesture; |
| 85 | |
| 86 | /** |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 87 | * Whether we are currently handling a motion gesture in #onInterceptTouchEvent, but haven't |
| 88 | * intercepted yet. |
| 89 | */ |
| 90 | private boolean mIntercepting; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 91 | private boolean mQsExpanded; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 92 | private boolean mQsExpandedWhenExpandingStarted; |
John Spurlock | bc3a5e9 | 2014-05-30 16:20:05 -0400 | [diff] [blame] | 93 | private boolean mQsFullyExpanded; |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 94 | private boolean mKeyguardShowing; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 95 | private int mStatusBarState; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 96 | private float mInitialHeightOnTouch; |
| 97 | private float mInitialTouchX; |
| 98 | private float mInitialTouchY; |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 99 | private float mLastTouchX; |
| 100 | private float mLastTouchY; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 101 | private float mQsExpansionHeight; |
| 102 | private int mQsMinExpansionHeight; |
| 103 | private int mQsMaxExpansionHeight; |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 104 | private int mQsPeekHeight; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 105 | private boolean mStackScrollerOverscrolling; |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 106 | private boolean mQsExpansionFromOverscroll; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 107 | private boolean mQsExpansionEnabled = true; |
| 108 | private ValueAnimator mQsExpansionAnimator; |
Jorim Jaggi | 87cd5e7 | 2014-05-12 23:29:10 +0200 | [diff] [blame] | 109 | private FlingAnimationUtils mFlingAnimationUtils; |
Selim Cinek | 9dbbca8 | 2014-05-15 15:23:37 +0200 | [diff] [blame] | 110 | private int mStatusBarMinHeight; |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 111 | private boolean mUnlockIconActive; |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 112 | private int mNotificationsHeaderCollideDistance; |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 113 | private int mUnlockMoveDistance; |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 114 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 115 | private Interpolator mFastOutSlowInInterpolator; |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 116 | private Interpolator mFastOutLinearInterpolator; |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 117 | private ObjectAnimator mClockAnimator; |
| 118 | private int mClockAnimationTarget = -1; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 119 | private int mTopPaddingAdjustment; |
| 120 | private KeyguardClockPositionAlgorithm mClockPositionAlgorithm = |
| 121 | new KeyguardClockPositionAlgorithm(); |
| 122 | private KeyguardClockPositionAlgorithm.Result mClockPositionResult = |
| 123 | new KeyguardClockPositionAlgorithm.Result(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 124 | private boolean mIsExpanding; |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 125 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 126 | private boolean mBlockTouches; |
| 127 | private ArrayList<View> mSwipeTranslationViews = new ArrayList<>(); |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 128 | private int mNotificationScrimWaitDistance; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * If we are in a panel collapsing motion, we reset scrollY of our scroll view but still |
| 132 | * need to take this into account in our panel height calculation. |
| 133 | */ |
| 134 | private int mScrollYOverride = -1; |
Jorim Jaggi | bd00310 | 2014-07-04 00:02:42 +0200 | [diff] [blame] | 135 | private boolean mQsAnimatorExpand; |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 136 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 137 | public NotificationPanelView(Context context, AttributeSet attrs) { |
| 138 | super(context, attrs); |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 139 | mSystemIconsCopy = new MirrorView(context); |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 140 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 141 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 142 | public void setStatusBar(PhoneStatusBar bar) { |
| 143 | mStatusBar = bar; |
| 144 | } |
| 145 | |
Daniel Sandler | 13522a2 | 2012-09-27 14:46:58 -0400 | [diff] [blame] | 146 | @Override |
| 147 | protected void onFinishInflate() { |
| 148 | super.onFinishInflate(); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 149 | mHeader = (StatusBarHeaderView) findViewById(R.id.header); |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 150 | mHeader.setOnClickListener(this); |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 151 | mHeader.setOverlayParent(this); |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 152 | mKeyguardStatusView = findViewById(R.id.keyguard_status_view); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 153 | mQsContainer = findViewById(R.id.quick_settings_container); |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 154 | mQsPanel = (QSPanel) findViewById(R.id.quick_settings_panel); |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 155 | mClockView = (TextView) findViewById(R.id.clock_view); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 156 | mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view); |
| 157 | mScrollView.setListener(this); |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 158 | mReserveNotificationSpace = findViewById(R.id.reserve_notification_space); |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 159 | mNotificationStackScroller = (NotificationStackScrollLayout) |
| 160 | findViewById(R.id.notification_stack_scroller); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 161 | mNotificationStackScroller.setOnHeightChangedListener(this); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 162 | mNotificationStackScroller.setOverscrollTopChangedListener(this); |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 163 | mNotificationStackScroller.setScrollView(mScrollView); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 164 | mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(), |
| 165 | android.R.interpolator.fast_out_slow_in); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 166 | mFastOutLinearInterpolator = AnimationUtils.loadInterpolator(getContext(), |
| 167 | android.R.interpolator.fast_out_linear_in); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 168 | mKeyguardBottomArea = (KeyguardBottomAreaView) findViewById(R.id.keyguard_bottom_area); |
| 169 | mSwipeTranslationViews.add(mNotificationStackScroller); |
Jorim Jaggi | a27b004 | 2014-06-14 03:58:56 +0000 | [diff] [blame] | 170 | mSwipeTranslationViews.add(mKeyguardStatusView); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 171 | mPageSwiper = new KeyguardPageSwipeHelper(this, getContext()); |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Override |
| 175 | protected void loadDimens() { |
| 176 | super.loadDimens(); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 177 | mNotificationTopPadding = getResources().getDimensionPixelSize( |
| 178 | R.dimen.notifications_top_padding); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 179 | mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.4f); |
Selim Cinek | 9dbbca8 | 2014-05-15 15:23:37 +0200 | [diff] [blame] | 180 | mStatusBarMinHeight = getResources().getDimensionPixelSize( |
| 181 | com.android.internal.R.dimen.status_bar_height); |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 182 | mQsPeekHeight = getResources().getDimensionPixelSize(R.dimen.qs_peek_height); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 183 | mNotificationsHeaderCollideDistance = |
| 184 | getResources().getDimensionPixelSize(R.dimen.header_notifications_collide_distance); |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 185 | mUnlockMoveDistance = getResources().getDimensionPixelOffset(R.dimen.unlock_move_distance); |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 186 | mClockPositionAlgorithm.loadDimens(getResources()); |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 187 | mNotificationScrimWaitDistance = |
| 188 | getResources().getDimensionPixelSize(R.dimen.notification_scrim_wait_distance); |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Override |
| 192 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 193 | super.onLayout(changed, left, top, right, bottom); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 194 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 195 | // Update Clock Pivot |
| 196 | mKeyguardStatusView.setPivotX(getWidth() / 2); |
| 197 | mKeyguardStatusView.setPivotY( |
| 198 | (FONT_HEIGHT - CAP_HEIGHT) / 2048f * mClockView.getTextSize()); |
| 199 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 200 | // Calculate quick setting heights. |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 201 | mQsMinExpansionHeight = mHeader.getCollapsedHeight() + mQsPeekHeight; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 202 | mQsMaxExpansionHeight = mHeader.getExpandedHeight() + mQsContainer.getHeight(); |
John Spurlock | 2684d5e | 2014-05-28 20:27:44 -0400 | [diff] [blame] | 203 | if (mQsExpanded) { |
John Spurlock | bc3a5e9 | 2014-05-30 16:20:05 -0400 | [diff] [blame] | 204 | if (mQsFullyExpanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 205 | mQsExpansionHeight = mQsMaxExpansionHeight; |
| 206 | requestScrollerTopPaddingUpdate(false /* animate */); |
John Spurlock | bc3a5e9 | 2014-05-30 16:20:05 -0400 | [diff] [blame] | 207 | } |
John Spurlock | 2684d5e | 2014-05-28 20:27:44 -0400 | [diff] [blame] | 208 | } else { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 209 | if (!mStackScrollerOverscrolling) { |
| 210 | setQsExpansion(mQsMinExpansionHeight); |
| 211 | } |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 212 | positionClockAndNotifications(); |
| 213 | mNotificationStackScroller.setStackHeight(getExpandedHeight()); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 214 | } |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 215 | } |
| 216 | |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 217 | /** |
| 218 | * Positions the clock and notifications dynamically depending on how many notifications are |
| 219 | * showing. |
| 220 | */ |
| 221 | private void positionClockAndNotifications() { |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 222 | boolean animate = mNotificationStackScroller.isAddOrRemoveAnimationPending(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 223 | int stackScrollerPadding; |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 224 | if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) { |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 225 | int bottom = mHeader.getCollapsedHeight(); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 226 | stackScrollerPadding = bottom + mQsPeekHeight |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 227 | + mNotificationTopPadding; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 228 | mTopPaddingAdjustment = 0; |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 229 | } else { |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 230 | mClockPositionAlgorithm.setup( |
| 231 | mStatusBar.getMaxKeyguardNotifications(), |
| 232 | getMaxPanelHeight(), |
| 233 | getExpandedHeight(), |
| 234 | mNotificationStackScroller.getNotGoneChildCount(), |
| 235 | getHeight(), |
| 236 | mKeyguardStatusView.getHeight()); |
| 237 | mClockPositionAlgorithm.run(mClockPositionResult); |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 238 | if (animate || mClockAnimator != null) { |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 239 | startClockAnimation(mClockPositionResult.clockY); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 240 | } else { |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 241 | mKeyguardStatusView.setY(mClockPositionResult.clockY); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 242 | } |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 243 | updateClock(mClockPositionResult.clockAlpha, mClockPositionResult.clockScale); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 244 | stackScrollerPadding = mClockPositionResult.stackScrollerPadding; |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 245 | mTopPaddingAdjustment = mClockPositionResult.stackScrollerPaddingAdjustment; |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 246 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 247 | mNotificationStackScroller.setIntrinsicPadding(stackScrollerPadding); |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 248 | requestScrollerTopPaddingUpdate(animate); |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 251 | private void startClockAnimation(int y) { |
| 252 | if (mClockAnimationTarget == y) { |
| 253 | return; |
| 254 | } |
| 255 | mClockAnimationTarget = y; |
| 256 | getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { |
| 257 | @Override |
| 258 | public boolean onPreDraw() { |
| 259 | getViewTreeObserver().removeOnPreDrawListener(this); |
| 260 | if (mClockAnimator != null) { |
| 261 | mClockAnimator.removeAllListeners(); |
| 262 | mClockAnimator.cancel(); |
| 263 | } |
Jorim Jaggi | a1b1c7a | 2014-06-03 16:29:05 +0200 | [diff] [blame] | 264 | mClockAnimator = ObjectAnimator |
| 265 | .ofFloat(mKeyguardStatusView, View.Y, mClockAnimationTarget); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 266 | mClockAnimator.setInterpolator(mFastOutSlowInInterpolator); |
| 267 | mClockAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 268 | mClockAnimator.addListener(new AnimatorListenerAdapter() { |
| 269 | @Override |
| 270 | public void onAnimationEnd(Animator animation) { |
| 271 | mClockAnimator = null; |
| 272 | mClockAnimationTarget = -1; |
| 273 | } |
| 274 | }); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 275 | mClockAnimator.start(); |
Jorim Jaggi | 75c9504 | 2014-05-16 19:09:59 +0200 | [diff] [blame] | 276 | return true; |
| 277 | } |
| 278 | }); |
| 279 | } |
| 280 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 281 | private void updateClock(float alpha, float scale) { |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 282 | mKeyguardStatusView.setAlpha(alpha); |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 283 | mKeyguardStatusView.setScaleX(scale); |
| 284 | mKeyguardStatusView.setScaleY(scale); |
Jorim Jaggi | 069cd03 | 2014-05-15 03:09:01 +0200 | [diff] [blame] | 285 | } |
| 286 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 287 | public void animateToFullShade() { |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 288 | mAnimateNextTopPaddingChange = true; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 289 | mNotificationStackScroller.goToFullShade(); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 290 | requestLayout(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 293 | public void setQsExpansionEnabled(boolean qsExpansionEnabled) { |
| 294 | mQsExpansionEnabled = qsExpansionEnabled; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Selim Cinek | 3c4635c | 2014-05-29 02:12:47 +0200 | [diff] [blame] | 297 | @Override |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 298 | public void resetViews() { |
| 299 | mBlockTouches = false; |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 300 | mUnlockIconActive = false; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 301 | mPageSwiper.reset(); |
| 302 | closeQs(); |
Jorim Jaggi | dbbf45e | 2014-06-25 21:54:48 +0200 | [diff] [blame] | 303 | mNotificationStackScroller.setOverScrollAmount(0f, true /* onTop */, false /* animate */, |
| 304 | true /* cancelAnimators */); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 307 | public void closeQs() { |
| 308 | cancelAnimation(); |
| 309 | setQsExpansion(mQsMinExpansionHeight); |
| 310 | } |
| 311 | |
Jorim Jaggi | bd00310 | 2014-07-04 00:02:42 +0200 | [diff] [blame] | 312 | public void animateCloseQs() { |
| 313 | if (mQsExpansionAnimator != null) { |
| 314 | if (!mQsAnimatorExpand) { |
| 315 | return; |
| 316 | } |
| 317 | float height = mQsExpansionHeight; |
| 318 | mQsExpansionAnimator.cancel(); |
| 319 | setQsExpansion(height); |
| 320 | } |
| 321 | flingSettings(0 /* vel */, false); |
| 322 | } |
| 323 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 324 | public void openQs() { |
| 325 | cancelAnimation(); |
| 326 | if (mQsExpansionEnabled) { |
| 327 | setQsExpansion(mQsMaxExpansionHeight); |
| 328 | } |
| 329 | } |
| 330 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 331 | @Override |
| 332 | public void fling(float vel, boolean always) { |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 333 | GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder(); |
| 334 | if (gr != null) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 335 | gr.tag("fling " + ((vel > 0) ? "open" : "closed"), "notifications,v=" + vel); |
Daniel Sandler | 151f00d | 2012-10-02 22:33:08 -0400 | [diff] [blame] | 336 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 337 | super.fling(vel, always); |
| 338 | } |
Chet Haase | 4d179dc | 2012-08-22 07:14:42 -0700 | [diff] [blame] | 339 | |
Casey Burkhardt | 23b0a4e | 2013-04-29 12:18:32 -0700 | [diff] [blame] | 340 | @Override |
| 341 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 342 | if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 343 | event.getText() |
| 344 | .add(getContext().getString(R.string.accessibility_desc_notification_shade)); |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | return super.dispatchPopulateAccessibilityEvent(event); |
| 349 | } |
| 350 | |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 351 | @Override |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 352 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 353 | if (mBlockTouches) { |
| 354 | return false; |
| 355 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 356 | int pointerIndex = event.findPointerIndex(mTrackingPointer); |
| 357 | if (pointerIndex < 0) { |
| 358 | pointerIndex = 0; |
| 359 | mTrackingPointer = event.getPointerId(pointerIndex); |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 360 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 361 | final float x = event.getX(pointerIndex); |
| 362 | final float y = event.getY(pointerIndex); |
| 363 | |
| 364 | switch (event.getActionMasked()) { |
| 365 | case MotionEvent.ACTION_DOWN: |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 366 | mIntercepting = true; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 367 | mInitialTouchY = y; |
| 368 | mInitialTouchX = x; |
| 369 | initVelocityTracker(); |
| 370 | trackMovement(event); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 371 | if (shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, 0)) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 372 | getParent().requestDisallowInterceptTouchEvent(true); |
| 373 | } |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 374 | if (mQsExpansionAnimator != null) { |
| 375 | onQsExpansionStarted(); |
| 376 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 377 | mQsTracking = true; |
| 378 | mIntercepting = false; |
| 379 | mNotificationStackScroller.removeLongPressCallback(); |
| 380 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 381 | break; |
| 382 | case MotionEvent.ACTION_POINTER_UP: |
| 383 | final int upPointer = event.getPointerId(event.getActionIndex()); |
| 384 | if (mTrackingPointer == upPointer) { |
| 385 | // gesture is ongoing, find a new pointer to track |
| 386 | final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; |
| 387 | mTrackingPointer = event.getPointerId(newIndex); |
| 388 | mInitialTouchX = event.getX(newIndex); |
| 389 | mInitialTouchY = event.getY(newIndex); |
| 390 | } |
| 391 | break; |
| 392 | |
| 393 | case MotionEvent.ACTION_MOVE: |
| 394 | final float h = y - mInitialTouchY; |
| 395 | trackMovement(event); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 396 | if (mQsTracking) { |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 397 | |
| 398 | // Already tracking because onOverscrolled was called. We need to update here |
| 399 | // so we don't stop for a frame until the next touch event gets handled in |
| 400 | // onTouchEvent. |
| 401 | setQsExpansion(h + mInitialHeightOnTouch); |
| 402 | trackMovement(event); |
| 403 | mIntercepting = false; |
| 404 | return true; |
| 405 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 406 | if (Math.abs(h) > mTouchSlop && Math.abs(h) > Math.abs(x - mInitialTouchX) |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 407 | && shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, h)) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 408 | onQsExpansionStarted(); |
| 409 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 410 | mInitialTouchY = y; |
| 411 | mInitialTouchX = x; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 412 | mQsTracking = true; |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 413 | mIntercepting = false; |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 414 | mNotificationStackScroller.removeLongPressCallback(); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 415 | return true; |
| 416 | } |
| 417 | break; |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 418 | |
| 419 | case MotionEvent.ACTION_CANCEL: |
| 420 | case MotionEvent.ACTION_UP: |
Jorim Jaggi | c9a52ab | 2014-05-12 23:46:19 +0200 | [diff] [blame] | 421 | trackMovement(event); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 422 | if (mQsTracking) { |
| 423 | flingQsWithCurrentVelocity(); |
| 424 | mQsTracking = false; |
Jorim Jaggi | c9a52ab | 2014-05-12 23:46:19 +0200 | [diff] [blame] | 425 | } |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 426 | mIntercepting = false; |
| 427 | break; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 428 | } |
| 429 | return !mQsExpanded && super.onInterceptTouchEvent(event); |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | @Override |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 433 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
| 434 | |
Jorim Jaggi | ce50b81 | 2014-05-24 16:29:57 +0200 | [diff] [blame] | 435 | // Block request when interacting with the scroll view so we can still intercept the |
| 436 | // scrolling when QS is expanded. |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame^] | 437 | if (mScrollView.isHandlingTouchEvent()) { |
Jorim Jaggi | ce50b81 | 2014-05-24 16:29:57 +0200 | [diff] [blame] | 438 | return; |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 439 | } |
Jorim Jaggi | ce50b81 | 2014-05-24 16:29:57 +0200 | [diff] [blame] | 440 | super.requestDisallowInterceptTouchEvent(disallowIntercept); |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 443 | private void flingQsWithCurrentVelocity() { |
Jorim Jaggi | c9a52ab | 2014-05-12 23:46:19 +0200 | [diff] [blame] | 444 | float vel = getCurrentVelocity(); |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 445 | flingSettings(vel, flingExpandsQs(vel)); |
Jorim Jaggi | c9a52ab | 2014-05-12 23:46:19 +0200 | [diff] [blame] | 446 | } |
| 447 | |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 448 | private boolean flingExpandsQs(float vel) { |
| 449 | if (Math.abs(vel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
| 450 | return getQsExpansionFraction() > 0.5f; |
| 451 | } else { |
| 452 | return vel > 0; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | private float getQsExpansionFraction() { |
| 457 | return (mQsExpansionHeight - mQsMinExpansionHeight) |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 458 | / (getTempQsMaxExpansion() - mQsMinExpansionHeight); |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 459 | } |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 460 | |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 461 | @Override |
Daniel Sandler | 040c2e4 | 2012-10-17 00:56:33 -0400 | [diff] [blame] | 462 | public boolean onTouchEvent(MotionEvent event) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 463 | if (mBlockTouches) { |
| 464 | return false; |
| 465 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 466 | // TODO: Handle doublefinger swipe to notifications again. Look at history for a reference |
| 467 | // implementation. |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 468 | if ((!mIsExpanding || mHintAnimationRunning) |
| 469 | && !mQsExpanded |
| 470 | && mStatusBar.getBarState() != StatusBarState.SHADE) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 471 | mPageSwiper.onTouchEvent(event); |
| 472 | if (mPageSwiper.isSwipingInProgress()) { |
| 473 | return true; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 474 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 475 | } |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 476 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN && getExpandedFraction() == 1f |
| 477 | && mStatusBar.getBarState() != StatusBarState.KEYGUARD) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 478 | |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 479 | // Down in the empty area while fully expanded - go to QS. |
| 480 | mQsTracking = true; |
| 481 | mConflictingQsExpansionGesture = true; |
| 482 | onQsExpansionStarted(); |
| 483 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 484 | mInitialTouchY = event.getX(); |
| 485 | mInitialTouchX = event.getY(); |
| 486 | } |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 487 | if (mExpandedHeight != 0) { |
| 488 | handleQsDown(event); |
| 489 | } |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 490 | if (mQsTracking || mQsExpanded) { |
| 491 | onQsTouch(event); |
| 492 | if (!mConflictingQsExpansionGesture) { |
| 493 | return true; |
| 494 | } |
| 495 | } |
| 496 | if (event.getActionMasked() == MotionEvent.ACTION_CANCEL |
| 497 | || event.getActionMasked() == MotionEvent.ACTION_UP) { |
| 498 | mConflictingQsExpansionGesture = false; |
| 499 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 500 | super.onTouchEvent(event); |
| 501 | return true; |
| 502 | } |
| 503 | |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 504 | private void handleQsDown(MotionEvent event) { |
| 505 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN |
| 506 | && shouldQuickSettingsIntercept(event.getX(), event.getY(), 0)) { |
| 507 | mQsTracking = true; |
| 508 | onQsExpansionStarted(); |
| 509 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 510 | mInitialTouchY = event.getX(); |
| 511 | mInitialTouchX = event.getY(); |
| 512 | } |
| 513 | } |
| 514 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 515 | @Override |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 516 | protected boolean flingExpands(float vel, float vectorVel) { |
| 517 | boolean expands = super.flingExpands(vel, vectorVel); |
| 518 | |
| 519 | // If we are already running a QS expansion, make sure that we keep the panel open. |
| 520 | if (mQsExpansionAnimator != null) { |
| 521 | expands = true; |
| 522 | } |
| 523 | return expands; |
| 524 | } |
| 525 | |
| 526 | @Override |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 527 | protected boolean hasConflictingGestures() { |
| 528 | return mStatusBar.getBarState() != StatusBarState.SHADE; |
| 529 | } |
| 530 | |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 531 | private void onQsTouch(MotionEvent event) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 532 | int pointerIndex = event.findPointerIndex(mTrackingPointer); |
| 533 | if (pointerIndex < 0) { |
| 534 | pointerIndex = 0; |
| 535 | mTrackingPointer = event.getPointerId(pointerIndex); |
| 536 | } |
| 537 | final float y = event.getY(pointerIndex); |
| 538 | final float x = event.getX(pointerIndex); |
| 539 | |
| 540 | switch (event.getActionMasked()) { |
| 541 | case MotionEvent.ACTION_DOWN: |
| 542 | mQsTracking = true; |
| 543 | mInitialTouchY = y; |
| 544 | mInitialTouchX = x; |
| 545 | onQsExpansionStarted(); |
| 546 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 547 | initVelocityTracker(); |
| 548 | trackMovement(event); |
| 549 | break; |
| 550 | |
| 551 | case MotionEvent.ACTION_POINTER_UP: |
| 552 | final int upPointer = event.getPointerId(event.getActionIndex()); |
| 553 | if (mTrackingPointer == upPointer) { |
| 554 | // gesture is ongoing, find a new pointer to track |
| 555 | final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; |
| 556 | final float newY = event.getY(newIndex); |
| 557 | final float newX = event.getX(newIndex); |
| 558 | mTrackingPointer = event.getPointerId(newIndex); |
| 559 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 560 | mInitialTouchY = newY; |
| 561 | mInitialTouchX = newX; |
| 562 | } |
| 563 | break; |
| 564 | |
| 565 | case MotionEvent.ACTION_MOVE: |
| 566 | final float h = y - mInitialTouchY; |
| 567 | setQsExpansion(h + mInitialHeightOnTouch); |
| 568 | trackMovement(event); |
| 569 | break; |
| 570 | |
| 571 | case MotionEvent.ACTION_UP: |
| 572 | case MotionEvent.ACTION_CANCEL: |
| 573 | mQsTracking = false; |
| 574 | mTrackingPointer = -1; |
| 575 | trackMovement(event); |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 576 | float fraction = getQsExpansionFraction(); |
| 577 | if ((fraction != 0f || y >= mInitialTouchY) |
| 578 | && (fraction != 1f || y <= mInitialTouchY)) { |
| 579 | flingQsWithCurrentVelocity(); |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 580 | } else { |
| 581 | mScrollYOverride = -1; |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 582 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 583 | if (mVelocityTracker != null) { |
| 584 | mVelocityTracker.recycle(); |
| 585 | mVelocityTracker = null; |
| 586 | } |
| 587 | break; |
| 588 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 589 | } |
| 590 | |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 591 | @Override |
| 592 | public void onOverscrolled(int amount) { |
| 593 | if (mIntercepting) { |
| 594 | onQsExpansionStarted(amount); |
| 595 | mInitialHeightOnTouch = mQsExpansionHeight; |
| 596 | mInitialTouchY = mLastTouchY; |
| 597 | mInitialTouchX = mLastTouchX; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 598 | mQsTracking = true; |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 602 | @Override |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 603 | public void onOverscrollTopChanged(float amount, boolean isRubberbanded) { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 604 | cancelAnimation(); |
| 605 | float rounded = amount >= 1f ? amount : 0f; |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 606 | mStackScrollerOverscrolling = rounded != 0f && isRubberbanded; |
| 607 | mQsExpansionFromOverscroll = rounded != 0f; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 608 | setQsExpansion(mQsMinExpansionHeight + rounded); |
| 609 | updateQsState(); |
| 610 | } |
| 611 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 612 | @Override |
| 613 | public void flingTopOverscroll(float velocity, boolean open) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 614 | setQsExpansion(mQsExpansionHeight); |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 615 | flingSettings(velocity, open, new Runnable() { |
| 616 | @Override |
| 617 | public void run() { |
| 618 | mStackScrollerOverscrolling = false; |
| 619 | mQsExpansionFromOverscroll = false; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 620 | updateQsState(); |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 621 | } |
| 622 | }); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 623 | } |
| 624 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 625 | private void onQsExpansionStarted() { |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 626 | onQsExpansionStarted(0); |
| 627 | } |
| 628 | |
| 629 | private void onQsExpansionStarted(int overscrollAmount) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 630 | cancelAnimation(); |
| 631 | |
| 632 | // Reset scroll position and apply that position to the expanded height. |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 633 | float height = mQsExpansionHeight - mScrollView.getScrollY() - overscrollAmount; |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 634 | if (mScrollView.getScrollY() != 0) { |
| 635 | mScrollYOverride = mScrollView.getScrollY(); |
| 636 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 637 | mScrollView.scrollTo(0, 0); |
| 638 | setQsExpansion(height); |
| 639 | } |
| 640 | |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 641 | private void setQsExpanded(boolean expanded) { |
| 642 | boolean changed = mQsExpanded != expanded; |
| 643 | if (changed) { |
| 644 | mQsExpanded = expanded; |
| 645 | updateQsState(); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 646 | requestPanelHeightUpdate(); |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 647 | mNotificationStackScroller.setInterceptDelegateEnabled(expanded); |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 648 | mStatusBar.setQsExpanded(expanded); |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 649 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 652 | public void setBarState(int statusBarState) { |
| 653 | boolean keyguardShowing = statusBarState == StatusBarState.KEYGUARD |
| 654 | || statusBarState == StatusBarState.SHADE_LOCKED; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 655 | if (!mKeyguardShowing && keyguardShowing) { |
| 656 | setQsTranslation(mQsExpansionHeight); |
| 657 | mHeader.setTranslationY(0f); |
| 658 | } |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 659 | mStatusBarState = statusBarState; |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 660 | mKeyguardShowing = keyguardShowing; |
| 661 | updateQsState(); |
| 662 | } |
| 663 | |
| 664 | private void updateQsState() { |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 665 | boolean expandVisually = mQsExpanded || mStackScrollerOverscrolling; |
| 666 | mHeader.setExpanded(expandVisually, mStackScrollerOverscrolling); |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 667 | mNotificationStackScroller.setScrollingEnabled(mStatusBarState != StatusBarState.KEYGUARD |
| 668 | && (!mQsExpanded || mQsExpansionFromOverscroll)); |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 669 | mQsPanel.setVisibility(expandVisually ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 670 | mQsContainer.setVisibility( |
| 671 | mKeyguardShowing && !expandVisually ? View.INVISIBLE : View.VISIBLE); |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 672 | mScrollView.setTouchEnabled(mQsExpanded); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | private void setQsExpansion(float height) { |
| 676 | height = Math.min(Math.max(height, mQsMinExpansionHeight), mQsMaxExpansionHeight); |
John Spurlock | bc3a5e9 | 2014-05-30 16:20:05 -0400 | [diff] [blame] | 677 | mQsFullyExpanded = height == mQsMaxExpansionHeight; |
Jorim Jaggi | 290600a | 2014-05-30 17:02:20 +0200 | [diff] [blame] | 678 | if (height > mQsMinExpansionHeight && !mQsExpanded && !mStackScrollerOverscrolling) { |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 679 | setQsExpanded(true); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 680 | } else if (height <= mQsMinExpansionHeight && mQsExpanded) { |
Jorim Jaggi | f62f2bb | 2014-05-25 22:28:41 +0200 | [diff] [blame] | 681 | setQsExpanded(false); |
John Spurlock | 73203eb | 2014-04-15 16:14:46 -0400 | [diff] [blame] | 682 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 683 | mQsExpansionHeight = height; |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 684 | mHeader.setExpansion(getQsExpansionFraction()); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 685 | setQsTranslation(height); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 686 | requestScrollerTopPaddingUpdate(false /* animate */); |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 687 | updateNotificationScrim(height); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 688 | } |
| 689 | |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 690 | private void updateNotificationScrim(float height) { |
| 691 | int startDistance = mQsMinExpansionHeight + mNotificationScrimWaitDistance; |
| 692 | float progress = (height - startDistance) / (mQsMaxExpansionHeight - startDistance); |
| 693 | progress = Math.max(0.0f, Math.min(progress, 1.0f)); |
| 694 | mNotificationStackScroller.setScrimAlpha(progress); |
| 695 | } |
| 696 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 697 | private void setQsTranslation(float height) { |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 698 | mQsContainer.setY(height - mQsContainer.getHeight() + getHeaderTranslation()); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 701 | private void requestScrollerTopPaddingUpdate(boolean animate) { |
| 702 | mNotificationStackScroller.updateTopPadding(mQsExpansionHeight, |
| 703 | mScrollView.getScrollY(), |
| 704 | mAnimateNextTopPaddingChange || animate); |
Selim Cinek | 758afb1 | 2014-06-04 18:46:12 +0200 | [diff] [blame] | 705 | mAnimateNextTopPaddingChange = false; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | private void trackMovement(MotionEvent event) { |
| 709 | if (mVelocityTracker != null) mVelocityTracker.addMovement(event); |
Jorim Jaggi | fc1a824 | 2014-05-12 19:30:05 +0200 | [diff] [blame] | 710 | mLastTouchX = event.getX(); |
| 711 | mLastTouchY = event.getY(); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | private void initVelocityTracker() { |
| 715 | if (mVelocityTracker != null) { |
| 716 | mVelocityTracker.recycle(); |
| 717 | } |
| 718 | mVelocityTracker = VelocityTracker.obtain(); |
| 719 | } |
| 720 | |
| 721 | private float getCurrentVelocity() { |
| 722 | if (mVelocityTracker == null) { |
| 723 | return 0; |
| 724 | } |
| 725 | mVelocityTracker.computeCurrentVelocity(1000); |
| 726 | return mVelocityTracker.getYVelocity(); |
| 727 | } |
| 728 | |
| 729 | private void cancelAnimation() { |
| 730 | if (mQsExpansionAnimator != null) { |
| 731 | mQsExpansionAnimator.cancel(); |
| 732 | } |
| 733 | } |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 734 | |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 735 | private void flingSettings(float vel, boolean expand) { |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 736 | flingSettings(vel, expand, null); |
| 737 | } |
| 738 | |
| 739 | private void flingSettings(float vel, boolean expand, final Runnable onFinishRunnable) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 740 | float target = expand ? mQsMaxExpansionHeight : mQsMinExpansionHeight; |
Jorim Jaggi | 9cd731a | 2014-05-22 14:26:06 +0200 | [diff] [blame] | 741 | if (target == mQsExpansionHeight) { |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 742 | mScrollYOverride = -1; |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 743 | if (onFinishRunnable != null) { |
| 744 | onFinishRunnable.run(); |
| 745 | } |
Jorim Jaggi | 9cd731a | 2014-05-22 14:26:06 +0200 | [diff] [blame] | 746 | return; |
| 747 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 748 | ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target); |
Jorim Jaggi | 87cd5e7 | 2014-05-12 23:29:10 +0200 | [diff] [blame] | 749 | mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 750 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 751 | @Override |
| 752 | public void onAnimationUpdate(ValueAnimator animation) { |
| 753 | setQsExpansion((Float) animation.getAnimatedValue()); |
| 754 | } |
| 755 | }); |
| 756 | animator.addListener(new AnimatorListenerAdapter() { |
| 757 | @Override |
| 758 | public void onAnimationEnd(Animator animation) { |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 759 | mScrollYOverride = -1; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 760 | mQsExpansionAnimator = null; |
Jorim Jaggi | 475b21d | 2014-07-01 18:13:24 +0200 | [diff] [blame] | 761 | if (onFinishRunnable != null) { |
| 762 | onFinishRunnable.run(); |
| 763 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 764 | } |
| 765 | }); |
| 766 | animator.start(); |
| 767 | mQsExpansionAnimator = animator; |
Jorim Jaggi | bd00310 | 2014-07-04 00:02:42 +0200 | [diff] [blame] | 768 | mQsAnimatorExpand = expand; |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /** |
| 772 | * @return Whether we should intercept a gesture to open Quick Settings. |
| 773 | */ |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 774 | private boolean shouldQuickSettingsIntercept(float x, float y, float yDiff) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 775 | if (!mQsExpansionEnabled) { |
| 776 | return false; |
| 777 | } |
Jorim Jaggi | bc5f496 | 2014-05-12 00:00:52 +0200 | [diff] [blame] | 778 | boolean onHeader = x >= mHeader.getLeft() && x <= mHeader.getRight() |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 779 | && y >= mHeader.getTop() && y <= mHeader.getBottom(); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 780 | if (mQsExpanded) { |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 781 | return onHeader || (mScrollView.isScrolledToBottom() && yDiff < 0); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 782 | } else { |
| 783 | return onHeader; |
| 784 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 788 | public void setVisibility(int visibility) { |
| 789 | int oldVisibility = getVisibility(); |
| 790 | super.setVisibility(visibility); |
| 791 | if (visibility != oldVisibility) { |
| 792 | reparentStatusIcons(visibility == VISIBLE); |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * When the notification panel gets expanded, we need to move the status icons in the header |
| 798 | * card. |
| 799 | */ |
| 800 | private void reparentStatusIcons(boolean toHeader) { |
| 801 | if (mStatusBar == null) { |
| 802 | return; |
| 803 | } |
| 804 | LinearLayout systemIcons = mStatusBar.getSystemIcons(); |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 805 | ViewGroup parent = ((ViewGroup) systemIcons.getParent()); |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 806 | if (toHeader) { |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 807 | int index = parent.indexOfChild(systemIcons); |
| 808 | parent.removeView(systemIcons); |
| 809 | mSystemIconsCopy.setMirroredView( |
| 810 | systemIcons, systemIcons.getWidth(), systemIcons.getHeight()); |
| 811 | parent.addView(mSystemIconsCopy, index); |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 812 | mHeader.attachSystemIcons(systemIcons); |
| 813 | } else { |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 814 | ViewGroup newParent = mStatusBar.getSystemIconArea(); |
| 815 | int index = newParent.indexOfChild(mSystemIconsCopy); |
| 816 | parent.removeView(systemIcons); |
Jorim Jaggi | 13c1b1f | 2014-05-11 21:55:00 +0200 | [diff] [blame] | 817 | mHeader.onSystemIconsDetached(); |
Jorim Jaggi | 605f190 | 2014-06-25 05:23:42 +0200 | [diff] [blame] | 818 | mSystemIconsCopy.setMirroredView(null, 0, 0); |
| 819 | newParent.removeView(mSystemIconsCopy); |
| 820 | newParent.addView(systemIcons, index); |
Jorim Jaggi | 0d74eeb | 2014-05-09 22:05:24 +0200 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | |
| 824 | @Override |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 825 | protected boolean isScrolledToBottom() { |
Selim Cinek | b688bf7 | 2014-06-16 16:36:51 -0700 | [diff] [blame] | 826 | if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) { |
| 827 | return true; |
| 828 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 829 | if (!isInSettings()) { |
| 830 | return mNotificationStackScroller.isScrolledToBottom(); |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 831 | } |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 832 | return super.isScrolledToBottom(); |
| 833 | } |
| 834 | |
| 835 | @Override |
| 836 | protected int getMaxPanelHeight() { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 837 | int min = mStatusBarMinHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 838 | if (mStatusBar.getBarState() != StatusBarState.KEYGUARD |
| 839 | && mNotificationStackScroller.getNotGoneChildCount() == 0) { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 840 | int minHeight = (int) ((mQsMinExpansionHeight + getOverExpansionAmount()) |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 841 | * HEADER_RUBBERBAND_FACTOR); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 842 | min = Math.max(min, minHeight); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 843 | } |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 844 | int maxHeight; |
| 845 | if (mQsExpanded || mIsExpanding && mQsExpandedWhenExpandingStarted) { |
| 846 | maxHeight = (int) calculatePanelHeightQsExpanded(); |
| 847 | } else { |
| 848 | int emptyBottomMargin = mNotificationStackScroller.getEmptyBottomMargin(); |
| 849 | maxHeight = mNotificationStackScroller.getHeight() - emptyBottomMargin |
| 850 | - mTopPaddingAdjustment; |
| 851 | maxHeight += mNotificationStackScroller.getTopPaddingOverflow(); |
| 852 | } |
| 853 | maxHeight = Math.max(maxHeight, min); |
Jorim Jaggi | 1d48069 | 2014-05-20 19:41:58 +0200 | [diff] [blame] | 854 | return maxHeight; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | private boolean isInSettings() { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 858 | return mQsExpanded; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | @Override |
| 862 | protected void onHeightUpdated(float expandedHeight) { |
Jorim Jaggi | 7d16bb1 | 2014-05-22 04:24:50 +0200 | [diff] [blame] | 863 | if (!mQsExpanded) { |
| 864 | positionClockAndNotifications(); |
| 865 | } |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 866 | if (mQsExpanded && !mQsTracking && mQsExpansionAnimator == null |
| 867 | && !mQsExpansionFromOverscroll) { |
| 868 | float panelHeightQsCollapsed = mNotificationStackScroller.getIntrinsicPadding() |
| 869 | + mNotificationStackScroller.getMinStackHeight() |
| 870 | + mNotificationStackScroller.getNotificationTopPadding(); |
| 871 | float panelHeightQsExpanded = calculatePanelHeightQsExpanded(); |
| 872 | float t = (expandedHeight - panelHeightQsCollapsed) |
| 873 | / (panelHeightQsExpanded - panelHeightQsCollapsed); |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 874 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 875 | setQsExpansion(mQsMinExpansionHeight |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 876 | + t * (getTempQsMaxExpansion() - mQsMinExpansionHeight)); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 877 | } |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 878 | mNotificationStackScroller.setStackHeight(expandedHeight); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 879 | updateHeader(); |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 880 | updateUnlockIcon(); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 881 | updateNotificationTranslucency(); |
| 882 | } |
| 883 | |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 884 | /** |
| 885 | * @return a temporary override of {@link #mQsMaxExpansionHeight}, which is needed when |
| 886 | * collapsing QS / the panel when QS was scrolled |
| 887 | */ |
| 888 | private int getTempQsMaxExpansion() { |
| 889 | int qsTempMaxExpansion = mQsMaxExpansionHeight; |
| 890 | if (mScrollYOverride != -1) { |
| 891 | qsTempMaxExpansion -= mScrollYOverride; |
| 892 | } |
| 893 | return qsTempMaxExpansion; |
| 894 | } |
| 895 | |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 896 | private float calculatePanelHeightQsExpanded() { |
| 897 | float notificationHeight = mNotificationStackScroller.getHeight() |
| 898 | - mNotificationStackScroller.getEmptyBottomMargin() |
| 899 | - mNotificationStackScroller.getTopPadding(); |
| 900 | float totalHeight = mQsMaxExpansionHeight + notificationHeight |
| 901 | + mNotificationStackScroller.getNotificationTopPadding(); |
| 902 | if (totalHeight > mNotificationStackScroller.getHeight()) { |
| 903 | float fullyCollapsedHeight = mQsMaxExpansionHeight |
| 904 | + mNotificationStackScroller.getMinStackHeight() |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 905 | + mNotificationStackScroller.getNotificationTopPadding() |
| 906 | - getScrollViewScrollY(); |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 907 | totalHeight = Math.max(fullyCollapsedHeight, mNotificationStackScroller.getHeight()); |
| 908 | } |
| 909 | return totalHeight; |
| 910 | } |
| 911 | |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 912 | private int getScrollViewScrollY() { |
| 913 | if (mScrollYOverride != -1) { |
| 914 | return mScrollYOverride; |
| 915 | } else { |
| 916 | return mScrollView.getScrollY(); |
| 917 | } |
| 918 | } |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 919 | private void updateNotificationTranslucency() { |
Jorim Jaggi | ad46ffef | 2014-07-04 18:05:06 +0200 | [diff] [blame] | 920 | float alpha = (getNotificationsTopY() + mNotificationStackScroller.getItemHeight()) |
| 921 | / (mQsMinExpansionHeight + mNotificationStackScroller.getItemHeight() / 2); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 922 | alpha = Math.max(0, Math.min(alpha, 1)); |
| 923 | alpha = (float) Math.pow(alpha, 0.75); |
| 924 | |
| 925 | // TODO: Draw a rect with DST_OUT over the notifications to achieve the same effect - |
| 926 | // this would be much more efficient. |
| 927 | mNotificationStackScroller.setAlpha(alpha); |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 930 | @Override |
| 931 | protected float getOverExpansionAmount() { |
| 932 | return mNotificationStackScroller.getCurrentOverScrollAmount(true /* top */); |
| 933 | } |
| 934 | |
| 935 | @Override |
| 936 | protected float getOverExpansionPixels() { |
| 937 | return mNotificationStackScroller.getCurrentOverScrolledPixels(true /* top */); |
| 938 | } |
| 939 | |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 940 | private void updateUnlockIcon() { |
| 941 | if (mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 942 | || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) { |
| 943 | boolean active = getMaxPanelHeight() - getExpandedHeight() > mUnlockMoveDistance; |
| 944 | if (active && !mUnlockIconActive && mTracking) { |
| 945 | mKeyguardBottomArea.getLockIcon().animate() |
| 946 | .alpha(1f) |
| 947 | .scaleY(LOCK_ICON_ACTIVE_SCALE) |
| 948 | .scaleX(LOCK_ICON_ACTIVE_SCALE) |
| 949 | .setInterpolator(mFastOutLinearInterpolator) |
| 950 | .setDuration(150); |
| 951 | } else if (!active && mUnlockIconActive && mTracking) { |
| 952 | mKeyguardBottomArea.getLockIcon().animate() |
| 953 | .alpha(KeyguardPageSwipeHelper.SWIPE_RESTING_ALPHA_AMOUNT) |
| 954 | .scaleY(1f) |
| 955 | .scaleX(1f) |
| 956 | .setInterpolator(mFastOutLinearInterpolator) |
| 957 | .setDuration(150); |
| 958 | } |
| 959 | mUnlockIconActive = active; |
| 960 | } |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Hides the header when notifications are colliding with it. |
| 965 | */ |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 966 | private void updateHeader() { |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 967 | if (mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 968 | || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) { |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 969 | updateHeaderKeyguard(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 970 | } else { |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 971 | updateHeaderShade(); |
Jorim Jaggi | 457cc35 | 2014-06-02 22:47:42 +0200 | [diff] [blame] | 972 | } |
| 973 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 974 | } |
| 975 | |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 976 | private void updateHeaderShade() { |
| 977 | mHeader.setAlpha(1f); |
| 978 | mHeader.setTranslationY(getHeaderTranslation()); |
| 979 | setQsTranslation(mQsExpansionHeight); |
| 980 | } |
| 981 | |
| 982 | private float getHeaderTranslation() { |
| 983 | if (mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 984 | || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) { |
| 985 | return 0; |
| 986 | } |
| 987 | if (mNotificationStackScroller.getNotGoneChildCount() == 0) { |
| 988 | if (mExpandedHeight / HEADER_RUBBERBAND_FACTOR >= mQsMinExpansionHeight) { |
| 989 | return 0; |
| 990 | } else { |
| 991 | return mExpandedHeight / HEADER_RUBBERBAND_FACTOR - mQsMinExpansionHeight; |
| 992 | } |
| 993 | } |
| 994 | return Math.min(0, mNotificationStackScroller.getTranslationY()) / HEADER_RUBBERBAND_FACTOR; |
| 995 | } |
| 996 | |
| 997 | private void updateHeaderKeyguard() { |
| 998 | mHeader.setTranslationY(0f); |
| 999 | float alpha; |
| 1000 | if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) { |
| 1001 | |
| 1002 | // When on Keyguard, we hide the header as soon as the top card of the notification |
| 1003 | // stack scroller is close enough (collision distance) to the bottom of the header. |
Jorim Jaggi | ad46ffef | 2014-07-04 18:05:06 +0200 | [diff] [blame] | 1004 | alpha = getNotificationsTopY() |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1005 | / |
| 1006 | (mQsMinExpansionHeight + mNotificationsHeaderCollideDistance); |
| 1007 | |
| 1008 | } else { |
| 1009 | |
| 1010 | // In SHADE_LOCKED, the top card is already really close to the header. Hide it as |
| 1011 | // soon as we start translating the stack. |
Jorim Jaggi | ad46ffef | 2014-07-04 18:05:06 +0200 | [diff] [blame] | 1012 | alpha = getNotificationsTopY() / mQsMinExpansionHeight; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1013 | } |
| 1014 | alpha = Math.max(0, Math.min(alpha, 1)); |
| 1015 | alpha = (float) Math.pow(alpha, 0.75); |
| 1016 | mHeader.setAlpha(alpha); |
| 1017 | mKeyguardBottomArea.setAlpha(alpha); |
| 1018 | setQsTranslation(mQsExpansionHeight); |
| 1019 | } |
| 1020 | |
Jorim Jaggi | ad46ffef | 2014-07-04 18:05:06 +0200 | [diff] [blame] | 1021 | private float getNotificationsTopY() { |
| 1022 | if (mNotificationStackScroller.getNotGoneChildCount() == 0) { |
| 1023 | return getExpandedHeight(); |
| 1024 | } |
| 1025 | return mNotificationStackScroller.getNotificationsTopY(); |
| 1026 | } |
| 1027 | |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 1028 | @Override |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1029 | protected void onExpandingStarted() { |
| 1030 | super.onExpandingStarted(); |
| 1031 | mNotificationStackScroller.onExpansionStarted(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1032 | mIsExpanding = true; |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1033 | mQsExpandedWhenExpandingStarted = mQsExpanded; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1034 | if (mQsExpanded) { |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1035 | onQsExpansionStarted(); |
| 1036 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | @Override |
| 1040 | protected void onExpandingFinished() { |
| 1041 | super.onExpandingFinished(); |
| 1042 | mNotificationStackScroller.onExpansionStopped(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1043 | mIsExpanding = false; |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1044 | mScrollYOverride = -1; |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 1045 | if (mExpandedHeight == 0f) { |
| 1046 | mHeader.setListening(false); |
| 1047 | mQsPanel.setListening(false); |
| 1048 | } else { |
| 1049 | mHeader.setListening(true); |
| 1050 | mQsPanel.setListening(true); |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | @Override |
| 1055 | public void instantExpand() { |
| 1056 | super.instantExpand(); |
| 1057 | mHeader.setListening(true); |
| 1058 | mQsPanel.setListening(true); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1059 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1060 | |
| 1061 | @Override |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1062 | protected void setOverExpansion(float overExpansion, boolean isPixels) { |
Jorim Jaggi | dc96d63 | 2014-07-01 18:48:52 +0200 | [diff] [blame] | 1063 | if (mConflictingQsExpansionGesture) { |
| 1064 | return; |
| 1065 | } |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1066 | if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) { |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1067 | mNotificationStackScroller.setOnHeightChangedListener(null); |
| 1068 | if (isPixels) { |
| 1069 | mNotificationStackScroller.setOverScrolledPixels( |
| 1070 | overExpansion, true /* onTop */, false /* animate */); |
| 1071 | } else { |
| 1072 | mNotificationStackScroller.setOverScrollAmount( |
| 1073 | overExpansion, true /* onTop */, false /* animate */); |
| 1074 | } |
| 1075 | mNotificationStackScroller.setOnHeightChangedListener(this); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1076 | } |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | @Override |
Jorim Jaggi | 282a615 | 2014-06-02 23:37:53 +0200 | [diff] [blame] | 1080 | protected void onTrackingStarted() { |
| 1081 | super.onTrackingStarted(); |
| 1082 | if (mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 1083 | || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED) { |
| 1084 | mPageSwiper.animateHideLeftRightIcon(); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | @Override |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 1089 | protected void onTrackingStopped(boolean expand) { |
| 1090 | super.onTrackingStopped(expand); |
Jorim Jaggi | 47c85a3 | 2014-06-05 17:25:40 +0200 | [diff] [blame] | 1091 | if (expand) { |
| 1092 | mNotificationStackScroller.setOverScrolledPixels( |
| 1093 | 0.0f, true /* onTop */, true /* animate */); |
| 1094 | } |
Jorim Jaggi | 282a615 | 2014-06-02 23:37:53 +0200 | [diff] [blame] | 1095 | if (expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 1096 | || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) { |
| 1097 | mPageSwiper.showAllIcons(true); |
| 1098 | } |
Jorim Jaggi | 8dd95e0 | 2014-06-03 16:19:33 +0200 | [diff] [blame] | 1099 | if (!expand && (mStatusBar.getBarState() == StatusBarState.KEYGUARD |
| 1100 | || mStatusBar.getBarState() == StatusBarState.SHADE_LOCKED)) { |
| 1101 | mKeyguardBottomArea.getLockIcon().animate() |
| 1102 | .alpha(0f) |
| 1103 | .scaleX(2f) |
| 1104 | .scaleY(2f) |
| 1105 | .setInterpolator(mFastOutLinearInterpolator) |
| 1106 | .setDuration(100); |
| 1107 | } |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 1108 | } |
| 1109 | |
Selim Cinek | 24120a5 | 2014-05-26 10:05:42 +0200 | [diff] [blame] | 1110 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1111 | public void onHeightChanged(ExpandableView view) { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1112 | |
| 1113 | // Block update if we are in quick settings and just the top padding changed |
| 1114 | // (i.e. view == null). |
| 1115 | if (view == null && mQsExpanded) { |
| 1116 | return; |
| 1117 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1118 | requestPanelHeightUpdate(); |
| 1119 | } |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 1120 | |
| 1121 | @Override |
| 1122 | public void onScrollChanged() { |
| 1123 | if (mQsExpanded) { |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 1124 | requestScrollerTopPaddingUpdate(false /* animate */); |
Jorim Jaggi | 5630625 | 2014-07-03 00:40:09 +0200 | [diff] [blame] | 1125 | requestPanelHeightUpdate(); |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | @Override |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1130 | protected void onConfigurationChanged(Configuration newConfig) { |
| 1131 | super.onConfigurationChanged(newConfig); |
| 1132 | mPageSwiper.onConfigurationChanged(); |
| 1133 | } |
| 1134 | |
| 1135 | @Override |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 1136 | public void onClick(View v) { |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 1137 | if (v == mHeader) { |
Jorim Jaggi | d7daab7 | 2014-05-06 22:22:20 +0200 | [diff] [blame] | 1138 | onQsExpansionStarted(); |
| 1139 | if (mQsExpanded) { |
| 1140 | flingSettings(0 /* vel */, false /* expand */); |
| 1141 | } else if (mQsExpansionEnabled) { |
| 1142 | flingSettings(0 /* vel */, true /* expand */); |
| 1143 | } |
| 1144 | } |
| 1145 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1146 | |
| 1147 | @Override |
| 1148 | public void onAnimationToSideStarted(boolean rightPage) { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 1149 | boolean start = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? rightPage : !rightPage; |
| 1150 | if (start) { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1151 | mKeyguardBottomArea.launchPhone(); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 1152 | } else { |
| 1153 | mKeyguardBottomArea.launchCamera(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1154 | } |
| 1155 | mBlockTouches = true; |
| 1156 | } |
| 1157 | |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 1158 | @Override |
| 1159 | protected void onEdgeClicked(boolean right) { |
| 1160 | if ((right && getRightIcon().getVisibility() != View.VISIBLE) |
| 1161 | || (!right && getLeftIcon().getVisibility() != View.VISIBLE)) { |
| 1162 | return; |
| 1163 | } |
| 1164 | mHintAnimationRunning = true; |
| 1165 | mPageSwiper.startHintAnimation(right, new Runnable() { |
| 1166 | @Override |
| 1167 | public void run() { |
| 1168 | mHintAnimationRunning = false; |
| 1169 | mStatusBar.onHintFinished(); |
| 1170 | } |
| 1171 | }); |
Jorim Jaggi | 93a2bb2 | 2014-06-02 19:57:28 +0200 | [diff] [blame] | 1172 | startHighlightIconAnimation(right ? getRightIcon() : getLeftIcon()); |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 1173 | boolean start = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? right : !right; |
| 1174 | if (start) { |
| 1175 | mStatusBar.onPhoneHintStarted(); |
| 1176 | } else { |
| 1177 | mStatusBar.onCameraHintStarted(); |
| 1178 | } |
| 1179 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1180 | |
| 1181 | @Override |
Jorim Jaggi | 93a2bb2 | 2014-06-02 19:57:28 +0200 | [diff] [blame] | 1182 | protected void startUnlockHintAnimation() { |
| 1183 | super.startUnlockHintAnimation(); |
| 1184 | startHighlightIconAnimation(getCenterIcon()); |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Starts the highlight (making it fully opaque) animation on an icon. |
| 1189 | */ |
| 1190 | private void startHighlightIconAnimation(final View icon) { |
| 1191 | icon.animate() |
| 1192 | .alpha(1.0f) |
| 1193 | .setDuration(KeyguardPageSwipeHelper.HINT_PHASE1_DURATION) |
| 1194 | .setInterpolator(mFastOutSlowInInterpolator) |
| 1195 | .withEndAction(new Runnable() { |
| 1196 | @Override |
| 1197 | public void run() { |
| 1198 | icon.animate().alpha(KeyguardPageSwipeHelper.SWIPE_RESTING_ALPHA_AMOUNT) |
| 1199 | .setDuration(KeyguardPageSwipeHelper.HINT_PHASE1_DURATION) |
| 1200 | .setInterpolator(mFastOutSlowInInterpolator); |
| 1201 | } |
| 1202 | }); |
| 1203 | } |
| 1204 | |
| 1205 | @Override |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1206 | public float getPageWidth() { |
| 1207 | return getWidth(); |
| 1208 | } |
| 1209 | |
| 1210 | @Override |
| 1211 | public ArrayList<View> getTranslationViews() { |
| 1212 | return mSwipeTranslationViews; |
| 1213 | } |
| 1214 | |
| 1215 | @Override |
| 1216 | public View getLeftIcon() { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 1217 | return getLayoutDirection() == LAYOUT_DIRECTION_RTL |
| 1218 | ? mKeyguardBottomArea.getCameraImageView() |
| 1219 | : mKeyguardBottomArea.getPhoneImageView(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | @Override |
| 1223 | public View getCenterIcon() { |
| 1224 | return mKeyguardBottomArea.getLockIcon(); |
| 1225 | } |
| 1226 | |
| 1227 | @Override |
| 1228 | public View getRightIcon() { |
Jorim Jaggi | b3f0a2f | 2014-06-02 19:29:39 +0200 | [diff] [blame] | 1229 | return getLayoutDirection() == LAYOUT_DIRECTION_RTL |
| 1230 | ? mKeyguardBottomArea.getPhoneImageView() |
| 1231 | : mKeyguardBottomArea.getCameraImageView(); |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 1232 | } |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1233 | |
| 1234 | @Override |
| 1235 | protected float getPeekHeight() { |
| 1236 | if (mNotificationStackScroller.getNotGoneChildCount() > 0) { |
| 1237 | return mNotificationStackScroller.getPeekHeight(); |
| 1238 | } else { |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 1239 | return mQsMinExpansionHeight * HEADER_RUBBERBAND_FACTOR; |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 1240 | } |
| 1241 | } |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 1242 | |
| 1243 | @Override |
| 1244 | protected float getCannedFlingDurationFactor() { |
| 1245 | if (mQsExpanded) { |
| 1246 | return 0.7f; |
| 1247 | } else { |
| 1248 | return 0.6f; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | @Override |
| 1253 | protected boolean isTrackingBlocked() { |
| 1254 | return mConflictingQsExpansionGesture && mQsExpanded; |
| 1255 | } |
Jorim Jaggi | 5404542 | 2014-07-03 18:30:40 +0200 | [diff] [blame] | 1256 | |
| 1257 | public void notifyVisibleChildrenChanged() { |
| 1258 | if (mNotificationStackScroller.getNotGoneChildCount() != 0) { |
| 1259 | mReserveNotificationSpace.setVisibility(View.VISIBLE); |
| 1260 | } else { |
| 1261 | mReserveNotificationSpace.setVisibility(View.GONE); |
| 1262 | } |
| 1263 | } |
Jorim Jaggi | bd00310 | 2014-07-04 00:02:42 +0200 | [diff] [blame] | 1264 | |
| 1265 | public boolean isQsExpanded() { |
| 1266 | return mQsExpanded; |
| 1267 | } |
Jorim Jaggi | 853b070 | 2014-07-05 04:31:14 +0200 | [diff] [blame] | 1268 | |
| 1269 | @Override |
| 1270 | public boolean shouldDelayChildPressedState() { |
| 1271 | return true; |
| 1272 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 1273 | } |