Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f50fb5b1 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

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
parent 816dc71d
Loading
Loading
Loading
Loading
+25 −17
Original line number Diff line number Diff line
@@ -438,13 +438,10 @@ 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() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // Save the screenshot once we have a bit of time now
        mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotToCornerAnimation);

        saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() {
            @Override
            void onActionsReady(Uri uri, List<Notification.Action> smartActions,
@@ -453,12 +450,23 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
                    mNotificationsController.notifyScreenshotError(
                            R.string.screenshot_failed_to_capture_text);
                } else {
                            mScreenshotHandler.post(() ->
                                    createScreenshotActionsShadeAnimation(smartActions,
                                            actions).start());
                    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 {
                            createScreenshotActionsShadeAnimation(smartActions,
                                    actions).start();
                        }
                    });
                }
                mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT);
                mScreenshotHandler.sendMessageDelayed(
                        mScreenshotHandler.obtainMessage(MESSAGE_CORNER_TIMEOUT),
+0 −5
Original line number Diff line number Diff line
@@ -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();