Merge "Adding a delete action to the screenshot notification." into mnc-dev
This commit is contained in:
@@ -225,6 +225,12 @@
|
|||||||
|
|
||||||
<!-- Callback for dismissing screenshot notification after a share target is picked -->
|
<!-- Callback for dismissing screenshot notification after a share target is picked -->
|
||||||
<receiver android:name=".screenshot.GlobalScreenshot$TargetChosenReceiver"
|
<receiver android:name=".screenshot.GlobalScreenshot$TargetChosenReceiver"
|
||||||
|
android:process=":screenshot"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
|
<!-- Callback for deleting screenshot notification -->
|
||||||
|
<receiver android:name=".screenshot.GlobalScreenshot$DeleteScreenshotReceiver"
|
||||||
|
android:process=":screenshot"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
<!-- started from UsbDeviceSettingsManager -->
|
<!-- started from UsbDeviceSettingsManager -->
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
24
packages/SystemUI/res/drawable/ic_screenshot_delete.xml
Normal file
24
packages/SystemUI/res/drawable/ic_screenshot_delete.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (C) 2015 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="32dp"
|
||||||
|
android:height="32dp"
|
||||||
|
android:viewportWidth="48.0"
|
||||||
|
android:viewportHeight="48.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M12,38c0,2.21 1.79,4 4,4h16c2.21,0 4,-1.79 4,-4V14H12v24zM38,8h-7l-2,-2H19l-2,2h-7v4h28V8z"/>
|
||||||
|
</vector>
|
||||||
24
packages/SystemUI/res/drawable/ic_screenshot_share.xml
Normal file
24
packages/SystemUI/res/drawable/ic_screenshot_share.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (C) 2015 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="32dp"
|
||||||
|
android:height="32dp"
|
||||||
|
android:viewportWidth="48.0"
|
||||||
|
android:viewportHeight="48.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M36,32.17c-1.52,0 -2.89,0.59 -3.93,1.54L17.82,25.4c0.11,-0.45 0.18,-0.92 0.18,-1.4s-0.07,-0.95 -0.18,-1.4l14.1,-8.23c1.07,1 2.5,1.62 4.08,1.62 3.31,0 6,-2.69 6,-6s-2.69,-6 -6,-6 -6,2.69 -6,6c0,0.48 0.07,0.95 0.18,1.4l-14.1,8.23c-1.07,-1 -2.5,-1.62 -4.08,-1.62 -3.31,0 -6,2.69 -6,6s2.69,6 6,6c1.58,0 3.01,-0.62 4.08,-1.62l14.25,8.31c-0.1,0.42 -0.16,0.86 -0.16,1.31 0,3.22 2.61,5.83 5.83,5.83s5.83,-2.61 5.83,-5.83 -2.61,-5.83 -5.83,-5.83z"/>
|
||||||
|
</vector>
|
||||||
@@ -253,6 +253,17 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
|
|||||||
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||||
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||||
|
|
||||||
|
OutputStream out = resolver.openOutputStream(uri);
|
||||||
|
image.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
// Update file size in the database
|
||||||
|
values.clear();
|
||||||
|
values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
|
||||||
|
resolver.update(uri, values, null, null);
|
||||||
|
|
||||||
|
// Create a share action for the notification
|
||||||
final PendingIntent callback = PendingIntent.getBroadcast(context, 0,
|
final PendingIntent callback = PendingIntent.getBroadcast(context, 0,
|
||||||
new Intent(context, GlobalScreenshot.TargetChosenReceiver.class)
|
new Intent(context, GlobalScreenshot.TargetChosenReceiver.class)
|
||||||
.putExtra(GlobalScreenshot.CANCEL_ID, mNotificationId),
|
.putExtra(GlobalScreenshot.CANCEL_ID, mNotificationId),
|
||||||
@@ -261,21 +272,19 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
|
|||||||
callback.getIntentSender());
|
callback.getIntentSender());
|
||||||
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
|
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
mNotificationBuilder.addAction(R.drawable.ic_screenshot_share,
|
||||||
|
r.getString(com.android.internal.R.string.share),
|
||||||
|
PendingIntent.getActivity(context, 0, chooserIntent,
|
||||||
|
PendingIntent.FLAG_CANCEL_CURRENT));
|
||||||
|
|
||||||
mNotificationBuilder.addAction(R.drawable.ic_menu_share,
|
// Create a delete action for the notification
|
||||||
r.getString(com.android.internal.R.string.share),
|
final PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0,
|
||||||
PendingIntent.getActivity(context, 0, chooserIntent,
|
new Intent(context, GlobalScreenshot.DeleteScreenshotReceiver.class)
|
||||||
PendingIntent.FLAG_CANCEL_CURRENT));
|
.putExtra(GlobalScreenshot.CANCEL_ID, mNotificationId)
|
||||||
|
.putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()),
|
||||||
OutputStream out = resolver.openOutputStream(uri);
|
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
|
||||||
image.compress(Bitmap.CompressFormat.PNG, 100, out);
|
mNotificationBuilder.addAction(R.drawable.ic_screenshot_delete,
|
||||||
out.flush();
|
r.getString(com.android.internal.R.string.delete), deleteAction);
|
||||||
out.close();
|
|
||||||
|
|
||||||
// update file size in the database
|
|
||||||
values.clear();
|
|
||||||
values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
|
|
||||||
resolver.update(uri, values, null, null);
|
|
||||||
|
|
||||||
params[0].imageUri = uri;
|
params[0].imageUri = uri;
|
||||||
params[0].image = null;
|
params[0].image = null;
|
||||||
@@ -348,6 +357,29 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An AsyncTask that deletes an image from the media store in the background.
|
||||||
|
*/
|
||||||
|
class DeleteImageInBackgroundTask extends AsyncTask<Uri, Void, Void> {
|
||||||
|
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:
|
* TODO:
|
||||||
* - Performance when over gl surfaces? Ie. Gallery
|
* - Performance when over gl surfaces? Ie. Gallery
|
||||||
@@ -358,6 +390,7 @@ class GlobalScreenshot {
|
|||||||
private static final String TAG = "GlobalScreenshot";
|
private static final String TAG = "GlobalScreenshot";
|
||||||
|
|
||||||
static final String CANCEL_ID = "android:cancel_id";
|
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_FLASH_TO_PEAK_DURATION = 130;
|
||||||
private static final int SCREENSHOT_DROP_IN_DURATION = 430;
|
private static final int SCREENSHOT_DROP_IN_DURATION = 430;
|
||||||
@@ -761,11 +794,33 @@ class GlobalScreenshot {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the notification
|
||||||
final NotificationManager nm =
|
final NotificationManager nm =
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
final int id = intent.getIntExtra(CANCEL_ID, 0);
|
final int id = intent.getIntExtra(CANCEL_ID, 0);
|
||||||
nm.cancel(id);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user