Removing unnecessary delays, ensuring transition thumbnail is the size of the header. (Bug. 16987565)

Change-Id: Ic104876c5fe16997eca00e0a2b3d8644c927120c
This commit is contained in:
Winson Chung
2014-09-05 13:17:22 +02:00
parent d78d4f3acd
commit 2e7f3bdcc9
9 changed files with 92 additions and 66 deletions

View File

@@ -84,13 +84,13 @@ public class ActivityOptions {
* Initial width of the animation.
* @hide
*/
public static final String KEY_ANIM_START_WIDTH = "android:animStartWidth";
public static final String KEY_ANIM_WIDTH = "android:animWidth";
/**
* Initial height of the animation.
* @hide
*/
public static final String KEY_ANIM_START_HEIGHT = "android:animStartHeight";
public static final String KEY_ANIM_HEIGHT = "android:animHeight";
/**
* Callback for when animation is started.
@@ -140,8 +140,8 @@ public class ActivityOptions {
private Bitmap mThumbnail;
private int mStartX;
private int mStartY;
private int mStartWidth;
private int mStartHeight;
private int mWidth;
private int mHeight;
private IRemoteCallback mAnimationStartedListener;
private ResultReceiver mTransitionReceiver;
private boolean mIsReturning;
@@ -238,13 +238,13 @@ public class ActivityOptions {
* defines the coordinate space for <var>startX</var> and <var>startY</var>.
* @param startX The x starting location of the new activity, relative to <var>source</var>.
* @param startY The y starting location of the activity, relative to <var>source</var>.
* @param startWidth The initial width of the new activity.
* @param startHeight The initial height of the new activity.
* @param width The initial width of the new activity.
* @param height The initial height of the new activity.
* @return Returns a new ActivityOptions object that you can use to
* supply these options as the options Bundle when starting an activity.
*/
public static ActivityOptions makeScaleUpAnimation(View source,
int startX, int startY, int startWidth, int startHeight) {
int startX, int startY, int width, int height) {
ActivityOptions opts = new ActivityOptions();
opts.mPackageName = source.getContext().getPackageName();
opts.mAnimationType = ANIM_SCALE_UP;
@@ -252,8 +252,8 @@ public class ActivityOptions {
source.getLocationOnScreen(pts);
opts.mStartX = pts[0] + startX;
opts.mStartY = pts[1] + startY;
opts.mStartWidth = startWidth;
opts.mStartHeight = startHeight;
opts.mWidth = width;
opts.mHeight = height;
return opts;
}
@@ -359,9 +359,10 @@ public class ActivityOptions {
* @hide
*/
public static ActivityOptions makeThumbnailAspectScaleUpAnimation(View source,
Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) {
return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY, listener,
true);
Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight,
OnAnimationStartedListener listener) {
return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY,
targetWidth, targetHeight, listener, true);
}
/**
@@ -382,13 +383,15 @@ public class ActivityOptions {
* @hide
*/
public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source,
Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) {
return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY, listener,
false);
Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight,
OnAnimationStartedListener listener) {
return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY,
targetWidth, targetHeight, listener, false);
}
private static ActivityOptions makeAspectScaledThumbnailAnimation(View source, Bitmap thumbnail,
int startX, int startY, OnAnimationStartedListener listener, boolean scaleUp) {
int startX, int startY, int targetWidth, int targetHeight,
OnAnimationStartedListener listener, boolean scaleUp) {
ActivityOptions opts = new ActivityOptions();
opts.mPackageName = source.getContext().getPackageName();
opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_ASPECT_SCALE_UP :
@@ -398,6 +401,8 @@ public class ActivityOptions {
source.getLocationOnScreen(pts);
opts.mStartX = pts[0] + startX;
opts.mStartY = pts[1] + startY;
opts.mWidth = targetWidth;
opts.mHeight = targetHeight;
opts.setOnAnimationStartedListener(source.getHandler(), listener);
return opts;
}
@@ -543,8 +548,8 @@ public class ActivityOptions {
case ANIM_SCALE_UP:
mStartX = opts.getInt(KEY_ANIM_START_X, 0);
mStartY = opts.getInt(KEY_ANIM_START_Y, 0);
mStartWidth = opts.getInt(KEY_ANIM_START_WIDTH, 0);
mStartHeight = opts.getInt(KEY_ANIM_START_HEIGHT, 0);
mWidth = opts.getInt(KEY_ANIM_WIDTH, 0);
mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0);
break;
case ANIM_THUMBNAIL_SCALE_UP:
@@ -554,6 +559,8 @@ public class ActivityOptions {
mThumbnail = (Bitmap) opts.getParcelable(KEY_ANIM_THUMBNAIL);
mStartX = opts.getInt(KEY_ANIM_START_X, 0);
mStartY = opts.getInt(KEY_ANIM_START_Y, 0);
mWidth = opts.getInt(KEY_ANIM_WIDTH, 0);
mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0);
mAnimationStartedListener = IRemoteCallback.Stub.asInterface(
opts.getBinder(KEY_ANIM_START_LISTENER));
break;
@@ -605,13 +612,13 @@ public class ActivityOptions {
}
/** @hide */
public int getStartWidth() {
return mStartWidth;
public int getWidth() {
return mWidth;
}
/** @hide */
public int getStartHeight() {
return mStartHeight;
public int getHeight() {
return mHeight;
}
/** @hide */
@@ -690,8 +697,8 @@ public class ActivityOptions {
case ANIM_SCALE_UP:
mStartX = otherOptions.mStartX;
mStartY = otherOptions.mStartY;
mStartWidth = otherOptions.mStartWidth;
mStartHeight = otherOptions.mStartHeight;
mWidth = otherOptions.mWidth;
mHeight = otherOptions.mHeight;
if (mAnimationStartedListener != null) {
try {
mAnimationStartedListener.sendResult(null);
@@ -707,6 +714,8 @@ public class ActivityOptions {
mThumbnail = otherOptions.mThumbnail;
mStartX = otherOptions.mStartX;
mStartY = otherOptions.mStartY;
mWidth = otherOptions.mWidth;
mHeight = otherOptions.mHeight;
if (mAnimationStartedListener != null) {
try {
mAnimationStartedListener.sendResult(null);
@@ -755,8 +764,8 @@ public class ActivityOptions {
case ANIM_SCALE_UP:
b.putInt(KEY_ANIM_START_X, mStartX);
b.putInt(KEY_ANIM_START_Y, mStartY);
b.putInt(KEY_ANIM_START_WIDTH, mStartWidth);
b.putInt(KEY_ANIM_START_HEIGHT, mStartHeight);
b.putInt(KEY_ANIM_WIDTH, mWidth);
b.putInt(KEY_ANIM_HEIGHT, mHeight);
break;
case ANIM_THUMBNAIL_SCALE_UP:
case ANIM_THUMBNAIL_SCALE_DOWN:
@@ -765,6 +774,8 @@ public class ActivityOptions {
b.putParcelable(KEY_ANIM_THUMBNAIL, mThumbnail);
b.putInt(KEY_ANIM_START_X, mStartX);
b.putInt(KEY_ANIM_START_Y, mStartY);
b.putInt(KEY_ANIM_WIDTH, mWidth);
b.putInt(KEY_ANIM_HEIGHT, mHeight);
b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener
!= null ? mAnimationStartedListener.asBinder() : null);
break;

View File

@@ -94,7 +94,8 @@ interface IWindowManager
void overridePendingAppTransitionThumb(in Bitmap srcThumb, int startX, int startY,
IRemoteCallback startedCallback, boolean scaleUp);
void overridePendingAppTransitionAspectScaledThumb(in Bitmap srcThumb, int startX,
int startY, IRemoteCallback startedCallback, boolean scaleUp);
int startY, int targetWidth, int targetHeight, IRemoteCallback startedCallback,
boolean scaleUp);
void executeAppTransition();
void setAppStartingWindow(IBinder token, String pkg, int theme,
in CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,

View File

@@ -385,9 +385,9 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
toTask);
if (toTransform != null && toTask.key != null) {
Rect toTaskRect = toTransform.rect;
// XXX: Reduce the memory usage the to the task bar height
Bitmap thumbnail = Bitmap.createBitmap(toTaskRect.width(), toTaskRect.height(),
int toHeaderWidth = (int) (mHeaderBar.getMeasuredWidth() * toTransform.scale);
int toHeaderHeight = (int) (mHeaderBar.getMeasuredHeight() * toTransform.scale);
Bitmap thumbnail = Bitmap.createBitmap(toHeaderWidth, toHeaderHeight,
Bitmap.Config.ARGB_8888);
if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
thumbnail.eraseColor(0xFFff0000);
@@ -401,7 +401,8 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
mStartAnimationTriggered = false;
return ActivityOptions.makeThumbnailAspectScaleDownAnimation(mStatusBarView,
thumbnail, toTaskRect.left, toTaskRect.top, this);
thumbnail, toTaskRect.left, toTaskRect.top, toTaskRect.width(),
toTaskRect.height(), this);
}
// If both the screenshot and thumbnail fails, then just fall back to the default transition

View File

@@ -413,10 +413,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
final SystemServicesProxy ssp =
RecentsTaskLoader.getInstance().getSystemServicesProxy();
ActivityOptions opts = null;
int thumbnailWidth = transform.rect.width();
int thumbnailHeight = transform.rect.height();
if (task.thumbnail != null && thumbnailWidth > 0 && thumbnailHeight > 0 &&
task.thumbnail.getWidth() > 0 && task.thumbnail.getHeight() > 0) {
if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
task.thumbnail.getHeight() > 0) {
Bitmap b;
if (tv != null) {
// Disable any focused state before we draw the header
@@ -424,7 +422,11 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
tv.unsetFocusedTask();
}
b = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ARGB_8888);
float scale = tv.getScaleX();
int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
Bitmap.Config.ARGB_8888);
if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
b.eraseColor(0xFFff0000);
} else {
@@ -435,7 +437,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
}
} else {
// Notify the system to skip the thumbnail layer by using an ALPHA_8 bitmap
b = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ALPHA_8);
b = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);
}
ActivityOptions.OnAnimationStartedListener animStartedListener = null;
if (lockToTask) {
@@ -456,7 +458,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
};
}
opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
b, offsetX, offsetY, animStartedListener);
b, offsetX, offsetY, transform.rect.width(), transform.rect.height(),
animStartedListener);
}
final ActivityOptions launchOpts = opts;

