Merge "Follow-on fixes for long screenshot activity" into sc-dev

This commit is contained in:
Matt Casey
2021-02-24 01:02:09 +00:00
committed by Android (Google) Code Review
3 changed files with 35 additions and 21 deletions

View File

@@ -46,6 +46,7 @@ public class LongScreenshotActivity extends Activity {
private final UiEventLogger mUiEventLogger;
private final ScrollCaptureController mScrollCaptureController;
private final ScrollCaptureClient.Connection mConnection;
private ImageView mPreview;
private View mSave;
@@ -69,8 +70,10 @@ public class LongScreenshotActivity extends Activity {
Context context) {
mUiEventLogger = uiEventLogger;
mScrollCaptureController = new ScrollCaptureController(context,
ScreenshotController.sScrollConnection, mainExecutor, bgExecutor, imageExporter);
mScrollCaptureController = new ScrollCaptureController(context, mainExecutor, bgExecutor,
imageExporter);
mConnection = ScreenshotController.takeScrollCaptureConnection();
}
@Override
@@ -98,15 +101,20 @@ public class LongScreenshotActivity extends Activity {
public void onStart() {
super.onStart();
if (mPreview.getDrawable() == null) {
if (mConnection == null) {
Log.e(TAG, "Failed to get scroll capture connection, bailing out");
finishAndRemoveTask();
return;
}
doCapture();
}
}
private void disableButtons() {
mSave.setEnabled(false);
mCancel.setEnabled(false);
mEdit.setEnabled(false);
mShare.setEnabled(false);
private void setButtonsEnabled(boolean enabled) {
mSave.setEnabled(enabled);
mCancel.setEnabled(enabled);
mEdit.setEnabled(enabled);
mShare.setEnabled(enabled);
}
private void doEdit(Uri uri) {
@@ -115,8 +123,7 @@ public class LongScreenshotActivity extends Activity {
if (!TextUtils.isEmpty(editorPackage)) {
intent.setComponent(ComponentName.unflattenFromString(editorPackage));
}
intent.setType("image/png");
intent.setData(uri);
intent.setDataAndType(uri, "image/png");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
@@ -127,12 +134,11 @@ public class LongScreenshotActivity extends Activity {
private void doShare(Uri uri) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.setData(uri);
intent.putExtra(Intent.EXTRA_STREAM, 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);
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
}
@@ -140,7 +146,7 @@ public class LongScreenshotActivity extends Activity {
private void onClicked(View v) {
int id = v.getId();
v.setPressed(true);
disableButtons();
setButtonsEnabled(false);
if (id == R.id.save) {
startExport(PendingAction.SAVE);
} else if (id == R.id.cancel) {
@@ -160,10 +166,12 @@ public class LongScreenshotActivity extends Activity {
@Override
public void onError() {
Log.e(TAG, "Error exporting image data.");
setButtonsEnabled(true);
}
@Override
public void onExportComplete(Uri outputUri) {
setButtonsEnabled(true);
switch (action) {
case EDIT:
doEdit(outputUri);
@@ -181,7 +189,8 @@ public class LongScreenshotActivity extends Activity {
}
private void doCapture() {
mScrollCaptureController.start(new ScrollCaptureController.ScrollCaptureCallback() {
mScrollCaptureController.start(mConnection,
new ScrollCaptureController.ScrollCaptureCallback() {
@Override
public void onError() {
Log.e(TAG, "Error!");

View File

@@ -101,7 +101,7 @@ import javax.inject.Inject;
public class ScreenshotController {
private static final String TAG = logTag(ScreenshotController.class);
public static ScrollCaptureClient.Connection sScrollConnection;
private static ScrollCaptureClient.Connection sScrollConnection;
/**
* POD used in the AsyncTask which saves an image in the background.
@@ -222,6 +222,12 @@ public class ScreenshotController {
| ActivityInfo.CONFIG_SCREEN_LAYOUT
| ActivityInfo.CONFIG_ASSETS_PATHS);
public static @Nullable ScrollCaptureClient.Connection takeScrollCaptureConnection() {
ScrollCaptureClient.Connection connection = sScrollConnection;
sScrollConnection = null;
return connection;
}
@Inject
ScreenshotController(
Context context,

View File

@@ -53,7 +53,6 @@ public class ScrollCaptureController {
public static final int MAX_HEIGHT = 12000;
private final Connection mConnection;
private final Context mContext;
private final Executor mUiExecutor;
@@ -65,10 +64,9 @@ public class ScrollCaptureController {
private UUID mRequestId;
private ScrollCaptureCallback mCaptureCallback;
public ScrollCaptureController(Context context, Connection connection, Executor uiExecutor,
Executor bgExecutor, ImageExporter exporter) {
public ScrollCaptureController(Context context, Executor uiExecutor, Executor bgExecutor,
ImageExporter exporter) {
mContext = context;
mConnection = connection;
mUiExecutor = uiExecutor;
mBgExecutor = bgExecutor;
mImageExporter = exporter;
@@ -78,16 +76,17 @@ public class ScrollCaptureController {
/**
* Run scroll capture!
*
* @param connection connection to the remote window to be used
* @param callback request callback to report back to the service
*/
public void start(ScrollCaptureCallback callback) {
public void start(Connection connection, ScrollCaptureCallback callback) {
mCaptureTime = ZonedDateTime.now();
mRequestId = UUID.randomUUID();
mCaptureCallback = callback;
float maxPages = Settings.Secure.getFloat(mContext.getContentResolver(),
SETTING_KEY_MAX_PAGES, MAX_PAGES_DEFAULT);
mConnection.start(this::startCapture, maxPages);
connection.start(this::startCapture, maxPages);
}
/**