Stretch small wallpapers to cover the screen in the picker.

Helpful if you're using tiny color swatches as wallpapers.

Bug: 17017748
Change-Id: I3ed518996c7d58470c5a194ce064f90d73454448
diff --git a/src/com/android/launcher2/WallpaperChooserDialogFragment.java b/src/com/android/launcher2/WallpaperChooserDialogFragment.java
index b99d8ec..ea9d3e8 100644
--- a/src/com/android/launcher2/WallpaperChooserDialogFragment.java
+++ b/src/com/android/launcher2/WallpaperChooserDialogFragment.java
@@ -26,6 +26,7 @@
 import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
+import android.graphics.Matrix;
 import android.graphics.drawable.Drawable;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -323,6 +324,7 @@
         Bitmap mBitmap;
         int mIntrinsicWidth;
         int mIntrinsicHeight;
+        Matrix mMatrix;
 
         /* package */void setBitmap(Bitmap bitmap) {
             mBitmap = bitmap;
@@ -330,16 +332,35 @@
                 return;
             mIntrinsicWidth = mBitmap.getWidth();
             mIntrinsicHeight = mBitmap.getHeight();
+            mMatrix = null;
         }
 
         @Override
         public void draw(Canvas canvas) {
             if (mBitmap == null) return;
-            int width = canvas.getWidth();
-            int height = canvas.getHeight();
-            int x = (width - mIntrinsicWidth) / 2;
-            int y = (height - mIntrinsicHeight) / 2;
-            canvas.drawBitmap(mBitmap, x, y, null);
+ 
+            if (mMatrix == null) {
+                final int vwidth = canvas.getWidth();
+                final int vheight = canvas.getHeight();
+                final int dwidth = mIntrinsicWidth;
+                final int dheight = mIntrinsicHeight;
+
+                float scale = 1.0f;
+
+                if (dwidth < vwidth || dheight < vheight) {
+                    scale = Math.max((float) vwidth / (float) dwidth,
+                            (float) vheight / (float) dheight);
+                }
+
+                float dx = (vwidth - dwidth * scale) * 0.5f + 0.5f;
+                float dy = (vheight - dheight * scale) * 0.5f + 0.5f;
+
+                mMatrix = new Matrix();
+                mMatrix.setScale(scale, scale);
+                mMatrix.postTranslate((int) dx, (int) dy);
+            }
+
+            canvas.drawBitmap(mBitmap, mMatrix, null);
         }
 
         @Override