blob: 58187b699e5343db6bc4aa1d03a4ea00b0f13552 [file] [log] [blame]
Dianne Hackborna1111872010-11-23 20:55:11 -08001/*
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 Hackborn6e1eb762011-02-17 16:07:28 -080017package com.android.server.wm;
Dianne Hackborna1111872010-11-23 20:55:11 -080018
Dianne Hackborn4dcece82012-02-10 14:50:32 -080019import java.io.PrintWriter;
20
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080021import android.content.Context;
Dianne Hackborna1111872010-11-23 20:55:11 -080022import android.graphics.Matrix;
Dianne Hackborna1111872010-11-23 20:55:11 -080023import android.graphics.PixelFormat;
24import android.graphics.Rect;
Dianne Hackborna1111872010-11-23 20:55:11 -080025import android.util.Slog;
Dianne Hackborna1111872010-11-23 20:55:11 -080026import android.view.Surface;
27import android.view.SurfaceSession;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080028import android.view.animation.Animation;
29import android.view.animation.AnimationUtils;
30import android.view.animation.Transformation;
Dianne Hackborna1111872010-11-23 20:55:11 -080031
Craig Mautnere32c3072012-03-12 15:25:35 -070032class ScreenRotationAnimation {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080033 static final String TAG = "ScreenRotationAnimation";
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080034 static final boolean DEBUG_STATE = false;
35 static final boolean DEBUG_TRANSFORMS = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080036
Dianne Hackborn50660e22011-02-02 17:12:25 -080037 static final int FREEZE_LAYER = WindowManagerService.TYPE_LAYER_MULTIPLIER * 200;
38
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080039 final Context mContext;
Dianne Hackborna1111872010-11-23 20:55:11 -080040 Surface mSurface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070041 BlackFrame mBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080042 int mWidth, mHeight;
43
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080044 int mSnapshotRotation;
45 int mSnapshotDeltaRotation;
46 int mOriginalRotation;
47 int mOriginalWidth, mOriginalHeight;
Dianne Hackborna1111872010-11-23 20:55:11 -080048 int mCurRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -080049
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080050 // For all animations, "exit" is for the UI elements that are going
51 // away (that is the snapshot of the old screen), and "enter" is for
52 // the new UI elements that are appearing (that is the active windows
53 // in their final orientation).
54
55 // The starting animation for the exiting and entering elements. This
56 // animation applies a transformation while the rotation is in progress.
57 // It is started immediately, before the new entering UI is ready.
58 Animation mStartExitAnimation;
59 final Transformation mStartExitTransformation = new Transformation();
60 Animation mStartEnterAnimation;
61 final Transformation mStartEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080062 Animation mStartFrameAnimation;
63 final Transformation mStartFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080064
65 // The finishing animation for the exiting and entering elements. This
66 // animation needs to undo the transformation of the starting animation.
67 // It starts running once the new rotation UI elements are ready to be
68 // displayed.
69 Animation mFinishExitAnimation;
70 final Transformation mFinishExitTransformation = new Transformation();
71 Animation mFinishEnterAnimation;
72 final Transformation mFinishEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080073 Animation mFinishFrameAnimation;
74 final Transformation mFinishFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080075
76 // The current active animation to move from the old to the new rotated
77 // state. Which animation is run here will depend on the old and new
78 // rotations.
79 Animation mRotateExitAnimation;
80 final Transformation mRotateExitTransformation = new Transformation();
81 Animation mRotateEnterAnimation;
82 final Transformation mRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080083 Animation mRotateFrameAnimation;
84 final Transformation mRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080085
86 // A previously running rotate animation. This will be used if we need
87 // to switch to a new rotation before finishing the previous one.
88 Animation mLastRotateExitAnimation;
89 final Transformation mLastRotateExitTransformation = new Transformation();
90 Animation mLastRotateEnterAnimation;
91 final Transformation mLastRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080092 Animation mLastRotateFrameAnimation;
93 final Transformation mLastRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080094
95 // Complete transformations being applied.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080096 final Transformation mExitTransformation = new Transformation();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080097 final Transformation mEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080098 final Transformation mFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080099
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800100 boolean mStarted;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800101 boolean mAnimRunning;
102 boolean mFinishAnimReady;
103 long mFinishAnimStartTime;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800104
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800105 final Matrix mFrameInitialMatrix = new Matrix();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800106 final Matrix mSnapshotInitialMatrix = new Matrix();
107 final Matrix mSnapshotFinalMatrix = new Matrix();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800108 final Matrix mTmpMatrix = new Matrix();
Dianne Hackborna1111872010-11-23 20:55:11 -0800109 final float[] mTmpFloats = new float[9];
Craig Mautnerdbb79912012-03-01 18:59:14 -0800110 private boolean mMoreRotateEnter;
111 private boolean mMoreRotateExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800112 private boolean mMoreRotateFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800113 private boolean mMoreFinishEnter;
114 private boolean mMoreFinishExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800115 private boolean mMoreFinishFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800116 private boolean mMoreStartEnter;
117 private boolean mMoreStartExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800118 private boolean mMoreStartFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -0800119
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800120 public void printTo(String prefix, PrintWriter pw) {
121 pw.print(prefix); pw.print("mSurface="); pw.print(mSurface);
122 pw.print(" mWidth="); pw.print(mWidth);
123 pw.print(" mHeight="); pw.println(mHeight);
124 pw.print(prefix); pw.print("mBlackFrame="); pw.println(mBlackFrame);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800125 if (mBlackFrame != null) {
126 mBlackFrame.printTo(prefix + " ", pw);
127 }
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800128 pw.print(prefix); pw.print("mSnapshotRotation="); pw.print(mSnapshotRotation);
129 pw.print(" mSnapshotDeltaRotation="); pw.print(mSnapshotDeltaRotation);
130 pw.print(" mCurRotation="); pw.println(mCurRotation);
131 pw.print(prefix); pw.print("mOriginalRotation="); pw.print(mOriginalRotation);
132 pw.print(" mOriginalWidth="); pw.print(mOriginalWidth);
133 pw.print(" mOriginalHeight="); pw.println(mOriginalHeight);
134 pw.print(prefix); pw.print("mStarted="); pw.print(mStarted);
135 pw.print(" mAnimRunning="); pw.print(mAnimRunning);
136 pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady);
137 pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime);
138 pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation);
139 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
140 pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
141 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800142 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
143 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800144 pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
145 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
146 pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
147 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800148 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
149 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800150 pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
151 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
152 pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
153 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800154 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
155 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800156 pw.print(prefix); pw.print("mExitTransformation=");
157 mExitTransformation.printShortString(pw); pw.println();
158 pw.print(prefix); pw.print("mEnterTransformation=");
159 mEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800160 pw.print(prefix); pw.print("mFrameTransformation=");
161 mEnterTransformation.printShortString(pw); pw.println();
162 pw.print(prefix); pw.print("mFrameInitialMatrix=");
163 mFrameInitialMatrix.printShortString(pw);
164 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800165 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
166 mSnapshotInitialMatrix.printShortString(pw);
167 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
168 pw.println();
169 }
170
Jeff Brownbc68a592011-07-25 12:58:12 -0700171 public ScreenRotationAnimation(Context context, SurfaceSession session,
172 boolean inTransaction, int originalWidth, int originalHeight, int originalRotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800173 mContext = context;
Dianne Hackborna1111872010-11-23 20:55:11 -0800174
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800175 // Screenshot does NOT include rotation!
176 mSnapshotRotation = 0;
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700177 if (originalRotation == Surface.ROTATION_90
178 || originalRotation == Surface.ROTATION_270) {
179 mWidth = originalHeight;
180 mHeight = originalWidth;
181 } else {
182 mWidth = originalWidth;
183 mHeight = originalHeight;
184 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800185
Jeff Brownbc68a592011-07-25 12:58:12 -0700186 mOriginalRotation = originalRotation;
187 mOriginalWidth = originalWidth;
188 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800189
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800190 if (!inTransaction) {
Dianne Hackborn36991742011-10-11 21:35:26 -0700191 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800192 ">>> OPEN TRANSACTION ScreenRotationAnimation");
193 Surface.openTransaction();
194 }
Dianne Hackborn352cc982011-01-04 11:34:18 -0800195
Dianne Hackborna1111872010-11-23 20:55:11 -0800196 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800197 try {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800198 mSurface = new Surface(session, 0, "FreezeSurface",
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700199 -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700200 if (mSurface == null || !mSurface.isValid()) {
201 // Screenshot failed, punt.
202 mSurface = null;
203 return;
204 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800205 mSurface.setLayer(FREEZE_LAYER);
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700206 mSurface.show();
Dianne Hackborn352cc982011-01-04 11:34:18 -0800207 } catch (Surface.OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800208 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800209 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800210
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700211 if (WindowManagerService.SHOW_TRANSACTIONS ||
212 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
213 " FREEZE " + mSurface + ": CREATE");
214
Jeff Brownbc68a592011-07-25 12:58:12 -0700215 setRotation(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800216 } finally {
217 if (!inTransaction) {
218 Surface.closeTransaction();
Dianne Hackborn36991742011-10-11 21:35:26 -0700219 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800220 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800221 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800222 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800223 }
224
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800225 boolean hasScreenshot() {
226 return mSurface != null;
227 }
228
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800229 static int deltaRotation(int oldRotation, int newRotation) {
230 int delta = newRotation - oldRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800231 if (delta < 0) delta += 4;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800232 return delta;
233 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800234
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800235 void setSnapshotTransform(Matrix matrix, float alpha) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800236 if (mSurface != null) {
237 matrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700238 mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X],
239 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800240 mSurface.setMatrix(
241 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
242 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
243 mSurface.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800244 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800245 float[] srcPnts = new float[] { 0, 0, mWidth, mHeight };
246 float[] dstPnts = new float[4];
247 matrix.mapPoints(dstPnts, srcPnts);
248 Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1]
249 + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")");
250 Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1]
251 + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")");
252 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800253 }
254 }
255
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800256 public static void createRotationMatrix(int rotation, int width, int height,
257 Matrix outMatrix) {
258 switch (rotation) {
259 case Surface.ROTATION_0:
260 outMatrix.reset();
261 break;
262 case Surface.ROTATION_90:
263 outMatrix.setRotate(90, 0, 0);
264 outMatrix.postTranslate(height, 0);
265 break;
266 case Surface.ROTATION_180:
267 outMatrix.setRotate(180, 0, 0);
268 outMatrix.postTranslate(width, height);
269 break;
270 case Surface.ROTATION_270:
271 outMatrix.setRotate(270, 0, 0);
272 outMatrix.postTranslate(0, width);
273 break;
274 }
275 }
276
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800277 // Must be called while in a transaction.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800278 private void setRotation(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800279 mCurRotation = rotation;
280
281 // Compute the transformation matrix that must be applied
282 // to the snapshot to make it stay in the same original position
283 // with the current screen rotation.
284 int delta = deltaRotation(rotation, mSnapshotRotation);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800285 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800286
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800287 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800288 setSnapshotTransform(mSnapshotInitialMatrix, 1.0f);
289 }
290
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800291 // Must be called while in a transaction.
292 public boolean setRotation(int rotation, SurfaceSession session,
293 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
294 setRotation(rotation);
295 return startAnimation(session, maxAnimationDuration, animationScale,
296 finalWidth, finalHeight, false);
297 }
298
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800299 /**
300 * Returns true if animating.
301 */
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800302 private boolean startAnimation(SurfaceSession session, long maxAnimationDuration,
303 float animationScale, int finalWidth, int finalHeight, boolean dismissing) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800304 if (mSurface == null) {
305 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800306 return false;
307 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800308 if (mStarted) {
309 return true;
310 }
311
312 mStarted = true;
313
314 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800315
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800316 // Figure out how the screen has moved from the original rotation.
317 int delta = deltaRotation(mCurRotation, mOriginalRotation);
318
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800319 if (mFinishExitAnimation == null && (!dismissing || delta != Surface.ROTATION_0)) {
320 if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations");
321 firstStart = true;
322 mStartExitAnimation = AnimationUtils.loadAnimation(mContext,
323 com.android.internal.R.anim.screen_rotate_start_exit);
324 mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
325 com.android.internal.R.anim.screen_rotate_start_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800326 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
327 com.android.internal.R.anim.screen_rotate_start_frame);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800328 mFinishExitAnimation = AnimationUtils.loadAnimation(mContext,
329 com.android.internal.R.anim.screen_rotate_finish_exit);
330 mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext,
331 com.android.internal.R.anim.screen_rotate_finish_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800332 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
333 com.android.internal.R.anim.screen_rotate_finish_frame);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800334 }
335
336 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
337 + finalWidth + " finalHeight=" + finalHeight
338 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
339
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800340 switch (delta) {
341 case Surface.ROTATION_0:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800342 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800343 com.android.internal.R.anim.screen_rotate_0_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800344 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800345 com.android.internal.R.anim.screen_rotate_0_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800346 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
347 com.android.internal.R.anim.screen_rotate_0_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800348 break;
349 case Surface.ROTATION_90:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800350 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800351 com.android.internal.R.anim.screen_rotate_plus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800352 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800353 com.android.internal.R.anim.screen_rotate_plus_90_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800354 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
355 com.android.internal.R.anim.screen_rotate_plus_90_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800356 break;
357 case Surface.ROTATION_180:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800358 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800359 com.android.internal.R.anim.screen_rotate_180_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800360 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800361 com.android.internal.R.anim.screen_rotate_180_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800362 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
363 com.android.internal.R.anim.screen_rotate_180_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800364 break;
365 case Surface.ROTATION_270:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800366 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800367 com.android.internal.R.anim.screen_rotate_minus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800368 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800369 com.android.internal.R.anim.screen_rotate_minus_90_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800370 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
371 com.android.internal.R.anim.screen_rotate_minus_90_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800372 break;
373 }
374
Dianne Hackborn191874e32012-03-09 11:03:36 -0800375 // Compute partial steps between original and final sizes. These
376 // are used for the dimensions of the exiting and entering elements,
377 // so they are never stretched too significantly.
378 final int halfWidth = (finalWidth + mOriginalWidth) / 2;
379 final int halfHeight = (finalHeight + mOriginalHeight) / 2;
380
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800381 // Initialize the animations. This is a hack, redefining what "parent"
382 // means to allow supplying the last and next size. In this definition
383 // "%p" is the original (let's call it "previous") size, and "%" is the
384 // screen's current/new size.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800385 if (firstStart) {
386 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
387 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800388 halfWidth, halfHeight);
389 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800390 mOriginalWidth, mOriginalHeight);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800391 mStartFrameAnimation.initialize(finalWidth, finalHeight,
392 mOriginalWidth, mOriginalHeight);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800393 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800394 halfWidth, halfHeight);
395 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800396 mOriginalWidth, mOriginalHeight);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800397 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
398 mOriginalWidth, mOriginalHeight);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800399 }
400 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
401 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800402 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800403 mAnimRunning = false;
404 mFinishAnimReady = false;
405 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800406
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800407 if (firstStart) {
408 mStartExitAnimation.restrictDuration(maxAnimationDuration);
409 mStartExitAnimation.scaleCurrentDuration(animationScale);
410 mStartEnterAnimation.restrictDuration(maxAnimationDuration);
411 mStartEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800412 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
413 mStartFrameAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800414 mFinishExitAnimation.restrictDuration(maxAnimationDuration);
415 mFinishExitAnimation.scaleCurrentDuration(animationScale);
416 mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
417 mFinishEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800418 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
419 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800420 }
421 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
422 mRotateExitAnimation.scaleCurrentDuration(animationScale);
423 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
424 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800425 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
426 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800427
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800428 if (mBlackFrame == null) {
429 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
430 WindowManagerService.TAG,
431 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
432 Surface.openTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800433
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800434 // Compute the transformation matrix that must be applied
435 // the the black frame to make it stay in the initial position
436 // before the new screen rotation. This is different than the
437 // snapshot transformation because the snapshot is always based
438 // of the native orientation of the screen, not the orientation
439 // we were last in.
440 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
441
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800442 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800443 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
444 mOriginalWidth*2, mOriginalHeight*2);
445 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
446 mBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 1);
447 mBlackFrame.setMatrix(mFrameInitialMatrix);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800448 } catch (Surface.OutOfResourcesException e) {
449 Slog.w(TAG, "Unable to allocate black surface", e);
450 } finally {
451 Surface.closeTransaction();
452 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
453 WindowManagerService.TAG,
454 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
455 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800456 }
457
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800458 return true;
459 }
460
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800461 /**
462 * Returns true if animating.
463 */
464 public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
465 float animationScale, int finalWidth, int finalHeight) {
466 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
467 if (mSurface == null) {
468 // Can't do animation.
469 return false;
470 }
471 if (!mStarted) {
472 startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight,
473 true);
474 }
475 if (!mStarted) {
476 return false;
477 }
478 if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true");
479 mFinishAnimReady = true;
480 return true;
481 }
482
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800483 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800484 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800485 if (mSurface != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700486 if (WindowManagerService.SHOW_TRANSACTIONS ||
487 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
488 " FREEZE " + mSurface + ": DESTROY");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800489 mSurface.destroy();
490 mSurface = null;
491 }
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700492 if (mBlackFrame != null) {
493 mBlackFrame.kill();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800494 mBlackFrame = null;
Dianne Hackborn352cc982011-01-04 11:34:18 -0800495 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800496 if (mStartExitAnimation != null) {
497 mStartExitAnimation.cancel();
498 mStartExitAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800499 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800500 if (mStartEnterAnimation != null) {
501 mStartEnterAnimation.cancel();
502 mStartEnterAnimation = null;
503 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800504 if (mStartFrameAnimation != null) {
505 mStartFrameAnimation.cancel();
506 mStartFrameAnimation = null;
507 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800508 if (mFinishExitAnimation != null) {
509 mFinishExitAnimation.cancel();
510 mFinishExitAnimation = null;
511 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800512 if (mFinishEnterAnimation != null) {
513 mFinishEnterAnimation.cancel();
514 mFinishEnterAnimation = null;
515 }
516 if (mFinishFrameAnimation != null) {
517 mFinishFrameAnimation.cancel();
518 mFinishFrameAnimation = null;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800519 }
520 if (mRotateExitAnimation != null) {
521 mRotateExitAnimation.cancel();
522 mRotateExitAnimation = null;
523 }
524 if (mRotateEnterAnimation != null) {
525 mRotateEnterAnimation.cancel();
526 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800527 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800528 if (mRotateFrameAnimation != null) {
529 mRotateFrameAnimation.cancel();
530 mRotateFrameAnimation = null;
531 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800532 }
533
534 public boolean isAnimating() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800535 return mStartEnterAnimation != null || mStartExitAnimation != null
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800536 || mStartFrameAnimation != null
537 || mFinishEnterAnimation != null || mFinishExitAnimation != null
538 || mFinishFrameAnimation != null
539 || mRotateEnterAnimation != null || mRotateExitAnimation != null
540 || mRotateFrameAnimation != null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800541 }
542
Craig Mautnere32c3072012-03-12 15:25:35 -0700543 private boolean stepAnimation(long now) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800544
545 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
546 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
547 mFinishAnimStartTime = now;
548 }
549
550 // If the start animation is no longer running, we want to keep its
551 // transformation intact until the finish animation also completes.
552
553 mMoreStartExit = false;
554 if (mStartExitAnimation != null) {
555 mStartExitTransformation.clear();
556 mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
557 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
558 if (!mMoreStartExit) {
559 if (DEBUG_STATE) Slog.v(TAG, "Start exit animation done!");
560 mStartExitAnimation.cancel();
561 mStartExitAnimation = null;
562 }
563 }
564
565 mMoreStartEnter = false;
566 if (mStartEnterAnimation != null) {
567 mStartEnterTransformation.clear();
568 mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
569 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
570 if (!mMoreStartEnter) {
571 if (DEBUG_STATE) Slog.v(TAG, "Start enter animation done!");
572 mStartEnterAnimation.cancel();
573 mStartEnterAnimation = null;
574 }
575 }
576
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800577 mMoreStartFrame = false;
578 if (mStartFrameAnimation != null) {
579 mStartFrameTransformation.clear();
580 mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
581 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
582 if (!mMoreStartFrame) {
583 if (DEBUG_STATE) Slog.v(TAG, "Start frame animation done!");
584 mStartFrameAnimation.cancel();
585 mStartFrameAnimation = null;
586 }
587 }
588
Craig Mautnerdbb79912012-03-01 18:59:14 -0800589 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
590 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
591
592 mFinishExitTransformation.clear();
593 mMoreFinishExit = false;
594 if (mFinishExitAnimation != null) {
595 mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
596 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
597 if (!mMoreStartExit && !mMoreFinishExit) {
598 if (DEBUG_STATE) Slog.v(TAG, "Finish exit animation done, clearing start/finish anims!");
599 mStartExitTransformation.clear();
600 mFinishExitAnimation.cancel();
601 mFinishExitAnimation = null;
602 mFinishExitTransformation.clear();
603 }
604 }
605
606 mFinishEnterTransformation.clear();
607 mMoreFinishEnter = false;
608 if (mFinishEnterAnimation != null) {
609 mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
610 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
611 if (!mMoreStartEnter && !mMoreFinishEnter) {
612 if (DEBUG_STATE) Slog.v(TAG, "Finish enter animation done, clearing start/finish anims!");
613 mStartEnterTransformation.clear();
614 mFinishEnterAnimation.cancel();
615 mFinishEnterAnimation = null;
616 mFinishEnterTransformation.clear();
617 }
618 }
619
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800620 mFinishFrameTransformation.clear();
621 mMoreFinishFrame = false;
622 if (mFinishFrameAnimation != null) {
623 mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
624 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
625 if (!mMoreStartFrame && !mMoreFinishFrame) {
626 if (DEBUG_STATE) Slog.v(TAG, "Finish frame animation done, clearing start/finish anims!");
627 mStartFrameTransformation.clear();
628 mFinishFrameAnimation.cancel();
629 mFinishFrameAnimation = null;
630 mFinishFrameTransformation.clear();
631 }
632 }
633
Craig Mautnerdbb79912012-03-01 18:59:14 -0800634 mRotateExitTransformation.clear();
635 mMoreRotateExit = false;
636 if (mRotateExitAnimation != null) {
637 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
638 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800639 if (!mMoreFinishExit && !mMoreRotateExit) {
640 if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
641 mRotateExitAnimation.cancel();
642 mRotateExitAnimation = null;
643 mRotateExitTransformation.clear();
644 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800645 }
646
647 mRotateEnterTransformation.clear();
648 mMoreRotateEnter = false;
649 if (mRotateEnterAnimation != null) {
650 mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
651 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800652 if (!mMoreFinishEnter && !mMoreRotateEnter) {
653 if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
654 mRotateEnterAnimation.cancel();
655 mRotateEnterAnimation = null;
656 mRotateEnterTransformation.clear();
657 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800658 }
659
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800660 mRotateFrameTransformation.clear();
661 mMoreRotateFrame = false;
662 if (mRotateFrameAnimation != null) {
663 mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
664 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
665 if (!mMoreFinishFrame && !mMoreRotateFrame) {
666 if (DEBUG_STATE) Slog.v(TAG, "Rotate frame animation done!");
667 mRotateFrameAnimation.cancel();
668 mRotateFrameAnimation = null;
669 mRotateFrameTransformation.clear();
670 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800671 }
672
673 mExitTransformation.set(mRotateExitTransformation);
674 mExitTransformation.compose(mStartExitTransformation);
675 mExitTransformation.compose(mFinishExitTransformation);
676
677 mEnterTransformation.set(mRotateEnterTransformation);
678 mEnterTransformation.compose(mStartEnterTransformation);
679 mEnterTransformation.compose(mFinishEnterTransformation);
680
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800681 //mFrameTransformation.set(mRotateExitTransformation);
682 //mFrameTransformation.compose(mStartExitTransformation);
683 //mFrameTransformation.compose(mFinishExitTransformation);
684 mFrameTransformation.set(mRotateFrameTransformation);
685 mFrameTransformation.compose(mStartFrameTransformation);
686 mFrameTransformation.compose(mFinishFrameTransformation);
687 mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
688
Craig Mautnerdbb79912012-03-01 18:59:14 -0800689 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
690 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800691 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800692
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800693 final boolean more = mMoreStartEnter || mMoreStartExit || mMoreStartFrame
694 || mMoreFinishEnter || mMoreFinishExit || mMoreFinishFrame
695 || mMoreRotateEnter || mMoreRotateExit || mMoreRotateFrame
696 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800697
698 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
699
700 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
701
702 return more;
703 }
704
705 void updateSurfaces() {
706 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
707 if (mSurface != null) {
708 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
709 mSurface.hide();
710 }
711 }
712
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800713 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800714 if (mBlackFrame != null) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800715 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Craig Mautnerdbb79912012-03-01 18:59:14 -0800716 mBlackFrame.hide();
717 }
718 } else {
719 if (mBlackFrame != null) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800720 mBlackFrame.setMatrix(mFrameTransformation.getMatrix());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800721 }
722 }
723
724 setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
725 }
726
Craig Mautnere32c3072012-03-12 15:25:35 -0700727 public boolean stepAnimationLocked(long now) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800728 if (!isAnimating()) {
729 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800730 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800731 return false;
732 }
733
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800734 if (!mAnimRunning) {
735 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
736 if (mStartEnterAnimation != null) {
737 mStartEnterAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700738 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800739 if (mStartExitAnimation != null) {
740 mStartExitAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700741 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800742 if (mStartFrameAnimation != null) {
743 mStartFrameAnimation.setStartTime(now);
744 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800745 if (mFinishEnterAnimation != null) {
746 mFinishEnterAnimation.setStartTime(0);
747 }
748 if (mFinishExitAnimation != null) {
749 mFinishExitAnimation.setStartTime(0);
750 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800751 if (mFinishFrameAnimation != null) {
752 mFinishFrameAnimation.setStartTime(0);
753 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800754 if (mRotateEnterAnimation != null) {
755 mRotateEnterAnimation.setStartTime(now);
756 }
757 if (mRotateExitAnimation != null) {
758 mRotateExitAnimation.setStartTime(now);
759 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800760 if (mRotateFrameAnimation != null) {
761 mRotateFrameAnimation.setStartTime(now);
762 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800763 mAnimRunning = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800764 }
Craig Mautnere32c3072012-03-12 15:25:35 -0700765
766 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800767 }
768
769 public Transformation getEnterTransformation() {
770 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800771 }
772}