From 8858e6e98dfd9f1bbc8bea2688aacd59a65de1eb Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 27 May 2015 17:18:56 -0700 Subject: Adding a delete action to the screenshot notification. Bug: 21161917 Change-Id: I03e2073ef09e9aea00b523eddbe2b9122d280d89 --- packages/SystemUI/AndroidManifest.xml | 6 ++ .../SystemUI/res/drawable-hdpi/ic_menu_share.png | Bin 1371 -> 0 bytes .../SystemUI/res/drawable-mdpi/ic_menu_share.png | Bin 1037 -> 0 bytes .../SystemUI/res/drawable-xhdpi/ic_menu_share.png | Bin 1846 -> 0 bytes .../SystemUI/res/drawable-xxhdpi/ic_menu_share.png | Bin 1279 -> 0 bytes .../SystemUI/res/drawable/ic_screenshot_delete.xml | 24 ++++++ .../SystemUI/res/drawable/ic_screenshot_share.xml | 24 ++++++ .../systemui/screenshot/GlobalScreenshot.java | 85 +++++++++++++++++---- 8 files changed, 124 insertions(+), 15 deletions(-) delete mode 100644 packages/SystemUI/res/drawable-hdpi/ic_menu_share.png delete mode 100644 packages/SystemUI/res/drawable-mdpi/ic_menu_share.png delete mode 100644 packages/SystemUI/res/drawable-xhdpi/ic_menu_share.png delete mode 100644 packages/SystemUI/res/drawable-xxhdpi/ic_menu_share.png create mode 100644 packages/SystemUI/res/drawable/ic_screenshot_delete.xml create mode 100644 packages/SystemUI/res/drawable/ic_screenshot_share.xml (limited to 'packages') diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index e47c7a0..cc8e46b 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -225,6 +225,12 @@ + + + diff --git a/packages/SystemUI/res/drawable-hdpi/ic_menu_share.png b/packages/SystemUI/res/drawable-hdpi/ic_menu_share.png deleted file mode 100644 index 11ab480..0000000 Binary files a/packages/SystemUI/res/drawable-hdpi/ic_menu_share.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable-mdpi/ic_menu_share.png b/packages/SystemUI/res/drawable-mdpi/ic_menu_share.png deleted file mode 100644 index 30e69bb..0000000 Binary files a/packages/SystemUI/res/drawable-mdpi/ic_menu_share.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable-xhdpi/ic_menu_share.png b/packages/SystemUI/res/drawable-xhdpi/ic_menu_share.png deleted file mode 100644 index af3e112..0000000 Binary files a/packages/SystemUI/res/drawable-xhdpi/ic_menu_share.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable-xxhdpi/ic_menu_share.png b/packages/SystemUI/res/drawable-xxhdpi/ic_menu_share.png deleted file mode 100644 index d450531..0000000 Binary files a/packages/SystemUI/res/drawable-xxhdpi/ic_menu_share.png and /dev/null differ diff --git a/packages/SystemUI/res/drawable/ic_screenshot_delete.xml b/packages/SystemUI/res/drawable/ic_screenshot_delete.xml new file mode 100644 index 0000000..e35c73d --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_screenshot_delete.xml @@ -0,0 +1,24 @@ + + + + diff --git a/packages/SystemUI/res/drawable/ic_screenshot_share.xml b/packages/SystemUI/res/drawable/ic_screenshot_share.xml new file mode 100644 index 0000000..62733ec --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_screenshot_share.xml @@ -0,0 +1,24 @@ + + + + diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index f16f6bd..7e32c3a 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -253,30 +253,39 @@ class SaveImageInBackgroundTask extends AsyncTask { + private static final String TAG = "DeleteImageInBackgroundTask"; + + private Context mContext; + + DeleteImageInBackgroundTask(Context context) { + mContext = context; + } + + @Override + protected Void doInBackground(Uri... params) { + if (params.length != 1) return null; + + Uri screenshotUri = params[0]; + ContentResolver resolver = mContext.getContentResolver(); + resolver.delete(screenshotUri, null, null); + return null; + } +} + +/** * TODO: * - Performance when over gl surfaces? Ie. Gallery * - what do we say in the Toast? Which icon do we get if the user uses another @@ -358,6 +390,7 @@ class GlobalScreenshot { private static final String TAG = "GlobalScreenshot"; static final String CANCEL_ID = "android:cancel_id"; + static final String SCREENSHOT_URI_ID = "android:screenshot_uri_id"; private static final int SCREENSHOT_FLASH_TO_PEAK_DURATION = 130; private static final int SCREENSHOT_DROP_IN_DURATION = 430; @@ -761,11 +794,33 @@ class GlobalScreenshot { return; } + // Clear the notification final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + final int id = intent.getIntExtra(CANCEL_ID, 0); + nm.cancel(id); + } + } + + /** + * Removes the last screenshot. + */ + public static class DeleteScreenshotReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (!intent.hasExtra(CANCEL_ID) || !intent.hasExtra(SCREENSHOT_URI_ID)) { + return; + } + // Clear the notification + final NotificationManager nm = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final int id = intent.getIntExtra(CANCEL_ID, 0); + final Uri uri = Uri.parse(intent.getStringExtra(SCREENSHOT_URI_ID)); nm.cancel(id); + + // And delete the image from the media store + new DeleteImageInBackgroundTask(context).execute(uri); } } } -- cgit v1.1