blob: 3dcfd3ca416803eb5df1baca987cf6f58fc83713 [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 Hackborn187ae2102012-04-11 18:12:06 -070036 static final boolean TWO_PHASE_ANIMATION = false;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070037 static final boolean USE_CUSTOM_BLACK_FRAME = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080038
Dianne Hackborn50660e22011-02-02 17:12:25 -080039 static final int FREEZE_LAYER = WindowManagerService.TYPE_LAYER_MULTIPLIER * 200;
40
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080041 final Context mContext;
Dianne Hackborna1111872010-11-23 20:55:11 -080042 Surface mSurface;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070043 BlackFrame mCustomBlackFrame;
44 BlackFrame mExitingBlackFrame;
45 BlackFrame mEnteringBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080046 int mWidth, mHeight;
47
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080048 int mOriginalRotation;
49 int mOriginalWidth, mOriginalHeight;
Dianne Hackborna1111872010-11-23 20:55:11 -080050 int mCurRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -080051
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080052 // For all animations, "exit" is for the UI elements that are going
53 // away (that is the snapshot of the old screen), and "enter" is for
54 // the new UI elements that are appearing (that is the active windows
55 // in their final orientation).
56
57 // The starting animation for the exiting and entering elements. This
58 // animation applies a transformation while the rotation is in progress.
59 // It is started immediately, before the new entering UI is ready.
60 Animation mStartExitAnimation;
61 final Transformation mStartExitTransformation = new Transformation();
62 Animation mStartEnterAnimation;
63 final Transformation mStartEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080064 Animation mStartFrameAnimation;
65 final Transformation mStartFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080066
67 // The finishing animation for the exiting and entering elements. This
68 // animation needs to undo the transformation of the starting animation.
69 // It starts running once the new rotation UI elements are ready to be
70 // displayed.
71 Animation mFinishExitAnimation;
72 final Transformation mFinishExitTransformation = new Transformation();
73 Animation mFinishEnterAnimation;
74 final Transformation mFinishEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080075 Animation mFinishFrameAnimation;
76 final Transformation mFinishFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080077
78 // The current active animation to move from the old to the new rotated
79 // state. Which animation is run here will depend on the old and new
80 // rotations.
81 Animation mRotateExitAnimation;
82 final Transformation mRotateExitTransformation = new Transformation();
83 Animation mRotateEnterAnimation;
84 final Transformation mRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080085 Animation mRotateFrameAnimation;
86 final Transformation mRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080087
88 // A previously running rotate animation. This will be used if we need
89 // to switch to a new rotation before finishing the previous one.
90 Animation mLastRotateExitAnimation;
91 final Transformation mLastRotateExitTransformation = new Transformation();
92 Animation mLastRotateEnterAnimation;
93 final Transformation mLastRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080094 Animation mLastRotateFrameAnimation;
95 final Transformation mLastRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080096
97 // Complete transformations being applied.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080098 final Transformation mExitTransformation = new Transformation();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080099 final Transformation mEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800100 final Transformation mFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800101
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800102 boolean mStarted;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800103 boolean mAnimRunning;
104 boolean mFinishAnimReady;
105 long mFinishAnimStartTime;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800106
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800107 final Matrix mFrameInitialMatrix = new Matrix();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800108 final Matrix mSnapshotInitialMatrix = new Matrix();
109 final Matrix mSnapshotFinalMatrix = new Matrix();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700110 final Matrix mExitFrameFinalMatrix = new Matrix();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800111 final Matrix mTmpMatrix = new Matrix();
Dianne Hackborna1111872010-11-23 20:55:11 -0800112 final float[] mTmpFloats = new float[9];
Craig Mautnerdbb79912012-03-01 18:59:14 -0800113 private boolean mMoreRotateEnter;
114 private boolean mMoreRotateExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800115 private boolean mMoreRotateFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800116 private boolean mMoreFinishEnter;
117 private boolean mMoreFinishExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800118 private boolean mMoreFinishFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800119 private boolean mMoreStartEnter;
120 private boolean mMoreStartExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800121 private boolean mMoreStartFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -0800122
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800123 public void printTo(String prefix, PrintWriter pw) {
124 pw.print(prefix); pw.print("mSurface="); pw.print(mSurface);
125 pw.print(" mWidth="); pw.print(mWidth);
126 pw.print(" mHeight="); pw.println(mHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700127 if (USE_CUSTOM_BLACK_FRAME) {
128 pw.print(prefix); pw.print("mCustomBlackFrame="); pw.println(mCustomBlackFrame);
129 if (mCustomBlackFrame != null) {
130 mCustomBlackFrame.printTo(prefix + " ", pw);
131 }
132 }
133 pw.print(prefix); pw.print("mExitingBlackFrame="); pw.println(mExitingBlackFrame);
134 if (mExitingBlackFrame != null) {
135 mExitingBlackFrame.printTo(prefix + " ", pw);
136 }
137 pw.print(prefix); pw.print("mEnteringBlackFrame="); pw.println(mEnteringBlackFrame);
138 if (mEnteringBlackFrame != null) {
139 mEnteringBlackFrame.printTo(prefix + " ", pw);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800140 }
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700141 pw.print(prefix); pw.print("mCurRotation="); pw.print(mCurRotation);
142 pw.print(" mOriginalRotation="); pw.println(mOriginalRotation);
143 pw.print(prefix); pw.print("mOriginalWidth="); pw.print(mOriginalWidth);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800144 pw.print(" mOriginalHeight="); pw.println(mOriginalHeight);
145 pw.print(prefix); pw.print("mStarted="); pw.print(mStarted);
146 pw.print(" mAnimRunning="); pw.print(mAnimRunning);
147 pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady);
148 pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime);
149 pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation);
150 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
151 pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
152 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800153 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
154 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800155 pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
156 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
157 pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
158 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800159 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
160 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800161 pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
162 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
163 pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
164 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800165 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
166 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800167 pw.print(prefix); pw.print("mExitTransformation=");
168 mExitTransformation.printShortString(pw); pw.println();
169 pw.print(prefix); pw.print("mEnterTransformation=");
170 mEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800171 pw.print(prefix); pw.print("mFrameTransformation=");
172 mEnterTransformation.printShortString(pw); pw.println();
173 pw.print(prefix); pw.print("mFrameInitialMatrix=");
174 mFrameInitialMatrix.printShortString(pw);
175 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800176 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
177 mSnapshotInitialMatrix.printShortString(pw);
178 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
179 pw.println();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700180 pw.print(prefix); pw.print("mExitFrameFinalMatrix=");
181 mExitFrameFinalMatrix.printShortString(pw);
182 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800183 }
184
Jeff Brownbc68a592011-07-25 12:58:12 -0700185 public ScreenRotationAnimation(Context context, SurfaceSession session,
186 boolean inTransaction, int originalWidth, int originalHeight, int originalRotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800187 mContext = context;
Dianne Hackborna1111872010-11-23 20:55:11 -0800188
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800189 // Screenshot does NOT include rotation!
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700190 if (originalRotation == Surface.ROTATION_90
191 || originalRotation == Surface.ROTATION_270) {
192 mWidth = originalHeight;
193 mHeight = originalWidth;
194 } else {
195 mWidth = originalWidth;
196 mHeight = originalHeight;
197 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800198
Jeff Brownbc68a592011-07-25 12:58:12 -0700199 mOriginalRotation = originalRotation;
200 mOriginalWidth = originalWidth;
201 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800202
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800203 if (!inTransaction) {
Dianne Hackborn36991742011-10-11 21:35:26 -0700204 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800205 ">>> OPEN TRANSACTION ScreenRotationAnimation");
206 Surface.openTransaction();
207 }
Dianne Hackborn352cc982011-01-04 11:34:18 -0800208
Dianne Hackborna1111872010-11-23 20:55:11 -0800209 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800210 try {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800211 mSurface = new Surface(session, 0, "FreezeSurface",
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700212 -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700213 if (!mSurface.isValid()) {
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700214 // Screenshot failed, punt.
215 mSurface = null;
216 return;
217 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700218 mSurface.setLayer(FREEZE_LAYER + 1);
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700219 mSurface.show();
Dianne Hackborn352cc982011-01-04 11:34:18 -0800220 } catch (Surface.OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800221 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800222 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800223
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700224 if (WindowManagerService.SHOW_TRANSACTIONS ||
225 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
226 " FREEZE " + mSurface + ": CREATE");
227
Jeff Brownbc68a592011-07-25 12:58:12 -0700228 setRotation(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800229 } finally {
230 if (!inTransaction) {
231 Surface.closeTransaction();
Dianne Hackborn36991742011-10-11 21:35:26 -0700232 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800233 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800234 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800235 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800236 }
237
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800238 boolean hasScreenshot() {
239 return mSurface != null;
240 }
241
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800242 static int deltaRotation(int oldRotation, int newRotation) {
243 int delta = newRotation - oldRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800244 if (delta < 0) delta += 4;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800245 return delta;
246 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800247
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800248 void setSnapshotTransform(Matrix matrix, float alpha) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800249 if (mSurface != null) {
250 matrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700251 mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X],
252 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800253 mSurface.setMatrix(
254 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
255 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
256 mSurface.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800257 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800258 float[] srcPnts = new float[] { 0, 0, mWidth, mHeight };
259 float[] dstPnts = new float[4];
260 matrix.mapPoints(dstPnts, srcPnts);
261 Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1]
262 + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")");
263 Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1]
264 + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")");
265 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800266 }
267 }
268
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800269 public static void createRotationMatrix(int rotation, int width, int height,
270 Matrix outMatrix) {
271 switch (rotation) {
272 case Surface.ROTATION_0:
273 outMatrix.reset();
274 break;
275 case Surface.ROTATION_90:
276 outMatrix.setRotate(90, 0, 0);
277 outMatrix.postTranslate(height, 0);
278 break;
279 case Surface.ROTATION_180:
280 outMatrix.setRotate(180, 0, 0);
281 outMatrix.postTranslate(width, height);
282 break;
283 case Surface.ROTATION_270:
284 outMatrix.setRotate(270, 0, 0);
285 outMatrix.postTranslate(0, width);
286 break;
287 }
288 }
289
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800290 // Must be called while in a transaction.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800291 private void setRotation(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800292 mCurRotation = rotation;
293
294 // Compute the transformation matrix that must be applied
295 // to the snapshot to make it stay in the same original position
296 // with the current screen rotation.
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700297 int delta = deltaRotation(rotation, Surface.ROTATION_0);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800298 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800299
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800300 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800301 setSnapshotTransform(mSnapshotInitialMatrix, 1.0f);
302 }
303
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800304 // Must be called while in a transaction.
305 public boolean setRotation(int rotation, SurfaceSession session,
306 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
307 setRotation(rotation);
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700308 if (TWO_PHASE_ANIMATION) {
309 return startAnimation(session, maxAnimationDuration, animationScale,
310 finalWidth, finalHeight, false);
311 } else {
312 // Don't start animation yet.
313 return false;
314 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800315 }
316
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800317 /**
318 * Returns true if animating.
319 */
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800320 private boolean startAnimation(SurfaceSession session, long maxAnimationDuration,
321 float animationScale, int finalWidth, int finalHeight, boolean dismissing) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800322 if (mSurface == null) {
323 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800324 return false;
325 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800326 if (mStarted) {
327 return true;
328 }
329
330 mStarted = true;
331
332 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800333
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800334 // Figure out how the screen has moved from the original rotation.
335 int delta = deltaRotation(mCurRotation, mOriginalRotation);
336
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700337 if (TWO_PHASE_ANIMATION && mFinishExitAnimation == null
338 && (!dismissing || delta != Surface.ROTATION_0)) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800339 if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations");
340 firstStart = true;
341 mStartExitAnimation = AnimationUtils.loadAnimation(mContext,
342 com.android.internal.R.anim.screen_rotate_start_exit);
343 mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
344 com.android.internal.R.anim.screen_rotate_start_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700345 if (USE_CUSTOM_BLACK_FRAME) {
346 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
347 com.android.internal.R.anim.screen_rotate_start_frame);
348 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800349 mFinishExitAnimation = AnimationUtils.loadAnimation(mContext,
350 com.android.internal.R.anim.screen_rotate_finish_exit);
351 mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext,
352 com.android.internal.R.anim.screen_rotate_finish_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700353 if (USE_CUSTOM_BLACK_FRAME) {
354 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
355 com.android.internal.R.anim.screen_rotate_finish_frame);
356 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800357 }
358
359 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
360 + finalWidth + " finalHeight=" + finalHeight
361 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
362
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800363 switch (delta) {
364 case Surface.ROTATION_0:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800365 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800366 com.android.internal.R.anim.screen_rotate_0_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800367 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800368 com.android.internal.R.anim.screen_rotate_0_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700369 if (USE_CUSTOM_BLACK_FRAME) {
370 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
371 com.android.internal.R.anim.screen_rotate_0_frame);
372 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800373 break;
374 case Surface.ROTATION_90:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800375 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800376 com.android.internal.R.anim.screen_rotate_plus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800377 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800378 com.android.internal.R.anim.screen_rotate_plus_90_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700379 if (USE_CUSTOM_BLACK_FRAME) {
380 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
381 com.android.internal.R.anim.screen_rotate_plus_90_frame);
382 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800383 break;
384 case Surface.ROTATION_180:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800385 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800386 com.android.internal.R.anim.screen_rotate_180_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800387 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800388 com.android.internal.R.anim.screen_rotate_180_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800389 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
390 com.android.internal.R.anim.screen_rotate_180_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800391 break;
392 case Surface.ROTATION_270:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800393 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800394 com.android.internal.R.anim.screen_rotate_minus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800395 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800396 com.android.internal.R.anim.screen_rotate_minus_90_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700397 if (USE_CUSTOM_BLACK_FRAME) {
398 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
399 com.android.internal.R.anim.screen_rotate_minus_90_frame);
400 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800401 break;
402 }
403
Dianne Hackborn191874e32012-03-09 11:03:36 -0800404 // Compute partial steps between original and final sizes. These
405 // are used for the dimensions of the exiting and entering elements,
406 // so they are never stretched too significantly.
407 final int halfWidth = (finalWidth + mOriginalWidth) / 2;
408 final int halfHeight = (finalHeight + mOriginalHeight) / 2;
409
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800410 // Initialize the animations. This is a hack, redefining what "parent"
411 // means to allow supplying the last and next size. In this definition
412 // "%p" is the original (let's call it "previous") size, and "%" is the
413 // screen's current/new size.
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700414 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800415 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
416 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800417 halfWidth, halfHeight);
418 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800419 mOriginalWidth, mOriginalHeight);
420 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800421 halfWidth, halfHeight);
422 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800423 mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700424 if (USE_CUSTOM_BLACK_FRAME) {
425 mStartFrameAnimation.initialize(finalWidth, finalHeight,
426 mOriginalWidth, mOriginalHeight);
427 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
428 mOriginalWidth, mOriginalHeight);
429 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800430 }
431 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
432 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700433 if (USE_CUSTOM_BLACK_FRAME) {
434 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth,
435 mOriginalHeight);
436 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800437 mAnimRunning = false;
438 mFinishAnimReady = false;
439 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800440
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700441 if (TWO_PHASE_ANIMATION && firstStart) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800442 mStartExitAnimation.restrictDuration(maxAnimationDuration);
443 mStartExitAnimation.scaleCurrentDuration(animationScale);
444 mStartEnterAnimation.restrictDuration(maxAnimationDuration);
445 mStartEnterAnimation.scaleCurrentDuration(animationScale);
446 mFinishExitAnimation.restrictDuration(maxAnimationDuration);
447 mFinishExitAnimation.scaleCurrentDuration(animationScale);
448 mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
449 mFinishEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700450 if (USE_CUSTOM_BLACK_FRAME) {
451 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
452 mStartFrameAnimation.scaleCurrentDuration(animationScale);
453 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
454 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
455 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800456 }
457 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
458 mRotateExitAnimation.scaleCurrentDuration(animationScale);
459 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
460 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700461 if (USE_CUSTOM_BLACK_FRAME) {
462 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
463 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
464 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800465
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700466 if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800467 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
468 WindowManagerService.TAG,
469 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
470 Surface.openTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800471
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800472 // Compute the transformation matrix that must be applied
473 // the the black frame to make it stay in the initial position
474 // before the new screen rotation. This is different than the
475 // snapshot transformation because the snapshot is always based
476 // of the native orientation of the screen, not the orientation
477 // we were last in.
478 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
479
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800480 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800481 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
482 mOriginalWidth*2, mOriginalHeight*2);
483 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700484 mCustomBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 3);
485 mCustomBlackFrame.setMatrix(mFrameInitialMatrix);
486 } catch (Surface.OutOfResourcesException e) {
487 Slog.w(TAG, "Unable to allocate black surface", e);
488 } finally {
489 Surface.closeTransaction();
490 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
491 WindowManagerService.TAG,
492 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
493 }
494 }
495
496 if (mExitingBlackFrame == null) {
497 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
498 WindowManagerService.TAG,
499 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
500 Surface.openTransaction();
501
502 // Compute the transformation matrix that must be applied
503 // the the black frame to make it stay in the initial position
504 // before the new screen rotation. This is different than the
505 // snapshot transformation because the snapshot is always based
506 // of the native orientation of the screen, not the orientation
507 // we were last in.
508 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
509
510 try {
511 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
512 mOriginalWidth*2, mOriginalHeight*2);
513 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
514 mExitingBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 2);
515 mExitingBlackFrame.setMatrix(mFrameInitialMatrix);
516 } catch (Surface.OutOfResourcesException e) {
517 Slog.w(TAG, "Unable to allocate black surface", e);
518 } finally {
519 Surface.closeTransaction();
520 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
521 WindowManagerService.TAG,
522 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
523 }
524 }
525
526 if (false && mEnteringBlackFrame == null) {
527 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
528 WindowManagerService.TAG,
529 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
530 Surface.openTransaction();
531
532 try {
533 Rect outer = new Rect(-finalWidth*1, -finalHeight*1,
534 finalWidth*2, finalHeight*2);
535 Rect inner = new Rect(0, 0, finalWidth, finalHeight);
536 mEnteringBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800537 } catch (Surface.OutOfResourcesException e) {
538 Slog.w(TAG, "Unable to allocate black surface", e);
539 } finally {
540 Surface.closeTransaction();
541 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
542 WindowManagerService.TAG,
543 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
544 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800545 }
546
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800547 return true;
548 }
549
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800550 /**
551 * Returns true if animating.
552 */
553 public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
554 float animationScale, int finalWidth, int finalHeight) {
555 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
556 if (mSurface == null) {
557 // Can't do animation.
558 return false;
559 }
560 if (!mStarted) {
561 startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight,
562 true);
563 }
564 if (!mStarted) {
565 return false;
566 }
567 if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true");
568 mFinishAnimReady = true;
569 return true;
570 }
571
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800572 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800573 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800574 if (mSurface != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700575 if (WindowManagerService.SHOW_TRANSACTIONS ||
576 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
577 " FREEZE " + mSurface + ": DESTROY");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800578 mSurface.destroy();
579 mSurface = null;
580 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700581 if (mCustomBlackFrame != null) {
582 mCustomBlackFrame.kill();
583 mCustomBlackFrame = null;
584 }
585 if (mExitingBlackFrame != null) {
586 mExitingBlackFrame.kill();
587 mExitingBlackFrame = null;
588 }
589 if (mEnteringBlackFrame != null) {
590 mEnteringBlackFrame.kill();
591 mEnteringBlackFrame = null;
Dianne Hackborn352cc982011-01-04 11:34:18 -0800592 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800593 if (mStartExitAnimation != null) {
594 mStartExitAnimation.cancel();
595 mStartExitAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800596 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800597 if (mStartEnterAnimation != null) {
598 mStartEnterAnimation.cancel();
599 mStartEnterAnimation = null;
600 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800601 if (mStartFrameAnimation != null) {
602 mStartFrameAnimation.cancel();
603 mStartFrameAnimation = null;
604 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800605 if (mFinishExitAnimation != null) {
606 mFinishExitAnimation.cancel();
607 mFinishExitAnimation = null;
608 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800609 if (mFinishEnterAnimation != null) {
610 mFinishEnterAnimation.cancel();
611 mFinishEnterAnimation = null;
612 }
613 if (mFinishFrameAnimation != null) {
614 mFinishFrameAnimation.cancel();
615 mFinishFrameAnimation = null;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800616 }
617 if (mRotateExitAnimation != null) {
618 mRotateExitAnimation.cancel();
619 mRotateExitAnimation = null;
620 }
621 if (mRotateEnterAnimation != null) {
622 mRotateEnterAnimation.cancel();
623 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800624 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800625 if (mRotateFrameAnimation != null) {
626 mRotateFrameAnimation.cancel();
627 mRotateFrameAnimation = null;
628 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800629 }
630
631 public boolean isAnimating() {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700632 if (TWO_PHASE_ANIMATION) {
633 return hasAnimations() || mFinishAnimReady;
634 } else {
635 return hasAnimations();
636 }
637 }
638
639 private boolean hasAnimations() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800640 return mStartEnterAnimation != null || mStartExitAnimation != null
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800641 || mStartFrameAnimation != null
642 || mFinishEnterAnimation != null || mFinishExitAnimation != null
643 || mFinishFrameAnimation != null
644 || mRotateEnterAnimation != null || mRotateExitAnimation != null
645 || mRotateFrameAnimation != null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800646 }
647
Craig Mautnere32c3072012-03-12 15:25:35 -0700648 private boolean stepAnimation(long now) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800649 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
650 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
651 mFinishAnimStartTime = now;
652 }
653
Craig Mautnerdbb79912012-03-01 18:59:14 -0800654 mMoreStartExit = false;
655 if (mStartExitAnimation != null) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800656 mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
657 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800658 }
659
660 mMoreStartEnter = false;
661 if (mStartEnterAnimation != null) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800662 mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
663 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800664 }
665
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800666 mMoreStartFrame = false;
667 if (mStartFrameAnimation != null) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800668 mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
669 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800670 }
671
Craig Mautnerdbb79912012-03-01 18:59:14 -0800672 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
673 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
674
Craig Mautnerdbb79912012-03-01 18:59:14 -0800675 mMoreFinishExit = false;
676 if (mFinishExitAnimation != null) {
677 mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
678 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800679 }
680
Craig Mautnerdbb79912012-03-01 18:59:14 -0800681 mMoreFinishEnter = false;
682 if (mFinishEnterAnimation != null) {
683 mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
684 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800685 }
686
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800687 mMoreFinishFrame = false;
688 if (mFinishFrameAnimation != null) {
689 mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
690 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800691 }
692
Craig Mautnerdbb79912012-03-01 18:59:14 -0800693 mMoreRotateExit = false;
694 if (mRotateExitAnimation != null) {
695 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
696 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700697 }
698
699 mMoreRotateEnter = false;
700 if (mRotateEnterAnimation != null) {
701 mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
702 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
703 }
704
705 mMoreRotateFrame = false;
706 if (mRotateFrameAnimation != null) {
707 mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
708 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
709 }
710
711 if (!mMoreStartExit && !mMoreRotateExit && !mMoreFinishExit) {
712 if (mStartExitAnimation != null) {
713 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing start exit anim!");
714 mStartExitAnimation.cancel();
715 mStartExitAnimation = null;
716 mStartExitTransformation.clear();
717 }
718 if (mFinishExitAnimation != null) {
719 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing finish exit anim!");
720 mFinishExitAnimation.cancel();
721 mFinishExitAnimation = null;
722 mFinishExitTransformation.clear();
723 }
724 if (mRotateExitAnimation != null) {
725 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing rotate exit anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800726 mRotateExitAnimation.cancel();
727 mRotateExitAnimation = null;
728 mRotateExitTransformation.clear();
729 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800730 }
731
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700732 if (!mMoreStartEnter && !mMoreRotateEnter && !mMoreFinishEnter) {
733 if (mStartEnterAnimation != null) {
734 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing start enter anim!");
735 mStartEnterAnimation.cancel();
736 mStartEnterAnimation = null;
737 mStartEnterTransformation.clear();
738 }
739 if (mFinishEnterAnimation != null) {
740 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing finish enter anim!");
741 mFinishEnterAnimation.cancel();
742 mFinishEnterAnimation = null;
743 mFinishEnterTransformation.clear();
744 }
745 if (mRotateEnterAnimation != null) {
746 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing rotate enter anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800747 mRotateEnterAnimation.cancel();
748 mRotateEnterAnimation = null;
749 mRotateEnterTransformation.clear();
750 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800751 }
752
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700753 if (USE_CUSTOM_BLACK_FRAME && !mMoreStartFrame && !mMoreRotateFrame && !mMoreFinishFrame) {
754 if (mStartFrameAnimation != null) {
755 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing start frame anim!");
756 mStartFrameAnimation.cancel();
757 mStartFrameAnimation = null;
758 mStartFrameTransformation.clear();
759 }
760 if (mFinishFrameAnimation != null) {
761 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing finish frame anim!");
762 mFinishFrameAnimation.cancel();
763 mFinishFrameAnimation = null;
764 mFinishFrameTransformation.clear();
765 }
766 if (mRotateFrameAnimation != null) {
767 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing rotate frame anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800768 mRotateFrameAnimation.cancel();
769 mRotateFrameAnimation = null;
770 mRotateFrameTransformation.clear();
771 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800772 }
773
774 mExitTransformation.set(mRotateExitTransformation);
775 mExitTransformation.compose(mStartExitTransformation);
776 mExitTransformation.compose(mFinishExitTransformation);
777
778 mEnterTransformation.set(mRotateEnterTransformation);
779 mEnterTransformation.compose(mStartEnterTransformation);
780 mEnterTransformation.compose(mFinishEnterTransformation);
781
782 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
783 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700784
785 if (USE_CUSTOM_BLACK_FRAME) {
786 //mFrameTransformation.set(mRotateExitTransformation);
787 //mFrameTransformation.compose(mStartExitTransformation);
788 //mFrameTransformation.compose(mFinishExitTransformation);
789 mFrameTransformation.set(mRotateFrameTransformation);
790 mFrameTransformation.compose(mStartFrameTransformation);
791 mFrameTransformation.compose(mFinishFrameTransformation);
792 mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
793 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
794 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800795
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800796 final boolean more = mMoreStartEnter || mMoreStartExit || mMoreStartFrame
797 || mMoreFinishEnter || mMoreFinishExit || mMoreFinishFrame
798 || mMoreRotateEnter || mMoreRotateExit || mMoreRotateFrame
799 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800800
801 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
802
803 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
804
805 return more;
806 }
807
808 void updateSurfaces() {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700809 if (!mStarted) {
810 return;
811 }
812
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700813 if (mSurface != null) {
814 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800815 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
816 mSurface.hide();
817 }
818 }
819
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700820 if (mCustomBlackFrame != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700821 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800822 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700823 mCustomBlackFrame.hide();
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700824 } else {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700825 mCustomBlackFrame.setMatrix(mFrameTransformation.getMatrix());
826 }
827 }
828
829 if (mExitingBlackFrame != null) {
830 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
831 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
832 mExitingBlackFrame.hide();
833 } else {
834 mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
835 mExitingBlackFrame.setMatrix(mExitFrameFinalMatrix);
836 mExitingBlackFrame.setAlpha(mExitTransformation.getAlpha());
837 }
838 }
839
840 if (mEnteringBlackFrame != null) {
841 if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
842 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
843 mEnteringBlackFrame.hide();
844 } else {
845 mEnteringBlackFrame.setMatrix(mEnterTransformation.getMatrix());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800846 }
847 }
848
849 setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
850 }
851
Craig Mautnere32c3072012-03-12 15:25:35 -0700852 public boolean stepAnimationLocked(long now) {
Dianne Hackborn187ae2102012-04-11 18:12:06 -0700853 if (!hasAnimations()) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800854 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800855 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800856 return false;
857 }
858
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800859 if (!mAnimRunning) {
860 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
861 if (mStartEnterAnimation != null) {
862 mStartEnterAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700863 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800864 if (mStartExitAnimation != null) {
865 mStartExitAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700866 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800867 if (mStartFrameAnimation != null) {
868 mStartFrameAnimation.setStartTime(now);
869 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800870 if (mFinishEnterAnimation != null) {
871 mFinishEnterAnimation.setStartTime(0);
872 }
873 if (mFinishExitAnimation != null) {
874 mFinishExitAnimation.setStartTime(0);
875 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800876 if (mFinishFrameAnimation != null) {
877 mFinishFrameAnimation.setStartTime(0);
878 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800879 if (mRotateEnterAnimation != null) {
880 mRotateEnterAnimation.setStartTime(now);
881 }
882 if (mRotateExitAnimation != null) {
883 mRotateExitAnimation.setStartTime(now);
884 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800885 if (mRotateFrameAnimation != null) {
886 mRotateFrameAnimation.setStartTime(now);
887 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800888 mAnimRunning = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800889 }
Craig Mautnere32c3072012-03-12 15:25:35 -0700890
891 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800892 }
893
894 public Transformation getEnterTransformation() {
895 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800896 }
897}