summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Matt Casey <mrcasey@google.com> 2021-02-02 22:05:45 -0500
committer Matt Casey <mrcasey@google.com> 2021-02-02 22:05:45 -0500
commite1f553b0ff38e5e164238580c36d66ce75aaa80f (patch)
treef2d7b7aecb0fc3a804424bd948381d72806d97cf
parent6950419d5ecacb5de886b4eccf5c0d36a39a38fb (diff)
Wait until action taken before long screenshot is exported.
Just supporting the same actions as before for now. This will be more important once we're honoring the crop bounds (since the export bitmap can't be known ahead of time). Also fix the share intent to show sharesheet. Bug: 179175119 Bug: 179176057 Test: Validated that share and edit functionality worked and was deferred (via logging). Change-Id: I684a01e063b20fcf4eb61315c649769064cadf41
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java104
1 files changed, 51 insertions, 53 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
index fd7db4bfffb4..db295332bbdd 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScrollCaptureController.java
@@ -51,6 +51,12 @@ import java.util.function.Consumer;
public class ScrollCaptureController implements OnComputeInternalInsetsListener {
private static final String TAG = "ScrollCaptureController";
+ // TODO: Support saving without additional action.
+ private enum PendingAction {
+ SHARE,
+ EDIT
+ }
+
public static final int MAX_PAGES = 5;
public static final int MAX_HEIGHT = 12000;
@@ -72,9 +78,6 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
private View mEdit;
private View mShare;
- private ListenableFuture<ImageExporter.Result> mExportFuture;
- private Runnable mPendingAction;
-
public ScrollCaptureController(Context context, Connection connection, Executor uiExecutor,
Executor bgExecutor, ImageExporter exporter, UiEventLogger uiEventLogger) {
mContext = context;
@@ -139,25 +142,17 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
if (id == R.id.close) {
v.setPressed(true);
disableButtons();
- finish();
+ doFinish();
} else if (id == R.id.edit) {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_EDIT);
v.setPressed(true);
disableButtons();
- edit();
+ startExport(PendingAction.EDIT);
} else if (id == R.id.share) {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_SHARE);
v.setPressed(true);
disableButtons();
- share();
- }
- }
-
- private void finish() {
- if (mExportFuture == null) {
- doFinish();
- } else {
- mExportFuture.addListener(this::doFinish, mUiExecutor);
+ startExport(PendingAction.SHARE);
}
}
@@ -169,31 +164,53 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
.removeOnComputeInternalInsetsListener(this);
}
- private void edit() {
- String editorPackage = mContext.getString(R.string.config_screenshotEditor);
- sendIntentWhenReady(Intent.ACTION_EDIT, editorPackage);
+ private void startExport(PendingAction action) {
+ ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
+ mBgExecutor, mRequestId, mImageTileSet.toBitmap(), 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();
+ } catch (InterruptedException | ExecutionException e) {
+ Log.e(TAG, "failed to export", e);
+ mCallback.onFinish();
+ }
+ }, mUiExecutor);
}
- private void share() {
- sendIntentWhenReady(Intent.ACTION_SEND, null);
+ 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_GRANT_READ_URI_PERMISSION);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ Intent sharingChooserIntent = Intent.createChooser(intent, null)
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK)
+ .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+
+ mContext.startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
}
- void sendIntentWhenReady(String action, String component) {
- if (mExportFuture != null) {
- mExportFuture.addListener(() -> {
- try {
- ImageExporter.Result result = mExportFuture.get();
- sendIntent(action, component, result.uri);
- mCallback.onFinish();
- } catch (InterruptedException | ExecutionException e) {
- Log.e(TAG, "failed to export", e);
- mCallback.onFinish();
- }
+ private void doShare(Uri uri) {
+ Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.setType("image/png");
+ intent.setData(uri);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ Intent sharingChooserIntent = Intent.createChooser(intent, null)
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK)
+ .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- }, mUiExecutor);
- } else {
- mPendingAction = this::edit;
- }
+ mContext.startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
}
private void setContentView(@IdRes int id) {
@@ -248,25 +265,6 @@ public class ScrollCaptureController implements OnComputeInternalInsetsListener
session.end(mCallback::onFinish);
} else {
mPreview.setImageDrawable(mImageTileSet.getDrawable());
- mExportFuture = mImageExporter.export(
- mBgExecutor, mRequestId, mImageTileSet.toBitmap(), mCaptureTime);
- // The user chose an action already, link it to the result
- if (mPendingAction != null) {
- mExportFuture.addListener(mPendingAction, mUiExecutor);
- }
}
}
-
- void sendIntent(String action, String component, Uri uri) {
- Intent intent = new Intent(action);
- if (!TextUtils.isEmpty(component)) {
- intent.setComponent(ComponentName.unflattenFromString(component));
- }
- intent.setType("image/png");
- intent.setData(uri);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-
- mContext.startActivityAsUser(intent, UserHandle.CURRENT);
- }
}