diff options
author | Pranav Vashi <neobuddy89@gmail.com> | 2020-06-09 11:09:55 -0400 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2021-09-27 21:17:05 +0800 |
commit | 14ef50786a8fdefd0e6fa9e33a4b63308151f456 (patch) | |
tree | 7ecea9a419d517feba0c75e4d59091b28609bc88 | |
parent | eb07016034ecf4216cf53fabcb431e793f5aa0c0 (diff) |
[crdroid][11.0] Reapply "Post a silent notification if screenshot is dismissed"
This reverts commit 5d4cb837cc3cb0be1efa06ed37fc1f55b473c904.
neobuddy89: Also remove broken "Delete" action
Change-Id: I6d02c88945df5131931e4d337fa8f07e2d1ddba8
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java | 12 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationsController.java | 59 |
2 files changed, 71 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index 5387568de9ee..1b4440e7907a 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -222,6 +222,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset private Animator mScreenshotAnimation; private Runnable mOnCompleteRunnable; private Animator mDismissAnimation; + private SavedImageData mImageData; private boolean mInDarkMode; private boolean mDirectionLTR; private boolean mOrientationPortrait; @@ -249,6 +250,9 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset switch (msg.what) { case MESSAGE_CORNER_TIMEOUT: mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT); + if (mImageData != null) { + mNotificationsController.showSilentScreenshotNotification(mImageData); + } GlobalScreenshot.this.dismissScreenshot("timeout", false); mOnCompleteRunnable.run(); break; @@ -679,6 +683,9 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset mDismissButton = mScreenshotLayout.findViewById(R.id.global_screenshot_dismiss_button); mDismissButton.setOnClickListener(view -> { mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL); + if (mImageData != null) { + mNotificationsController.showSilentScreenshotNotification(mImageData); + } dismissScreenshot("dismiss_button", false); mOnCompleteRunnable.run(); }); @@ -865,6 +872,10 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset }); } + mImageData = null; // make sure we clear the current stored data + mNotificationsController.reset(); + mNotificationsController.setImage(mScreenBitmap); + mSaveInBgTask = new SaveImageInBackgroundTask(mContext, mScreenshotSmartActions, data); mSaveInBgTask.execute(); } @@ -874,6 +885,7 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset */ private void showUiOnActionsReady(SavedImageData imageData) { logSuccessOnActionsReady(imageData); + mImageData = imageData; AccessibilityManager accessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationsController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationsController.java index b8a468e0ce45..c74543af1831 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationsController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationsController.java @@ -228,6 +228,65 @@ public class ScreenshotNotificationsController { } /** + * Shows a silent notification with the saved screenshot and actions that can be taken with it. + * + * @param actionData SavedImageData struct with image URI and actions + */ + public void showSilentScreenshotNotification( + GlobalScreenshot.SavedImageData actionData) { + mNotificationBuilder.addAction(actionData.shareAction); + mNotificationBuilder.addAction(actionData.editAction); + for (Notification.Action smartAction : actionData.smartActions) { + mNotificationBuilder.addAction(smartAction); + } + + // Create the intent to show the screenshot in gallery + Intent launchIntent = new Intent(Intent.ACTION_VIEW); + launchIntent.setDataAndType(actionData.uri, "image/png"); + launchIntent.setFlags( + Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); + + final long now = System.currentTimeMillis(); + + // Update the text and the icon for the existing notification + mPublicNotificationBuilder + .setContentTitle(mResources.getString(R.string.screenshot_saved_title)) + .setContentText(mResources.getString(R.string.screenshot_saved_text)) + .setContentIntent(PendingIntent.getActivity(mContext, 0, launchIntent, 0)) + .setSmallIcon(R.drawable.stat_notify_image) + .setCategory(Notification.CATEGORY_PROGRESS) + .setWhen(now) + .setShowWhen(true) + .setAutoCancel(true) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setGroup("silent") + .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY); + mNotificationBuilder + .setContentTitle(mResources.getString(R.string.screenshot_saved_title)) + .setContentText(mResources.getString(R.string.screenshot_saved_text)) + .setContentIntent(PendingIntent.getActivity(mContext, 0, launchIntent, 0)) + .setSmallIcon(R.drawable.stat_notify_image) + .setCategory(Notification.CATEGORY_PROGRESS) + .setWhen(now) + .setShowWhen(true) + .setAutoCancel(true) + .setColor(mContext.getColor( + com.android.internal.R.color.system_notification_accent_color)) + .setPublicVersion(mPublicNotificationBuilder.build()) + .setStyle(mNotificationStyle) + .setFlag(Notification.FLAG_NO_CLEAR, false) + .setGroup("silent") + .setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY); + + SystemUI.overrideNotificationAppName(mContext, mPublicNotificationBuilder, true); + SystemUI.overrideNotificationAppName(mContext, mNotificationBuilder, true); + + mNotificationManager.notify(SystemMessageProto.SystemMessage.NOTE_GLOBAL_SCREENSHOT, + mNotificationBuilder.build()); + } + + /** * Sends a notification that the screenshot capture has failed. */ public void notifyScreenshotError(int msgResId) { |