View File

@@ -839,25 +839,28 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks,
@Override
public void onClick(final View v) {
// We purposely post the handler delayed to allow for the touch feedback to draw
final TaskView tv = this;
postDelayed(new Runnable() {
@Override
public void run() {
if (Constants.DebugFlags.App.EnableTaskFiltering && v == mHeaderView.mApplicationIcon) {
mCb.onTaskViewAppIconClicked(tv);
} else if (v == mHeaderView.mDismissButton) {
dismissTask();
} else {
if (v == mActionButtonView) {
// Reset the translation of the action button before we animate it out
mActionButtonView.setTranslationZ(0f);
final boolean delayViewClick = (v != this);
if (delayViewClick) {
// We purposely post the handler delayed to allow for the touch feedback to draw
postDelayed(new Runnable() {
@Override
public void run() {
if (Constants.DebugFlags.App.EnableTaskFiltering && v == mHeaderView.mApplicationIcon) {
mCb.onTaskViewAppIconClicked(tv);
} else if (v == mHeaderView.mDismissButton) {
dismissTask();
}
mCb.onTaskViewClicked(tv, tv.getTask(),
(v == mFooterView || v == mActionButtonView));
}
}, 125);
} else {
if (v == mActionButtonView) {
// Reset the translation of the action button before we animate it out
mActionButtonView.setTranslationZ(0f);
}
}, 125);
mCb.onTaskViewClicked(tv, tv.getTask(),
(v == mFooterView || v == mActionButtonView));
}
}
/**** View.OnLongClickListener Implementation ****/

View File

@@ -698,12 +698,12 @@ final class ActivityRecord {
case ActivityOptions.ANIM_SCALE_UP:
service.mWindowManager.overridePendingAppTransitionScaleUp(
pendingOptions.getStartX(), pendingOptions.getStartY(),
pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
pendingOptions.getWidth(), pendingOptions.getHeight());
if (intent.getSourceBounds() == null) {
intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
pendingOptions.getStartY(),
pendingOptions.getStartX()+pendingOptions.getStartWidth(),
pendingOptions.getStartY()+pendingOptions.getStartHeight()));
pendingOptions.getStartX()+pendingOptions.getWidth(),
pendingOptions.getStartY()+pendingOptions.getHeight()));
}
break;
case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
@@ -728,15 +728,14 @@ final class ActivityRecord {
service.mWindowManager.overridePendingAppTransitionAspectScaledThumb(
pendingOptions.getThumbnail(),
pendingOptions.getStartX(), pendingOptions.getStartY(),
pendingOptions.getWidth(), pendingOptions.getHeight(),
pendingOptions.getOnAnimationStartListener(),
(animationType == ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP));
if (intent.getSourceBounds() == null) {
intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
pendingOptions.getStartY(),
pendingOptions.getStartX()
+ pendingOptions.getThumbnail().getWidth(),
pendingOptions.getStartY()
+ pendingOptions.getThumbnail().getHeight()));
pendingOptions.getStartX() + pendingOptions.getWidth(),
pendingOptions.getStartY() + pendingOptions.getHeight()));
}
break;
default:

