blob: a0ea7fae493db927a822af11f88c5bcad41cff46 [file] [log] [blame]
Jason Monk162011e2016-02-19 08:11:55 -05001/*
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
15package com.android.systemui.qs;
16
17import android.util.Log;
18import android.view.View;
Jason Monk8fb77872016-03-03 16:39:42 -050019import android.view.View.OnAttachStateChangeListener;
Jason Monk162011e2016-02-19 08:11:55 -050020import android.view.View.OnLayoutChangeListener;
Jason Monk9ffd9f62016-06-07 16:06:59 -040021
Jason Monkde850bb2017-02-01 19:26:30 -050022import com.android.systemui.Dependency;
Amin Shaikh5da602f2018-02-02 15:00:25 -050023import com.android.systemui.plugins.qs.QS;
24import com.android.systemui.plugins.qs.QSTile;
Jason Monk702e2eb2017-03-03 16:53:44 -050025import com.android.systemui.plugins.qs.QSTileView;
Jason Monk162011e2016-02-19 08:11:55 -050026import com.android.systemui.qs.PagedTileLayout.PageListener;
Jason Monk702e2eb2017-03-03 16:53:44 -050027import com.android.systemui.qs.QSHost.Callback;
Amin Shaikh5da602f2018-02-02 15:00:25 -050028import com.android.systemui.qs.QSPanel.QSTileLayout;
Jason Monk162011e2016-02-19 08:11:55 -050029import com.android.systemui.qs.TouchAnimator.Builder;
30import com.android.systemui.qs.TouchAnimator.Listener;
Jason Monk8fb77872016-03-03 16:39:42 -050031import com.android.systemui.tuner.TunerService;
32import com.android.systemui.tuner.TunerService.Tunable;
Matt Pietal5a19cb62019-10-30 12:31:07 -040033import com.android.systemui.util.Utils;
Jason Monk162011e2016-02-19 08:11:55 -050034
35import java.util.ArrayList;
36import java.util.Collection;
37
Jason Monk8fb77872016-03-03 16:39:42 -050038public class QSAnimator implements Callback, PageListener, Listener, OnLayoutChangeListener,
39 OnAttachStateChangeListener, Tunable {
Jason Monk162011e2016-02-19 08:11:55 -050040
41 private static final String TAG = "QSAnimator";
42
Jason Monk8fb77872016-03-03 16:39:42 -050043 private static final String ALLOW_FANCY_ANIMATION = "sysui_qs_fancy_anim";
44 private static final String MOVE_FULL_ROWS = "sysui_qs_move_whole_rows";
45
Jason Monkb46059a2016-06-30 14:22:42 -040046 public static final float EXPANDED_TILE_DELAY = .86f;
Jason Monk162011e2016-02-19 08:11:55 -050047
Rohan Shahdb2cfa32018-02-20 11:27:22 -080048
Jason Monk162011e2016-02-19 08:11:55 -050049 private final ArrayList<View> mAllViews = new ArrayList<>();
Rohan Shaha8401992018-01-25 18:22:44 -080050 /**
51 * List of {@link View}s representing Quick Settings that are being animated from the quick QS
52 * position to the normal QS panel.
53 */
54 private final ArrayList<View> mQuickQsViews = new ArrayList<>();
Jason Monk162011e2016-02-19 08:11:55 -050055 private final QuickQSPanel mQuickQsPanel;
56 private final QSPanel mQsPanel;
Jason Monk0ceef212016-11-02 14:05:23 -040057 private final QS mQs;
Jason Monk162011e2016-02-19 08:11:55 -050058
Jason Monk8fb77872016-03-03 16:39:42 -050059 private PagedTileLayout mPagedLayout;
60
Jason Monk162011e2016-02-19 08:11:55 -050061 private boolean mOnFirstPage = true;
62 private TouchAnimator mFirstPageAnimator;
63 private TouchAnimator mFirstPageDelayedAnimator;
Jason Monka97776a2016-03-09 15:13:02 -050064 private TouchAnimator mTranslationXAnimator;
65 private TouchAnimator mTranslationYAnimator;
Jason Monk162011e2016-02-19 08:11:55 -050066 private TouchAnimator mNonfirstPageAnimator;
Amin Shaikh5da602f2018-02-02 15:00:25 -050067 private TouchAnimator mNonfirstPageDelayedAnimator;
Jason Monkb46059a2016-06-30 14:22:42 -040068 private TouchAnimator mBrightnessAnimator;
Jason Monk162011e2016-02-19 08:11:55 -050069
Jason Monk8fb77872016-03-03 16:39:42 -050070 private boolean mOnKeyguard;
71
72 private boolean mAllowFancy;
73 private boolean mFullRows;
74 private int mNumQuickTiles;
Jason Monkbe8612d2016-03-30 16:19:06 -040075 private float mLastPosition;
Jason Monk9ffd9f62016-06-07 16:06:59 -040076 private QSTileHost mHost;
Selim Cinekb0fada62019-06-17 19:03:59 -070077 private boolean mShowCollapsedOnKeyguard;
Jason Monk8fb77872016-03-03 16:39:42 -050078
Jason Monk0ceef212016-11-02 14:05:23 -040079 public QSAnimator(QS qs, QuickQSPanel quickPanel, QSPanel panel) {
80 mQs = qs;
Jason Monk162011e2016-02-19 08:11:55 -050081 mQuickQsPanel = quickPanel;
82 mQsPanel = panel;
Jason Monk8fb77872016-03-03 16:39:42 -050083 mQsPanel.addOnAttachStateChangeListener(this);
Jason Monk0ceef212016-11-02 14:05:23 -040084 qs.getView().addOnLayoutChangeListener(this);
85 if (mQsPanel.isAttachedToWindow()) {
86 onViewAttachedToWindow(null);
87 }
Jason Monk162011e2016-02-19 08:11:55 -050088 QSTileLayout tileLayout = mQsPanel.getTileLayout();
89 if (tileLayout instanceof PagedTileLayout) {
Jason Monk8fb77872016-03-03 16:39:42 -050090 mPagedLayout = ((PagedTileLayout) tileLayout);
Jason Monk162011e2016-02-19 08:11:55 -050091 } else {
92 Log.w(TAG, "QS Not using page layout");
93 }
Amin Shaikh5da602f2018-02-02 15:00:25 -050094 panel.setPageListener(this);
Jason Monk162011e2016-02-19 08:11:55 -050095 }
96
Jason Monk51fb85a2016-03-28 14:06:04 -040097 public void onRtlChanged() {
98 updateAnimators();
99 }
100
Jason Monk8fb77872016-03-03 16:39:42 -0500101 public void setOnKeyguard(boolean onKeyguard) {
102 mOnKeyguard = onKeyguard;
Selim Cinekb0fada62019-06-17 19:03:59 -0700103 updateQQSVisibility();
Jason Monk8fb77872016-03-03 16:39:42 -0500104 if (mOnKeyguard) {
105 clearAnimationState();
106 }
107 }
108
Selim Cinekb0fada62019-06-17 19:03:59 -0700109
110 /**
111 * Sets whether or not the keyguard is currently being shown with a collapsed header.
112 */
113 void setShowCollapsedOnKeyguard(boolean showCollapsedOnKeyguard) {
114 mShowCollapsedOnKeyguard = showCollapsedOnKeyguard;
115 updateQQSVisibility();
116 setCurrentPosition();
117 }
118
119
120 private void setCurrentPosition() {
121 setPosition(mLastPosition);
122 }
123
124 private void updateQQSVisibility() {
125 mQuickQsPanel.setVisibility(mOnKeyguard
126 && !mShowCollapsedOnKeyguard ? View.INVISIBLE : View.VISIBLE);
127 }
128
Jason Monk162011e2016-02-19 08:11:55 -0500129 public void setHost(QSTileHost qsh) {
Jason Monk9ffd9f62016-06-07 16:06:59 -0400130 mHost = qsh;
Jason Monk162011e2016-02-19 08:11:55 -0500131 qsh.addCallback(this);
Jason Monka9df9992016-03-15 12:41:13 -0400132 updateAnimators();
Jason Monk162011e2016-02-19 08:11:55 -0500133 }
134
135 @Override
Jason Monk8fb77872016-03-03 16:39:42 -0500136 public void onViewAttachedToWindow(View v) {
Jason Monkde850bb2017-02-01 19:26:30 -0500137 Dependency.get(TunerService.class).addTunable(this, ALLOW_FANCY_ANIMATION,
Jason Monk8fb77872016-03-03 16:39:42 -0500138 MOVE_FULL_ROWS, QuickQSPanel.NUM_QUICK_TILES);
139 }
140
141 @Override
142 public void onViewDetachedFromWindow(View v) {
Jason Monk9ffd9f62016-06-07 16:06:59 -0400143 if (mHost != null) {
144 mHost.removeCallback(this);
145 }
Jason Monkde850bb2017-02-01 19:26:30 -0500146 Dependency.get(TunerService.class).removeTunable(this);
Jason Monk8fb77872016-03-03 16:39:42 -0500147 }
148
149 @Override
150 public void onTuningChanged(String key, String newValue) {
151 if (ALLOW_FANCY_ANIMATION.equals(key)) {
Henrik Baarda2c86e82019-03-14 12:23:04 +0100152 mAllowFancy = TunerService.parseIntegerSwitch(newValue, true);
Jason Monk8fb77872016-03-03 16:39:42 -0500153 if (!mAllowFancy) {
154 clearAnimationState();
155 }
156 } else if (MOVE_FULL_ROWS.equals(key)) {
Henrik Baarda2c86e82019-03-14 12:23:04 +0100157 mFullRows = TunerService.parseIntegerSwitch(newValue, true);
Jason Monk8fb77872016-03-03 16:39:42 -0500158 } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) {
Fabian Kozynskic8d8f052019-09-09 09:15:04 -0400159 mNumQuickTiles = QuickQSPanel.parseNumTiles(newValue);
Jason Monk8fb77872016-03-03 16:39:42 -0500160 clearAnimationState();
161 }
162 updateAnimators();
163 }
164
165 @Override
Jason Monk66eaf312016-02-25 12:29:29 -0500166 public void onPageChanged(boolean isFirst) {
167 if (mOnFirstPage == isFirst) return;
168 if (!isFirst) {
Jason Monk162011e2016-02-19 08:11:55 -0500169 clearAnimationState();
170 }
Jason Monk66eaf312016-02-25 12:29:29 -0500171 mOnFirstPage = isFirst;
Jason Monk162011e2016-02-19 08:11:55 -0500172 }
173
174 private void updateAnimators() {
175 TouchAnimator.Builder firstPageBuilder = new Builder();
Jason Monkfa0f47a2016-03-08 09:17:56 -0500176 TouchAnimator.Builder translationXBuilder = new Builder();
Jason Monk162011e2016-02-19 08:11:55 -0500177 TouchAnimator.Builder translationYBuilder = new Builder();
Jason Monk98196b02016-03-14 10:33:02 -0400178
Jason Monka9df9992016-03-15 12:41:13 -0400179 if (mQsPanel.getHost() == null) return;
Jason Monk702e2eb2017-03-03 16:53:44 -0500180 Collection<QSTile> tiles = mQsPanel.getHost().getTiles();
Jason Monk162011e2016-02-19 08:11:55 -0500181 int count = 0;
182 int[] loc1 = new int[2];
183 int[] loc2 = new int[2];
Jason Monk789e9c02016-03-28 16:00:09 -0400184 int lastXDiff = 0;
Jason Monk789e9c02016-03-28 16:00:09 -0400185 int lastX = 0;
Jason Monk98196b02016-03-14 10:33:02 -0400186
Jason Monkbc8ffc22016-03-09 10:58:49 -0500187 clearAnimationState();
Jason Monk162011e2016-02-19 08:11:55 -0500188 mAllViews.clear();
Rohan Shaha8401992018-01-25 18:22:44 -0800189 mQuickQsViews.clear();
Jason Monk98196b02016-03-14 10:33:02 -0400190
Jason Monkf13413e2017-02-15 15:49:32 -0500191 QSTileLayout tileLayout = mQsPanel.getTileLayout();
192 mAllViews.add((View) tileLayout);
Jason Monkbdefffd2017-06-26 11:22:21 -0400193 int height = mQs.getView() != null ? mQs.getView().getMeasuredHeight() : 0;
Fabian Kozynski802279f2018-09-07 13:44:54 -0400194 int width = mQs.getView() != null ? mQs.getView().getMeasuredWidth() : 0;
Jason Monkbdefffd2017-06-26 11:22:21 -0400195 int heightDiff = height - mQs.getHeader().getBottom()
Jason Monke5b770e2017-03-03 21:49:29 -0500196 + mQs.getHeader().getPaddingBottom();
197 firstPageBuilder.addFloat(tileLayout, "translationY", heightDiff, 0);
Jason Monk98196b02016-03-14 10:33:02 -0400198
Jason Monk702e2eb2017-03-03 16:53:44 -0500199 for (QSTile tile : tiles) {
200 QSTileView tileView = mQsPanel.getTileView(tile);
Jason Monk6e6af2c2016-09-20 14:34:26 -0400201 if (tileView == null) {
202 Log.e(TAG, "tileView is null " + tile.getTileSpec());
203 continue;
204 }
Xiaohui Chen2f3551b2016-04-07 10:37:25 -0700205 final View tileIcon = tileView.getIcon().getIconView();
Jason Monk0ceef212016-11-02 14:05:23 -0400206 View view = mQs.getView();
Fabian Kozynski802279f2018-09-07 13:44:54 -0400207
208 // This case: less tiles to animate in small displays.
209 if (count < mQuickQsPanel.getTileLayout().getNumVisibleTiles() && mAllowFancy) {
Jason Monk162011e2016-02-19 08:11:55 -0500210 // Quick tiles.
Jason Monk9f1422d2017-03-08 09:11:51 -0500211 QSTileView quickTileView = mQuickQsPanel.getTileView(tile);
212 if (quickTileView == null) continue;
Jason Monk162011e2016-02-19 08:11:55 -0500213
Jason Monk789e9c02016-03-28 16:00:09 -0400214 lastX = loc1[0];
Jason Monk0ceef212016-11-02 14:05:23 -0400215 getRelativePosition(loc1, quickTileView.getIcon().getIconView(), view);
216 getRelativePosition(loc2, tileIcon, view);
Jason Monk162011e2016-02-19 08:11:55 -0500217 final int xDiff = loc2[0] - loc1[0];
218 final int yDiff = loc2[1] - loc1[1];
Jason Monk789e9c02016-03-28 16:00:09 -0400219 lastXDiff = loc1[0] - lastX;
Jason Monk162011e2016-02-19 08:11:55 -0500220
Fabian Kozynski802279f2018-09-07 13:44:54 -0400221 if (count < tileLayout.getNumVisibleTiles()) {
222 // Move the quick tile right from its location to the new one.
223 translationXBuilder.addFloat(quickTileView, "translationX", 0, xDiff);
224 translationYBuilder.addFloat(quickTileView, "translationY", 0, yDiff);
Jason Monk162011e2016-02-19 08:11:55 -0500225
Fabian Kozynski802279f2018-09-07 13:44:54 -0400226 // Counteract the parent translation on the tile. So we have a static base to
227 // animate the label position off from.
228 //firstPageBuilder.addFloat(tileView, "translationY", mQsPanel.getHeight(), 0);
229
230 // Move the real tile from the quick tile position to its final
231 // location.
232 translationXBuilder.addFloat(tileView, "translationX", -xDiff, 0);
233 translationYBuilder.addFloat(tileView, "translationY", -yDiff, 0);
234
235 } else { // These tiles disappear when expanding
236 firstPageBuilder.addFloat(quickTileView, "alpha", 1, 0);
237 translationYBuilder.addFloat(quickTileView, "translationY", 0, yDiff);
Fabian Kozynskid9e8aa32019-04-12 10:09:48 -0400238
239 // xDiff is negative here and this makes it "more" negative
240 final int translationX = mQsPanel.isLayoutRtl() ? xDiff - width : xDiff + width;
241 translationXBuilder.addFloat(quickTileView, "translationX", 0,
242 translationX);
Fabian Kozynski802279f2018-09-07 13:44:54 -0400243 }
Jason Monk162011e2016-02-19 08:11:55 -0500244
Rohan Shaha8401992018-01-25 18:22:44 -0800245 mQuickQsViews.add(tileView.getIconWithBackground());
Jason Monk0f0de132016-12-19 15:36:13 -0500246 mAllViews.add(tileView.getIcon());
Jason Monk162011e2016-02-19 08:11:55 -0500247 mAllViews.add(quickTileView);
Jason Monk8fb77872016-03-03 16:39:42 -0500248 } else if (mFullRows && isIconInAnimatedRow(count)) {
Jason Monk789e9c02016-03-28 16:00:09 -0400249 // TODO: Refactor some of this, it shares a lot with the above block.
250 // Move the last tile position over by the last difference between quick tiles.
251 // This makes the extra icons seems as if they are coming from positions in the
252 // quick panel.
253 loc1[0] += lastXDiff;
Jason Monk0ceef212016-11-02 14:05:23 -0400254 getRelativePosition(loc2, tileIcon, view);
Jason Monk789e9c02016-03-28 16:00:09 -0400255 final int xDiff = loc2[0] - loc1[0];
256 final int yDiff = loc2[1] - loc1[1];
257
Fabian Kozynski52728302018-09-07 12:45:59 +0000258 firstPageBuilder.addFloat(tileView, "translationY", heightDiff, 0);
Fabian Kozynski40c9f0d2018-08-29 16:21:42 -0400259 translationXBuilder.addFloat(tileView, "translationX", -xDiff, 0);
Fabian Kozynski52728302018-09-07 12:45:59 +0000260 translationYBuilder.addFloat(tileView, "translationY", -yDiff, 0);
261 translationYBuilder.addFloat(tileIcon, "translationY", -yDiff, 0);
Jason Monk789e9c02016-03-28 16:00:09 -0400262
Jason Monk8fb77872016-03-03 16:39:42 -0500263 mAllViews.add(tileIcon);
Jason Monk98196b02016-03-14 10:33:02 -0400264 } else {
Jason Monkb46059a2016-06-30 14:22:42 -0400265 firstPageBuilder.addFloat(tileView, "alpha", 0, 1);
Jason Monke5b770e2017-03-03 21:49:29 -0500266 firstPageBuilder.addFloat(tileView, "translationY", -heightDiff, 0);
Jason Monk162011e2016-02-19 08:11:55 -0500267 }
268 mAllViews.add(tileView);
Jason Monk8fb77872016-03-03 16:39:42 -0500269 count++;
Jason Monk162011e2016-02-19 08:11:55 -0500270 }
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400271
272
Matt Pietal5a19cb62019-10-30 12:31:07 -0400273 if (Utils.useQsMediaPlayer(mQsPanel.getContext())) {
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400274 View qsMediaView = mQsPanel.getMediaPanel();
275 View qqsMediaView = mQuickQsPanel.getMediaPlayer().getView();
276 translationXBuilder.addFloat(qsMediaView, "alpha", 0, 1);
277 translationXBuilder.addFloat(qqsMediaView, "alpha", 1, 0);
278 }
279
Jason Monk8fb77872016-03-03 16:39:42 -0500280 if (mAllowFancy) {
Jason Monkb46059a2016-06-30 14:22:42 -0400281 // Make brightness appear static position and alpha in through second half.
282 View brightness = mQsPanel.getBrightnessView();
283 if (brightness != null) {
Jason Monke5b770e2017-03-03 21:49:29 -0500284 firstPageBuilder.addFloat(brightness, "translationY", heightDiff, 0);
Jason Monkb46059a2016-06-30 14:22:42 -0400285 mBrightnessAnimator = new TouchAnimator.Builder()
286 .addFloat(brightness, "alpha", 0, 1)
287 .setStartDelay(.5f)
288 .build();
289 mAllViews.add(brightness);
290 } else {
291 mBrightnessAnimator = null;
292 }
Jason Monk98196b02016-03-14 10:33:02 -0400293 mFirstPageAnimator = firstPageBuilder
294 .setListener(this)
295 .build();
296 // Fade in the tiles/labels as we reach the final position.
297 mFirstPageDelayedAnimator = new TouchAnimator.Builder()
298 .setStartDelay(EXPANDED_TILE_DELAY)
Jason Monkf13413e2017-02-15 15:49:32 -0500299 .addFloat(tileLayout, "alpha", 0, 1)
Jason Monkce4be852017-03-27 17:09:30 -0400300 .addFloat(mQsPanel.getDivider(), "alpha", 0, 1)
Jason Monkdf36aed2016-07-25 11:21:56 -0400301 .addFloat(mQsPanel.getFooter().getView(), "alpha", 0, 1).build();
Jason Monkce4be852017-03-27 17:09:30 -0400302 mAllViews.add(mQsPanel.getDivider());
Jason Monkdf36aed2016-07-25 11:21:56 -0400303 mAllViews.add(mQsPanel.getFooter().getView());
Jason Monk08a79192016-08-02 13:36:52 -0400304 float px = 0;
305 float py = 1;
306 if (tiles.size() <= 3) {
307 px = 1;
308 } else if (tiles.size() <= 6) {
309 px = .4f;
310 }
311 PathInterpolatorBuilder interpolatorBuilder = new PathInterpolatorBuilder(0, 0, px, py);
Jason Monka97776a2016-03-09 15:13:02 -0500312 translationXBuilder.setInterpolator(interpolatorBuilder.getXInterpolator());
313 translationYBuilder.setInterpolator(interpolatorBuilder.getYInterpolator());
314 mTranslationXAnimator = translationXBuilder.build();
315 mTranslationYAnimator = translationYBuilder.build();
Jason Monk8fb77872016-03-03 16:39:42 -0500316 }
Jason Monk162011e2016-02-19 08:11:55 -0500317 mNonfirstPageAnimator = new TouchAnimator.Builder()
318 .addFloat(mQuickQsPanel, "alpha", 1, 0)
Jason Monkce4be852017-03-27 17:09:30 -0400319 .addFloat(mQsPanel.getDivider(), "alpha", 0, 1)
Jason Monk79a9f2f2016-03-10 14:55:22 -0500320 .setListener(mNonFirstPageListener)
Jason Monk162011e2016-02-19 08:11:55 -0500321 .setEndDelay(.5f)
322 .build();
Amin Shaikh5da602f2018-02-02 15:00:25 -0500323 mNonfirstPageDelayedAnimator = new TouchAnimator.Builder()
324 .setStartDelay(.14f)
325 .addFloat(tileLayout, "alpha", 0, 1).build();
Jason Monk162011e2016-02-19 08:11:55 -0500326 }
327
Jason Monk8fb77872016-03-03 16:39:42 -0500328 private boolean isIconInAnimatedRow(int count) {
329 if (mPagedLayout == null) {
330 return false;
331 }
332 final int columnCount = mPagedLayout.getColumnCount();
333 return count < ((mNumQuickTiles + columnCount - 1) / columnCount) * columnCount;
334 }
335
Jason Monk162011e2016-02-19 08:11:55 -0500336 private void getRelativePosition(int[] loc1, View view, View parent) {
337 loc1[0] = 0 + view.getWidth() / 2;
338 loc1[1] = 0;
339 getRelativePositionInt(loc1, view, parent);
340 }
341
342 private void getRelativePositionInt(int[] loc1, View view, View parent) {
343 if(view == parent || view == null) return;
Jason Monk61d118d2016-05-20 14:44:16 -0400344 // Ignore tile pages as they can have some offset we don't want to take into account in
345 // RTL.
346 if (!(view instanceof PagedTileLayout.TilePage)) {
347 loc1[0] += view.getLeft();
348 loc1[1] += view.getTop();
349 }
Jason Monk162011e2016-02-19 08:11:55 -0500350 getRelativePositionInt(loc1, (View) view.getParent(), parent);
351 }
352
353 public void setPosition(float position) {
354 if (mFirstPageAnimator == null) return;
Jason Monk8fb77872016-03-03 16:39:42 -0500355 if (mOnKeyguard) {
Selim Cinekb0fada62019-06-17 19:03:59 -0700356 if (mShowCollapsedOnKeyguard) {
357 position = 0;
358 } else {
359 position = 1;
360 }
Jason Monk8fb77872016-03-03 16:39:42 -0500361 }
Jason Monkbe8612d2016-03-30 16:19:06 -0400362 mLastPosition = position;
Jason Monk8fb77872016-03-03 16:39:42 -0500363 if (mOnFirstPage && mAllowFancy) {
Jason Monk162011e2016-02-19 08:11:55 -0500364 mQuickQsPanel.setAlpha(1);
365 mFirstPageAnimator.setPosition(position);
366 mFirstPageDelayedAnimator.setPosition(position);
Jason Monka97776a2016-03-09 15:13:02 -0500367 mTranslationXAnimator.setPosition(position);
368 mTranslationYAnimator.setPosition(position);
Jason Monkb46059a2016-06-30 14:22:42 -0400369 if (mBrightnessAnimator != null) {
370 mBrightnessAnimator.setPosition(position);
371 }
Jason Monk162011e2016-02-19 08:11:55 -0500372 } else {
373 mNonfirstPageAnimator.setPosition(position);
Amin Shaikh5da602f2018-02-02 15:00:25 -0500374 mNonfirstPageDelayedAnimator.setPosition(position);
Jason Monk162011e2016-02-19 08:11:55 -0500375 }
376 }
377
378 @Override
379 public void onAnimationAtStart() {
Jason Monkdf5459d2016-02-29 10:47:35 -0500380 mQuickQsPanel.setVisibility(View.VISIBLE);
Jason Monk162011e2016-02-19 08:11:55 -0500381 }
382
383 @Override
384 public void onAnimationAtEnd() {
385 mQuickQsPanel.setVisibility(View.INVISIBLE);
Rohan Shaha8401992018-01-25 18:22:44 -0800386 final int N = mQuickQsViews.size();
Jason Monke80654b2016-02-24 14:53:57 -0500387 for (int i = 0; i < N; i++) {
Rohan Shaha8401992018-01-25 18:22:44 -0800388 mQuickQsViews.get(i).setVisibility(View.VISIBLE);
Jason Monke80654b2016-02-24 14:53:57 -0500389 }
Jason Monk162011e2016-02-19 08:11:55 -0500390 }
391
392 @Override
393 public void onAnimationStarted() {
Selim Cinekb0fada62019-06-17 19:03:59 -0700394 updateQQSVisibility();
Jason Monke80654b2016-02-24 14:53:57 -0500395 if (mOnFirstPage) {
Rohan Shaha8401992018-01-25 18:22:44 -0800396 final int N = mQuickQsViews.size();
Jason Monke80654b2016-02-24 14:53:57 -0500397 for (int i = 0; i < N; i++) {
Rohan Shaha8401992018-01-25 18:22:44 -0800398 mQuickQsViews.get(i).setVisibility(View.INVISIBLE);
Jason Monke80654b2016-02-24 14:53:57 -0500399 }
400 }
Jason Monk162011e2016-02-19 08:11:55 -0500401 }
402
403 private void clearAnimationState() {
404 final int N = mAllViews.size();
405 mQuickQsPanel.setAlpha(0);
406 for (int i = 0; i < N; i++) {
407 View v = mAllViews.get(i);
408 v.setAlpha(1);
Jason Monka2bd0462016-04-12 13:55:16 -0400409 v.setTranslationX(0);
410 v.setTranslationY(0);
Jason Monk162011e2016-02-19 08:11:55 -0500411 }
Rohan Shaha8401992018-01-25 18:22:44 -0800412 final int N2 = mQuickQsViews.size();
Jason Monk8fb77872016-03-03 16:39:42 -0500413 for (int i = 0; i < N2; i++) {
Rohan Shaha8401992018-01-25 18:22:44 -0800414 mQuickQsViews.get(i).setVisibility(View.VISIBLE);
Jason Monk8fb77872016-03-03 16:39:42 -0500415 }
Jason Monk162011e2016-02-19 08:11:55 -0500416 }
417
418 @Override
419 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
420 int oldTop, int oldRight, int oldBottom) {
Jason Monk51fb85a2016-03-28 14:06:04 -0400421 mQsPanel.post(mUpdateAnimators);
Jason Monk162011e2016-02-19 08:11:55 -0500422 }
423
424 @Override
425 public void onTilesChanged() {
426 // Give the QS panels a moment to generate their new tiles, then create all new animators
427 // hooked up to the new views.
428 mQsPanel.post(mUpdateAnimators);
429 }
430
Jason Monk79a9f2f2016-03-10 14:55:22 -0500431 private final TouchAnimator.Listener mNonFirstPageListener =
432 new TouchAnimator.ListenerAdapter() {
433 @Override
dongwan0605.kim03c9afa2017-01-03 15:40:07 +0900434 public void onAnimationAtEnd() {
435 mQuickQsPanel.setVisibility(View.INVISIBLE);
436 }
437
438 @Override
Jason Monk79a9f2f2016-03-10 14:55:22 -0500439 public void onAnimationStarted() {
440 mQuickQsPanel.setVisibility(View.VISIBLE);
441 }
442 };
443
Jason Monk162011e2016-02-19 08:11:55 -0500444 private Runnable mUpdateAnimators = new Runnable() {
445 @Override
446 public void run() {
447 updateAnimators();
Selim Cinekb0fada62019-06-17 19:03:59 -0700448 setCurrentPosition();
Jason Monk162011e2016-02-19 08:11:55 -0500449 }
450 };
451}