Start saving screenshot in background earlier

Currently, we only start saving the screenshot after the animation
into the corner is complete. Since it takes non-negligible time to
save (~.5 seconds, more if smart screenshots don't exit earlier),
and we don't pop up the actions shade until we've finished saving,
this difference is user-visible. Beginning the async saving task
earlier mitigates the apparent delay.

Bug: 148605860
Test: manual

Change-Id: Icc98fc4f9920fb89cb08654c2ab8ee6f6d3321fa
This commit is contained in:
Miranda Kephart
2020-01-28 17:12:28 -05:00
parent 816dc71d25
commit f50fb5b183
2 changed files with 25 additions and 22 deletions

View File

@@ -438,27 +438,35 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
ValueAnimator screenshotDropInAnim = screenRect != null ? createRectAnimation(screenRect)
: createScreenshotDropInAnimation();
ValueAnimator screenshotFadeOutAnim = createScreenshotToCornerAnimation(w, h);
ValueAnimator screenshotToCornerAnimation = createScreenshotToCornerAnimation(w, h);
mScreenshotAnimation = new AnimatorSet();
mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotFadeOutAnim);
mScreenshotAnimation.addListener(new AnimatorListenerAdapter() {
mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotToCornerAnimation);
saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() {
@Override
public void onAnimationEnd(Animator animation) {
// Save the screenshot once we have a bit of time now
saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() {
@Override
void onActionsReady(Uri uri, List<Notification.Action> smartActions,
List<Notification.Action> actions) {
if (uri == null) {
mNotificationsController.notifyScreenshotError(
R.string.screenshot_failed_to_capture_text);
void onActionsReady(Uri uri, List<Notification.Action> smartActions,
List<Notification.Action> actions) {
if (uri == null) {
mNotificationsController.notifyScreenshotError(
R.string.screenshot_failed_to_capture_text);
} else {
mScreenshotHandler.post(() -> {
if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) {
mScreenshotAnimation.addListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
createScreenshotActionsShadeAnimation(
smartActions, actions).start();
}
});
} else {
mScreenshotHandler.post(() ->
createScreenshotActionsShadeAnimation(smartActions,
actions).start());
createScreenshotActionsShadeAnimation(smartActions,
actions).start();
}
}
});
});
}
mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT);
mScreenshotHandler.sendMessageDelayed(
mScreenshotHandler.obtainMessage(MESSAGE_CORNER_TIMEOUT),

View File

@@ -38,7 +38,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -124,10 +123,6 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
return null;
}
// By default, AsyncTask sets the worker thread to have background thread priority,
// so bump it back up so that we save a little quicker.
Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
ContentResolver resolver = mContext.getContentResolver();
Bitmap image = mParams.image;
Resources r = mContext.getResources();