blob: ab084f9aa48f9840d8a583eed437ff8b1522ff65 [file] [log] [blame]
Dianne Hackborna1111872010-11-23 20:55:11 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080017package com.android.server.wm;
Dianne Hackborna1111872010-11-23 20:55:11 -080018
Dianne Hackborn4dcece82012-02-10 14:50:32 -080019import java.io.PrintWriter;
20
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080021import android.content.Context;
Dianne Hackborna1111872010-11-23 20:55:11 -080022import android.graphics.Matrix;
Dianne Hackborna1111872010-11-23 20:55:11 -080023import android.graphics.PixelFormat;
24import android.graphics.Rect;
Dianne Hackborna1111872010-11-23 20:55:11 -080025import android.util.Slog;
Dianne Hackborna1111872010-11-23 20:55:11 -080026import android.view.Surface;
27import android.view.SurfaceSession;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080028import android.view.animation.Animation;
29import android.view.animation.AnimationUtils;
30import android.view.animation.Transformation;
Dianne Hackborna1111872010-11-23 20:55:11 -080031
Craig Mautnere32c3072012-03-12 15:25:35 -070032class ScreenRotationAnimation {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080033 static final String TAG = "ScreenRotationAnimation";
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080034 static final boolean DEBUG_STATE = false;
35 static final boolean DEBUG_TRANSFORMS = false;
Dianne Hackborna1111872010-11-23 20:55:11 -080036
Dianne Hackborn50660e22011-02-02 17:12:25 -080037 static final int FREEZE_LAYER = WindowManagerService.TYPE_LAYER_MULTIPLIER * 200;
38
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080039 final Context mContext;
Dianne Hackborna1111872010-11-23 20:55:11 -080040 Surface mSurface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070041 BlackFrame mBlackFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -080042 int mWidth, mHeight;
43
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080044 int mSnapshotDeltaRotation;
45 int mOriginalRotation;
46 int mOriginalWidth, mOriginalHeight;
Dianne Hackborna1111872010-11-23 20:55:11 -080047 int mCurRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -080048
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080049 // For all animations, "exit" is for the UI elements that are going
50 // away (that is the snapshot of the old screen), and "enter" is for
51 // the new UI elements that are appearing (that is the active windows
52 // in their final orientation).
53
54 // The starting animation for the exiting and entering elements. This
55 // animation applies a transformation while the rotation is in progress.
56 // It is started immediately, before the new entering UI is ready.
57 Animation mStartExitAnimation;
58 final Transformation mStartExitTransformation = new Transformation();
59 Animation mStartEnterAnimation;
60 final Transformation mStartEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080061 Animation mStartFrameAnimation;
62 final Transformation mStartFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080063
64 // The finishing animation for the exiting and entering elements. This
65 // animation needs to undo the transformation of the starting animation.
66 // It starts running once the new rotation UI elements are ready to be
67 // displayed.
68 Animation mFinishExitAnimation;
69 final Transformation mFinishExitTransformation = new Transformation();
70 Animation mFinishEnterAnimation;
71 final Transformation mFinishEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080072 Animation mFinishFrameAnimation;
73 final Transformation mFinishFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080074
75 // The current active animation to move from the old to the new rotated
76 // state. Which animation is run here will depend on the old and new
77 // rotations.
78 Animation mRotateExitAnimation;
79 final Transformation mRotateExitTransformation = new Transformation();
80 Animation mRotateEnterAnimation;
81 final Transformation mRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080082 Animation mRotateFrameAnimation;
83 final Transformation mRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080084
85 // A previously running rotate animation. This will be used if we need
86 // to switch to a new rotation before finishing the previous one.
87 Animation mLastRotateExitAnimation;
88 final Transformation mLastRotateExitTransformation = new Transformation();
89 Animation mLastRotateEnterAnimation;
90 final Transformation mLastRotateEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080091 Animation mLastRotateFrameAnimation;
92 final Transformation mLastRotateFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080093
94 // Complete transformations being applied.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080095 final Transformation mExitTransformation = new Transformation();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080096 final Transformation mEnterTransformation = new Transformation();
Dianne Hackborn9fd74802012-03-01 19:26:31 -080097 final Transformation mFrameTransformation = new Transformation();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -080098
Dianne Hackbornf9d0be92010-11-24 12:35:25 -080099 boolean mStarted;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800100 boolean mAnimRunning;
101 boolean mFinishAnimReady;
102 long mFinishAnimStartTime;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800103
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800104 final Matrix mFrameInitialMatrix = new Matrix();
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800105 final Matrix mSnapshotInitialMatrix = new Matrix();
106 final Matrix mSnapshotFinalMatrix = new Matrix();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800107 final Matrix mTmpMatrix = new Matrix();
Dianne Hackborna1111872010-11-23 20:55:11 -0800108 final float[] mTmpFloats = new float[9];
Craig Mautnerdbb79912012-03-01 18:59:14 -0800109 private boolean mMoreRotateEnter;
110 private boolean mMoreRotateExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800111 private boolean mMoreRotateFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800112 private boolean mMoreFinishEnter;
113 private boolean mMoreFinishExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800114 private boolean mMoreFinishFrame;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800115 private boolean mMoreStartEnter;
116 private boolean mMoreStartExit;
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800117 private boolean mMoreStartFrame;
Dianne Hackborna1111872010-11-23 20:55:11 -0800118
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800119 public void printTo(String prefix, PrintWriter pw) {
120 pw.print(prefix); pw.print("mSurface="); pw.print(mSurface);
121 pw.print(" mWidth="); pw.print(mWidth);
122 pw.print(" mHeight="); pw.println(mHeight);
123 pw.print(prefix); pw.print("mBlackFrame="); pw.println(mBlackFrame);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800124 if (mBlackFrame != null) {
125 mBlackFrame.printTo(prefix + " ", pw);
126 }
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700127 pw.print(prefix); pw.print(" mSnapshotDeltaRotation="); pw.print(mSnapshotDeltaRotation);
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800128 pw.print(" mCurRotation="); pw.println(mCurRotation);
129 pw.print(prefix); pw.print("mOriginalRotation="); pw.print(mOriginalRotation);
130 pw.print(" mOriginalWidth="); pw.print(mOriginalWidth);
131 pw.print(" mOriginalHeight="); pw.println(mOriginalHeight);
132 pw.print(prefix); pw.print("mStarted="); pw.print(mStarted);
133 pw.print(" mAnimRunning="); pw.print(mAnimRunning);
134 pw.print(" mFinishAnimReady="); pw.print(mFinishAnimReady);
135 pw.print(" mFinishAnimStartTime="); pw.println(mFinishAnimStartTime);
136 pw.print(prefix); pw.print("mStartExitAnimation="); pw.print(mStartExitAnimation);
137 pw.print(" "); mStartExitTransformation.printShortString(pw); pw.println();
138 pw.print(prefix); pw.print("mStartEnterAnimation="); pw.print(mStartEnterAnimation);
139 pw.print(" "); mStartEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800140 pw.print(prefix); pw.print("mStartFrameAnimation="); pw.print(mStartFrameAnimation);
141 pw.print(" "); mStartFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800142 pw.print(prefix); pw.print("mFinishExitAnimation="); pw.print(mFinishExitAnimation);
143 pw.print(" "); mFinishExitTransformation.printShortString(pw); pw.println();
144 pw.print(prefix); pw.print("mFinishEnterAnimation="); pw.print(mFinishEnterAnimation);
145 pw.print(" "); mFinishEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800146 pw.print(prefix); pw.print("mFinishFrameAnimation="); pw.print(mFinishFrameAnimation);
147 pw.print(" "); mFinishFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800148 pw.print(prefix); pw.print("mRotateExitAnimation="); pw.print(mRotateExitAnimation);
149 pw.print(" "); mRotateExitTransformation.printShortString(pw); pw.println();
150 pw.print(prefix); pw.print("mRotateEnterAnimation="); pw.print(mRotateEnterAnimation);
151 pw.print(" "); mRotateEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800152 pw.print(prefix); pw.print("mRotateFrameAnimation="); pw.print(mRotateFrameAnimation);
153 pw.print(" "); mRotateFrameTransformation.printShortString(pw); pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800154 pw.print(prefix); pw.print("mExitTransformation=");
155 mExitTransformation.printShortString(pw); pw.println();
156 pw.print(prefix); pw.print("mEnterTransformation=");
157 mEnterTransformation.printShortString(pw); pw.println();
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800158 pw.print(prefix); pw.print("mFrameTransformation=");
159 mEnterTransformation.printShortString(pw); pw.println();
160 pw.print(prefix); pw.print("mFrameInitialMatrix=");
161 mFrameInitialMatrix.printShortString(pw);
162 pw.println();
Dianne Hackborn4dcece82012-02-10 14:50:32 -0800163 pw.print(prefix); pw.print("mSnapshotInitialMatrix=");
164 mSnapshotInitialMatrix.printShortString(pw);
165 pw.print(" mSnapshotFinalMatrix="); mSnapshotFinalMatrix.printShortString(pw);
166 pw.println();
167 }
168
Jeff Brownbc68a592011-07-25 12:58:12 -0700169 public ScreenRotationAnimation(Context context, SurfaceSession session,
170 boolean inTransaction, int originalWidth, int originalHeight, int originalRotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800171 mContext = context;
Dianne Hackborna1111872010-11-23 20:55:11 -0800172
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800173 // Screenshot does NOT include rotation!
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700174 if (originalRotation == Surface.ROTATION_90
175 || originalRotation == Surface.ROTATION_270) {
176 mWidth = originalHeight;
177 mHeight = originalWidth;
178 } else {
179 mWidth = originalWidth;
180 mHeight = originalHeight;
181 }
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800182
Jeff Brownbc68a592011-07-25 12:58:12 -0700183 mOriginalRotation = originalRotation;
184 mOriginalWidth = originalWidth;
185 mOriginalHeight = originalHeight;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800186
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800187 if (!inTransaction) {
Dianne Hackborn36991742011-10-11 21:35:26 -0700188 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800189 ">>> OPEN TRANSACTION ScreenRotationAnimation");
190 Surface.openTransaction();
191 }
Dianne Hackborn352cc982011-01-04 11:34:18 -0800192
Dianne Hackborna1111872010-11-23 20:55:11 -0800193 try {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800194 try {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800195 mSurface = new Surface(session, 0, "FreezeSurface",
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700196 -1, mWidth, mHeight, PixelFormat.OPAQUE, Surface.FX_SURFACE_SCREENSHOT | Surface.HIDDEN);
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700197 if (!mSurface.isValid()) {
Mathias Agopian0ab84ef2011-10-13 16:02:48 -0700198 // Screenshot failed, punt.
199 mSurface = null;
200 return;
201 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800202 mSurface.setLayer(FREEZE_LAYER);
Mathias Agopiane65beaa2011-11-01 14:39:06 -0700203 mSurface.show();
Dianne Hackborn352cc982011-01-04 11:34:18 -0800204 } catch (Surface.OutOfResourcesException e) {
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800205 Slog.w(TAG, "Unable to allocate freeze surface", e);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800206 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800207
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700208 if (WindowManagerService.SHOW_TRANSACTIONS ||
209 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
210 " FREEZE " + mSurface + ": CREATE");
211
Jeff Brownbc68a592011-07-25 12:58:12 -0700212 setRotation(originalRotation);
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800213 } finally {
214 if (!inTransaction) {
215 Surface.closeTransaction();
Dianne Hackborn36991742011-10-11 21:35:26 -0700216 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(WindowManagerService.TAG,
Dianne Hackborn94cb2eb2011-01-13 21:09:44 -0800217 "<<< CLOSE TRANSACTION ScreenRotationAnimation");
Dianne Hackborn352cc982011-01-04 11:34:18 -0800218 }
Dianne Hackborn0f761d62010-11-30 22:06:10 -0800219 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800220 }
221
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800222 boolean hasScreenshot() {
223 return mSurface != null;
224 }
225
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800226 static int deltaRotation(int oldRotation, int newRotation) {
227 int delta = newRotation - oldRotation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800228 if (delta < 0) delta += 4;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800229 return delta;
230 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800231
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800232 void setSnapshotTransform(Matrix matrix, float alpha) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800233 if (mSurface != null) {
234 matrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -0700235 mSurface.setPosition(mTmpFloats[Matrix.MTRANS_X],
236 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn352cc982011-01-04 11:34:18 -0800237 mSurface.setMatrix(
238 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
239 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
240 mSurface.setAlpha(alpha);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800241 if (DEBUG_TRANSFORMS) {
Dianne Hackborn352cc982011-01-04 11:34:18 -0800242 float[] srcPnts = new float[] { 0, 0, mWidth, mHeight };
243 float[] dstPnts = new float[4];
244 matrix.mapPoints(dstPnts, srcPnts);
245 Slog.i(TAG, "Original : (" + srcPnts[0] + "," + srcPnts[1]
246 + ")-(" + srcPnts[2] + "," + srcPnts[3] + ")");
247 Slog.i(TAG, "Transformed: (" + dstPnts[0] + "," + dstPnts[1]
248 + ")-(" + dstPnts[2] + "," + dstPnts[3] + ")");
249 }
Dianne Hackborna1111872010-11-23 20:55:11 -0800250 }
251 }
252
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800253 public static void createRotationMatrix(int rotation, int width, int height,
254 Matrix outMatrix) {
255 switch (rotation) {
256 case Surface.ROTATION_0:
257 outMatrix.reset();
258 break;
259 case Surface.ROTATION_90:
260 outMatrix.setRotate(90, 0, 0);
261 outMatrix.postTranslate(height, 0);
262 break;
263 case Surface.ROTATION_180:
264 outMatrix.setRotate(180, 0, 0);
265 outMatrix.postTranslate(width, height);
266 break;
267 case Surface.ROTATION_270:
268 outMatrix.setRotate(270, 0, 0);
269 outMatrix.postTranslate(0, width);
270 break;
271 }
272 }
273
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800274 // Must be called while in a transaction.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800275 private void setRotation(int rotation) {
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800276 mCurRotation = rotation;
277
278 // Compute the transformation matrix that must be applied
279 // to the snapshot to make it stay in the same original position
280 // with the current screen rotation.
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700281 int delta = deltaRotation(rotation, Surface.ROTATION_0);
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800282 createRotationMatrix(delta, mWidth, mHeight, mSnapshotInitialMatrix);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800283
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800284 if (DEBUG_STATE) Slog.v(TAG, "**** ROTATION: " + delta);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800285 setSnapshotTransform(mSnapshotInitialMatrix, 1.0f);
286 }
287
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800288 // Must be called while in a transaction.
289 public boolean setRotation(int rotation, SurfaceSession session,
290 long maxAnimationDuration, float animationScale, int finalWidth, int finalHeight) {
291 setRotation(rotation);
292 return startAnimation(session, maxAnimationDuration, animationScale,
293 finalWidth, finalHeight, false);
294 }
295
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800296 /**
297 * Returns true if animating.
298 */
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800299 private boolean startAnimation(SurfaceSession session, long maxAnimationDuration,
300 float animationScale, int finalWidth, int finalHeight, boolean dismissing) {
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800301 if (mSurface == null) {
302 // Can't do animation.
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800303 return false;
304 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800305 if (mStarted) {
306 return true;
307 }
308
309 mStarted = true;
310
311 boolean firstStart = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800312
Dianne Hackbornde75cb42011-03-02 17:11:21 -0800313 // Figure out how the screen has moved from the original rotation.
314 int delta = deltaRotation(mCurRotation, mOriginalRotation);
315
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800316 if (mFinishExitAnimation == null && (!dismissing || delta != Surface.ROTATION_0)) {
317 if (DEBUG_STATE) Slog.v(TAG, "Creating start and finish animations");
318 firstStart = true;
319 mStartExitAnimation = AnimationUtils.loadAnimation(mContext,
320 com.android.internal.R.anim.screen_rotate_start_exit);
321 mStartEnterAnimation = AnimationUtils.loadAnimation(mContext,
322 com.android.internal.R.anim.screen_rotate_start_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800323 mStartFrameAnimation = AnimationUtils.loadAnimation(mContext,
324 com.android.internal.R.anim.screen_rotate_start_frame);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800325 mFinishExitAnimation = AnimationUtils.loadAnimation(mContext,
326 com.android.internal.R.anim.screen_rotate_finish_exit);
327 mFinishEnterAnimation = AnimationUtils.loadAnimation(mContext,
328 com.android.internal.R.anim.screen_rotate_finish_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800329 mFinishFrameAnimation = AnimationUtils.loadAnimation(mContext,
330 com.android.internal.R.anim.screen_rotate_finish_frame);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800331 }
332
333 if (DEBUG_STATE) Slog.v(TAG, "Rotation delta: " + delta + " finalWidth="
334 + finalWidth + " finalHeight=" + finalHeight
335 + " origWidth=" + mOriginalWidth + " origHeight=" + mOriginalHeight);
336
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800337 switch (delta) {
338 case Surface.ROTATION_0:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800339 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800340 com.android.internal.R.anim.screen_rotate_0_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800341 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800342 com.android.internal.R.anim.screen_rotate_0_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800343 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
344 com.android.internal.R.anim.screen_rotate_0_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800345 break;
346 case Surface.ROTATION_90:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800347 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800348 com.android.internal.R.anim.screen_rotate_plus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800349 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800350 com.android.internal.R.anim.screen_rotate_plus_90_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800351 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
352 com.android.internal.R.anim.screen_rotate_plus_90_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800353 break;
354 case Surface.ROTATION_180:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800355 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800356 com.android.internal.R.anim.screen_rotate_180_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800357 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800358 com.android.internal.R.anim.screen_rotate_180_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800359 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
360 com.android.internal.R.anim.screen_rotate_180_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800361 break;
362 case Surface.ROTATION_270:
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800363 mRotateExitAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800364 com.android.internal.R.anim.screen_rotate_minus_90_exit);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800365 mRotateEnterAnimation = AnimationUtils.loadAnimation(mContext,
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800366 com.android.internal.R.anim.screen_rotate_minus_90_enter);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800367 mRotateFrameAnimation = AnimationUtils.loadAnimation(mContext,
368 com.android.internal.R.anim.screen_rotate_minus_90_frame);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800369 break;
370 }
371
Dianne Hackborn191874e32012-03-09 11:03:36 -0800372 // Compute partial steps between original and final sizes. These
373 // are used for the dimensions of the exiting and entering elements,
374 // so they are never stretched too significantly.
375 final int halfWidth = (finalWidth + mOriginalWidth) / 2;
376 final int halfHeight = (finalHeight + mOriginalHeight) / 2;
377
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800378 // Initialize the animations. This is a hack, redefining what "parent"
379 // means to allow supplying the last and next size. In this definition
380 // "%p" is the original (let's call it "previous") size, and "%" is the
381 // screen's current/new size.
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800382 if (firstStart) {
383 if (DEBUG_STATE) Slog.v(TAG, "Initializing start and finish animations");
384 mStartEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800385 halfWidth, halfHeight);
386 mStartExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800387 mOriginalWidth, mOriginalHeight);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800388 mStartFrameAnimation.initialize(finalWidth, finalHeight,
389 mOriginalWidth, mOriginalHeight);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800390 mFinishEnterAnimation.initialize(finalWidth, finalHeight,
Dianne Hackborn191874e32012-03-09 11:03:36 -0800391 halfWidth, halfHeight);
392 mFinishExitAnimation.initialize(halfWidth, halfHeight,
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800393 mOriginalWidth, mOriginalHeight);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800394 mFinishFrameAnimation.initialize(finalWidth, finalHeight,
395 mOriginalWidth, mOriginalHeight);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800396 }
397 mRotateEnterAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
398 mRotateExitAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800399 mRotateFrameAnimation.initialize(finalWidth, finalHeight, mOriginalWidth, mOriginalHeight);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800400 mAnimRunning = false;
401 mFinishAnimReady = false;
402 mFinishAnimStartTime = -1;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800403
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800404 if (firstStart) {
405 mStartExitAnimation.restrictDuration(maxAnimationDuration);
406 mStartExitAnimation.scaleCurrentDuration(animationScale);
407 mStartEnterAnimation.restrictDuration(maxAnimationDuration);
408 mStartEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800409 mStartFrameAnimation.restrictDuration(maxAnimationDuration);
410 mStartFrameAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800411 mFinishExitAnimation.restrictDuration(maxAnimationDuration);
412 mFinishExitAnimation.scaleCurrentDuration(animationScale);
413 mFinishEnterAnimation.restrictDuration(maxAnimationDuration);
414 mFinishEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800415 mFinishFrameAnimation.restrictDuration(maxAnimationDuration);
416 mFinishFrameAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800417 }
418 mRotateExitAnimation.restrictDuration(maxAnimationDuration);
419 mRotateExitAnimation.scaleCurrentDuration(animationScale);
420 mRotateEnterAnimation.restrictDuration(maxAnimationDuration);
421 mRotateEnterAnimation.scaleCurrentDuration(animationScale);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800422 mRotateFrameAnimation.restrictDuration(maxAnimationDuration);
423 mRotateFrameAnimation.scaleCurrentDuration(animationScale);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800424
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800425 if (mBlackFrame == null) {
426 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
427 WindowManagerService.TAG,
428 ">>> OPEN TRANSACTION ScreenRotationAnimation.startAnimation");
429 Surface.openTransaction();
Dianne Hackborn50660e22011-02-02 17:12:25 -0800430
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800431 // Compute the transformation matrix that must be applied
432 // the the black frame to make it stay in the initial position
433 // before the new screen rotation. This is different than the
434 // snapshot transformation because the snapshot is always based
435 // of the native orientation of the screen, not the orientation
436 // we were last in.
437 createRotationMatrix(delta, mOriginalWidth, mOriginalHeight, mFrameInitialMatrix);
438
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800439 try {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800440 Rect outer = new Rect(-mOriginalWidth*1, -mOriginalHeight*1,
441 mOriginalWidth*2, mOriginalHeight*2);
442 Rect inner = new Rect(0, 0, mOriginalWidth, mOriginalHeight);
443 mBlackFrame = new BlackFrame(session, outer, inner, FREEZE_LAYER + 1);
444 mBlackFrame.setMatrix(mFrameInitialMatrix);
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800445 } catch (Surface.OutOfResourcesException e) {
446 Slog.w(TAG, "Unable to allocate black surface", e);
447 } finally {
448 Surface.closeTransaction();
449 if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS || DEBUG_STATE) Slog.i(
450 WindowManagerService.TAG,
451 "<<< CLOSE TRANSACTION ScreenRotationAnimation.startAnimation");
452 }
Dianne Hackborn50660e22011-02-02 17:12:25 -0800453 }
454
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800455 return true;
456 }
457
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800458 /**
459 * Returns true if animating.
460 */
461 public boolean dismiss(SurfaceSession session, long maxAnimationDuration,
462 float animationScale, int finalWidth, int finalHeight) {
463 if (DEBUG_STATE) Slog.v(TAG, "Dismiss!");
464 if (mSurface == null) {
465 // Can't do animation.
466 return false;
467 }
468 if (!mStarted) {
469 startAnimation(session, maxAnimationDuration, animationScale, finalWidth, finalHeight,
470 true);
471 }
472 if (!mStarted) {
473 return false;
474 }
475 if (DEBUG_STATE) Slog.v(TAG, "Setting mFinishAnimReady = true");
476 mFinishAnimReady = true;
477 return true;
478 }
479
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800480 public void kill() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800481 if (DEBUG_STATE) Slog.v(TAG, "Kill!");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800482 if (mSurface != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700483 if (WindowManagerService.SHOW_TRANSACTIONS ||
484 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
485 " FREEZE " + mSurface + ": DESTROY");
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800486 mSurface.destroy();
487 mSurface = null;
488 }
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700489 if (mBlackFrame != null) {
490 mBlackFrame.kill();
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800491 mBlackFrame = null;
Dianne Hackborn352cc982011-01-04 11:34:18 -0800492 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800493 if (mStartExitAnimation != null) {
494 mStartExitAnimation.cancel();
495 mStartExitAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800496 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800497 if (mStartEnterAnimation != null) {
498 mStartEnterAnimation.cancel();
499 mStartEnterAnimation = null;
500 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800501 if (mStartFrameAnimation != null) {
502 mStartFrameAnimation.cancel();
503 mStartFrameAnimation = null;
504 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800505 if (mFinishExitAnimation != null) {
506 mFinishExitAnimation.cancel();
507 mFinishExitAnimation = null;
508 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800509 if (mFinishEnterAnimation != null) {
510 mFinishEnterAnimation.cancel();
511 mFinishEnterAnimation = null;
512 }
513 if (mFinishFrameAnimation != null) {
514 mFinishFrameAnimation.cancel();
515 mFinishFrameAnimation = null;
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800516 }
517 if (mRotateExitAnimation != null) {
518 mRotateExitAnimation.cancel();
519 mRotateExitAnimation = null;
520 }
521 if (mRotateEnterAnimation != null) {
522 mRotateEnterAnimation.cancel();
523 mRotateEnterAnimation = null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800524 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800525 if (mRotateFrameAnimation != null) {
526 mRotateFrameAnimation.cancel();
527 mRotateFrameAnimation = null;
528 }
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800529 }
530
531 public boolean isAnimating() {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800532 return mStartEnterAnimation != null || mStartExitAnimation != null
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800533 || mStartFrameAnimation != null
534 || mFinishEnterAnimation != null || mFinishExitAnimation != null
535 || mFinishFrameAnimation != null
536 || mRotateEnterAnimation != null || mRotateExitAnimation != null
537 || mRotateFrameAnimation != null;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800538 }
539
Craig Mautnere32c3072012-03-12 15:25:35 -0700540 private boolean stepAnimation(long now) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800541
542 if (mFinishAnimReady && mFinishAnimStartTime < 0) {
543 if (DEBUG_STATE) Slog.v(TAG, "Step: finish anim now ready");
544 mFinishAnimStartTime = now;
545 }
546
547 // If the start animation is no longer running, we want to keep its
548 // transformation intact until the finish animation also completes.
549
550 mMoreStartExit = false;
551 if (mStartExitAnimation != null) {
552 mStartExitTransformation.clear();
553 mMoreStartExit = mStartExitAnimation.getTransformation(now, mStartExitTransformation);
554 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start exit: " + mStartExitTransformation);
555 if (!mMoreStartExit) {
556 if (DEBUG_STATE) Slog.v(TAG, "Start exit animation done!");
557 mStartExitAnimation.cancel();
558 mStartExitAnimation = null;
559 }
560 }
561
562 mMoreStartEnter = false;
563 if (mStartEnterAnimation != null) {
564 mStartEnterTransformation.clear();
565 mMoreStartEnter = mStartEnterAnimation.getTransformation(now, mStartEnterTransformation);
566 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start enter: " + mStartEnterTransformation);
567 if (!mMoreStartEnter) {
568 if (DEBUG_STATE) Slog.v(TAG, "Start enter animation done!");
569 mStartEnterAnimation.cancel();
570 mStartEnterAnimation = null;
571 }
572 }
573
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800574 mMoreStartFrame = false;
575 if (mStartFrameAnimation != null) {
576 mStartFrameTransformation.clear();
577 mMoreStartFrame = mStartFrameAnimation.getTransformation(now, mStartFrameTransformation);
578 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped start frame: " + mStartFrameTransformation);
579 if (!mMoreStartFrame) {
580 if (DEBUG_STATE) Slog.v(TAG, "Start frame animation done!");
581 mStartFrameAnimation.cancel();
582 mStartFrameAnimation = null;
583 }
584 }
585
Craig Mautnerdbb79912012-03-01 18:59:14 -0800586 long finishNow = mFinishAnimReady ? (now - mFinishAnimStartTime) : 0;
587 if (DEBUG_STATE) Slog.v(TAG, "Step: finishNow=" + finishNow);
588
589 mFinishExitTransformation.clear();
590 mMoreFinishExit = false;
591 if (mFinishExitAnimation != null) {
592 mMoreFinishExit = mFinishExitAnimation.getTransformation(finishNow, mFinishExitTransformation);
593 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish exit: " + mFinishExitTransformation);
594 if (!mMoreStartExit && !mMoreFinishExit) {
595 if (DEBUG_STATE) Slog.v(TAG, "Finish exit animation done, clearing start/finish anims!");
596 mStartExitTransformation.clear();
597 mFinishExitAnimation.cancel();
598 mFinishExitAnimation = null;
599 mFinishExitTransformation.clear();
600 }
601 }
602
603 mFinishEnterTransformation.clear();
604 mMoreFinishEnter = false;
605 if (mFinishEnterAnimation != null) {
606 mMoreFinishEnter = mFinishEnterAnimation.getTransformation(finishNow, mFinishEnterTransformation);
607 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish enter: " + mFinishEnterTransformation);
608 if (!mMoreStartEnter && !mMoreFinishEnter) {
609 if (DEBUG_STATE) Slog.v(TAG, "Finish enter animation done, clearing start/finish anims!");
610 mStartEnterTransformation.clear();
611 mFinishEnterAnimation.cancel();
612 mFinishEnterAnimation = null;
613 mFinishEnterTransformation.clear();
614 }
615 }
616
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800617 mFinishFrameTransformation.clear();
618 mMoreFinishFrame = false;
619 if (mFinishFrameAnimation != null) {
620 mMoreFinishFrame = mFinishFrameAnimation.getTransformation(finishNow, mFinishFrameTransformation);
621 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped finish frame: " + mFinishFrameTransformation);
622 if (!mMoreStartFrame && !mMoreFinishFrame) {
623 if (DEBUG_STATE) Slog.v(TAG, "Finish frame animation done, clearing start/finish anims!");
624 mStartFrameTransformation.clear();
625 mFinishFrameAnimation.cancel();
626 mFinishFrameAnimation = null;
627 mFinishFrameTransformation.clear();
628 }
629 }
630
Craig Mautnerdbb79912012-03-01 18:59:14 -0800631 mRotateExitTransformation.clear();
632 mMoreRotateExit = false;
633 if (mRotateExitAnimation != null) {
634 mMoreRotateExit = mRotateExitAnimation.getTransformation(now, mRotateExitTransformation);
635 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate exit: " + mRotateExitTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800636 if (!mMoreFinishExit && !mMoreRotateExit) {
637 if (DEBUG_STATE) Slog.v(TAG, "Rotate exit animation done!");
638 mRotateExitAnimation.cancel();
639 mRotateExitAnimation = null;
640 mRotateExitTransformation.clear();
641 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800642 }
643
644 mRotateEnterTransformation.clear();
645 mMoreRotateEnter = false;
646 if (mRotateEnterAnimation != null) {
647 mMoreRotateEnter = mRotateEnterAnimation.getTransformation(now, mRotateEnterTransformation);
648 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate enter: " + mRotateEnterTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800649 if (!mMoreFinishEnter && !mMoreRotateEnter) {
650 if (DEBUG_STATE) Slog.v(TAG, "Rotate enter animation done!");
651 mRotateEnterAnimation.cancel();
652 mRotateEnterAnimation = null;
653 mRotateEnterTransformation.clear();
654 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800655 }
656
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800657 mRotateFrameTransformation.clear();
658 mMoreRotateFrame = false;
659 if (mRotateFrameAnimation != null) {
660 mMoreRotateFrame = mRotateFrameAnimation.getTransformation(now, mRotateFrameTransformation);
661 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Stepped rotate frame: " + mRotateFrameTransformation);
662 if (!mMoreFinishFrame && !mMoreRotateFrame) {
663 if (DEBUG_STATE) Slog.v(TAG, "Rotate frame animation done!");
664 mRotateFrameAnimation.cancel();
665 mRotateFrameAnimation = null;
666 mRotateFrameTransformation.clear();
667 }
Craig Mautnerdbb79912012-03-01 18:59:14 -0800668 }
669
670 mExitTransformation.set(mRotateExitTransformation);
671 mExitTransformation.compose(mStartExitTransformation);
672 mExitTransformation.compose(mFinishExitTransformation);
673
674 mEnterTransformation.set(mRotateEnterTransformation);
675 mEnterTransformation.compose(mStartEnterTransformation);
676 mEnterTransformation.compose(mFinishEnterTransformation);
677
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800678 //mFrameTransformation.set(mRotateExitTransformation);
679 //mFrameTransformation.compose(mStartExitTransformation);
680 //mFrameTransformation.compose(mFinishExitTransformation);
681 mFrameTransformation.set(mRotateFrameTransformation);
682 mFrameTransformation.compose(mStartFrameTransformation);
683 mFrameTransformation.compose(mFinishFrameTransformation);
684 mFrameTransformation.getMatrix().preConcat(mFrameInitialMatrix);
685
Craig Mautnerdbb79912012-03-01 18:59:14 -0800686 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final exit: " + mExitTransformation);
687 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final enter: " + mEnterTransformation);
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800688 if (DEBUG_TRANSFORMS) Slog.v(TAG, "Final frame: " + mFrameTransformation);
Craig Mautnerdbb79912012-03-01 18:59:14 -0800689
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800690 final boolean more = mMoreStartEnter || mMoreStartExit || mMoreStartFrame
691 || mMoreFinishEnter || mMoreFinishExit || mMoreFinishFrame
692 || mMoreRotateEnter || mMoreRotateExit || mMoreRotateFrame
693 || !mFinishAnimReady;
Craig Mautnerdbb79912012-03-01 18:59:14 -0800694
695 mSnapshotFinalMatrix.setConcat(mExitTransformation.getMatrix(), mSnapshotInitialMatrix);
696
697 if (DEBUG_STATE) Slog.v(TAG, "Step: more=" + more);
698
699 return more;
700 }
701
702 void updateSurfaces() {
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700703 if (mSurface != null) {
704 if (!mMoreStartExit && !mMoreFinishExit && !mMoreRotateExit) {
Craig Mautnerdbb79912012-03-01 18:59:14 -0800705 if (DEBUG_STATE) Slog.v(TAG, "Exit animations done, hiding screenshot surface");
706 mSurface.hide();
707 }
708 }
709
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700710 if (mBlackFrame != null) {
711 if (!mMoreStartFrame && !mMoreFinishFrame && !mMoreRotateFrame) {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800712 if (DEBUG_STATE) Slog.v(TAG, "Frame animations done, hiding black frame");
Craig Mautnerdbb79912012-03-01 18:59:14 -0800713 mBlackFrame.hide();
Craig Mautnerbf90eaa2012-03-15 11:28:53 -0700714 } else {
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800715 mBlackFrame.setMatrix(mFrameTransformation.getMatrix());
Craig Mautnerdbb79912012-03-01 18:59:14 -0800716 }
717 }
718
719 setSnapshotTransform(mSnapshotFinalMatrix, mExitTransformation.getAlpha());
720 }
721
Craig Mautnere32c3072012-03-12 15:25:35 -0700722 public boolean stepAnimationLocked(long now) {
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800723 if (!isAnimating()) {
724 if (DEBUG_STATE) Slog.v(TAG, "Step: no animations running");
Craig Mautnera731cd32012-03-02 15:23:55 -0800725 mFinishAnimReady = false;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800726 return false;
727 }
728
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800729 if (!mAnimRunning) {
730 if (DEBUG_STATE) Slog.v(TAG, "Step: starting start, finish, rotate");
731 if (mStartEnterAnimation != null) {
732 mStartEnterAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700733 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800734 if (mStartExitAnimation != null) {
735 mStartExitAnimation.setStartTime(now);
Dianne Hackborn89620282011-09-11 12:47:45 -0700736 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800737 if (mStartFrameAnimation != null) {
738 mStartFrameAnimation.setStartTime(now);
739 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800740 if (mFinishEnterAnimation != null) {
741 mFinishEnterAnimation.setStartTime(0);
742 }
743 if (mFinishExitAnimation != null) {
744 mFinishExitAnimation.setStartTime(0);
745 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800746 if (mFinishFrameAnimation != null) {
747 mFinishFrameAnimation.setStartTime(0);
748 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800749 if (mRotateEnterAnimation != null) {
750 mRotateEnterAnimation.setStartTime(now);
751 }
752 if (mRotateExitAnimation != null) {
753 mRotateExitAnimation.setStartTime(now);
754 }
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800755 if (mRotateFrameAnimation != null) {
756 mRotateFrameAnimation.setStartTime(now);
757 }
Dianne Hackbornfd1c5ed2012-01-13 13:09:16 -0800758 mAnimRunning = true;
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800759 }
Craig Mautnere32c3072012-03-12 15:25:35 -0700760
761 return stepAnimation(now);
Dianne Hackbornf9d0be92010-11-24 12:35:25 -0800762 }
763
764 public Transformation getEnterTransformation() {
765 return mEnterTransformation;
Dianne Hackborna1111872010-11-23 20:55:11 -0800766 }
767}