Adding signposting to Phone UI in Workspace/AppsCustomize.

Change-Id: Id63f247745a5ec1a63bbaff84602e4c91354f789
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index dfdbce9..5b4f150 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -84,7 +84,6 @@
     private IconCache mIconCache;
 
     // Dimens
-    private Runnable mOnSizeChangedCallback;
     private int mContentWidth;
     private int mMaxWidgetSpan, mMinWidgetSpan;
     private int mWidgetWidthGap, mWidgetHeightGap;
@@ -190,11 +189,6 @@
         mWidgetCountY = Math.max(1, (int) Math.round(mCellCountY / 3f));
         mContentWidth = mWidgetSpacingLayout.getContentWidth();
 
-        // Notify our parent so that we can synchronize the tab bar width to this page width
-        if (mOnSizeChangedCallback != null) {
-            mOnSizeChangedCallback.run();
-        }
-
         invalidatePageData();
     }
 
@@ -213,10 +207,6 @@
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 
-    public void setOnSizeChangedCallback(Runnable r) {
-        mOnSizeChangedCallback = r;
-    }
-
     /** Removes and returns the ResolveInfo with the specified ComponentName */
     private ResolveInfo removeResolveInfoWithComponentName(List<ResolveInfo> list,
             ComponentName cn) {
@@ -886,4 +876,9 @@
         // TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we
         // should stop this now.
     }
+
+    @Override
+    protected int getPageWidthForScrollingIndicator() {
+        return getPageContentWidth();
+    }
 }
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index d83db74..1fa23cf 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -41,6 +41,7 @@
 import android.view.ViewParent;
 import android.view.animation.Interpolator;
 import android.widget.Checkable;
+import android.widget.ImageView;
 import android.widget.Scroller;
 
 import com.android.launcher.R;
@@ -162,6 +163,13 @@
     // All syncs and layout passes are deferred until data is ready.
     protected boolean mIsDataReady = false;
 
+    // Scrolling indicator
+    private ImageView mScrollIndicator;
+    private boolean mHasScrollIndicator = true;
+    private static final int sScrollIndicatorFadeInDuration = 150;
+    private static final int sScrollIndicatorFastFadeOutDuration = 50;
+    private static final int sScrollIndicatorFadeOutDuration = 650;
+
     public interface PageSwitchListener {
         void onPageSwitch(View newPage, int newPageIndex);
     }
