blob: 7b5bf08165cbbf91cb4367346f28bdd42d7570a4 [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 Mautnerdbb79912012-03-01 18:59:14 -080032class ScreenRotationAnimation implements WindowManagerService.StepAnimator {
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 Mautnerdbb79912012-03-01 18:59:14 -0800543 @Override
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800544 public boolean stepAnimation(long now) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800545
546 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
547 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
548 mFinishAnimStartTime = now;
549 }
550
551 // If the start animation is no longer running, we want to keep its
552 // transformation intact until the finish animation also completes.
553
554 mMoreStartExit = false;
555 if (mStartExitAnimation != null) {
556 mStartExitTransformation.clear();
557 mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
558 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
559 if (!mMoreStartExit) {
560 if (DEBUG_STATE) Slog.v(TAG, "Start exit animation done!");
561 mStartExitAnimation.cancel();
562 mStartExitAnimation = null;
563 }
564 }
565
566 mMoreStartEnter = false;
567 if (mStartEnterAnimation != null) {
568 mStartEnterTransformation.clear();
569 mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
570 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
571 if (!mMoreStartEnter) {
572 if (DEBUG_STATE) Slog.v(TAG, "Start enter animation done!");
573 mStartEnterAnimation.cancel();
574 mStartEnterAnimation = null;
575 }
576 }
577
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800578 mMoreStartFrame = false;
579 if (mStartFrameAnimation != null) {
580 mStartFrameTransformation.clear();
581 mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
582 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
583 if (!mMoreStartFrame) {
584 if (DEBUG_STATE) Slog.v(TAG, "Start frame animation done!");
585 mStartFrameAnimation.cancel();
586 mStartFrameAnimation = null;
587 }
588 }
589
Craig Mautnerdbb79912012-03-01 18:59:14 -0800590 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
591 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
592
593 mFinishExitTransformation.clear();
594 mMoreFinishExit = false;
595 if (mFinishExitAnimation != null) {
596 mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
597 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
598 if (!mMoreStartExit && !mMoreFinishExit) {
599 if (DEBUG_STATE) Slog.v(TAG, "Finish exit animation done, clearing start/finish anims!");
600 mStartExitTransformation.clear();
601 mFinishExitAnimation.cancel();
602 mFinishExitAnimation = null;
603 mFinishExitTransformation.clear();
604 }
605 }
606
607 mFinishEnterTransformation.clear();
608 mMoreFinishEnter = false;
609 if (mFinishEnterAnimation != null) {
610 mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
611 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
612 if (!mMoreStartEnter && !mMoreFinishEnter) {
613 if (DEBUG_STATE) Slog.v(TAG, "Finish enter animation done, clearing start/finish anims!");
614 mStartEnterTransformation.clear();
615 mFinishEnterAnimation.cancel();
616 mFinishEnterAnimation = null;
617 mFinishEnterTransformation.clear();
618 }
619 }
620
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800621 mFinishFrameTransformation.clear();
622 mMoreFinishFrame = false;
623 if (mFinishFrameAnimation != null) {
624 mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
625 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
626 if (!mMoreStartFrame && !mMoreFinishFrame) {
627 if (DEBUG_STATE) Slog.v(TAG, "Finish frame animation done, clearing start/finish anims!");
628 mStartFrameTransformation.clear();
629 mFinishFrameAnimation.cancel();
630 mFinishFrameAnimation = null;
631 mFinishFrameTransformation.clear();
632 }
633 }
634
Craig Mautnerdbb79912012-03-01 18:59:14 -0800635 mRotateExitTransformation.clear();
636 mMoreRotateExit = false;
637 if (mRotateExitAnimation != null) {
638 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
639 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800640 if (!mMoreFinishExit && !mMoreRotateExit) {
641 if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
642 mRotateExitAnimation.cancel();
643 mRotateExitAnimation = null;
644 mRotateExitTransformation.clear();
645 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800646 }
647
648 mRotateEnterTransformation.clear();
649 mMoreRotateEnter = false;
650 if (mRotateEnterAnimation != null) {
651 mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
652 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800653 if (!mMoreFinishEnter && !mMoreRotateEnter) {
654 if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
655 mRotateEnterAnimation.cancel();
656 mRotateEnterAnimation = null;
657 mRotateEnterTransformation.clear();
658 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800659 }
660
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800661 mRotateFrameTransformation.clear();
662 mMoreRotateFrame = false;
663 if (mRotateFrameAnimation != null) {
664 mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
665 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
666 if (!mMoreFinishFrame && !mMoreRotateFrame) {
667 if (DEBUG_STATE) Slog.v(TAG, "Rotate frame animation done!");
668 mRotateFrameAnimation.cancel();
669 mRotateFrameAnimation = null;
670 mRotateFrameTransformation.clear();
671 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800672 }
673
674 mExitTransformation.set(mRotateExitTransformation);
675 mExitTransformation.compose(mStartExitTransformation);
676 mExitTransformation.compose(mFinishExitTransformation);
677
678 mEnterTransformation.set(mRotateEnterTransformation);
679 mEnterTransformation.compose(mStartEnterTransformation);
680 mEnterTransformation.compose(mFinishEnterTransformation);
681
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800682 //mFrameTransformation.set(mRotateExitTransformation);
683 //mFrameTransformation.compose(mStartExitTransformation);
684 //mFrameTransformation.compose(mFinishExitTransformation);
685 mFrameTransformation.set(mRotateFrameTransformation);
686 mFrameTransformation.compose(mStartFrameTransformation);
687 mFrameTransformation.compose(mFinishFrameTransformation);
688 mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
689
Craig Mautnerdbb79912012-03-01 18:59:14 -0800690 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
691 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800692 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800693
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800694 final boolean more = mMoreStartEnter || mMoreStartExit || mMoreStartFrame
695 || mMoreFinishEnter || mMoreFinishExit || mMoreFinishFrame
696 || mMoreRotateEnter || mMoreRotateExit || mMoreRotateFrame
697 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800698
699 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
700
701 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
702
703 return more;
704 }
705
706 void updateSurfaces() {
707 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
708 if (mSurface != null) {
709 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
710 mSurface.hide();
711 }
712 }
713
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800714 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800715 if (mBlackFrame != null) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800716 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Craig Mautnerdbb79912012-03-01 18:59:14 -0800717 mBlackFrame.hide();
718 }
719 } else {
720 if (mBlackFrame != null) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800721 mBlackFrame.setMatrix(mFrameTransformation.getMatrix());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800722 }
723 }
724
725 setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
726 }
727
728 public boolean startAndFinishAnimationLocked(long now) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800729 if (!isAnimating()) {
730 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800731 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800732 return false;
733 }
734
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800735 if (!mAnimRunning) {
736 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
737 if (mStartEnterAnimation != null) {
738 mStartEnterAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700739 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800740 if (mStartExitAnimation != null) {
741 mStartExitAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700742 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800743 if (mStartFrameAnimation != null) {
744 mStartFrameAnimation.setStartTime(now);
745 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800746 if (mFinishEnterAnimation != null) {
747 mFinishEnterAnimation.setStartTime(0);
748 }
749 if (mFinishExitAnimation != null) {
750 mFinishExitAnimation.setStartTime(0);
751 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800752 if (mFinishFrameAnimation != null) {
753 mFinishFrameAnimation.setStartTime(0);
754 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800755 if (mRotateEnterAnimation != null) {
756 mRotateEnterAnimation.setStartTime(now);
757 }
758 if (mRotateExitAnimation != null) {
759 mRotateExitAnimation.setStartTime(now);
760 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800761 if (mRotateFrameAnimation != null) {
762 mRotateFrameAnimation.setStartTime(now);
763 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800764 mAnimRunning = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800765 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800766
767 return true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800768 }
769
770 public Transformation getEnterTransformation() {
771 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800772 }
773}