2222import android .animation .ValueAnimator ;
2323import android .animation .ValueAnimator .AnimatorUpdateListener ;
2424import android .app .Notification ;
25+ import android .app .Notification .BigPictureStyle ;
2526import android .app .NotificationManager ;
2627import android .app .PendingIntent ;
2728import android .content .ContentResolver ;
3132import android .content .res .Resources ;
3233import android .graphics .Bitmap ;
3334import android .graphics .Canvas ;
35+ import android .graphics .ColorMatrix ;
36+ import android .graphics .ColorMatrixColorFilter ;
3437import android .graphics .Matrix ;
38+ import android .graphics .Paint ;
3539import android .graphics .PixelFormat ;
3640import android .graphics .PointF ;
41+ import android .graphics .RectF ;
3742import android .media .MediaActionSound ;
3843import android .net .Uri ;
3944import 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