Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.notification; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ValueAnimator; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 23 | import android.graphics.Matrix; |
| 24 | import android.graphics.Rect; |
| 25 | import android.os.RemoteException; |
| 26 | import android.util.MathUtils; |
| 27 | import android.view.IRemoteAnimationFinishedCallback; |
| 28 | import android.view.IRemoteAnimationRunner; |
| 29 | import android.view.RemoteAnimationAdapter; |
| 30 | import android.view.RemoteAnimationTarget; |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 31 | import android.view.SyncRtSurfaceTransactionApplier; |
| 32 | import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams; |
Selim Cinek | ab4589a | 2019-04-29 18:42:59 -0700 | [diff] [blame] | 33 | import android.view.View; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 34 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 35 | import com.android.internal.policy.ScreenDecorationsUtils; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 36 | import com.android.systemui.Interpolators; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 37 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 38 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 39 | import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment; |
| 40 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
| 41 | import com.android.systemui.statusbar.phone.StatusBarWindowView; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 42 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 43 | /** |
| 44 | * A class that allows activities to be launched in a seamless way where the notification |
| 45 | * transforms nicely into the starting window. |
| 46 | */ |
| 47 | public class ActivityLaunchAnimator { |
| 48 | |
| 49 | private static final int ANIMATION_DURATION = 400; |
| 50 | public static final long ANIMATION_DURATION_FADE_CONTENT = 67; |
| 51 | public static final long ANIMATION_DURATION_FADE_APP = 200; |
| 52 | public static final long ANIMATION_DELAY_ICON_FADE_IN = ANIMATION_DURATION - |
| 53 | CollapsedStatusBarFragment.FADE_IN_DURATION - CollapsedStatusBarFragment.FADE_IN_DELAY |
| 54 | - 16; |
Selim Cinek | fc5c199 | 2018-01-29 12:40:32 -0800 | [diff] [blame] | 55 | private static final long LAUNCH_TIMEOUT = 500; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 56 | private final NotificationPanelView mNotificationPanel; |
| 57 | private final NotificationListContainer mNotificationContainer; |
| 58 | private final StatusBarWindowView mStatusBarWindow; |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 59 | private final float mWindowCornerRadius; |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 60 | private Callback mCallback; |
Selim Cinek | fc5c199 | 2018-01-29 12:40:32 -0800 | [diff] [blame] | 61 | private final Runnable mTimeoutRunnable = () -> { |
| 62 | setAnimationPending(false); |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 63 | mCallback.onExpandAnimationTimedOut(); |
Selim Cinek | fc5c199 | 2018-01-29 12:40:32 -0800 | [diff] [blame] | 64 | }; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 65 | private boolean mAnimationPending; |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 66 | private boolean mAnimationRunning; |
| 67 | private boolean mIsLaunchForActivity; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 68 | |
| 69 | public ActivityLaunchAnimator(StatusBarWindowView statusBarWindow, |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 70 | Callback callback, |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 71 | NotificationPanelView notificationPanel, |
| 72 | NotificationListContainer container) { |
| 73 | mNotificationPanel = notificationPanel; |
| 74 | mNotificationContainer = container; |
| 75 | mStatusBarWindow = statusBarWindow; |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 76 | mCallback = callback; |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 77 | mWindowCornerRadius = ScreenDecorationsUtils |
| 78 | .getWindowCornerRadius(statusBarWindow.getResources()); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 81 | public RemoteAnimationAdapter getLaunchAnimation( |
Selim Cinek | ab4589a | 2019-04-29 18:42:59 -0700 | [diff] [blame] | 82 | View sourceView, boolean occluded) { |
| 83 | if (!(sourceView instanceof ExpandableNotificationRow) || !mCallback.areLaunchAnimationsEnabled() || occluded) { |
Jorim Jaggi | 77d0f36c | 2018-03-16 17:49:49 +0100 | [diff] [blame] | 84 | return null; |
| 85 | } |
Selim Cinek | ab4589a | 2019-04-29 18:42:59 -0700 | [diff] [blame] | 86 | AnimationRunner animationRunner = new AnimationRunner( |
| 87 | (ExpandableNotificationRow) sourceView); |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 88 | return new RemoteAnimationAdapter(animationRunner, ANIMATION_DURATION, |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 89 | ANIMATION_DURATION - 150 /* statusBarTransitionDelay */); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 92 | public boolean isAnimationPending() { |
| 93 | return mAnimationPending; |
| 94 | } |
| 95 | |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Set the launch result the intent requested |
| 98 | * |
| 99 | * @param launchResult the launch result |
| 100 | * @param wasIntentActivity was this launch for an activity |
| 101 | */ |
| 102 | public void setLaunchResult(int launchResult, boolean wasIntentActivity) { |
| 103 | mIsLaunchForActivity = wasIntentActivity; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 104 | setAnimationPending((launchResult == ActivityManager.START_TASK_TO_FRONT |
| 105 | || launchResult == ActivityManager.START_SUCCESS) |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 106 | && mCallback.areLaunchAnimationsEnabled()); |
| 107 | } |
| 108 | |
| 109 | public boolean isLaunchForActivity() { |
| 110 | return mIsLaunchForActivity; |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | private void setAnimationPending(boolean pending) { |
| 114 | mAnimationPending = pending; |
| 115 | mStatusBarWindow.setExpandAnimationPending(pending); |
Selim Cinek | fc5c199 | 2018-01-29 12:40:32 -0800 | [diff] [blame] | 116 | if (pending) { |
| 117 | mStatusBarWindow.postDelayed(mTimeoutRunnable, LAUNCH_TIMEOUT); |
| 118 | } else { |
| 119 | mStatusBarWindow.removeCallbacks(mTimeoutRunnable); |
| 120 | } |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 123 | public boolean isAnimationRunning() { |
| 124 | return mAnimationRunning; |
| 125 | } |
| 126 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 127 | class AnimationRunner extends IRemoteAnimationRunner.Stub { |
| 128 | |
| 129 | private final ExpandableNotificationRow mSourceNotification; |
| 130 | private final ExpandAnimationParameters mParams; |
| 131 | private final Rect mWindowCrop = new Rect(); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 132 | private final float mNotificationCornerRadius; |
| 133 | private float mCornerRadius; |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 134 | private boolean mIsFullScreenLaunch = true; |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 135 | private final SyncRtSurfaceTransactionApplier mSyncRtTransactionApplier; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 136 | |
| 137 | public AnimationRunner(ExpandableNotificationRow sourceNofitication) { |
| 138 | mSourceNotification = sourceNofitication; |
| 139 | mParams = new ExpandAnimationParameters(); |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 140 | mSyncRtTransactionApplier = new SyncRtSurfaceTransactionApplier(mSourceNotification); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 141 | mNotificationCornerRadius = Math.max(mSourceNotification.getCurrentTopRoundness(), |
| 142 | mSourceNotification.getCurrentBottomRoundness()); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void onAnimationStart(RemoteAnimationTarget[] remoteAnimationTargets, |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame^] | 147 | RemoteAnimationTarget[] remoteAnimationWallpaperTargets, |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 148 | IRemoteAnimationFinishedCallback iRemoteAnimationFinishedCallback) |
| 149 | throws RemoteException { |
| 150 | mSourceNotification.post(() -> { |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 151 | RemoteAnimationTarget primary = getPrimaryRemoteAnimationTarget( |
| 152 | remoteAnimationTargets); |
| 153 | if (primary == null) { |
| 154 | setAnimationPending(false); |
| 155 | invokeCallback(iRemoteAnimationFinishedCallback); |
Selim Cinek | 7c236e9 | 2019-07-26 21:47:19 -0700 | [diff] [blame] | 156 | mNotificationPanel.collapse(false /* delayed */, 1.0f /* speedUpFactor */); |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
| 160 | setExpandAnimationRunning(true); |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 161 | mIsFullScreenLaunch = primary.position.y == 0 |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 162 | && primary.sourceContainerBounds.height() |
| 163 | >= mNotificationPanel.getHeight(); |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 164 | if (!mIsFullScreenLaunch) { |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 165 | mNotificationPanel.collapseWithDuration(ANIMATION_DURATION); |
| 166 | } |
| 167 | ValueAnimator anim = ValueAnimator.ofFloat(0, 1); |
| 168 | mParams.startPosition = mSourceNotification.getLocationOnScreen(); |
| 169 | mParams.startTranslationZ = mSourceNotification.getTranslationZ(); |
| 170 | mParams.startClipTopAmount = mSourceNotification.getClipTopAmount(); |
| 171 | if (mSourceNotification.isChildInGroup()) { |
| 172 | int parentClip = mSourceNotification |
| 173 | .getNotificationParent().getClipTopAmount(); |
| 174 | mParams.parentStartClipTopAmount = parentClip; |
| 175 | // We need to calculate how much the child is clipped by the parent |
| 176 | // because children always have 0 clipTopAmount |
| 177 | if (parentClip != 0) { |
| 178 | float childClip = parentClip |
| 179 | - mSourceNotification.getTranslationY(); |
| 180 | if (childClip > 0.0f) { |
| 181 | mParams.startClipTopAmount = (int) Math.ceil(childClip); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 182 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 183 | } |
| 184 | } |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 185 | int targetWidth = primary.sourceContainerBounds.width(); |
| 186 | int notificationHeight = mSourceNotification.getActualHeight() |
| 187 | - mSourceNotification.getClipBottomAmount(); |
| 188 | int notificationWidth = mSourceNotification.getWidth(); |
| 189 | anim.setDuration(ANIMATION_DURATION); |
| 190 | anim.setInterpolator(Interpolators.LINEAR); |
| 191 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 192 | @Override |
| 193 | public void onAnimationUpdate(ValueAnimator animation) { |
| 194 | mParams.linearProgress = animation.getAnimatedFraction(); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 195 | float progress = Interpolators.FAST_OUT_SLOW_IN.getInterpolation( |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 196 | mParams.linearProgress); |
| 197 | int newWidth = (int) MathUtils.lerp(notificationWidth, |
| 198 | targetWidth, progress); |
| 199 | mParams.left = (int) ((targetWidth - newWidth) / 2.0f); |
| 200 | mParams.right = mParams.left + newWidth; |
| 201 | mParams.top = (int) MathUtils.lerp(mParams.startPosition[1], |
| 202 | primary.position.y, progress); |
| 203 | mParams.bottom = (int) MathUtils.lerp(mParams.startPosition[1] |
| 204 | + notificationHeight, |
| 205 | primary.position.y + primary.sourceContainerBounds.bottom, |
| 206 | progress); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 207 | mCornerRadius = MathUtils.lerp(mNotificationCornerRadius, |
| 208 | mWindowCornerRadius, progress); |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 209 | applyParamsToWindow(primary); |
| 210 | applyParamsToNotification(mParams); |
| 211 | applyParamsToNotificationList(mParams); |
| 212 | } |
| 213 | }); |
| 214 | anim.addListener(new AnimatorListenerAdapter() { |
| 215 | @Override |
| 216 | public void onAnimationEnd(Animator animation) { |
| 217 | setExpandAnimationRunning(false); |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 218 | invokeCallback(iRemoteAnimationFinishedCallback); |
| 219 | } |
| 220 | }); |
| 221 | anim.start(); |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 222 | setAnimationPending(false); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 223 | }); |
| 224 | } |
| 225 | |
Jorim Jaggi | 9550772 | 2018-04-24 16:33:56 +0200 | [diff] [blame] | 226 | private void invokeCallback(IRemoteAnimationFinishedCallback callback) { |
| 227 | try { |
| 228 | callback.onAnimationFinished(); |
| 229 | } catch (RemoteException e) { |
| 230 | e.printStackTrace(); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | private RemoteAnimationTarget getPrimaryRemoteAnimationTarget( |
| 235 | RemoteAnimationTarget[] remoteAnimationTargets) { |
| 236 | RemoteAnimationTarget primary = null; |
| 237 | for (RemoteAnimationTarget app : remoteAnimationTargets) { |
| 238 | if (app.mode == RemoteAnimationTarget.MODE_OPENING) { |
| 239 | primary = app; |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | return primary; |
| 244 | } |
| 245 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 246 | private void setExpandAnimationRunning(boolean running) { |
| 247 | mNotificationPanel.setLaunchingNotification(running); |
| 248 | mSourceNotification.setExpandAnimationRunning(running); |
| 249 | mStatusBarWindow.setExpandAnimationRunning(running); |
| 250 | mNotificationContainer.setExpandingNotification(running ? mSourceNotification : null); |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 251 | mAnimationRunning = running; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 252 | if (!running) { |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 253 | mCallback.onExpandAnimationFinished(mIsFullScreenLaunch); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 254 | applyParamsToNotification(null); |
| 255 | applyParamsToNotificationList(null); |
| 256 | } |
| 257 | |
| 258 | } |
| 259 | |
| 260 | private void applyParamsToNotificationList(ExpandAnimationParameters params) { |
| 261 | mNotificationContainer.applyExpandAnimationParams(params); |
| 262 | mNotificationPanel.applyExpandAnimationParams(params); |
| 263 | } |
| 264 | |
| 265 | private void applyParamsToNotification(ExpandAnimationParameters params) { |
| 266 | mSourceNotification.applyExpandAnimationParams(params); |
| 267 | } |
| 268 | |
| 269 | private void applyParamsToWindow(RemoteAnimationTarget app) { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 270 | Matrix m = new Matrix(); |
| 271 | m.postTranslate(0, (float) (mParams.top - app.position.y)); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 272 | mWindowCrop.set(mParams.left, 0, mParams.right, mParams.getHeight()); |
Jorim Jaggi | 5bb571d | 2018-11-06 14:42:04 +0100 | [diff] [blame] | 273 | SurfaceParams params = new SurfaceParams(app.leash, 1f /* alpha */, m, mWindowCrop, |
Jorim Jaggi | 6768488 | 2019-01-22 17:36:34 +0100 | [diff] [blame] | 274 | app.prefixOrderIndex, mCornerRadius, true /* visible */); |
Jorim Jaggi | 64be98d | 2018-04-26 23:23:29 +0200 | [diff] [blame] | 275 | mSyncRtTransactionApplier.scheduleApply(params); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public void onAnimationCancelled() throws RemoteException { |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 280 | mSourceNotification.post(() -> { |
| 281 | setAnimationPending(false); |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 282 | mCallback.onLaunchAnimationCancelled(); |
Selim Cinek | 7e222c3c | 2018-01-25 12:22:41 -0800 | [diff] [blame] | 283 | }); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 284 | } |
| 285 | }; |
| 286 | |
| 287 | public static class ExpandAnimationParameters { |
| 288 | float linearProgress; |
| 289 | int[] startPosition; |
| 290 | float startTranslationZ; |
| 291 | int left; |
| 292 | int top; |
| 293 | int right; |
| 294 | int bottom; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 295 | int startClipTopAmount; |
| 296 | int parentStartClipTopAmount; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 297 | |
| 298 | public ExpandAnimationParameters() { |
| 299 | } |
| 300 | |
| 301 | public int getTop() { |
| 302 | return top; |
| 303 | } |
| 304 | |
Selim Cinek | c42db8d | 2018-12-04 13:29:25 -0800 | [diff] [blame] | 305 | public int getBottom() { |
| 306 | return bottom; |
| 307 | } |
| 308 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 309 | public int getWidth() { |
| 310 | return right - left; |
| 311 | } |
| 312 | |
| 313 | public int getHeight() { |
| 314 | return bottom - top; |
| 315 | } |
| 316 | |
| 317 | public int getTopChange() { |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 318 | // We need this compensation to ensure that the QS moves in sync. |
| 319 | int clipTopAmountCompensation = 0; |
| 320 | if (startClipTopAmount != 0.0f) { |
| 321 | clipTopAmountCompensation = (int) MathUtils.lerp(0, startClipTopAmount, |
| 322 | Interpolators.FAST_OUT_SLOW_IN.getInterpolation(linearProgress)); |
| 323 | } |
| 324 | return Math.min(top - startPosition[1] - clipTopAmountCompensation, 0); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 327 | public float getProgress() { |
| 328 | return linearProgress; |
| 329 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 330 | |
| 331 | public float getProgress(long delay, long duration) { |
| 332 | return MathUtils.constrain((linearProgress * ANIMATION_DURATION - delay) |
| 333 | / duration, 0.0f, 1.0f); |
| 334 | } |
| 335 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 336 | public int getStartClipTopAmount() { |
| 337 | return startClipTopAmount; |
| 338 | } |
| 339 | |
| 340 | public int getParentStartClipTopAmount() { |
| 341 | return parentStartClipTopAmount; |
| 342 | } |
| 343 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 344 | public float getStartTranslationZ() { |
| 345 | return startTranslationZ; |
| 346 | } |
| 347 | } |
Selim Cinek | 4a38f23 | 2018-06-22 13:48:33 -0700 | [diff] [blame] | 348 | |
| 349 | public interface Callback { |
| 350 | |
| 351 | /** |
| 352 | * Called when the launch animation was cancelled. |
| 353 | */ |
| 354 | void onLaunchAnimationCancelled(); |
| 355 | |
| 356 | /** |
| 357 | * Called when the launch animation has timed out without starting an actual animation. |
| 358 | */ |
| 359 | void onExpandAnimationTimedOut(); |
| 360 | |
| 361 | /** |
| 362 | * Called when the expand animation has finished. |
| 363 | * |
| 364 | * @param launchIsFullScreen True if this launch was fullscreen, such that now the window |
| 365 | * fills the whole screen |
| 366 | */ |
| 367 | void onExpandAnimationFinished(boolean launchIsFullScreen); |
| 368 | |
| 369 | /** |
| 370 | * Are animations currently enabled. |
| 371 | */ |
| 372 | boolean areLaunchAnimationsEnabled(); |
| 373 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 374 | } |