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

Unverified Commit 42c086bf authored by Cosmin Tanislav's avatar Cosmin Tanislav Committed by Michael Bestas
Browse files

SystemUI: screenshot: open long screenshot activity for partial screenshots

The partial screenshot UI is basically unusable. Replace it
with the long  screenshot UI which offers cropping, saving,
canceling, and sharing capabilities.

Change-Id: I27f7a811838f7e3f2057f567c7a350255996a8cb
parent 55b96e41
Loading
Loading
Loading
Loading
+44 −30
Original line number Diff line number Diff line
@@ -400,15 +400,8 @@ public class ScreenshotController {
    void takeScreenshotPartial(ComponentName topComponent,
            final Consumer<Uri> finisher, RequestCallback requestCallback) {
        Assert.isMainThread();
        mScreenshotView.reset();
        mCurrentRequestCallback = requestCallback;

        attachWindow();
        mWindow.setContentView(mScreenshotView);
        mScreenshotView.requestApplyInsets();

        mScreenshotView.takePartialScreenshot(
                rect -> takeScreenshotInternal(topComponent, finisher, rect));
        startPartialScreenshotActivity();
        finisher.accept(null);
    }

    /**
@@ -570,6 +563,13 @@ public class ScreenshotController {
        return screenshot;
    }

    private Bitmap captureScreenshot() {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getDefaultDisplay().getRealMetrics(displayMetrics);
        return captureScreenshot(
                new Rect(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels));
    }

    private void saveScreenshot(Bitmap screenshot, Consumer<Uri> finisher, Rect screenRect,
            Insets screenInsets, ComponentName topComponent, boolean showFlash) {
        withWindowAttached(() ->
@@ -691,6 +691,40 @@ public class ScreenshotController {
                onScrollCaptureResponseReady(future), mMainExecutor);
    }

    public void startLongScreenshotActivity(ScrollCaptureController.LongScreenshot longScreenshot) {
        mLongScreenshotHolder.setLongScreenshot(longScreenshot);
        mLongScreenshotHolder.setTransitionDestinationCallback(
                (transitionDestination, onTransitionEnd) ->
                        mScreenshotView.startLongScreenshotTransition(
                                transitionDestination, onTransitionEnd,
                                longScreenshot));
        mLongScreenshotHolder.setForegroundAppName(getForegroundAppLabel());

        final Intent intent = new Intent(mContext, LongScreenshotActivity.class);
        intent.setFlags(
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        mContext.startActivity(intent,
                ActivityOptions.makeCustomAnimation(mContext, 0, 0).toBundle());
        RemoteAnimationAdapter runner = new RemoteAnimationAdapter(
                SCREENSHOT_REMOTE_RUNNER, 0, 0);
        try {
            WindowManagerGlobal.getWindowManagerService()
                    .overridePendingAppTransitionRemote(runner, DEFAULT_DISPLAY);
        } catch (Exception e) {
            Log.e(TAG, "Error overriding screenshot app transition", e);
        }
    }

    private void startPartialScreenshotActivity() {
        Bitmap newScreenshot = captureScreenshot();

        ScrollCaptureController.BitmapScreenshot bitmapScreenshot =
            new ScrollCaptureController.BitmapScreenshot(mContext, newScreenshot);

        startLongScreenshotActivity(bitmapScreenshot);
    }

    private void onScrollCaptureResponseReady(Future<ScrollCaptureResponse> responseFuture) {
        try {
            if (mLastScrollCaptureResponse != null) {
@@ -756,27 +790,7 @@ public class ScreenshotController {
                return;
            }

            mLongScreenshotHolder.setLongScreenshot(longScreenshot);
            mLongScreenshotHolder.setTransitionDestinationCallback(
                    (transitionDestination, onTransitionEnd) ->
                            mScreenshotView.startLongScreenshotTransition(
                                    transitionDestination, onTransitionEnd,
                                    longScreenshot));

            final Intent intent = new Intent(mContext, LongScreenshotActivity.class);
            intent.setFlags(
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

            mContext.startActivity(intent,
                    ActivityOptions.makeCustomAnimation(mContext, 0, 0).toBundle());
            RemoteAnimationAdapter runner = new RemoteAnimationAdapter(
                    SCREENSHOT_REMOTE_RUNNER, 0, 0);
            try {
                WindowManagerGlobal.getWindowManagerService()
                        .overridePendingAppTransitionRemote(runner, DEFAULT_DISPLAY);
            } catch (Exception e) {
                Log.e(TAG, "Error overriding screenshot app transition", e);
            }
            startLongScreenshotActivity(longScreenshot);
        }, mMainExecutor);
    }

+68 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.BitmapDrawable;
import android.provider.Settings;
import android.util.Log;
import android.view.ScrollCaptureResponse;
@@ -138,6 +139,73 @@ public class ScrollCaptureController {
        }
    }

    static class BitmapScreenshot extends LongScreenshot {
        private final BitmapDrawable mBitmapDrawable;
        private final Bitmap mBitmap;

        BitmapScreenshot(Context context, Bitmap bitmap) {
            super(null, null);

            mBitmap = bitmap;
            mBitmapDrawable = new BitmapDrawable(context.getResources(), bitmap);
        }

        @Override
        public Bitmap toBitmap() {
            return mBitmap;
        }

        @Override
        public Bitmap toBitmap(Rect bounds) {
            // Not used anywhere
            return mBitmap;
        }

        @Override
        public void release() {
        }

        @Override
        public int getLeft() {
            return 0;
        }

        @Override
        public int getTop() {
            return 0;
        }

        @Override
        public int getBottom() {
            return getHeight();
        }

        @Override
        public int getWidth() {
            return mBitmap.getWidth();
        }

        @Override
        public int getHeight() {
            return mBitmap.getHeight();
        }

        @Override
        public int getPageHeight() {
            return getHeight();
        }

        @Override
        public String toString() {
            return "BitmapScrenshot{w=" + getWidth() + ", h=" + getHeight() + "}";
        }

        @Override
        public Drawable getDrawable() {
            return mBitmapDrawable;
        }
    }

    @Inject
    ScrollCaptureController(Context context, @Background Executor bgExecutor,
            ScrollCaptureClient client, ImageTileSet imageTileSet, UiEventLogger logger) {