Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.qs; |
| 16 | |
| 17 | import android.util.Log; |
| 18 | import android.view.View; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 19 | import android.view.View.OnAttachStateChangeListener; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 20 | import android.view.View.OnLayoutChangeListener; |
Jason Monk | 9ffd9f6 | 2016-06-07 16:06:59 -0400 | [diff] [blame] | 21 | |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 22 | import com.android.systemui.Dependency; |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 23 | import com.android.systemui.plugins.qs.QS; |
| 24 | import com.android.systemui.plugins.qs.QSTile; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 25 | import com.android.systemui.plugins.qs.QSTileView; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 26 | import com.android.systemui.qs.PagedTileLayout.PageListener; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 27 | import com.android.systemui.qs.QSHost.Callback; |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 28 | import com.android.systemui.qs.QSPanel.QSTileLayout; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 29 | import com.android.systemui.qs.TouchAnimator.Builder; |
| 30 | import com.android.systemui.qs.TouchAnimator.Listener; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 31 | import com.android.systemui.tuner.TunerService; |
| 32 | import com.android.systemui.tuner.TunerService.Tunable; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.Collection; |
| 36 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 37 | public class QSAnimator implements Callback, PageListener, Listener, OnLayoutChangeListener, |
| 38 | OnAttachStateChangeListener, Tunable { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 39 | |
| 40 | private static final String TAG = "QSAnimator"; |
| 41 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 42 | private static final String ALLOW_FANCY_ANIMATION = "sysui_qs_fancy_anim"; |
| 43 | private static final String MOVE_FULL_ROWS = "sysui_qs_move_whole_rows"; |
| 44 | |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 45 | public static final float EXPANDED_TILE_DELAY = .86f; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 46 | |
| 47 | private final ArrayList<View> mAllViews = new ArrayList<>(); |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 48 | /** |
| 49 | * List of {@link View}s representing Quick Settings that are being animated from the quick QS |
| 50 | * position to the normal QS panel. |
| 51 | */ |
| 52 | private final ArrayList<View> mQuickQsViews = new ArrayList<>(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 53 | private final QuickQSPanel mQuickQsPanel; |
| 54 | private final QSPanel mQsPanel; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 55 | private final QS mQs; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 56 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 57 | private PagedTileLayout mPagedLayout; |
| 58 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 59 | private boolean mOnFirstPage = true; |
| 60 | private TouchAnimator mFirstPageAnimator; |
| 61 | private TouchAnimator mFirstPageDelayedAnimator; |
Jason Monk | a97776a | 2016-03-09 15:13:02 -0500 | [diff] [blame] | 62 | private TouchAnimator mTranslationXAnimator; |
| 63 | private TouchAnimator mTranslationYAnimator; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 64 | private TouchAnimator mNonfirstPageAnimator; |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 65 | private TouchAnimator mNonfirstPageDelayedAnimator; |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 66 | private TouchAnimator mBrightnessAnimator; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 67 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 68 | private boolean mOnKeyguard; |
| 69 | |
| 70 | private boolean mAllowFancy; |
| 71 | private boolean mFullRows; |
| 72 | private int mNumQuickTiles; |
Jason Monk | be8612d | 2016-03-30 16:19:06 -0400 | [diff] [blame] | 73 | private float mLastPosition; |
Jason Monk | 9ffd9f6 | 2016-06-07 16:06:59 -0400 | [diff] [blame] | 74 | private QSTileHost mHost; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 75 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 76 | public QSAnimator(QS qs, QuickQSPanel quickPanel, QSPanel panel) { |
| 77 | mQs = qs; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 78 | mQuickQsPanel = quickPanel; |
| 79 | mQsPanel = panel; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 80 | mQsPanel.addOnAttachStateChangeListener(this); |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 81 | qs.getView().addOnLayoutChangeListener(this); |
| 82 | if (mQsPanel.isAttachedToWindow()) { |
| 83 | onViewAttachedToWindow(null); |
| 84 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 85 | QSTileLayout tileLayout = mQsPanel.getTileLayout(); |
| 86 | if (tileLayout instanceof PagedTileLayout) { |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 87 | mPagedLayout = ((PagedTileLayout) tileLayout); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 88 | } else { |
| 89 | Log.w(TAG, "QS Not using page layout"); |
| 90 | } |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 91 | panel.setPageListener(this); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Jason Monk | 51fb85a | 2016-03-28 14:06:04 -0400 | [diff] [blame] | 94 | public void onRtlChanged() { |
| 95 | updateAnimators(); |
| 96 | } |
| 97 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 98 | public void setOnKeyguard(boolean onKeyguard) { |
| 99 | mOnKeyguard = onKeyguard; |
Jason Monk | 5737ef3 | 2016-04-12 14:35:13 -0400 | [diff] [blame] | 100 | mQuickQsPanel.setVisibility(mOnKeyguard ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 101 | if (mOnKeyguard) { |
| 102 | clearAnimationState(); |
| 103 | } |
| 104 | } |
| 105 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 106 | public void setHost(QSTileHost qsh) { |
Jason Monk | 9ffd9f6 | 2016-06-07 16:06:59 -0400 | [diff] [blame] | 107 | mHost = qsh; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 108 | qsh.addCallback(this); |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 109 | updateAnimators(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 113 | public void onViewAttachedToWindow(View v) { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 114 | Dependency.get(TunerService.class).addTunable(this, ALLOW_FANCY_ANIMATION, |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 115 | MOVE_FULL_ROWS, QuickQSPanel.NUM_QUICK_TILES); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void onViewDetachedFromWindow(View v) { |
Jason Monk | 9ffd9f6 | 2016-06-07 16:06:59 -0400 | [diff] [blame] | 120 | if (mHost != null) { |
| 121 | mHost.removeCallback(this); |
| 122 | } |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 123 | Dependency.get(TunerService.class).removeTunable(this); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void onTuningChanged(String key, String newValue) { |
| 128 | if (ALLOW_FANCY_ANIMATION.equals(key)) { |
| 129 | mAllowFancy = newValue == null || Integer.parseInt(newValue) != 0; |
| 130 | if (!mAllowFancy) { |
| 131 | clearAnimationState(); |
| 132 | } |
| 133 | } else if (MOVE_FULL_ROWS.equals(key)) { |
Jason Monk | 39a2e70 | 2016-03-08 16:41:23 -0500 | [diff] [blame] | 134 | mFullRows = newValue == null || Integer.parseInt(newValue) != 0; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 135 | } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) { |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 136 | mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext()); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 137 | clearAnimationState(); |
| 138 | } |
| 139 | updateAnimators(); |
| 140 | } |
| 141 | |
| 142 | @Override |
Jason Monk | 66eaf31 | 2016-02-25 12:29:29 -0500 | [diff] [blame] | 143 | public void onPageChanged(boolean isFirst) { |
| 144 | if (mOnFirstPage == isFirst) return; |
| 145 | if (!isFirst) { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 146 | clearAnimationState(); |
| 147 | } |
Jason Monk | 66eaf31 | 2016-02-25 12:29:29 -0500 | [diff] [blame] | 148 | mOnFirstPage = isFirst; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | private void updateAnimators() { |
| 152 | TouchAnimator.Builder firstPageBuilder = new Builder(); |
Jason Monk | fa0f47a | 2016-03-08 09:17:56 -0500 | [diff] [blame] | 153 | TouchAnimator.Builder translationXBuilder = new Builder(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 154 | TouchAnimator.Builder translationYBuilder = new Builder(); |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 155 | |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 156 | if (mQsPanel.getHost() == null) return; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 157 | Collection<QSTile> tiles = mQsPanel.getHost().getTiles(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 158 | int count = 0; |
| 159 | int[] loc1 = new int[2]; |
| 160 | int[] loc2 = new int[2]; |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 161 | int lastXDiff = 0; |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 162 | int lastX = 0; |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 163 | |
Jason Monk | bc8ffc2 | 2016-03-09 10:58:49 -0500 | [diff] [blame] | 164 | clearAnimationState(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 165 | mAllViews.clear(); |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 166 | mQuickQsViews.clear(); |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 167 | |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 168 | QSTileLayout tileLayout = mQsPanel.getTileLayout(); |
| 169 | mAllViews.add((View) tileLayout); |
Jason Monk | bdefffd | 2017-06-26 11:22:21 -0400 | [diff] [blame] | 170 | int height = mQs.getView() != null ? mQs.getView().getMeasuredHeight() : 0; |
| 171 | int heightDiff = height - mQs.getHeader().getBottom() |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 172 | + mQs.getHeader().getPaddingBottom(); |
| 173 | firstPageBuilder.addFloat(tileLayout, "translationY", heightDiff, 0); |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 174 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 175 | for (QSTile tile : tiles) { |
| 176 | QSTileView tileView = mQsPanel.getTileView(tile); |
Jason Monk | 6e6af2c | 2016-09-20 14:34:26 -0400 | [diff] [blame] | 177 | if (tileView == null) { |
| 178 | Log.e(TAG, "tileView is null " + tile.getTileSpec()); |
| 179 | continue; |
| 180 | } |
Xiaohui Chen | 2f3551b | 2016-04-07 10:37:25 -0700 | [diff] [blame] | 181 | final View tileIcon = tileView.getIcon().getIconView(); |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 182 | View view = mQs.getView(); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 183 | if (count < mNumQuickTiles && mAllowFancy) { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 184 | // Quick tiles. |
Jason Monk | 9f1422d | 2017-03-08 09:11:51 -0500 | [diff] [blame] | 185 | QSTileView quickTileView = mQuickQsPanel.getTileView(tile); |
| 186 | if (quickTileView == null) continue; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 187 | |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 188 | lastX = loc1[0]; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 189 | getRelativePosition(loc1, quickTileView.getIcon().getIconView(), view); |
| 190 | getRelativePosition(loc2, tileIcon, view); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 191 | final int xDiff = loc2[0] - loc1[0]; |
| 192 | final int yDiff = loc2[1] - loc1[1]; |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 193 | lastXDiff = loc1[0] - lastX; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 194 | // Move the quick tile right from its location to the new one. |
Jason Monk | fa0f47a | 2016-03-08 09:17:56 -0500 | [diff] [blame] | 195 | translationXBuilder.addFloat(quickTileView, "translationX", 0, xDiff); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 196 | translationYBuilder.addFloat(quickTileView, "translationY", 0, yDiff); |
| 197 | |
| 198 | // Counteract the parent translation on the tile. So we have a static base to |
Jason Monk | e80654b | 2016-02-24 14:53:57 -0500 | [diff] [blame] | 199 | // animate the label position off from. |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 200 | //firstPageBuilder.addFloat(tileView, "translationY", mQsPanel.getHeight(), 0); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 201 | |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 202 | // Move the real tile from the quick tile position to its final |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 203 | // location. |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 204 | translationXBuilder.addFloat(tileView, "translationX", -xDiff, 0); |
| 205 | translationYBuilder.addFloat(tileView, "translationY", -yDiff, 0); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 206 | |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 207 | mQuickQsViews.add(tileView.getIconWithBackground()); |
Jason Monk | 0f0de13 | 2016-12-19 15:36:13 -0500 | [diff] [blame] | 208 | mAllViews.add(tileView.getIcon()); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 209 | mAllViews.add(quickTileView); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 210 | } else if (mFullRows && isIconInAnimatedRow(count)) { |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 211 | // TODO: Refactor some of this, it shares a lot with the above block. |
| 212 | // Move the last tile position over by the last difference between quick tiles. |
| 213 | // This makes the extra icons seems as if they are coming from positions in the |
| 214 | // quick panel. |
| 215 | loc1[0] += lastXDiff; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 216 | getRelativePosition(loc2, tileIcon, view); |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 217 | final int xDiff = loc2[0] - loc1[0]; |
| 218 | final int yDiff = loc2[1] - loc1[1]; |
| 219 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 220 | firstPageBuilder.addFloat(tileView, "translationY", heightDiff, 0); |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 221 | translationXBuilder.addFloat(tileView, "translationX", -xDiff, 0); |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 222 | translationYBuilder.addFloat(tileView, "translationY", -yDiff, 0); |
Jason Monk | 789e9c0 | 2016-03-28 16:00:09 -0400 | [diff] [blame] | 223 | translationYBuilder.addFloat(tileIcon, "translationY", -yDiff, 0); |
| 224 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 225 | mAllViews.add(tileIcon); |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 226 | } else { |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 227 | firstPageBuilder.addFloat(tileView, "alpha", 0, 1); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 228 | firstPageBuilder.addFloat(tileView, "translationY", -heightDiff, 0); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 229 | } |
| 230 | mAllViews.add(tileView); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 231 | count++; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 232 | } |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 233 | if (mAllowFancy) { |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 234 | // Make brightness appear static position and alpha in through second half. |
| 235 | View brightness = mQsPanel.getBrightnessView(); |
| 236 | if (brightness != null) { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 237 | firstPageBuilder.addFloat(brightness, "translationY", heightDiff, 0); |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 238 | mBrightnessAnimator = new TouchAnimator.Builder() |
| 239 | .addFloat(brightness, "alpha", 0, 1) |
| 240 | .setStartDelay(.5f) |
| 241 | .build(); |
| 242 | mAllViews.add(brightness); |
| 243 | } else { |
| 244 | mBrightnessAnimator = null; |
| 245 | } |
Jason Monk | 98196b0 | 2016-03-14 10:33:02 -0400 | [diff] [blame] | 246 | mFirstPageAnimator = firstPageBuilder |
| 247 | .setListener(this) |
| 248 | .build(); |
| 249 | // Fade in the tiles/labels as we reach the final position. |
| 250 | mFirstPageDelayedAnimator = new TouchAnimator.Builder() |
| 251 | .setStartDelay(EXPANDED_TILE_DELAY) |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 252 | .addFloat(mQsPanel.getPageIndicator(), "alpha", 0, 1) |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 253 | .addFloat(tileLayout, "alpha", 0, 1) |
Jason Monk | ce4be85 | 2017-03-27 17:09:30 -0400 | [diff] [blame] | 254 | .addFloat(mQsPanel.getDivider(), "alpha", 0, 1) |
Jason Monk | df36aed | 2016-07-25 11:21:56 -0400 | [diff] [blame] | 255 | .addFloat(mQsPanel.getFooter().getView(), "alpha", 0, 1).build(); |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 256 | mAllViews.add(mQsPanel.getPageIndicator()); |
Jason Monk | ce4be85 | 2017-03-27 17:09:30 -0400 | [diff] [blame] | 257 | mAllViews.add(mQsPanel.getDivider()); |
Jason Monk | df36aed | 2016-07-25 11:21:56 -0400 | [diff] [blame] | 258 | mAllViews.add(mQsPanel.getFooter().getView()); |
Jason Monk | 08a7919 | 2016-08-02 13:36:52 -0400 | [diff] [blame] | 259 | float px = 0; |
| 260 | float py = 1; |
| 261 | if (tiles.size() <= 3) { |
| 262 | px = 1; |
| 263 | } else if (tiles.size() <= 6) { |
| 264 | px = .4f; |
| 265 | } |
| 266 | PathInterpolatorBuilder interpolatorBuilder = new PathInterpolatorBuilder(0, 0, px, py); |
Jason Monk | a97776a | 2016-03-09 15:13:02 -0500 | [diff] [blame] | 267 | translationXBuilder.setInterpolator(interpolatorBuilder.getXInterpolator()); |
| 268 | translationYBuilder.setInterpolator(interpolatorBuilder.getYInterpolator()); |
| 269 | mTranslationXAnimator = translationXBuilder.build(); |
| 270 | mTranslationYAnimator = translationYBuilder.build(); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 271 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 272 | mNonfirstPageAnimator = new TouchAnimator.Builder() |
| 273 | .addFloat(mQuickQsPanel, "alpha", 1, 0) |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 274 | .addFloat(mQsPanel.getPageIndicator(), "alpha", 0, 1) |
Jason Monk | ce4be85 | 2017-03-27 17:09:30 -0400 | [diff] [blame] | 275 | .addFloat(mQsPanel.getDivider(), "alpha", 0, 1) |
Jason Monk | 79a9f2f | 2016-03-10 14:55:22 -0500 | [diff] [blame] | 276 | .setListener(mNonFirstPageListener) |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 277 | .setEndDelay(.5f) |
| 278 | .build(); |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 279 | mNonfirstPageDelayedAnimator = new TouchAnimator.Builder() |
| 280 | .setStartDelay(.14f) |
| 281 | .addFloat(tileLayout, "alpha", 0, 1).build(); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 282 | } |
| 283 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 284 | private boolean isIconInAnimatedRow(int count) { |
| 285 | if (mPagedLayout == null) { |
| 286 | return false; |
| 287 | } |
| 288 | final int columnCount = mPagedLayout.getColumnCount(); |
| 289 | return count < ((mNumQuickTiles + columnCount - 1) / columnCount) * columnCount; |
| 290 | } |
| 291 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 292 | private void getRelativePosition(int[] loc1, View view, View parent) { |
| 293 | loc1[0] = 0 + view.getWidth() / 2; |
| 294 | loc1[1] = 0; |
| 295 | getRelativePositionInt(loc1, view, parent); |
| 296 | } |
| 297 | |
| 298 | private void getRelativePositionInt(int[] loc1, View view, View parent) { |
| 299 | if(view == parent || view == null) return; |
Jason Monk | 61d118d | 2016-05-20 14:44:16 -0400 | [diff] [blame] | 300 | // Ignore tile pages as they can have some offset we don't want to take into account in |
| 301 | // RTL. |
| 302 | if (!(view instanceof PagedTileLayout.TilePage)) { |
| 303 | loc1[0] += view.getLeft(); |
| 304 | loc1[1] += view.getTop(); |
| 305 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 306 | getRelativePositionInt(loc1, (View) view.getParent(), parent); |
| 307 | } |
| 308 | |
| 309 | public void setPosition(float position) { |
| 310 | if (mFirstPageAnimator == null) return; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 311 | if (mOnKeyguard) { |
| 312 | return; |
| 313 | } |
Jason Monk | be8612d | 2016-03-30 16:19:06 -0400 | [diff] [blame] | 314 | mLastPosition = position; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 315 | if (mOnFirstPage && mAllowFancy) { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 316 | mQuickQsPanel.setAlpha(1); |
| 317 | mFirstPageAnimator.setPosition(position); |
| 318 | mFirstPageDelayedAnimator.setPosition(position); |
Jason Monk | a97776a | 2016-03-09 15:13:02 -0500 | [diff] [blame] | 319 | mTranslationXAnimator.setPosition(position); |
| 320 | mTranslationYAnimator.setPosition(position); |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 321 | if (mBrightnessAnimator != null) { |
| 322 | mBrightnessAnimator.setPosition(position); |
| 323 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 324 | } else { |
| 325 | mNonfirstPageAnimator.setPosition(position); |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 326 | mNonfirstPageDelayedAnimator.setPosition(position); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public void onAnimationAtStart() { |
Jason Monk | df5459d | 2016-02-29 10:47:35 -0500 | [diff] [blame] | 332 | mQuickQsPanel.setVisibility(View.VISIBLE); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void onAnimationAtEnd() { |
| 337 | mQuickQsPanel.setVisibility(View.INVISIBLE); |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 338 | final int N = mQuickQsViews.size(); |
Jason Monk | e80654b | 2016-02-24 14:53:57 -0500 | [diff] [blame] | 339 | for (int i = 0; i < N; i++) { |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 340 | mQuickQsViews.get(i).setVisibility(View.VISIBLE); |
Jason Monk | e80654b | 2016-02-24 14:53:57 -0500 | [diff] [blame] | 341 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public void onAnimationStarted() { |
Jason Monk | 5737ef3 | 2016-04-12 14:35:13 -0400 | [diff] [blame] | 346 | mQuickQsPanel.setVisibility(mOnKeyguard ? View.INVISIBLE : View.VISIBLE); |
Jason Monk | e80654b | 2016-02-24 14:53:57 -0500 | [diff] [blame] | 347 | if (mOnFirstPage) { |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 348 | final int N = mQuickQsViews.size(); |
Jason Monk | e80654b | 2016-02-24 14:53:57 -0500 | [diff] [blame] | 349 | for (int i = 0; i < N; i++) { |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 350 | mQuickQsViews.get(i).setVisibility(View.INVISIBLE); |
Jason Monk | e80654b | 2016-02-24 14:53:57 -0500 | [diff] [blame] | 351 | } |
| 352 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | private void clearAnimationState() { |
| 356 | final int N = mAllViews.size(); |
| 357 | mQuickQsPanel.setAlpha(0); |
| 358 | for (int i = 0; i < N; i++) { |
| 359 | View v = mAllViews.get(i); |
| 360 | v.setAlpha(1); |
Jason Monk | a2bd046 | 2016-04-12 13:55:16 -0400 | [diff] [blame] | 361 | v.setTranslationX(0); |
| 362 | v.setTranslationY(0); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 363 | } |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 364 | final int N2 = mQuickQsViews.size(); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 365 | for (int i = 0; i < N2; i++) { |
Rohan Shah | a840199 | 2018-01-25 18:22:44 -0800 | [diff] [blame] | 366 | mQuickQsViews.get(i).setVisibility(View.VISIBLE); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 367 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, |
| 372 | int oldTop, int oldRight, int oldBottom) { |
Jason Monk | 51fb85a | 2016-03-28 14:06:04 -0400 | [diff] [blame] | 373 | mQsPanel.post(mUpdateAnimators); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public void onTilesChanged() { |
| 378 | // Give the QS panels a moment to generate their new tiles, then create all new animators |
| 379 | // hooked up to the new views. |
| 380 | mQsPanel.post(mUpdateAnimators); |
| 381 | } |
| 382 | |
Jason Monk | 79a9f2f | 2016-03-10 14:55:22 -0500 | [diff] [blame] | 383 | private final TouchAnimator.Listener mNonFirstPageListener = |
| 384 | new TouchAnimator.ListenerAdapter() { |
| 385 | @Override |
dongwan0605.kim | 03c9afa | 2017-01-03 15:40:07 +0900 | [diff] [blame] | 386 | public void onAnimationAtEnd() { |
| 387 | mQuickQsPanel.setVisibility(View.INVISIBLE); |
| 388 | } |
| 389 | |
| 390 | @Override |
Jason Monk | 79a9f2f | 2016-03-10 14:55:22 -0500 | [diff] [blame] | 391 | public void onAnimationStarted() { |
| 392 | mQuickQsPanel.setVisibility(View.VISIBLE); |
| 393 | } |
| 394 | }; |
| 395 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 396 | private Runnable mUpdateAnimators = new Runnable() { |
| 397 | @Override |
| 398 | public void run() { |
| 399 | updateAnimators(); |
Jason Monk | be8612d | 2016-03-30 16:19:06 -0400 | [diff] [blame] | 400 | setPosition(mLastPosition); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 401 | } |
| 402 | }; |
| 403 | } |