Add ability to swipe from apps to widgets in AllAppsCustomize (issue 5453016)

Change-Id: I4d725cf1ee11d67f5149dbd0edbcb2e0af3b80ee
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index 8b7b956..25f67cb 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -48,6 +48,7 @@
     private ViewGroup mTabs;
     private ViewGroup mTabsContainer;
     private AppsCustomizePagedView mAppsCustomizePane;
+    private boolean mSuppressContentCallback = false;
     private ImageView mAnimationBuffer;
 
     private boolean mInTransition;
@@ -162,6 +163,7 @@
     private void onTabChangedStart() {
         mAppsCustomizePane.hideScrollingIndicator(false);
     }
+
     private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
         mAppsCustomizePane.setContentType(type);
     }
@@ -169,59 +171,67 @@
     @Override
     public void onTabChanged(String tabId) {
         final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
-        if (!mAppsCustomizePane.isContentType(type)) {
-            // Animate the changing of the tab content by fading pages in and out
-            final Resources res = getResources();
-            final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
-
-            // We post a runnable here because there is a delay while the first page is loading and
-            // the feedback from having changed the tab almost feels better than having it stick
-            post(new Runnable() {
-                @Override
-                public void run() {
-                    // Setup the animation buffer
-                    Bitmap b = Bitmap.createBitmap(mAppsCustomizePane.getMeasuredWidth(),
-                            mAppsCustomizePane.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
-                    Canvas c = new Canvas(b);
-                    mAppsCustomizePane.draw(c);
-                    mAppsCustomizePane.setAlpha(0f);
-                    mAnimationBuffer.setImageBitmap(b);
-                    mAnimationBuffer.setAlpha(1f);
-                    mAnimationBuffer.setVisibility(View.VISIBLE);
-                    c.setBitmap(null);
-                    b = null;
-
-                    // Toggle the new content
-                    onTabChangedStart();
-                    onTabChangedEnd(type);
-
-                    // Animate the transition
-                    ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
-                    outAnim.addListener(new AnimatorListenerAdapter() {
-                        @Override
-                        public void onAnimationEnd(Animator animation) {
-                            mAnimationBuffer.setVisibility(View.GONE);
-                            mAnimationBuffer.setImageBitmap(null);
-                        }
-                    });
-                    ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
-                    inAnim.addListener(new AnimatorListenerAdapter() {
-                        @Override
-                        public void onAnimationEnd(Animator animation) {
-                            if (!LauncherApplication.isScreenLarge()) {
-                                mAppsCustomizePane.flashScrollingIndicator();
-                            }
-                            mAppsCustomizePane.loadAssociatedPages(
-                                    mAppsCustomizePane.getCurrentPage());
-                        }
-                    });
-                    AnimatorSet animSet = new AnimatorSet();
-                    animSet.playTogether(outAnim, inAnim);
-                    animSet.setDuration(duration);
-                    animSet.start();
-                }
-            });
+        if (mSuppressContentCallback) {
+            mSuppressContentCallback = false;
+            return;
         }
+
+        // Animate the changing of the tab content by fading pages in and out
+        final Resources res = getResources();
+        final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
+
+        // We post a runnable here because there is a delay while the first page is loading and
+        // the feedback from having changed the tab almost feels better than having it stick
+        post(new Runnable() {
+            @Override
+            public void run() {
+                // Setup the animation buffer
+                Bitmap b = Bitmap.createBitmap(mAppsCustomizePane.getMeasuredWidth(),
+                        mAppsCustomizePane.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
+                Canvas c = new Canvas(b);
+                mAppsCustomizePane.draw(c);
+                mAppsCustomizePane.setAlpha(0f);
+                mAnimationBuffer.setImageBitmap(b);
+                mAnimationBuffer.setAlpha(1f);
+                mAnimationBuffer.setVisibility(View.VISIBLE);
+                c.setBitmap(null);
+                b = null;
+
+                // Toggle the new content
+                onTabChangedStart();
+                onTabChangedEnd(type);
+
+                // Animate the transition
+                ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
+                outAnim.addListener(new AnimatorListenerAdapter() {
+                    @Override
+                    public void onAnimationEnd(Animator animation) {
+                        mAnimationBuffer.setVisibility(View.GONE);
+                        mAnimationBuffer.setImageBitmap(null);
+                    }
+                });
+                ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
+                inAnim.addListener(new AnimatorListenerAdapter() {
+                    @Override
+                    public void onAnimationEnd(Animator animation) {
+                        if (!LauncherApplication.isScreenLarge()) {
+                            mAppsCustomizePane.flashScrollingIndicator();
+                        }
+                        mAppsCustomizePane.loadAssociatedPages(
+                                mAppsCustomizePane.getCurrentPage());
+                    }
+                });
+                AnimatorSet animSet = new AnimatorSet();
+                animSet.playTogether(outAnim, inAnim);
+                animSet.setDuration(duration);
+                animSet.start();
+            }
+        });
+    }
+
+    public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
+        mSuppressContentCallback = true;
+        setCurrentTabByTag(getTabTagForContentType(type));
     }
 
     /**