Skip to content

Commit b72ac9d

Browse files
cwrenAndroid (Google) Code Review
authored andcommitted
Merge "BigPicture notifications for screenshots." into jb-dev
2 parents e820b18 + 3745a3d commit b72ac9d

File tree

7 files changed

+74
-13
lines changed

7 files changed

+74
-13
lines changed

core/java/android/app/Notification.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,8 @@ protected RemoteViews getStandardView(int layoutId) {
16891689
*/
16901690
public static class BigPictureStyle extends Style {
16911691
private Bitmap mPicture;
1692+
private Bitmap mBigLargeIcon;
1693+
private boolean mBigLargeIconSet = false;
16921694

16931695
public BigPictureStyle() {
16941696
}
@@ -1719,6 +1721,16 @@ public BigPictureStyle bigPicture(Bitmap b) {
17191721
return this;
17201722
}
17211723

1724+
/**
1725+
* @hide
1726+
* Override the large icon when the big notification is shown.
1727+
*/
1728+
public BigPictureStyle bigLargeIcon(Bitmap b) {
1729+
mBigLargeIconSet = true;
1730+
mBigLargeIcon = b;
1731+
return this;
1732+
}
1733+
17221734
private RemoteViews makeBigContentView() {
17231735
RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture);
17241736

@@ -1731,6 +1743,9 @@ private RemoteViews makeBigContentView() {
17311743
public Notification build() {
17321744
checkBuilder();
17331745
Notification wip = mBuilder.buildUnstyled();
1746+
if (mBigLargeIconSet ) {
1747+
mBuilder.mLargeIcon = mBigLargeIcon;
1748+
}
17341749
wip.bigContentView = makeBigContentView();
17351750
return wip;
17361751
}

core/res/res/layout/notification_template_big_picture.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,25 @@
3838
android:scaleType="fitXY"
3939
android:src="@drawable/title_bar_shadow"
4040
/>
41-
<include layout="@layout/notification_template_base"
41+
<include layout="@layout/notification_template_base"
4242
android:layout_width="match_parent"
4343
android:layout_height="wrap_content"
4444
/>
45+
<FrameLayout
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
48+
android:layout_marginTop="208dp"
49+
android:layout_marginLeft="64dp"
50+
android:layout_gravity="bottom"
51+
android:background="#CC111111"
52+
>
53+
<include
54+
layout="@layout/notification_action_list"
55+
android:id="@+id/actions"
56+
android:layout_marginLeft="8dp"
57+
android:layout_gravity="bottom"
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
/>
61+
</FrameLayout>
4562
</FrameLayout>

core/res/res/values/public.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@
785785
<java-symbol type="string" name="serviceNotProvisioned" />
786786
<java-symbol type="string" name="serviceRegistered" />
787787
<java-symbol type="string" name="setup_autofill" />
788+
<java-symbol type="string" name="share" />
788789
<java-symbol type="string" name="shareactionprovider_share_with" />
789790
<java-symbol type="string" name="shareactionprovider_share_with_application" />
790791
<java-symbol type="string" name="short_format_month" />
1.34 KB
Loading
1.01 KB
Loading
1.8 KB
Loading

packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.animation.ValueAnimator;
2323
import android.animation.ValueAnimator.AnimatorUpdateListener;
2424
import android.app.Notification;
25+
import android.app.Notification.BigPictureStyle;
2526
import android.app.NotificationManager;
2627
import android.app.PendingIntent;
2728
import android.content.ContentResolver;
@@ -31,9 +32,13 @@
3132
import android.content.res.Resources;
3233
import android.graphics.Bitmap;
3334
import android.graphics.Canvas;
35+
import android.graphics.ColorMatrix;
36+
import android.graphics.ColorMatrixColorFilter;
3437
import android.graphics.Matrix;
38+
import android.graphics.Paint;
3539
import android.graphics.PixelFormat;
3640
import android.graphics.PointF;
41+
import android.graphics.RectF;
3742
import android.media.MediaActionSound;
3843
import android.net.Uri;
3944
import android.os.AsyncTask;
@@ -85,6 +90,7 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
8590
private String mImageFileName;
8691
private String mImageFilePath;
8792
private long mImageTime;
93+
private BigPictureStyle mNotificationStyle;
8894

8995
// WORKAROUND: We want the same notification across screenshots that we update so that we don't
9096
// spam a user's notification drawer. However, we only show the ticker for the saving state
@@ -109,16 +115,22 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
109115
// Create the large notification icon
110116
int imageWidth = data.image.getWidth();
111117
int imageHeight = data.image.getHeight();
112-
int iconWidth = data.iconSize;
113-
int iconHeight = data.iconSize;
114-
if (imageWidth > imageHeight) {
115-
iconWidth = (int) (((float) iconHeight / imageHeight) * imageWidth);
116-
} else {
117-
iconHeight = (int) (((float) iconWidth / imageWidth) * imageHeight);
118-
}
119-
Bitmap rawIcon = Bitmap.createScaledBitmap(data.image, iconWidth, iconHeight, true);
120-
Bitmap croppedIcon = Bitmap.createBitmap(rawIcon, (iconWidth - data.iconSize) / 2,
121-
(iconHeight - data.iconSize) / 2, data.iconSize, data.iconSize);
118+
int iconSize = data.iconSize;
119+
120+
final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;
121+
Bitmap preview = Bitmap.createBitmap(shortSide, shortSide, data.image.getConfig());
122+
Canvas c = new Canvas(preview);
123+
Paint paint = new Paint();
124+
ColorMatrix desat = new ColorMatrix();
125+
desat.setSaturation(0.25f);
126+
paint.setColorFilter(new ColorMatrixColorFilter(desat));
127+
Matrix matrix = new Matrix();
128+
matrix.postTranslate((shortSide - imageWidth) / 2,
129+
(shortSide - imageHeight) / 2);
130+
c.drawBitmap(data.image, matrix, paint);
131+
c.drawColor(0x40FFFFFF);
132+
133+
Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);
122134

123135
// Show the intermediate notification
124136
mTickerAddSpace = !mTickerAddSpace;
@@ -131,14 +143,21 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
131143
.setContentText(r.getString(R.string.screenshot_saving_text))
132144
.setSmallIcon(R.drawable.stat_notify_image)
133145
.setWhen(System.currentTimeMillis());
134-
Notification n = mNotificationBuilder.getNotification();
146+
147+
mNotificationStyle = new Notification.BigPictureStyle()
148+
.bigPicture(preview);
149+
mNotificationBuilder.setStyle(mNotificationStyle);
150+
151+
Notification n = mNotificationBuilder.build();
135152
n.flags |= Notification.FLAG_NO_CLEAR;
136153
mNotificationManager.notify(nId, n);
137154

138155
// On the tablet, the large icon makes the notification appear as if it is clickable (and
139156
// on small devices, the large icon is not shown) so defer showing the large icon until
140157
// we compose the final post-save notification below.
141158
mNotificationBuilder.setLargeIcon(croppedIcon);
159+
// But we still don't set it for the expanded view, allowing the smallIcon to show here.
160+
mNotificationStyle.bigLargeIcon(null);
142161
}
143162

144163
@Override
@@ -151,6 +170,7 @@ protected SaveImageInBackgroundData doInBackground(SaveImageInBackgroundData...
151170

152171
Context context = params[0].context;
153172
Bitmap image = params[0].image;
173+
Resources r = context.getResources();
154174

155175
try {
156176
// Save the screenshot to the MediaStore
@@ -165,6 +185,14 @@ protected SaveImageInBackgroundData doInBackground(SaveImageInBackgroundData...
165185
values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
166186
Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
167187

188+
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
189+
sharingIntent.setType("image/png");
190+
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
191+
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_CLOSE_SYSTEM_DIALOGS);
192+
mNotificationBuilder.addAction(R.drawable.ic_menu_share,
193+
r.getString(com.android.internal.R.string.share),
194+
PendingIntent.getActivity(context, 0, sharingIntent, 0));
195+
168196
OutputStream out = resolver.openOutputStream(uri);
169197
image.compress(Bitmap.CompressFormat.PNG, 100, out);
170198
out.flush();
@@ -207,7 +235,7 @@ protected void onPostExecute(SaveImageInBackgroundData params) {
207235
.setWhen(System.currentTimeMillis())
208236
.setAutoCancel(true);
209237

210-
Notification n = mNotificationBuilder.getNotification();
238+
Notification n = mNotificationBuilder.build();
211239
n.flags &= ~Notification.FLAG_NO_CLEAR;
212240
mNotificationManager.notify(mNotificationId, n);
213241
}

0 commit comments

Comments
 (0)