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