View File

@@ -569,9 +569,9 @@ public class AppTransition implements Dump {
int appWidth, int appHeight, int orientation, int transit, Rect containingFrame,
Rect contentInsets, boolean isFullScreen) {
Animation a;
final int thumbWidthI = mNextAppTransitionThumbnail.getWidth();
final int thumbWidthI = mNextAppTransitionStartWidth;
final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
final int thumbHeightI = mNextAppTransitionThumbnail.getHeight();
final int thumbHeightI = mNextAppTransitionStartHeight;
final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
// Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
@@ -993,7 +993,7 @@ public class AppTransition implements Dump {
}
void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
IRemoteCallback startedCallback, boolean scaleUp) {
int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
if (isTransitionSet()) {
mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
: NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
@@ -1002,6 +1002,8 @@ public class AppTransition implements Dump {
mNextAppTransitionScaleUp = scaleUp;
mNextAppTransitionStartX = startX;
mNextAppTransitionStartY = startY;
mNextAppTransitionStartWidth = targetWidth;
mNextAppTransitionStartHeight = targetHeight;
postAnimationCallback();
mNextAppTransitionCallback = startedCallback;
} else {
@@ -1138,6 +1140,10 @@ public class AppTransition implements Dump {
pw.print(mNextAppTransitionStartX);
pw.print(" mNextAppTransitionStartY=");
pw.println(mNextAppTransitionStartY);
pw.print(" mNextAppTransitionStartWidth=");
pw.print(mNextAppTransitionStartWidth);
pw.print(" mNextAppTransitionStartHeight=");
pw.println(mNextAppTransitionStartHeight);
pw.print(" mNextAppTransitionScaleUp="); pw.println(mNextAppTransitionScaleUp);
break;
}

View File

@@ -4031,10 +4031,11 @@ public class WindowManagerService extends IWindowManager.Stub
@Override
public void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX,
int startY, IRemoteCallback startedCallback, boolean scaleUp) {
int startY, int targetWidth, int targetHeight, IRemoteCallback startedCallback,
boolean scaleUp) {
synchronized(mWindowMap) {
mAppTransition.overridePendingAppTransitionAspectScaledThumb(srcThumb, startX,
startY, startedCallback, scaleUp);
startY, targetWidth, targetHeight, startedCallback, scaleUp);
}
}

View File

@@ -222,7 +222,8 @@ public class IWindowManagerImpl implements IWindowManager {
@Override
public void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX,
int startY, IRemoteCallback startedCallback, boolean scaleUp) {
int startY, int targetWidth, int targetHeight, IRemoteCallback startedCallback,
boolean scaleUp) {
// TODO Auto-generated method stub
}