Merge "Fix logging for successive screenshots" into rvc-dev

This commit is contained in:
Miranda Kephart
2020-05-27 19:47:51 +00:00
committed by Android (Google) Code Review
2 changed files with 64 additions and 47 deletions

View File

@@ -431,7 +431,13 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
data.createDeleteAction = false; data.createDeleteAction = false;
if (mSaveInBgTask != null) { if (mSaveInBgTask != null) {
mSaveInBgTask.ignoreResult(); // just log success/failure for the pre-existing screenshot
mSaveInBgTask.setActionsReadyListener(new ActionsReadyListener() {
@Override
void onActionsReady(SavedImageData imageData) {
logSuccessOnActionsReady(imageData);
}
});
} }
mSaveInBgTask = new SaveImageInBackgroundTask(mContext, data); mSaveInBgTask = new SaveImageInBackgroundTask(mContext, data);
@@ -636,6 +642,52 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
mScreenshotPreview.setTranslationY(0); mScreenshotPreview.setTranslationY(0);
} }
/**
* Sets up the action shade and its entrance animation, once we get the screenshot URI.
*/
private void showUiOnActionsReady(SavedImageData imageData) {
logSuccessOnActionsReady(imageData);
if (imageData.uri != null) {
mScreenshotHandler.post(() -> {
if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) {
mScreenshotAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
createScreenshotActionsShadeAnimation(imageData).start();
}
});
} else {
createScreenshotActionsShadeAnimation(imageData).start();
}
AccessibilityManager accessibilityManager = (AccessibilityManager)
mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
long timeoutMs = accessibilityManager.getRecommendedTimeoutMillis(
SCREENSHOT_CORNER_DEFAULT_TIMEOUT_MILLIS,
AccessibilityManager.FLAG_CONTENT_CONTROLS);
mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT);
mScreenshotHandler.sendMessageDelayed(
mScreenshotHandler.obtainMessage(MESSAGE_CORNER_TIMEOUT),
timeoutMs);
});
}
}
/**
* Logs success/failure of the screenshot saving task, and shows an error if it failed.
*/
private void logSuccessOnActionsReady(SavedImageData imageData) {
if (imageData.uri == null) {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_NOT_SAVED);
mNotificationsController.notifyScreenshotError(
R.string.screenshot_failed_to_capture_text);
} else {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SAVED);
}
}
/** /**
* Starts the animation after taking the screenshot * Starts the animation after taking the screenshot
*/ */
@@ -651,43 +703,11 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect); mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect);
saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() {
@Override @Override
void onActionsReady(SavedImageData imageData) { void onActionsReady(SavedImageData imageData) {
finisher.accept(imageData.uri); showUiOnActionsReady(imageData);
if (imageData.uri == null) { }
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_NOT_SAVED); });
mNotificationsController.notifyScreenshotError(
R.string.screenshot_failed_to_capture_text);
} else {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SAVED);
mScreenshotHandler.post(() -> {
if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) {
mScreenshotAnimation.addListener(
new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
createScreenshotActionsShadeAnimation(imageData)
.start();
}
});
} else {
createScreenshotActionsShadeAnimation(imageData).start();
}
AccessibilityManager accessibilityManager = (AccessibilityManager)
mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
long timeoutMs = accessibilityManager.getRecommendedTimeoutMillis(
SCREENSHOT_CORNER_DEFAULT_TIMEOUT_MILLIS,
AccessibilityManager.FLAG_CONTENT_CONTROLS);
mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT);
mScreenshotHandler.sendMessageDelayed(
mScreenshotHandler.obtainMessage(MESSAGE_CORNER_TIMEOUT),
timeoutMs);
});
}
}
});
mScreenshotHandler.post(() -> { mScreenshotHandler.post(() -> {
if (!mScreenshotLayout.isAttachedToWindow()) { if (!mScreenshotLayout.isAttachedToWindow()) {
mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams);

View File

@@ -214,6 +214,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri); mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri);
mParams.mActionsReadyListener.onActionsReady(mImageData); mParams.mActionsReadyListener.onActionsReady(mImageData);
mParams.finisher.accept(mImageData.uri);
mParams.image = null; mParams.image = null;
mParams.errorMsgResId = 0; mParams.errorMsgResId = 0;
} catch (Exception e) { } catch (Exception e) {
@@ -224,22 +225,18 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
mParams.errorMsgResId = R.string.screenshot_failed_to_save_text; mParams.errorMsgResId = R.string.screenshot_failed_to_save_text;
mImageData.reset(); mImageData.reset();
mParams.mActionsReadyListener.onActionsReady(mImageData); mParams.mActionsReadyListener.onActionsReady(mImageData);
mParams.finisher.accept(null);
} }
return null; return null;
} }
/** /**
* If we get a new screenshot request while this one is saving, we want to continue saving in * Update the listener run when the saving task completes. Used to avoid showing UI for the
* the background but not return anything. * first screenshot when a second one is taken.
*/ */
void ignoreResult() { void setActionsReadyListener(GlobalScreenshot.ActionsReadyListener listener) {
mParams.mActionsReadyListener = new GlobalScreenshot.ActionsReadyListener() { mParams.mActionsReadyListener = listener;
@Override
void onActionsReady(GlobalScreenshot.SavedImageData imageData) {
// do nothing
}
};
} }
@Override @Override