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