Deleting the WallpaperPicker code inside launcher.
Instead linking it to the packages/apps/WallpaperPicker project

Change-Id: Ib6830b180a22c22afece01e0a4f6e94e89d6452b
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 40aaf79..06810b4 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -113,10 +113,10 @@
 import com.android.launcher3.util.TestingUtils;
 import com.android.launcher3.util.Thunk;
 import com.android.launcher3.util.ViewOnDrawExecutor;
-import com.android.launcher3.util.WallpaperUtils;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
 import com.android.launcher3.widget.WidgetHostViewLoader;
 import com.android.launcher3.widget.WidgetsContainerView;
+import com.android.wallpaperpicker.WallpaperUtils;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java
new file mode 100644
index 0000000..62b9be4
--- /dev/null
+++ b/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+package com.android.launcher3;
+
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.os.Bundle;
+import android.util.Pair;
+
+import com.android.wallpaperpicker.tileinfo.DefaultWallpaperInfo;
+import com.android.wallpaperpicker.tileinfo.FileWallpaperInfo;
+import com.android.wallpaperpicker.tileinfo.WallpaperTileInfo;
+
+import java.io.File;
+import java.util.ArrayList;
+
+public class WallpaperPickerActivity extends com.android.wallpaperpicker.WallpaperPickerActivity {
+
+    @Override
+    public void startActivityForResultSafely(Intent intent, int requestCode) {
+        Utilities.startActivityForResultSafely(this, intent, requestCode);
+    }
+
+    @Override
+    public boolean enableRotation() {
+        return super.enableRotation() ||
+                getContentResolver().call(LauncherSettings.Settings.CONTENT_URI,
+                        LauncherSettings.Settings.METHOD_GET_BOOLEAN,
+                        Utilities.ALLOW_ROTATION_PREFERENCE_KEY, new Bundle())
+                        .getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
+    }
+
+    @Override
+    public ArrayList<WallpaperTileInfo> findBundledWallpapers() {
+        final PackageManager pm = getPackageManager();
+        final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24);
+
+        Partner partner = Partner.get(pm);
+        if (partner != null) {
+            final Resources partnerRes = partner.getResources();
+            final int resId = partnerRes.getIdentifier(Partner.RES_WALLPAPERS, "array",
+                    partner.getPackageName());
+            if (resId != 0) {
+                addWallpapers(bundled, partnerRes, partner.getPackageName(), resId);
+            }
+
+            // Add system wallpapers
+            File systemDir = partner.getWallpaperDirectory();
+            if (systemDir != null && systemDir.isDirectory()) {
+                for (File file : systemDir.listFiles()) {
+                    if (!file.isFile()) {
+                        continue;
+                    }
+                    String name = file.getName();
+                    int dotPos = name.lastIndexOf('.');
+                    String extension = "";
+                    if (dotPos >= -1) {
+                        extension = name.substring(dotPos);
+                        name = name.substring(0, dotPos);
+                    }
+
+                    if (name.endsWith("_small")) {
+                        // it is a thumbnail
+                        continue;
+                    }
+
+                    File thumbnail = new File(systemDir, name + "_small" + extension);
+                    Bitmap thumb = BitmapFactory.decodeFile(thumbnail.getAbsolutePath());
+                    if (thumb != null) {
+                        bundled.add(new FileWallpaperInfo(
+                                file, new BitmapDrawable(getResources(), thumb)));
+                    }
+                }
+            }
+        }
+
+        Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
+        if (r != null) {
+            try {
+                Resources wallpaperRes = pm.getResourcesForApplication(r.first);
+                addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second);
+            } catch (PackageManager.NameNotFoundException e) {
+            }
+        }
+
+        if (partner == null || !partner.hideDefaultWallpaper()) {
+            // Add an entry for the default wallpaper (stored in system resources)
+            WallpaperTileInfo defaultWallpaperInfo = DefaultWallpaperInfo.get(this);
+            if (defaultWallpaperInfo != null) {
+                bundled.add(0, defaultWallpaperInfo);
+            }
+        }
+        return bundled;
+    }
+}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index e6ab111..05f9d20 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -72,9 +72,9 @@
 import com.android.launcher3.util.LongArrayMap;
 import com.android.launcher3.util.Thunk;
 import com.android.launcher3.util.WallpaperOffsetInterpolator;
-import com.android.launcher3.util.WallpaperUtils;
 import com.android.launcher3.widget.PendingAddShortcutInfo;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
+import com.android.wallpaperpicker.WallpaperUtils;
 
 import java.util.ArrayList;
 import java.util.HashMap;
