Speed up recents -> app #2

Creating the thumbnail of the header for the transition was on the
critical path for starting the activity. This moves it off this path
by doing it after onPause().

Change-Id: Ic54a104d5ad4c40e88638566a3a69cc265a0a0fe
This commit is contained in:
Jorim Jaggi
2015-06-02 17:07:39 -07:00
parent 88f3db9e21
commit 6e18e00a24
2 changed files with 87 additions and 28 deletions

View File

@@ -81,6 +81,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
// Runnables to finish the Recents activity
FinishRecentsRunnable mFinishLaunchHomeRunnable;
// Runnable to be executed after we paused ourselves
Runnable mAfterPauseRunnable;
/**
* A common Runnable to finish Recents either by calling finish() (with a custom animation) or
* launching Home with some ActivityOptions. Generally we always launch home when we exit
@@ -447,6 +450,15 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
}
}
@Override
protected void onPause() {
super.onPause();
if (mAfterPauseRunnable != null) {
mRecentsView.post(mAfterPauseRunnable);
mAfterPauseRunnable = null;
}
}
@Override
protected void onStop() {
super.onStop();
@@ -628,6 +640,11 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
Recents.startScreenPinning(this, ssp);
}
@Override
public void runAfterPause(Runnable r) {
mAfterPauseRunnable = r;
}
/**** RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks Implementation ****/
@Override

View File

@@ -24,12 +24,17 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.IRemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManagerGlobal;
import android.widget.FrameLayout;
import com.android.systemui.R;
@@ -52,6 +57,8 @@ import java.util.List;
public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks,
RecentsPackageMonitor.PackageCallbacks {
private static final String TAG = "RecentsView";
/** The RecentsView callbacks */
public interface RecentsViewCallbacks {
public void onTaskViewClicked();
@@ -59,8 +66,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
public void onAllTaskViewsDismissed();
public void onExitToHomeAnimationTriggered();
public void onScreenPinningRequest();
public void onTaskResize(Task t);
public void runAfterPause(Runnable r);
}
RecentsConfiguration mConfig;
@@ -438,6 +445,62 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
}
}
private void postDrawHeaderThumbnailTransitionRunnable(final TaskView tv, final int offsetX,
final int offsetY, final TaskViewTransform transform,
final ActivityOptions.OnAnimationStartedListener animStartedListener) {
Runnable r = new Runnable() {
@Override
public void run() {
// Disable any focused state before we draw the header
if (tv.isFocusedTask()) {
tv.unsetFocusedTask();
}
float scale = tv.getScaleX();
int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale);
int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale);
Bitmap b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight,
Bitmap.Config.ARGB_8888);
if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) {
b.eraseColor(0xFFff0000);
} else {
Canvas c = new Canvas(b);
c.scale(tv.getScaleX(), tv.getScaleY());
tv.mHeaderView.draw(c);
c.setBitmap(null);
}
b = b.createAshmemBitmap();
int[] pts = new int[2];
tv.getLocationOnScreen(pts);
try {
WindowManagerGlobal.getWindowManagerService()
.overridePendingAppTransitionAspectScaledThumb(b,
pts[0] + offsetX,
pts[1] + offsetY,
transform.rect.width(),
transform.rect.height(),
new IRemoteCallback.Stub() {
@Override
public void sendResult(Bundle data)
throws RemoteException {
post(new Runnable() {
@Override
public void run() {
if (animStartedListener != null) {
animStartedListener.onAnimationStarted();
}
}
});
}
}, true);
} catch (RemoteException e) {
Log.w(TAG, "Error overriding app transition", e);
}
}
};
mCb.runAfterPause(r);
}
/**** TaskStackView.TaskStackCallbacks Implementation ****/
@Override
@@ -474,32 +537,6 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
ActivityOptions opts = null;
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
if (tv.isFocusedTask()) {
tv.unsetFocusedTask();
}
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 {
Canvas c = new Canvas(b);
c.scale(tv.getScaleX(), tv.getScaleY());
tv.mHeaderView.draw(c);
c.setBitmap(null);
}
} else {
// Notify the system to skip the thumbnail layer by using an ALPHA_8 bitmap
b = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);
}
Bitmap bImmut = b.createAshmemBitmap();
ActivityOptions.OnAnimationStartedListener animStartedListener = null;
if (lockToTask) {
animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
@@ -518,6 +555,10 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
}
};
}
if (tv != null) {
postDrawHeaderThumbnailTransitionRunnable(tv, offsetX, offsetY, transform,
animStartedListener);
}
if (mConfig.multiStackEnabled) {
opts = ActivityOptions.makeCustomAnimation(sourceView.getContext(),
R.anim.recents_from_unknown_enter,
@@ -525,7 +566,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
sourceView.getHandler(), animStartedListener);
} else {
opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView,
bImmut, offsetX, offsetY, transform.rect.width(), transform.rect.height(),
Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(),
offsetX, offsetY, transform.rect.width(), transform.rect.height(),
sourceView.getHandler(), animStartedListener);
}
}