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

Commit 99333423 authored by Matt Casey's avatar Matt Casey
Browse files

Honor crop bounds for long screenshot bitmap export

Make toBitmap take a rect of which parts we want to render. Enable the
CropView and use its selected bounds to derive that rect.

Bug: 179175127
Test: Take long screenshot, move crop bounds, edit and verify that
      bounds are matched.
Change-Id: I546ae4a7e8e39d7e9b88eb1f503b2d1bde31a3c7
parent e1f553b0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@

    <com.android.systemui.screenshot.CropView
        android:id="@+id/crop_view"
        android:visibility="gone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginVertical="8dp"
+13 −1
Original line number Diff line number Diff line
@@ -108,6 +108,15 @@ class ImageTileSet {
    }

    Bitmap toBitmap() {
        return toBitmap(new Rect(0, 0, getWidth(), getHeight()));
    }

    /**
     * @param bounds Selected portion of the tile set's bounds (equivalent to tile bounds coord
     *               space). For example, to get the whole doc, use Rect(0, 0, getWidth(),
     *               getHeight()).
     */
    Bitmap toBitmap(Rect bounds) {
        if (mTiles.isEmpty()) {
            return null;
        }
@@ -115,6 +124,9 @@ class ImageTileSet {
        output.setPosition(0, 0, getWidth(), getHeight());
        RecordingCanvas canvas = output.beginRecording();
        canvas.translate(-getLeft(), -getTop());
        // Additional translation to account for the requested bounds
        canvas.translate(-bounds.left, -bounds.top);
        canvas.clipRect(bounds);
        for (ImageTile tile : mTiles) {
            canvas.save();
            canvas.translate(tile.getLeft(), tile.getTop());
@@ -122,7 +134,7 @@ class ImageTileSet {
            canvas.restore();
        }
        output.endRecording();
        return HardwareRenderer.createHardwareBitmap(output, getWidth(), getHeight());
        return HardwareRenderer.createHardwareBitmap(output, bounds.width(), bounds.height());
    }

    int getLeft() {
+9 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.UiThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
import android.os.UserHandle;
import android.text.TextUtils;
@@ -77,6 +78,7 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
    private View mClose;
    private View mEdit;
    private View mShare;
    private CropView mCropView;

    public ScrollCaptureController(Context context, Connection connection, Executor uiExecutor,
            Executor bgExecutor, ImageExporter exporter, UiEventLogger uiEventLogger) {
@@ -114,6 +116,7 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
        mClose = findViewById(R.id.close);
        mEdit = findViewById(R.id.edit);
        mShare = findViewById(R.id.share);
        mCropView = findViewById(R.id.crop_view);

        mClose.setOnClickListener(this::onClicked);
        mEdit.setOnClickListener(this::onClicked);
@@ -165,8 +168,13 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
    }

    private void startExport(PendingAction action) {
        Rect croppedPortion = new Rect(
                0,
                (int) (mImageTileSet.getHeight() * mCropView.getTopBoundary()),
                mImageTileSet.getWidth(),
                (int) (mImageTileSet.getHeight() * mCropView.getBottomBoundary()));
        ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
                mBgExecutor, mRequestId, mImageTileSet.toBitmap(), mCaptureTime);
                mBgExecutor, mRequestId, mImageTileSet.toBitmap(croppedPortion), mCaptureTime);
        exportFuture.addListener(() -> {
            try {
                ImageExporter.Result result = exportFuture.get();