From 0606a73455534bdcc4f51718b5101dce4f863eb5 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Tue, 16 Feb 2021 16:40:04 -0500 Subject: [PATCH] Move long screenshot UI to an Activity Separate UI code from image acquisition. Using a static variable to get scroll capture connection from the Activity, can do something more elegant later. Doesn't do full activity restoration yet. Bug: 179906912 Test: Running through long screenshot flow, turning screen on/off, returning to task. Change-Id: If5715c7008bbf3a1c8918a202a733fb3f8e8f876 --- packages/SystemUI/AndroidManifest.xml | 5 + .../dagger/DefaultActivityBinder.java | 7 + .../screenshot/LongScreenshotActivity.java | 201 ++++++++++++++++++ .../screenshot/ScreenshotController.java | 22 +- .../screenshot/ScrollCaptureController.java | 184 +++------------- 5 files changed, 254 insertions(+), 165 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/screenshot/LongScreenshotActivity.java diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 2faca8dbdcbfa..fbe58c5056624 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -334,6 +334,11 @@ + + exportFuture = mImageExporter.export( mBgExecutor, mRequestId, mImageTileSet.toBitmap(croppedPortion), mCaptureTime); exportFuture.addListener(() -> { try { ImageExporter.Result result = exportFuture.get(); - if (action == PendingAction.EDIT) { - doEdit(result.uri); - } else if (action == PendingAction.SHARE) { - doShare(result.uri); - } - doFinish(); + callback.onExportComplete(result.uri); } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "failed to export", e); - mCallback.onFinish(); + callback.onError(); } }, mUiExecutor); } - private void doEdit(Uri uri) { - String editorPackage = mContext.getString(R.string.config_screenshotEditor); - Intent intent = new Intent(Intent.ACTION_EDIT); - if (!TextUtils.isEmpty(editorPackage)) { - intent.setComponent(ComponentName.unflattenFromString(editorPackage)); - } - intent.setType("image/png"); - intent.setData(uri); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - - mContext.startActivityAsUser(intent, UserHandle.CURRENT); - } - - private void doShare(Uri uri) { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("image/png"); - intent.setData(uri); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_GRANT_READ_URI_PERMISSION); - Intent sharingChooserIntent = Intent.createChooser(intent, null) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_GRANT_READ_URI_PERMISSION); - - mContext.startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT); - } - - private void setContentView(@IdRes int id) { - mWindow.setContentView(id); - } - - T findViewById(@IdRes int res) { - return mWindow.findViewById(res); - } - - private void onCaptureResult(CaptureResult result) { Log.d(TAG, "onCaptureResult: " + result); boolean emptyResult = result.captured.height() == 0; @@ -327,11 +194,26 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener Log.d(TAG, "afterCaptureComplete"); if (mImageTileSet.isEmpty()) { - session.end(mCallback::onFinish); + mCaptureCallback.onError(); } else { - mPreview.setImageDrawable(mImageTileSet.getDrawable()); - mMagnifierView.setImageTileset(mImageTileSet); - mCropView.animateBoundaryTo(CropView.CropBoundary.BOTTOM, 0.5f); + mCaptureCallback.onComplete(mImageTileSet); } } + + /** + * Callback for image capture completion or error. + */ + public interface ScrollCaptureCallback { + void onComplete(ImageTileSet imageTileSet); + void onError(); + } + + /** + * Callback for image export completion or error. + */ + public interface ExportCallback { + void onExportComplete(Uri outputUri); + void onError(); + } + }