@@ -306,10 +314,12 @@
 
     // a method that subclasses can override to add behavior
     protected void onPageBeginMoving() {
+        showScrollingIndicator();
     }
 
     // a method that subclasses can override to add behavior
     protected void onPageEndMoving() {
+        hideScrollingIndicator(false);
     }
 
     /**
@@ -612,6 +622,7 @@
     }
 
     protected void screenScrolled(int screenCenter) {
+        updateScrollingIndicator();
     }
 
     @Override
@@ -1583,6 +1594,8 @@
         }
 
         if (mContentIsRefreshable) {
+            hideScrollingIndicator(true);
+
             // Update all the pages
             syncPages();
 
@@ -1600,4 +1613,80 @@
             requestLayout();
         }
     }
+
+    private ImageView getScrollingIndicator() {
+        // We use mHasScrollIndicator to prevent future lookups if there is no sibling indicator
+        // found
+        if (mHasScrollIndicator && mScrollIndicator == null) {
+            ViewGroup parent = (ViewGroup) getParent();
+            mScrollIndicator = (ImageView) (parent.findViewById(R.id.paged_view_indicator));
+            mHasScrollIndicator = mScrollIndicator != null;
+            if (mHasScrollIndicator) {
+                mScrollIndicator.setVisibility(View.VISIBLE);
+            }
+        }
+        return mScrollIndicator;
+    }
+
+    protected boolean isScrollingIndicatorEnabled() {
+        return true;
+    }
+
+    protected void showScrollingIndicator() {
+        if (LauncherApplication.isScreenLarge()) return;
+        if (getChildCount() <= 1) return;
+        if (!isScrollingIndicatorEnabled()) return;
+
+        getScrollingIndicator();
+        if (mScrollIndicator != null) {
+            // Update the width of the indicator to the approx. width of each page in the full bar
+            mScrollIndicator.getLayoutParams().width = getPageWidthForScrollingIndicator() / getChildCount();
+            mScrollIndicator.requestLayout();
+
+            // Fade the indicator in
+            updateScrollingIndicatorPosition();
+            mScrollIndicator.animate().alpha(1f).setDuration(sScrollIndicatorFadeInDuration);
+        }
+    }
+
+    protected void hideScrollingIndicator(boolean immediately) {
+        if (LauncherApplication.isScreenLarge()) return;
+        if (getChildCount() <= 1) return;
+        if (!isScrollingIndicatorEnabled()) return;
+
+        getScrollingIndicator();
+        if (mScrollIndicator != null) {
+            // Fade the indicator out
+            updateScrollingIndicatorPosition();
+            mScrollIndicator.animate().alpha(0f).setDuration(immediately ?
+                    sScrollIndicatorFastFadeOutDuration : sScrollIndicatorFadeOutDuration);
+        }
+    }
+
+    private void updateScrollingIndicator() {
+        if (LauncherApplication.isScreenLarge()) return;
+        if (getChildCount() <= 1) return;
+        if (!isScrollingIndicatorEnabled()) return;
+
+        getScrollingIndicator();
+        if (mScrollIndicator != null) {
+            updateScrollingIndicatorPosition();
+        }
+    }
+
+    protected int getPageWidthForScrollingIndicator() {
+        return getMeasuredWidth();
+    }
+
+    private void updateScrollingIndicatorPosition() {
+        // We can make the page width smaller to make it look more centered
+        int pageWidth = getPageWidthForScrollingIndicator();
+        int pageOffset = (getMeasuredWidth() - pageWidth) / 2;
+        int maxPageWidth = getChildCount() * pageWidth;
+        float offset = (float) getScrollX() / maxPageWidth;
+        int indicatorWidth = pageWidth / getChildCount();
+        int indicatorCenterOffset = indicatorWidth / 2 - mScrollIndicator.getMeasuredWidth() / 2;
+        int indicatorPos = (int) (offset * pageWidth) + pageOffset + indicatorCenterOffset;
+        mScrollIndicator.setTranslationX(indicatorPos);
+    }
 }
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 1e01254..1048fd5 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -635,7 +635,14 @@
         }
     }
 
+    @Override
+    protected boolean isScrollingIndicatorEnabled() {
+        return mShrinkState != ShrinkState.SPRING_LOADED;
+    }
+
     protected void onPageBeginMoving() {
+        super.onPageBeginMoving();
+
         if (mNextPage != INVALID_PAGE) {
             // we're snapping to a particular screen
             enableChildrenCache(mCurrentPage, mNextPage);
@@ -644,14 +651,23 @@
             // swipe it either left or right (but we won't advance by more than one screen)
             enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1);
         }
-        showOutlines();
+
+        // Only show page outlines as we pan if we are on large screen
+        if (LauncherApplication.isScreenLarge()) {
+            showOutlines();
+        }
     }
 
     protected void onPageEndMoving() {
+        super.onPageEndMoving();
+
         clearChildrenCache();
         // Hide the outlines, as long as we're not dragging
         if (!mDragController.dragging()) {
-            hideOutlines();
+            // Only hide page outlines as we pan if we are on large screen
+            if (LauncherApplication.isScreenLarge()) {
+                hideOutlines();
+            }
         }
         mOverScrollMaxBackgroundAlpha = 0.0f;
         mOverScrollPageIndex = -1;
@@ -1081,6 +1097,8 @@
 
     @Override
     protected void screenScrolled(int screenCenter) {
+        super.screenScrolled(screenCenter);
+
         // If the screen is not xlarge, then don't rotate the CellLayouts
         // NOTE: If we don't update the side pages alpha, then we should not hide the side pages.
         //       see unshrink().
@@ -1425,6 +1443,9 @@
             updateWhichPagesAcceptDrops(shrinkState);
         }
 
+        // Hide the scrollbar
+        hideScrollingIndicator(true);
+
         CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage);
         if (currentPage == null) {
             Log.w(TAG, "currentPage is NULL! mCurrentPage " + mCurrentPage