diff options
author | Adam Powell <adamp@google.com> | 2015-04-17 12:13:40 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2015-04-17 19:42:52 -0700 |
commit | d4d34150b36e4f0722476f5eedaf279d466f5335 (patch) | |
tree | 679e43bea7afbefaecaa890f1577e729844f4f75 /packages/SystemUI/src/com/android/systemui/screenshot | |
parent | 66b4139d6a45c9f7641fa27a3d4810571831f35e (diff) | |
download | frameworks_base-d4d34150b36e4f0722476f5eedaf279d466f5335.zip frameworks_base-d4d34150b36e4f0722476f5eedaf279d466f5335.tar.gz frameworks_base-d4d34150b36e4f0722476f5eedaf279d466f5335.tar.bz2 |
Cancel a screenshot notification after a share target is chosen.
Use the (relatively) new API for supplying a callback when a user
makes a selection from the system ChooserActivity to clear out the
screenshot notification after it has been shared to another app.
Change-Id: If023a26d690c5ae8e29f28e2422f694ae4b654cb
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/screenshot')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index 105bf0f..715f4e4 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -25,6 +25,7 @@ import android.app.Notification; import android.app.Notification.BigPictureStyle; import android.app.NotificationManager; import android.app.PendingIntent; +import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; @@ -242,7 +243,12 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject); - Intent chooserIntent = Intent.createChooser(sharingIntent, null); + final PendingIntent callback = PendingIntent.getBroadcast(context, 0, + new Intent(context, GlobalScreenshot.TargetChosenReceiver.class) + .putExtra(GlobalScreenshot.CANCEL_ID, mNotificationId), + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); + Intent chooserIntent = Intent.createChooser(sharingIntent, null, + callback.getIntentSender()); chooserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); @@ -341,6 +347,8 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi class GlobalScreenshot { private static final String TAG = "GlobalScreenshot"; + static final String CANCEL_ID = "android:cancel_id"; + private static final int SCREENSHOT_FLASH_TO_PEAK_DURATION = 130; private static final int SCREENSHOT_DROP_IN_DURATION = 430; private static final int SCREENSHOT_DROP_OUT_DELAY = 500; @@ -732,4 +740,22 @@ class GlobalScreenshot { .build(); nManager.notify(R.id.notification_screenshot, n); } + + /** + * Removes the notification for a screenshot after a share target is chosen. + */ + public static class TargetChosenReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (!intent.hasExtra(CANCEL_ID)) { + return; + } + + final NotificationManager nm = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + final int id = intent.getIntExtra(CANCEL_ID, 0); + nm.cancel(id); + } + } } |