Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 18 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
| 21 | import android.graphics.Canvas; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 22 | import android.graphics.Matrix; |
| 23 | import android.graphics.Paint; |
| 24 | import android.graphics.PixelFormat; |
Jeff Brown | 8db9ac4 | 2011-01-21 14:39:52 -0800 | [diff] [blame] | 25 | import android.graphics.PorterDuff; |
| 26 | import android.graphics.PorterDuffXfermode; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 28 | import android.util.Slog; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 29 | import android.view.Surface; |
| 30 | import android.view.SurfaceSession; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 31 | import android.view.animation.Animation; |
| 32 | import android.view.animation.AnimationUtils; |
| 33 | import android.view.animation.Transformation; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 34 | |
| 35 | class ScreenRotationAnimation { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 36 | static final String TAG = "ScreenRotationAnimation"; |
| 37 | static final boolean DEBUG = false; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 38 | |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 39 | static final int FREEZE_LAYER = WindowManagerService.TYPE_LAYER_MULTIPLIER * 200; |
| 40 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 41 | final Context mContext; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 42 | Surface mSurface; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 43 | BlackFrame mBlackFrame; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 44 | int mWidth, mHeight; |
| 45 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 46 | int mSnapshotRotation; |
| 47 | int mSnapshotDeltaRotation; |
| 48 | int mOriginalRotation; |
| 49 | int mOriginalWidth, mOriginalHeight; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 50 | int mCurRotation; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 51 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 52 | Animation mExitAnimation; |
| 53 | final Transformation mExitTransformation = new Transformation(); |
| 54 | Animation mEnterAnimation; |
| 55 | final Transformation mEnterTransformation = new Transformation(); |
| 56 | boolean mStarted; |
| 57 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 58 | final Matrix mSnapshotInitialMatrix = new Matrix(); |
| 59 | final Matrix mSnapshotFinalMatrix = new Matrix(); |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 60 | final Matrix mTmpMatrix = new Matrix(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 61 | final float[] mTmpFloats = new float[9]; |
| 62 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 63 | public ScreenRotationAnimation(Context context, SurfaceSession session, |
| 64 | boolean inTransaction, int originalWidth, int originalHeight, int originalRotation) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 65 | mContext = context; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 66 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 67 | // Screenshot does NOT include rotation! |
| 68 | mSnapshotRotation = 0; |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 69 | if (originalRotation == Surface.ROTATION_90 |
| 70 | || originalRotation == Surface.ROTATION_270) { |
| 71 | mWidth = originalHeight; |
| 72 | mHeight = originalWidth; |
| 73 | } else { |
| 74 | mWidth = originalWidth; |
| 75 | mHeight = originalHeight; |
| 76 | } |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 77 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 78 | mOriginalRotation = originalRotation; |
| 79 | mOriginalWidth = originalWidth; |
| 80 | mOriginalHeight = originalHeight; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 81 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 82 | if (!inTransaction) { |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 83 | if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 84 | ">>> OPEN TRANSACTION ScreenRotationAnimation"); |
| 85 | Surface.openTransaction(); |
| 86 | } |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 87 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 88 | try { |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 89 | try { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 90 | mSurface = new Surface(session, 0, "FreezeSurface", |
Mathias Agopian | e65beaa | 2011-11-01 14:39:06 -0700 | [diff] [blame] | 91 | -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN); |
Mathias Agopian | 0ab84ef | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 92 | if (mSurface == null || !mSurface.isValid()) { |
| 93 | // Screenshot failed, punt. |
| 94 | mSurface = null; |
| 95 | return; |
| 96 | } |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 97 | mSurface.setLayer(FREEZE_LAYER + 1); |
Mathias Agopian | e65beaa | 2011-11-01 14:39:06 -0700 | [diff] [blame] | 98 | mSurface.show(); |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 99 | } catch (Surface.OutOfResourcesException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 100 | Slog.w(TAG, "Unable to allocate freeze surface", e); |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 101 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 102 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 103 | if (WindowManagerService.SHOW_TRANSACTIONS || |
| 104 | WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG, |
| 105 | " FREEZE " + mSurface + ": CREATE"); |
| 106 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 107 | setRotation(originalRotation); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 108 | } finally { |
| 109 | if (!inTransaction) { |
| 110 | Surface.closeTransaction(); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 111 | if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 112 | "<<< CLOSE TRANSACTION ScreenRotationAnimation"); |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 113 | } |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 114 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 117 | boolean hasScreenshot() { |
| 118 | return mSurface != null; |
| 119 | } |
| 120 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 121 | static int deltaRotation(int oldRotation, int newRotation) { |
| 122 | int delta = newRotation - oldRotation; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 123 | if (delta < 0) delta += 4; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 124 | return delta; |
| 125 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 126 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 127 | void setSnapshotTransform(Matrix matrix, float alpha) { |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 128 | if (mSurface != null) { |
| 129 | matrix.getValues(mTmpFloats); |
Dianne Hackborn | d040edb | 2011-08-31 12:47:58 -0700 | [diff] [blame] | 130 | mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X], |
| 131 | mTmpFloats[Matrix.MTRANS_Y]); |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 132 | mSurface.setMatrix( |
| 133 | mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], |
| 134 | mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]); |
| 135 | mSurface.setAlpha(alpha); |
| 136 | if (DEBUG) { |
| 137 | float[] srcPnts = new float[] { 0, 0, mWidth, mHeight }; |
| 138 | float[] dstPnts = new float[4]; |
| 139 | matrix.mapPoints(dstPnts, srcPnts); |
| 140 | Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1] |
| 141 | + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")"); |
| 142 | Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1] |
| 143 | + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")"); |
| 144 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 148 | public static void createRotationMatrix(int rotation, int width, int height, |
| 149 | Matrix outMatrix) { |
| 150 | switch (rotation) { |
| 151 | case Surface.ROTATION_0: |
| 152 | outMatrix.reset(); |
| 153 | break; |
| 154 | case Surface.ROTATION_90: |
| 155 | outMatrix.setRotate(90, 0, 0); |
| 156 | outMatrix.postTranslate(height, 0); |
| 157 | break; |
| 158 | case Surface.ROTATION_180: |
| 159 | outMatrix.setRotate(180, 0, 0); |
| 160 | outMatrix.postTranslate(width, height); |
| 161 | break; |
| 162 | case Surface.ROTATION_270: |
| 163 | outMatrix.setRotate(270, 0, 0); |
| 164 | outMatrix.postTranslate(0, width); |
| 165 | break; |
| 166 | } |
| 167 | } |
| 168 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 169 | // Must be called while in a transaction. |
| 170 | public void setRotation(int rotation) { |
| 171 | mCurRotation = rotation; |
| 172 | |
| 173 | // Compute the transformation matrix that must be applied |
| 174 | // to the snapshot to make it stay in the same original position |
| 175 | // with the current screen rotation. |
| 176 | int delta = deltaRotation(rotation, mSnapshotRotation); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 177 | createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 178 | |
| 179 | if (DEBUG) Slog.v(TAG, "**** ROTATION: " + delta); |
| 180 | setSnapshotTransform(mSnapshotInitialMatrix, 1.0f); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Returns true if animating. |
| 185 | */ |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 186 | public boolean dismiss(SurfaceSession session, long maxAnimationDuration, |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 187 | float animationScale, int finalWidth, int finalHeight) { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 188 | if (mSurface == null) { |
| 189 | // Can't do animation. |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 190 | return false; |
| 191 | } |
| 192 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 193 | // Figure out how the screen has moved from the original rotation. |
| 194 | int delta = deltaRotation(mCurRotation, mOriginalRotation); |
| 195 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 196 | switch (delta) { |
| 197 | case Surface.ROTATION_0: |
| 198 | mExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 199 | com.android.internal.R.anim.screen_rotate_0_exit); |
| 200 | mEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 201 | com.android.internal.R.anim.screen_rotate_0_enter); |
| 202 | break; |
| 203 | case Surface.ROTATION_90: |
| 204 | mExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 205 | com.android.internal.R.anim.screen_rotate_plus_90_exit); |
| 206 | mEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 207 | com.android.internal.R.anim.screen_rotate_plus_90_enter); |
| 208 | break; |
| 209 | case Surface.ROTATION_180: |
| 210 | mExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 211 | com.android.internal.R.anim.screen_rotate_180_exit); |
| 212 | mEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 213 | com.android.internal.R.anim.screen_rotate_180_enter); |
| 214 | break; |
| 215 | case Surface.ROTATION_270: |
| 216 | mExitAnimation = AnimationUtils.loadAnimation(mContext, |
| 217 | com.android.internal.R.anim.screen_rotate_minus_90_exit); |
| 218 | mEnterAnimation = AnimationUtils.loadAnimation(mContext, |
| 219 | com.android.internal.R.anim.screen_rotate_minus_90_enter); |
| 220 | break; |
| 221 | } |
| 222 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 223 | // Initialize the animations. This is a hack, redefining what "parent" |
| 224 | // means to allow supplying the last and next size. In this definition |
| 225 | // "%p" is the original (let's call it "previous") size, and "%" is the |
| 226 | // screen's current/new size. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 227 | mEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight); |
| 228 | mExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 229 | mStarted = false; |
| 230 | |
| 231 | mExitAnimation.restrictDuration(maxAnimationDuration); |
| 232 | mExitAnimation.scaleCurrentDuration(animationScale); |
| 233 | mEnterAnimation.restrictDuration(maxAnimationDuration); |
| 234 | mEnterAnimation.scaleCurrentDuration(animationScale); |
| 235 | |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 236 | if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG, |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 237 | ">>> OPEN TRANSACTION ScreenRotationAnimation.dismiss"); |
| 238 | Surface.openTransaction(); |
| 239 | |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 240 | try { |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 241 | Rect outer = new Rect(-finalWidth, -finalHeight, finalWidth * 2, finalHeight * 2); |
| 242 | Rect inner = new Rect(0, 0, finalWidth, finalHeight); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 243 | mBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER); |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 244 | } catch (Surface.OutOfResourcesException e) { |
| 245 | Slog.w(TAG, "Unable to allocate black surface", e); |
| 246 | } finally { |
| 247 | Surface.closeTransaction(); |
Dianne Hackborn | 3699174 | 2011-10-11 21:35:26 -0700 | [diff] [blame] | 248 | if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG, |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 249 | "<<< CLOSE TRANSACTION ScreenRotationAnimation.dismiss"); |
| 250 | } |
| 251 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 252 | return true; |
| 253 | } |
| 254 | |
| 255 | public void kill() { |
| 256 | if (mSurface != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 257 | if (WindowManagerService.SHOW_TRANSACTIONS || |
| 258 | WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG, |
| 259 | " FREEZE " + mSurface + ": DESTROY"); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 260 | mSurface.destroy(); |
| 261 | mSurface = null; |
| 262 | } |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 263 | if (mBlackFrame != null) { |
| 264 | mBlackFrame.kill(); |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 265 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 266 | if (mExitAnimation != null) { |
| 267 | mExitAnimation.cancel(); |
| 268 | mExitAnimation = null; |
| 269 | } |
| 270 | if (mEnterAnimation != null) { |
| 271 | mEnterAnimation.cancel(); |
| 272 | mEnterAnimation = null; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | public boolean isAnimating() { |
| 277 | return mEnterAnimation != null || mExitAnimation != null; |
| 278 | } |
| 279 | |
| 280 | public boolean stepAnimation(long now) { |
| 281 | if (mEnterAnimation == null && mExitAnimation == null) { |
| 282 | return false; |
| 283 | } |
| 284 | |
| 285 | if (!mStarted) { |
Dianne Hackborn | 8962028 | 2011-09-11 12:47:45 -0700 | [diff] [blame] | 286 | if (mEnterAnimation != null) { |
| 287 | mEnterAnimation.setStartTime(now); |
| 288 | } |
| 289 | if (mExitAnimation != null) { |
| 290 | mExitAnimation.setStartTime(now); |
| 291 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 292 | mStarted = true; |
| 293 | } |
| 294 | |
| 295 | mExitTransformation.clear(); |
| 296 | boolean moreExit = false; |
| 297 | if (mExitAnimation != null) { |
| 298 | moreExit = mExitAnimation.getTransformation(now, mExitTransformation); |
| 299 | if (DEBUG) Slog.v(TAG, "Stepped exit: " + mExitTransformation); |
| 300 | if (!moreExit) { |
| 301 | if (DEBUG) Slog.v(TAG, "Exit animation done!"); |
| 302 | mExitAnimation.cancel(); |
| 303 | mExitAnimation = null; |
| 304 | mExitTransformation.clear(); |
| 305 | if (mSurface != null) { |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 306 | mSurface.hide(); |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 307 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | mEnterTransformation.clear(); |
| 312 | boolean moreEnter = false; |
| 313 | if (mEnterAnimation != null) { |
| 314 | moreEnter = mEnterAnimation.getTransformation(now, mEnterTransformation); |
| 315 | if (!moreEnter) { |
| 316 | mEnterAnimation.cancel(); |
| 317 | mEnterAnimation = null; |
| 318 | mEnterTransformation.clear(); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 319 | if (mBlackFrame != null) { |
| 320 | mBlackFrame.hide(); |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 321 | } |
| 322 | } else { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 323 | if (mBlackFrame != null) { |
| 324 | mBlackFrame.setMatrix(mEnterTransformation.getMatrix()); |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 325 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Dianne Hackborn | 352cc98 | 2011-01-04 11:34:18 -0800 | [diff] [blame] | 329 | mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix); |
| 330 | setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha()); |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 331 | |
| 332 | return moreEnter || moreExit; |
| 333 | } |
| 334 | |
| 335 | public Transformation getEnterTransformation() { |
| 336 | return mEnterTransformation; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 337 | } |
| 338 | } |