diff --git a/src/com/android/launcher3/util/WallpaperUtils.java b/src/com/android/launcher3/util/WallpaperUtils.java
deleted file mode 100644
index 45c83bd..0000000
--- a/src/com/android/launcher3/util/WallpaperUtils.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.launcher3.util;
-
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.app.WallpaperManager;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.graphics.Point;
-import android.os.Build;
-import android.view.WindowManager;
-
-import com.android.launcher3.LauncherFiles;
-import com.android.launcher3.Utilities;
-
-/**
- * Utility methods for wallpaper management.
- */
-public final class WallpaperUtils {
-
-    public static final String WALLPAPER_WIDTH_KEY = "wallpaper.width";
-    public static final String WALLPAPER_HEIGHT_KEY = "wallpaper.height";
-    public static final float WALLPAPER_SCREENS_SPAN = 2f;
-
-    public static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
-
-    public static void saveWallpaperDimensions(int width, int height, Activity activity) {
-        if (Utilities.ATLEAST_KITKAT) {
-            // From Kitkat onwards, ImageWallpaper does not care about the
-            // desired width and desired height of the wallpaper.
-            return;
-        }
-        String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
-        SharedPreferences sp = activity.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
-        SharedPreferences.Editor editor = sp.edit();
-        if (width != 0 && height != 0) {
-            editor.putInt(WALLPAPER_WIDTH_KEY, width);
-            editor.putInt(WALLPAPER_HEIGHT_KEY, height);
-        } else {
-            editor.remove(WALLPAPER_WIDTH_KEY);
-            editor.remove(WALLPAPER_HEIGHT_KEY);
-        }
-        editor.commit();
-        suggestWallpaperDimensionPreK(activity, true);
-    }
-
-    public static void suggestWallpaperDimensionPreK(
-            Activity activity, boolean fallBackToDefaults) {
-        final Point defaultWallpaperSize = getDefaultWallpaperSize(
-                activity.getResources(), activity.getWindowManager());
-
-        SharedPreferences sp = activity.getSharedPreferences(
-                LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY, Context.MODE_MULTI_PROCESS);
-        // If we have saved a wallpaper width/height, use that instead
-        int width = sp.getInt(WALLPAPER_WIDTH_KEY, -1);
-        int height = sp.getInt(WALLPAPER_HEIGHT_KEY, -1);
-
-        if (width == -1 || height == -1) {
-            if (!fallBackToDefaults) {
-                return;
-            } else {
-                width = defaultWallpaperSize.x;
-                height = defaultWallpaperSize.y;
-            }
-        }
-
-        WallpaperManager wm = WallpaperManager.getInstance(activity);
-        if (width != wm.getDesiredMinimumWidth() || height != wm.getDesiredMinimumHeight()) {
-            wm.suggestDesiredDimensions(width, height);
-        }
-    }
-
-    public static void suggestWallpaperDimension(Activity activity) {
-        // Only live wallpapers care about desired size. Update the size to what launcher expects.
-        final Point size = getDefaultWallpaperSize(
-                activity.getResources(), activity.getWindowManager());
-        WallpaperManager wm = WallpaperManager.getInstance(activity);
-        if (size.x != wm.getDesiredMinimumWidth() || size.y != wm.getDesiredMinimumHeight()) {
-            wm.suggestDesiredDimensions(size.x, size.y);
-        }
-    }
-
-    /**
-     * As a ratio of screen height, the total distance we want the parallax effect to span
-     * horizontally
-     */
-    private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
-        float aspectRatio = width / (float) height;
-
-        // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
-        // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
-        // We will use these two data points to extrapolate how much the wallpaper parallax effect
-        // to span (ie travel) at any aspect ratio:
-
-        final float ASPECT_RATIO_LANDSCAPE = 16/10f;
-        final float ASPECT_RATIO_PORTRAIT = 10/16f;
-        final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
-        final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
-
-        // To find out the desired width at different aspect ratios, we use the following two
-        // formulas, where the coefficient on x is the aspect ratio (width/height):
-        //   (16/10)x + y = 1.5
-        //   (10/16)x + y = 1.2
-        // We solve for x and y and end up with a final formula:
-        final float x =
-            (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
-            (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
-        final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
-        return x * aspectRatio + y;
-    }
-
-    private static Point sDefaultWallpaperSize;
-
-    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
-    public static Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {
-        if (sDefaultWallpaperSize == null) {
-            Point realSize = new Point();
-            windowManager.getDefaultDisplay().getRealSize(realSize);
-            int maxDim = Math.max(realSize.x, realSize.y);
-            int minDim = Math.min(realSize.x, realSize.y);
-
-            // We need to ensure that there is enough extra space in the wallpaper
-            // for the intended parallax effects
-            final int defaultWidth, defaultHeight;
-            if (res.getConfiguration().smallestScreenWidthDp >= 720) {
-                defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
-                defaultHeight = maxDim;
-            } else {
-                defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
-                defaultHeight = maxDim;
-            }
-            sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
-        }
-        return sDefaultWallpaperSize;
-    }
-}