blob: e460f7fd4cd86c10a80e5a32267ad2f4786dd761 [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 Hackbornd6b32b62012-03-16 11:54:51 -070036 static final boolean USE_CUSTOM_BLACK_FRAME = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080037
Dianne Hackborn50660e22011-02-02 17:12:25 -080038 static final int FREEZE_LAYER = WindowManagerService.TYPE_LAYER_MULTIPLIER * 200;
39
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080040 final Context mContext;
Dianne Hackborna1111872010-11-23 20:55:11 -080041 Surface mSurface;
Dianne Hackbornd6b32b62012-03-16 11:54:51 -070042 BlackFrame mCustomBlackFrame;
43 BlackFrame mExitingBlackFrame;
44 BlackFrame mEnteringBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080045 int mWidth, mHeight;
46
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080047 int mSnapshotDeltaRotation;
48 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 }
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700141 pw.print(prefix); pw.print(" mSnapshotDeltaRotation="); pw.print(mSnapshotDeltaRotation);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800142 pw.print(" mCurRotation="); pw.println(mCurRotation);
143 pw.print(prefix); pw.print("mOriginalRotation="); pw.print(mOriginalRotation);
144 pw.print(" mOriginalWidth="); pw.print(mOriginalWidth);
145 pw.print(" mOriginalHeight="); pw.println(mOriginalHeight);
146 pw.print(prefix); pw.print("mStarted="); pw.print(mStarted);
147 pw.print(" mAnimRunning="); pw.print(mAnimRunning);
148 pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady);
149 pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime);
150 pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation);
151 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
152 pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
153 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800154 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
155 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800156 pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
157 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
158 pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
159 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800160 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
161 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800162 pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
163 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
164 pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
165 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800166 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
167 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800168 pw.print(prefix); pw.print("mExitTransformation=");
169 mExitTransformation.printShortString(pw); pw.println();
170 pw.print(prefix); pw.print("mEnterTransformation=");
171 mEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800172 pw.print(prefix); pw.print("mFrameTransformation=");
173 mEnterTransformation.printShortString(pw); pw.println();
174 pw.print(prefix); pw.print("mFrameInitialMatrix=");
175 mFrameInitialMatrix.printShortString(pw);
176 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800177 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
178 mSnapshotInitialMatrix.printShortString(pw);
179 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
180 pw.println();
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700181 pw.print(prefix); pw.print("mExitFrameFinalMatrix=");
182 mExitFrameFinalMatrix.printShortString(pw);
183 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800184 }
185
Jeff Brownbc68a592011-07-25 12:58:12 -0700186 public ScreenRotationAnimation(Context context, SurfaceSession session,
187 boolean inTransaction, int originalWidth, int originalHeight, int originalRotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800188 mContext = context;
Dianne Hackborna1111872010-11-23 20:55:11 -0800189
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800190 // Screenshot does NOT include rotation!
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700191 if (originalRotation == Surface.ROTATION_90
192 || originalRotation == Surface.ROTATION_270) {
193 mWidth = originalHeight;
194 mHeight = originalWidth;
195 } else {
196 mWidth = originalWidth;
197 mHeight = originalHeight;
198 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800199
Jeff Brownbc68a592011-07-25 12:58:12 -0700200 mOriginalRotation = originalRotation;
201 mOriginalWidth = originalWidth;
202 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800203
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800204 if (!inTransaction) {
Dianne Hackborn36991742011-10-11 21:35:26 -0700205 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800206 ">>> OPEN TRANSACTION ScreenRotationAnimation");
207 Surface.openTransaction();
208 }
Dianne Hackborn352cc982011-01-04 11:34:18 -0800209
Dianne Hackborna1111872010-11-23 20:55:11 -0800210 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800211 try {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800212 mSurface = new Surface(session, 0, "FreezeSurface",
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700213 -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700214 if (!mSurface.isValid()) {
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700215 // Screenshot failed, punt.
216 mSurface = null;
217 return;
218 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700219 mSurface.setLayer(FREEZE_LAYER + 1);
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700220 mSurface.show();
Dianne Hackborn352cc982011-01-04 11:34:18 -0800221 } catch (Surface.OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800222 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800223 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800224
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700225 if (WindowManagerService.SHOW_TRANSACTIONS ||
226 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
227 " FREEZE " + mSurface + ": CREATE");
228
Jeff Brownbc68a592011-07-25 12:58:12 -0700229 setRotation(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800230 } finally {
231 if (!inTransaction) {
232 Surface.closeTransaction();
Dianne Hackborn36991742011-10-11 21:35:26 -0700233 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800234 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800235 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800236 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800237 }
238
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800239 boolean hasScreenshot() {
240 return mSurface != null;
241 }
242
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800243 static int deltaRotation(int oldRotation, int newRotation) {
244 int delta = newRotation - oldRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800245 if (delta < 0) delta += 4;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800246 return delta;
247 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800248
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800249 void setSnapshotTransform(Matrix matrix, float alpha) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800250 if (mSurface != null) {
251 matrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700252 mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X],
253 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800254 mSurface.setMatrix(
255 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
256 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
257 mSurface.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800258 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800259 float[] srcPnts = new float[] { 0, 0, mWidth, mHeight };
260 float[] dstPnts = new float[4];
261 matrix.mapPoints(dstPnts, srcPnts);
262 Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1]
263 + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")");
264 Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1]
265 + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")");
266 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800267 }
268 }
269
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800270 public static void createRotationMatrix(int rotation, int width, int height,
271 Matrix outMatrix) {
272 switch (rotation) {
273 case Surface.ROTATION_0:
274 outMatrix.reset();
275 break;
276 case Surface.ROTATION_90:
277 outMatrix.setRotate(90, 0, 0);
278 outMatrix.postTranslate(height, 0);
279 break;
280 case Surface.ROTATION_180:
281 outMatrix.setRotate(180, 0, 0);
282 outMatrix.postTranslate(width, height);
283 break;
284 case Surface.ROTATION_270:
285 outMatrix.setRotate(270, 0, 0);
286 outMatrix.postTranslate(0, width);
287 break;
288 }
289 }
290
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800291 // Must be called while in a transaction.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800292 private void setRotation(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800293 mCurRotation = rotation;
294
295 // Compute the transformation matrix that must be applied
296 // to the snapshot to make it stay in the same original position
297 // with the current screen rotation.
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700298 int delta = deltaRotation(rotation, Surface.ROTATION_0);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800299 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800300
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800301 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800302 setSnapshotTransform(mSnapshotInitialMatrix, 1.0f);
303 }
304
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800305 // Must be called while in a transaction.
306 public boolean setRotation(int rotation, SurfaceSession session,
307 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
308 setRotation(rotation);
309 return startAnimation(session, maxAnimationDuration, animationScale,
310 finalWidth, finalHeight, false);
311 }
312
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800313 /**
314 * Returns true if animating.
315 */
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800316 private boolean startAnimation(SurfaceSession session, long maxAnimationDuration,
317 float animationScale, int finalWidth, int finalHeight, boolean dismissing) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800318 if (mSurface == null) {
319 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800320 return false;
321 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800322 if (mStarted) {
323 return true;
324 }
325
326 mStarted = true;
327
328 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800329
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800330 // Figure out how the screen has moved from the original rotation.
331 int delta = deltaRotation(mCurRotation, mOriginalRotation);
332
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800333 if (mFinishExitAnimation == null && (!dismissing || delta != Surface.ROTATION_0)) {
334 if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations");
335 firstStart = true;
336 mStartExitAnimation = AnimationUtils.loadAnimation(mContext,
337 com.android.internal.R.anim.screen_rotate_start_exit);
338 mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
339 com.android.internal.R.anim.screen_rotate_start_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700340 if (USE_CUSTOM_BLACK_FRAME) {
341 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
342 com.android.internal.R.anim.screen_rotate_start_frame);
343 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800344 mFinishExitAnimation = AnimationUtils.loadAnimation(mContext,
345 com.android.internal.R.anim.screen_rotate_finish_exit);
346 mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext,
347 com.android.internal.R.anim.screen_rotate_finish_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700348 if (USE_CUSTOM_BLACK_FRAME) {
349 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
350 com.android.internal.R.anim.screen_rotate_finish_frame);
351 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800352 }
353
354 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
355 + finalWidth + " finalHeight=" + finalHeight
356 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
357
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800358 switch (delta) {
359 case Surface.ROTATION_0:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800360 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800361 com.android.internal.R.anim.screen_rotate_0_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800362 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800363 com.android.internal.R.anim.screen_rotate_0_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700364 if (USE_CUSTOM_BLACK_FRAME) {
365 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
366 com.android.internal.R.anim.screen_rotate_0_frame);
367 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800368 break;
369 case Surface.ROTATION_90:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800370 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800371 com.android.internal.R.anim.screen_rotate_plus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800372 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800373 com.android.internal.R.anim.screen_rotate_plus_90_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700374 if (USE_CUSTOM_BLACK_FRAME) {
375 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
376 com.android.internal.R.anim.screen_rotate_plus_90_frame);
377 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800378 break;
379 case Surface.ROTATION_180:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800380 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800381 com.android.internal.R.anim.screen_rotate_180_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800382 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800383 com.android.internal.R.anim.screen_rotate_180_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800384 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
385 com.android.internal.R.anim.screen_rotate_180_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800386 break;
387 case Surface.ROTATION_270:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800388 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800389 com.android.internal.R.anim.screen_rotate_minus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800390 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800391 com.android.internal.R.anim.screen_rotate_minus_90_enter);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700392 if (USE_CUSTOM_BLACK_FRAME) {
393 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
394 com.android.internal.R.anim.screen_rotate_minus_90_frame);
395 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800396 break;
397 }
398
Dianne Hackborn191874e32012-03-09 11:03:36 -0800399 // Compute partial steps between original and final sizes. These
400 // are used for the dimensions of the exiting and entering elements,
401 // so they are never stretched too significantly.
402 final int halfWidth = (finalWidth + mOriginalWidth) / 2;
403 final int halfHeight = (finalHeight + mOriginalHeight) / 2;
404
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800405 // Initialize the animations. This is a hack, redefining what "parent"
406 // means to allow supplying the last and next size. In this definition
407 // "%p" is the original (let's call it "previous") size, and "%" is the
408 // screen's current/new size.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800409 if (firstStart) {
410 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
411 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800412 halfWidth, halfHeight);
413 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800414 mOriginalWidth, mOriginalHeight);
415 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800416 halfWidth, halfHeight);
417 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800418 mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700419 if (USE_CUSTOM_BLACK_FRAME) {
420 mStartFrameAnimation.initialize(finalWidth, finalHeight,
421 mOriginalWidth, mOriginalHeight);
422 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
423 mOriginalWidth, mOriginalHeight);
424 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800425 }
426 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
427 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700428 if (USE_CUSTOM_BLACK_FRAME) {
429 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth,
430 mOriginalHeight);
431 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800432 mAnimRunning = false;
433 mFinishAnimReady = false;
434 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800435
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800436 if (firstStart) {
437 mStartExitAnimation.restrictDuration(maxAnimationDuration);
438 mStartExitAnimation.scaleCurrentDuration(animationScale);
439 mStartEnterAnimation.restrictDuration(maxAnimationDuration);
440 mStartEnterAnimation.scaleCurrentDuration(animationScale);
441 mFinishExitAnimation.restrictDuration(maxAnimationDuration);
442 mFinishExitAnimation.scaleCurrentDuration(animationScale);
443 mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
444 mFinishEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700445 if (USE_CUSTOM_BLACK_FRAME) {
446 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
447 mStartFrameAnimation.scaleCurrentDuration(animationScale);
448 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
449 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
450 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800451 }
452 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
453 mRotateExitAnimation.scaleCurrentDuration(animationScale);
454 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
455 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700456 if (USE_CUSTOM_BLACK_FRAME) {
457 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
458 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
459 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800460
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700461 if (USE_CUSTOM_BLACK_FRAME && mCustomBlackFrame == null) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800462 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
463 WindowManagerService.TAG,
464 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
465 Surface.openTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800466
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800467 // Compute the transformation matrix that must be applied
468 // the the black frame to make it stay in the initial position
469 // before the new screen rotation. This is different than the
470 // snapshot transformation because the snapshot is always based
471 // of the native orientation of the screen, not the orientation
472 // we were last in.
473 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
474
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800475 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800476 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
477 mOriginalWidth*2, mOriginalHeight*2);
478 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700479 mCustomBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 3);
480 mCustomBlackFrame.setMatrix(mFrameInitialMatrix);
481 } catch (Surface.OutOfResourcesException e) {
482 Slog.w(TAG, "Unable to allocate black surface", e);
483 } finally {
484 Surface.closeTransaction();
485 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
486 WindowManagerService.TAG,
487 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
488 }
489 }
490
491 if (mExitingBlackFrame == null) {
492 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
493 WindowManagerService.TAG,
494 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
495 Surface.openTransaction();
496
497 // Compute the transformation matrix that must be applied
498 // the the black frame to make it stay in the initial position
499 // before the new screen rotation. This is different than the
500 // snapshot transformation because the snapshot is always based
501 // of the native orientation of the screen, not the orientation
502 // we were last in.
503 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
504
505 try {
506 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
507 mOriginalWidth*2, mOriginalHeight*2);
508 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
509 mExitingBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 2);
510 mExitingBlackFrame.setMatrix(mFrameInitialMatrix);
511 } catch (Surface.OutOfResourcesException e) {
512 Slog.w(TAG, "Unable to allocate black surface", e);
513 } finally {
514 Surface.closeTransaction();
515 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
516 WindowManagerService.TAG,
517 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
518 }
519 }
520
521 if (false && mEnteringBlackFrame == null) {
522 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
523 WindowManagerService.TAG,
524 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
525 Surface.openTransaction();
526
527 try {
528 Rect outer = new Rect(-finalWidth*1, -finalHeight*1,
529 finalWidth*2, finalHeight*2);
530 Rect inner = new Rect(0, 0, finalWidth, finalHeight);
531 mEnteringBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800532 } catch (Surface.OutOfResourcesException e) {
533 Slog.w(TAG, "Unable to allocate black surface", e);
534 } finally {
535 Surface.closeTransaction();
536 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
537 WindowManagerService.TAG,
538 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
539 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800540 }
541
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800542 return true;
543 }
544
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800545 /**
546 * Returns true if animating.
547 */
548 public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
549 float animationScale, int finalWidth, int finalHeight) {
550 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
551 if (mSurface == null) {
552 // Can't do animation.
553 return false;
554 }
555 if (!mStarted) {
556 startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight,
557 true);
558 }
559 if (!mStarted) {
560 return false;
561 }
562 if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true");
563 mFinishAnimReady = true;
564 return true;
565 }
566
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800567 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800568 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800569 if (mSurface != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700570 if (WindowManagerService.SHOW_TRANSACTIONS ||
571 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
572 " FREEZE " + mSurface + ": DESTROY");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800573 mSurface.destroy();
574 mSurface = null;
575 }
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700576 if (mCustomBlackFrame != null) {
577 mCustomBlackFrame.kill();
578 mCustomBlackFrame = null;
579 }
580 if (mExitingBlackFrame != null) {
581 mExitingBlackFrame.kill();
582 mExitingBlackFrame = null;
583 }
584 if (mEnteringBlackFrame != null) {
585 mEnteringBlackFrame.kill();
586 mEnteringBlackFrame = null;
Dianne Hackborn352cc982011-01-04 11:34:18 -0800587 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800588 if (mStartExitAnimation != null) {
589 mStartExitAnimation.cancel();
590 mStartExitAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800591 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800592 if (mStartEnterAnimation != null) {
593 mStartEnterAnimation.cancel();
594 mStartEnterAnimation = null;
595 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800596 if (mStartFrameAnimation != null) {
597 mStartFrameAnimation.cancel();
598 mStartFrameAnimation = null;
599 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800600 if (mFinishExitAnimation != null) {
601 mFinishExitAnimation.cancel();
602 mFinishExitAnimation = null;
603 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800604 if (mFinishEnterAnimation != null) {
605 mFinishEnterAnimation.cancel();
606 mFinishEnterAnimation = null;
607 }
608 if (mFinishFrameAnimation != null) {
609 mFinishFrameAnimation.cancel();
610 mFinishFrameAnimation = null;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800611 }
612 if (mRotateExitAnimation != null) {
613 mRotateExitAnimation.cancel();
614 mRotateExitAnimation = null;
615 }
616 if (mRotateEnterAnimation != null) {
617 mRotateEnterAnimation.cancel();
618 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800619 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800620 if (mRotateFrameAnimation != null) {
621 mRotateFrameAnimation.cancel();
622 mRotateFrameAnimation = null;
623 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800624 }
625
626 public boolean isAnimating() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800627 return mStartEnterAnimation != null || mStartExitAnimation != null
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800628 || mStartFrameAnimation != null
629 || mFinishEnterAnimation != null || mFinishExitAnimation != null
630 || mFinishFrameAnimation != null
631 || mRotateEnterAnimation != null || mRotateExitAnimation != null
632 || mRotateFrameAnimation != null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800633 }
634
Craig Mautnere32c3072012-03-12 15:25:35 -0700635 private boolean stepAnimation(long now) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800636
637 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
638 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
639 mFinishAnimStartTime = now;
640 }
641
Craig Mautnerdbb79912012-03-01 18:59:14 -0800642 mMoreStartExit = false;
643 if (mStartExitAnimation != null) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800644 mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
645 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800646 }
647
648 mMoreStartEnter = false;
649 if (mStartEnterAnimation != null) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800650 mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
651 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800652 }
653
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800654 mMoreStartFrame = false;
655 if (mStartFrameAnimation != null) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800656 mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
657 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800658 }
659
Craig Mautnerdbb79912012-03-01 18:59:14 -0800660 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
661 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
662
Craig Mautnerdbb79912012-03-01 18:59:14 -0800663 mMoreFinishExit = false;
664 if (mFinishExitAnimation != null) {
665 mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
666 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800667 }
668
Craig Mautnerdbb79912012-03-01 18:59:14 -0800669 mMoreFinishEnter = false;
670 if (mFinishEnterAnimation != null) {
671 mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
672 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800673 }
674
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800675 mMoreFinishFrame = false;
676 if (mFinishFrameAnimation != null) {
677 mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
678 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800679 }
680
Craig Mautnerdbb79912012-03-01 18:59:14 -0800681 mMoreRotateExit = false;
682 if (mRotateExitAnimation != null) {
683 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
684 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700685 }
686
687 mMoreRotateEnter = false;
688 if (mRotateEnterAnimation != null) {
689 mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
690 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
691 }
692
693 mMoreRotateFrame = false;
694 if (mRotateFrameAnimation != null) {
695 mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
696 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
697 }
698
699 if (!mMoreStartExit && !mMoreRotateExit && !mMoreFinishExit) {
700 if (mStartExitAnimation != null) {
701 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing start exit anim!");
702 mStartExitAnimation.cancel();
703 mStartExitAnimation = null;
704 mStartExitTransformation.clear();
705 }
706 if (mFinishExitAnimation != null) {
707 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing finish exit anim!");
708 mFinishExitAnimation.cancel();
709 mFinishExitAnimation = null;
710 mFinishExitTransformation.clear();
711 }
712 if (mRotateExitAnimation != null) {
713 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, clearing rotate exit anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800714 mRotateExitAnimation.cancel();
715 mRotateExitAnimation = null;
716 mRotateExitTransformation.clear();
717 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800718 }
719
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700720 if (!mMoreStartEnter && !mMoreRotateEnter && !mMoreFinishEnter) {
721 if (mStartEnterAnimation != null) {
722 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing start enter anim!");
723 mStartEnterAnimation.cancel();
724 mStartEnterAnimation = null;
725 mStartEnterTransformation.clear();
726 }
727 if (mFinishEnterAnimation != null) {
728 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing finish enter anim!");
729 mFinishEnterAnimation.cancel();
730 mFinishEnterAnimation = null;
731 mFinishEnterTransformation.clear();
732 }
733 if (mRotateEnterAnimation != null) {
734 if (DEBUG_STATE) Slog.v(TAG, "Enter animations done, clearing rotate enter anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800735 mRotateEnterAnimation.cancel();
736 mRotateEnterAnimation = null;
737 mRotateEnterTransformation.clear();
738 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800739 }
740
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700741 if (USE_CUSTOM_BLACK_FRAME && !mMoreStartFrame && !mMoreRotateFrame && !mMoreFinishFrame) {
742 if (mStartFrameAnimation != null) {
743 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing start frame anim!");
744 mStartFrameAnimation.cancel();
745 mStartFrameAnimation = null;
746 mStartFrameTransformation.clear();
747 }
748 if (mFinishFrameAnimation != null) {
749 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing finish frame anim!");
750 mFinishFrameAnimation.cancel();
751 mFinishFrameAnimation = null;
752 mFinishFrameTransformation.clear();
753 }
754 if (mRotateFrameAnimation != null) {
755 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, clearing rotate frame anim!");
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800756 mRotateFrameAnimation.cancel();
757 mRotateFrameAnimation = null;
758 mRotateFrameTransformation.clear();
759 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800760 }
761
762 mExitTransformation.set(mRotateExitTransformation);
763 mExitTransformation.compose(mStartExitTransformation);
764 mExitTransformation.compose(mFinishExitTransformation);
765
766 mEnterTransformation.set(mRotateEnterTransformation);
767 mEnterTransformation.compose(mStartEnterTransformation);
768 mEnterTransformation.compose(mFinishEnterTransformation);
769
770 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
771 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700772
773 if (USE_CUSTOM_BLACK_FRAME) {
774 //mFrameTransformation.set(mRotateExitTransformation);
775 //mFrameTransformation.compose(mStartExitTransformation);
776 //mFrameTransformation.compose(mFinishExitTransformation);
777 mFrameTransformation.set(mRotateFrameTransformation);
778 mFrameTransformation.compose(mStartFrameTransformation);
779 mFrameTransformation.compose(mFinishFrameTransformation);
780 mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
781 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
782 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800783
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800784 final boolean more = mMoreStartEnter || mMoreStartExit || mMoreStartFrame
785 || mMoreFinishEnter || mMoreFinishExit || mMoreFinishFrame
786 || mMoreRotateEnter || mMoreRotateExit || mMoreRotateFrame
787 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800788
789 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
790
791 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
792
793 return more;
794 }
795
796 void updateSurfaces() {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700797 if (mSurface != null) {
798 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800799 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
800 mSurface.hide();
801 }
802 }
803
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700804 if (mCustomBlackFrame != null) {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700805 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800806 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700807 mCustomBlackFrame.hide();
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700808 } else {
Dianne Hackbornd6b32b62012-03-16 11:54:51 -0700809 mCustomBlackFrame.setMatrix(mFrameTransformation.getMatrix());
810 }
811 }
812
813 if (mExitingBlackFrame != null) {
814 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
815 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding exiting frame");
816 mExitingBlackFrame.hide();
817 } else {
818 mExitFrameFinalMatrix.setConcat(mExitTransformation.getMatrix(), mFrameInitialMatrix);
819 mExitingBlackFrame.setMatrix(mExitFrameFinalMatrix);
820 mExitingBlackFrame.setAlpha(mExitTransformation.getAlpha());
821 }
822 }
823
824 if (mEnteringBlackFrame != null) {
825 if (!mMoreStartEnter && !mMoreFinishEnter && !mMoreRotateEnter) {
826 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding entering frame");
827 mEnteringBlackFrame.hide();
828 } else {
829 mEnteringBlackFrame.setMatrix(mEnterTransformation.getMatrix());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800830 }
831 }
832
833 setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
834 }
835
Craig Mautnere32c3072012-03-12 15:25:35 -0700836 public boolean stepAnimationLocked(long now) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800837 if (!isAnimating()) {
838 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800839 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800840 return false;
841 }
842
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800843 if (!mAnimRunning) {
844 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
845 if (mStartEnterAnimation != null) {
846 mStartEnterAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700847 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800848 if (mStartExitAnimation != null) {
849 mStartExitAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700850 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800851 if (mStartFrameAnimation != null) {
852 mStartFrameAnimation.setStartTime(now);
853 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800854 if (mFinishEnterAnimation != null) {
855 mFinishEnterAnimation.setStartTime(0);
856 }
857 if (mFinishExitAnimation != null) {
858 mFinishExitAnimation.setStartTime(0);
859 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800860 if (mFinishFrameAnimation != null) {
861 mFinishFrameAnimation.setStartTime(0);
862 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800863 if (mRotateEnterAnimation != null) {
864 mRotateEnterAnimation.setStartTime(now);
865 }
866 if (mRotateExitAnimation != null) {
867 mRotateExitAnimation.setStartTime(now);
868 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800869 if (mRotateFrameAnimation != null) {
870 mRotateFrameAnimation.setStartTime(now);
871 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800872 mAnimRunning = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800873 }
Craig Mautnere32c3072012-03-12 15:25:35 -0700874
875 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800876 }
877
878 public Transformation getEnterTransformation() {
879 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800880 }
881}