Adding some wallpaper buttons on the customization tray.

Also tweaking the fading algorithm for side pages.

Change-Id: Ia7743c2b71741926ff9ae52e6965d7aefc86604e
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index 4307391..6e7f9b6 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -52,7 +52,7 @@
 import com.android.launcher.R;
 
 public class CustomizePagedView extends PagedView
-    implements View.OnLongClickListener,
+    implements View.OnLongClickListener, View.OnClickListener,
                 DragSource {
 
     public enum CustomizationType {
@@ -108,6 +108,7 @@
     private List<AppWidgetProviderInfo> mWidgetList;
     private List<ResolveInfo> mFolderList;
     private List<ResolveInfo> mShortcutList;
+    private List<ResolveInfo> mWallpaperList;
 
     private static final int sCellCountX = 8;
     private static final int sCellCountY = 4;
@@ -188,6 +189,11 @@
         mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
         Collections.sort(mShortcutList, resolveInfoComparator);
 
+        // get the list of wallpapers
+        Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
+        mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent, 0);
+        Collections.sort(mWallpaperList, resolveInfoComparator);
+
         // reset the icon cache
         mPageViewIconCache.clear();
 
@@ -211,6 +217,39 @@
     }
 
     @Override
+    public void onClick(View v) {
+        if (!v.isInTouchMode()) {
+            return;
+        }
+
+        final View animView = v;
+        switch (mCustomizationType) {
+        case WallpaperCustomization:
+            // animate some feedback to the long press
+            animateClickFeedback(v, new Runnable() {
+                @Override
+                public void run() {
+                    // add the shortcut
+                    ResolveInfo info = (ResolveInfo) animView.getTag();
+                    Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
+                    if (info.labelRes == R.string.group_applications) {
+                        // Create app shortcuts is a special built-in case of shortcuts
+                        createShortcutIntent.putExtra(
+                                Intent.EXTRA_SHORTCUT_NAME,getContext().getString(
+                                        R.string.group_applications));
+                    } else {
+                        ComponentName name = new ComponentName(info.activityInfo.packageName,
+                                info.activityInfo.name);
+                        createShortcutIntent.setComponent(name);
+                    }
+                    mLauncher.prepareAddItemFromHomeCustomizationDrawer();
+                    mLauncher.processShortcut(createShortcutIntent);
+                }
+            });
+        }
+    }
+
+    @Override
     public boolean onLongClick(View v) {
         if (!v.isInTouchMode()) {
             return false;
@@ -476,7 +515,11 @@
             PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
                     R.layout.customize_paged_view_item, layout, false);
             icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache);
-            icon.setOnLongClickListener(this);
+            if (mCustomizationType == CustomizationType.WallpaperCustomization) {
+                icon.setOnClickListener(this);
+            } else {
+                icon.setOnLongClickListener(this);
+            }
 
             final int index = i - startIndex;
             final int x = index % sCellCountX;
@@ -486,34 +529,6 @@
         }
     }
 
-    private void syncWallpaperPages() {
-        // NOT CURRENTLY IMPLEMENTED
-
-        // we need to repopulate with PagedViewCellLayouts
-        removeAllViews();
-
-        // add any necessary pages
-        int numPages = 1;
-        for (int i = 0; i < numPages; ++i) {
-            PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
-            setupPage(layout);
-            addView(layout);
-        }
-    }
-
-    private void syncWallpaperPageItems(int page) {
-        PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
-        layout.removeAllViews();
-
-        TextView text = (TextView) mInflater.inflate(
-                R.layout.customize_paged_view_wallpaper_placeholder, layout, false);
-        // NOTE: this is just place holder text until MikeJurka implements wallpaper picker
-        text.setText("Wallpaper customization coming soon!");
-
-        setupPage(layout);
-        layout.addViewToCellLayout(text, -1, 0, new PagedViewCellLayout.LayoutParams(0, 0, 3, 1));
-    }
-
     @Override
     public void syncPages() {
         boolean centerPagedViewCellLayouts = false;
@@ -530,7 +545,7 @@
             centerPagedViewCellLayouts = true;
             break;
         case WallpaperCustomization:
-            syncWallpaperPages();
+            syncListPages(mWallpaperList);
             centerPagedViewCellLayouts = true;
             break;
         default:
@@ -570,7 +585,7 @@
             syncListPageItems(page, mShortcutList);
             break;
         case WallpaperCustomization:
-            syncWallpaperPageItems(page);
+            syncListPageItems(page, mWallpaperList);
             break;
         }
     }
diff --git a/src/com/android/launcher2/HolographicOutlineHelper.java b/src/com/android/launcher2/HolographicOutlineHelper.java
index 6210337..d6c5484 100644
--- a/src/com/android/launcher2/HolographicOutlineHelper.java
+++ b/src/com/android/launcher2/HolographicOutlineHelper.java
@@ -59,21 +59,17 @@
      * pages.
      */
     public float highlightAlphaInterpolator(float r) {
-        final float pivot = 0.3f;
-        if (r < pivot) {
-            return Math.max(0.5f, 0.65f * cubic(r / pivot));
-        } else {
-            return Math.min(1.0f, 0.65f * cubic(1 - (r - pivot) / (1 - pivot)));
-        }
+        float maxAlpha = 0.6f;
+        return (float) Math.pow(maxAlpha * (1.0f - r), 1.5f);
     }
 
     /**
      * Returns the interpolated view alpha for the effect we want when scrolling pages.
      */
     public float viewAlphaInterpolator(float r) {
-        final float pivot = 0.6f;
+        final float pivot = 0.95f;
         if (r < pivot) {
-            return r / pivot;
+            return (float) Math.pow(r / pivot, 1.5f);
         } else {
             return 1.0f;
         }
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 2cd7f20..9dbe61d 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -374,17 +374,23 @@
                     int childWidth = layout.getMeasuredWidth();
                     int halfChildWidth = (childWidth / 2);
                     int childCenter = getChildOffset(i) + halfChildWidth;
-                    int distanceFromScreenCenter = Math.abs(childCenter - screenCenter);
-                    float alpha = 0.0f;
-                    if (distanceFromScreenCenter < halfChildWidth) {
-                        alpha = 1.0f;
-                    } else if (distanceFromScreenCenter > childWidth) {
-                        alpha = 0.0f;
+
+                    int d = halfChildWidth;
+                    int distanceFromScreenCenter = childCenter - screenCenter;
+                    if (distanceFromScreenCenter > 0) {
+                        if (i > 0) {
+                            d += getChildAt(i - 1).getMeasuredWidth() / 2;
+                        }
                     } else {
-                        float dimAlpha = (float) (distanceFromScreenCenter - halfChildWidth) / halfChildWidth;
-                        dimAlpha = Math.max(0.0f, Math.min(1.0f, (dimAlpha * dimAlpha)));
-                        alpha = 1.0f - dimAlpha;
+                        if (i < childCount - 1) {
+                            d += getChildAt(i + 1).getMeasuredWidth() / 2;
+                        }
                     }
+
+                    float dimAlpha = (float) (Math.abs(distanceFromScreenCenter)) / d;
+                    dimAlpha = Math.max(0.0f, Math.min(1.0f, (dimAlpha * dimAlpha)));
+                    float alpha = 1.0f - dimAlpha;
+
                     if (Float.compare(alpha, layout.getAlpha()) != 0) {
                         layout.setAlpha(alpha);
                     }