Loading packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +58 −38 Original line number Diff line number Diff line Loading @@ -431,7 +431,13 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset data.createDeleteAction = false; 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); Loading Loading @@ -637,43 +643,24 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset } /** * Starts the animation after taking the screenshot * Sets up the action shade and its entrance animation, once we get the screenshot URI. */ private void startAnimation(final Consumer<Uri> finisher, int w, int h, @Nullable Rect screenRect) { // If power save is on, show a toast so there is some visual indication that a // screenshot has been taken. PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (powerManager.isPowerSaveMode()) { Toast.makeText(mContext, R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show(); } mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect); saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { @Override void onActionsReady(SavedImageData imageData) { finisher.accept(imageData.uri); 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); private void showUiOnActionsReady(SavedImageData imageData) { logSuccessOnActionsReady(imageData); if (imageData.uri != null) { mScreenshotHandler.post(() -> { if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) { mScreenshotAnimation.addListener( new AnimatorListenerAdapter() { mScreenshotAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); createScreenshotActionsShadeAnimation(imageData) .start(); createScreenshotActionsShadeAnimation(imageData).start(); } }); } else { createScreenshotActionsShadeAnimation(imageData).start(); } AccessibilityManager accessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); long timeoutMs = accessibilityManager.getRecommendedTimeoutMillis( Loading @@ -687,6 +674,39 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset }); } } /** * 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 */ private void startAnimation(final Consumer<Uri> finisher, int w, int h, @Nullable Rect screenRect) { // If power save is on, show a toast so there is some visual indication that a // screenshot has been taken. PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (powerManager.isPowerSaveMode()) { Toast.makeText(mContext, R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show(); } mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect); saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { @Override void onActionsReady(SavedImageData imageData) { showUiOnActionsReady(imageData); } }); mScreenshotHandler.post(() -> { if (!mScreenshotLayout.isAttachedToWindow()) { Loading packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +6 −9 Original line number Diff line number Diff line Loading @@ -214,6 +214,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri); mParams.mActionsReadyListener.onActionsReady(mImageData); mParams.finisher.accept(mImageData.uri); mParams.image = null; mParams.errorMsgResId = 0; } catch (Exception e) { Loading @@ -224,22 +225,18 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { mParams.errorMsgResId = R.string.screenshot_failed_to_save_text; mImageData.reset(); mParams.mActionsReadyListener.onActionsReady(mImageData); mParams.finisher.accept(null); } return null; } /** * If we get a new screenshot request while this one is saving, we want to continue saving in * the background but not return anything. * Update the listener run when the saving task completes. Used to avoid showing UI for the * first screenshot when a second one is taken. */ void ignoreResult() { mParams.mActionsReadyListener = new GlobalScreenshot.ActionsReadyListener() { @Override void onActionsReady(GlobalScreenshot.SavedImageData imageData) { // do nothing } }; void setActionsReadyListener(GlobalScreenshot.ActionsReadyListener listener) { mParams.mActionsReadyListener = listener; } @Override Loading Loading
packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +58 −38 Original line number Diff line number Diff line Loading @@ -431,7 +431,13 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset data.createDeleteAction = false; 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); Loading Loading @@ -637,43 +643,24 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset } /** * Starts the animation after taking the screenshot * Sets up the action shade and its entrance animation, once we get the screenshot URI. */ private void startAnimation(final Consumer<Uri> finisher, int w, int h, @Nullable Rect screenRect) { // If power save is on, show a toast so there is some visual indication that a // screenshot has been taken. PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (powerManager.isPowerSaveMode()) { Toast.makeText(mContext, R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show(); } mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect); saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { @Override void onActionsReady(SavedImageData imageData) { finisher.accept(imageData.uri); 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); private void showUiOnActionsReady(SavedImageData imageData) { logSuccessOnActionsReady(imageData); if (imageData.uri != null) { mScreenshotHandler.post(() -> { if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) { mScreenshotAnimation.addListener( new AnimatorListenerAdapter() { mScreenshotAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); createScreenshotActionsShadeAnimation(imageData) .start(); createScreenshotActionsShadeAnimation(imageData).start(); } }); } else { createScreenshotActionsShadeAnimation(imageData).start(); } AccessibilityManager accessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); long timeoutMs = accessibilityManager.getRecommendedTimeoutMillis( Loading @@ -687,6 +674,39 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset }); } } /** * 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 */ private void startAnimation(final Consumer<Uri> finisher, int w, int h, @Nullable Rect screenRect) { // If power save is on, show a toast so there is some visual indication that a // screenshot has been taken. PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (powerManager.isPowerSaveMode()) { Toast.makeText(mContext, R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show(); } mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect); saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { @Override void onActionsReady(SavedImageData imageData) { showUiOnActionsReady(imageData); } }); mScreenshotHandler.post(() -> { if (!mScreenshotLayout.isAttachedToWindow()) { Loading
packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +6 −9 Original line number Diff line number Diff line Loading @@ -214,6 +214,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { mImageData.deleteAction = createDeleteAction(mContext, mContext.getResources(), uri); mParams.mActionsReadyListener.onActionsReady(mImageData); mParams.finisher.accept(mImageData.uri); mParams.image = null; mParams.errorMsgResId = 0; } catch (Exception e) { Loading @@ -224,22 +225,18 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { mParams.errorMsgResId = R.string.screenshot_failed_to_save_text; mImageData.reset(); mParams.mActionsReadyListener.onActionsReady(mImageData); mParams.finisher.accept(null); } return null; } /** * If we get a new screenshot request while this one is saving, we want to continue saving in * the background but not return anything. * Update the listener run when the saving task completes. Used to avoid showing UI for the * first screenshot when a second one is taken. */ void ignoreResult() { mParams.mActionsReadyListener = new GlobalScreenshot.ActionsReadyListener() { @Override void onActionsReady(GlobalScreenshot.SavedImageData imageData) { // do nothing } }; void setActionsReadyListener(GlobalScreenshot.ActionsReadyListener listener) { mParams.mActionsReadyListener = listener; } @Override Loading