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