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