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
This commit is contained in:
@@ -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 share() {
|
||||
sendIntentWhenReady(Intent.ACTION_SEND, null);
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
}, mUiExecutor);
|
||||
} else {
|
||||
mPendingAction = this::edit;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user