Merge "Fixing issue with screenshot icon being stretched." into mnc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
index be33085..f16f6bd 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -137,21 +137,31 @@
         int previewWidth = data.previewWidth;
         int previewHeight = data.previewheight;
 
-        final int shortSide = mImageWidth < mImageHeight ? mImageWidth : mImageHeight;
-        Bitmap preview = Bitmap.createBitmap(previewWidth, previewHeight, data.image.getConfig());
-        Canvas c = new Canvas(preview);
+        Canvas c = new Canvas();
         Paint paint = new Paint();
         ColorMatrix desat = new ColorMatrix();
         desat.setSaturation(0.25f);
         paint.setColorFilter(new ColorMatrixColorFilter(desat));
         Matrix matrix = new Matrix();
-        matrix.postTranslate((previewWidth - mImageWidth) / 2,
-                            (previewHeight - mImageHeight) / 2);
+        int overlayColor = 0x40FFFFFF;
+
+        Bitmap picture = Bitmap.createBitmap(previewWidth, previewHeight, data.image.getConfig());
+        matrix.setTranslate((previewWidth - mImageWidth) / 2, (previewHeight - mImageHeight) / 2);
+        c.setBitmap(picture);
         c.drawBitmap(data.image, matrix, paint);
-        c.drawColor(0x40FFFFFF);
+        c.drawColor(overlayColor);
         c.setBitmap(null);
 
-        Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);
+        // Note, we can't use the preview for the small icon, since it is non-square
+        float scale = (float) iconSize / Math.min(mImageWidth, mImageHeight);
+        Bitmap icon = Bitmap.createBitmap(iconSize, iconSize, data.image.getConfig());
+        matrix.setScale(scale, scale);
+        matrix.postTranslate((iconSize - (scale * mImageWidth)) / 2,
+                (iconSize - (scale * mImageHeight)) / 2);
+        c.setBitmap(icon);
+        c.drawBitmap(data.image, matrix, paint);
+        c.drawColor(overlayColor);
+        c.setBitmap(null);
 
         // Show the intermediate notification
         mTickerAddSpace = !mTickerAddSpace;
@@ -169,7 +179,7 @@
             .setColor(r.getColor(com.android.internal.R.color.system_notification_accent_color));
 
         mNotificationStyle = new Notification.BigPictureStyle()
-            .bigPicture(preview);
+            .bigPicture(picture);
         mNotificationBuilder.setStyle(mNotificationStyle);
 
         // For "public" situations we want to show all the same info but
@@ -192,7 +202,7 @@
         // On the tablet, the large icon makes the notification appear as if it is clickable (and
         // on small devices, the large icon is not shown) so defer showing the large icon until
         // we compose the final post-save notification below.
-        mNotificationBuilder.setLargeIcon(croppedIcon);
+        mNotificationBuilder.setLargeIcon(icon);
         // But we still don't set it for the expanded view, allowing the smallIcon to show here.
         mNotificationStyle.bigLargeIcon((Bitmap) null);
     }