Merge "Updating pageindicator assets" into ub-launcher3-burnaby
diff --git a/WallpaperPicker/src/com/android/launcher3/CropView.java b/WallpaperPicker/src/com/android/launcher3/CropView.java
index 578b8ea..50f779a 100644
--- a/WallpaperPicker/src/com/android/launcher3/CropView.java
+++ b/WallpaperPicker/src/com/android/launcher3/CropView.java
@@ -21,7 +21,6 @@
 import android.graphics.Point;
 import android.graphics.RectF;
 import android.util.AttributeSet;
-import android.util.FloatMath;
 import android.view.MotionEvent;
 import android.view.ScaleGestureDetector;
 import android.view.ScaleGestureDetector.OnScaleGestureListener;
@@ -300,12 +299,12 @@
                     adjustment[0] = (edges.right - getWidth()) / scale;
                 }
                 if (edges.top > 0) {
-                    adjustment[1] = FloatMath.ceil(edges.top / scale);
+                    adjustment[1] = (float) Math.ceil(edges.top / scale);
                 } else if (edges.bottom < getHeight()) {
                     adjustment[1] = (edges.bottom - getHeight()) / scale;
                 }
                 for (int dim = 0; dim <= 1; dim++) {
-                    if (coef[dim] > 0) adjustment[dim] = FloatMath.ceil(adjustment[dim]);
+                    if (coef[dim] > 0) adjustment[dim] = (float) Math.ceil(adjustment[dim]);
                 }
 
                 mInverseRotateMatrix.mapPoints(adjustment);
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index c49286a..9332091 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -137,39 +137,32 @@
 
     public static class UriWallpaperInfo extends WallpaperTileInfo {
         private Uri mUri;
-        private boolean mFirstClick = true;
-        @Thunk BitmapRegionTileSource.UriBitmapSource mBitmapSource;
         public UriWallpaperInfo(Uri uri) {
             mUri = uri;
         }
         @Override
         public void onClick(final WallpaperPickerActivity a) {
-            final Runnable onLoad;
-            if (!mFirstClick) {
-                onLoad = null;
-            } else {
-                mFirstClick = false;
-                a.mSetWallpaperButton.setEnabled(false);
-                onLoad = new Runnable() {
-                    public void run() {
-                        if (mBitmapSource != null &&
-                                mBitmapSource.getLoadingState() == BitmapSource.State.LOADED) {
-                            a.selectTile(mView);
-                            a.mSetWallpaperButton.setEnabled(true);
-                        } else {
-                            ViewGroup parent = (ViewGroup) mView.getParent();
-                            if (parent != null) {
-                                parent.removeView(mView);
-                                Toast.makeText(a.getContext(), R.string.image_load_fail,
-                                        Toast.LENGTH_SHORT).show();
-                            }
+            a.setWallpaperButtonEnabled(false);
+            final BitmapRegionTileSource.UriBitmapSource bitmapSource =
+                    new BitmapRegionTileSource.UriBitmapSource(
+                            a.getContext(), mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE);
+            a.setCropViewTileSource(bitmapSource, true, false, null, new Runnable() {
+
+                @Override
+                public void run() {
+                    if (bitmapSource.getLoadingState() == BitmapSource.State.LOADED) {
+                        a.selectTile(mView);
+                        a.setWallpaperButtonEnabled(true);
+                    } else {
+                        ViewGroup parent = (ViewGroup) mView.getParent();
+                        if (parent != null) {
+                            parent.removeView(mView);
+                            Toast.makeText(a.getContext(), R.string.image_load_fail,
+                                    Toast.LENGTH_SHORT).show();
                         }
                     }
-                };
-            }
-            mBitmapSource = new BitmapRegionTileSource.UriBitmapSource(
-                    a.getContext(), mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE);
-            a.setCropViewTileSource(mBitmapSource, true, false, null, onLoad);
+                }
+            });
         }
         @Override
         public void onSave(final WallpaperPickerActivity a) {
@@ -203,11 +196,18 @@
             mThumb = thumb;
         }
         @Override
-        public void onClick(WallpaperPickerActivity a) {
+        public void onClick(final WallpaperPickerActivity a) {
+            a.setWallpaperButtonEnabled(false);
             BitmapRegionTileSource.UriBitmapSource bitmapSource =
                     new BitmapRegionTileSource.UriBitmapSource(a.getContext(),
                             Uri.fromFile(mFile), 1024);
-            a.setCropViewTileSource(bitmapSource, false, true, null, null);
+            a.setCropViewTileSource(bitmapSource, false, true, null, new Runnable() {
+
+                @Override
+                public void run() {
+                    a.setWallpaperButtonEnabled(true);
+                }
+            });
         }
         @Override
         public void onSave(WallpaperPickerActivity a) {
@@ -234,6 +234,7 @@
         }
         @Override
         public void onClick(final WallpaperPickerActivity a) {
+            a.setWallpaperButtonEnabled(false);
             BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
                     new BitmapRegionTileSource.ResourceBitmapSource(
                             mResources, mResId, BitmapRegionTileSource.MAX_PREVIEW_SIZE);
@@ -248,7 +249,13 @@
                             wallpaperSize.x, wallpaperSize.y, false);
                     return wallpaperSize.x / crop.width();
                 }
-            }, null);
+            }, new Runnable() {
+
+                @Override
+                public void run() {
+                    a.setWallpaperButtonEnabled(true);
+                }
+            });
         }
         @Override
         public void onSave(WallpaperPickerActivity a) {
@@ -420,7 +427,7 @@
                     }
                     return;
                 }
-                mSetWallpaperButton.setEnabled(true);
+                setWallpaperButtonEnabled(true);
                 WallpaperTileInfo info = (WallpaperTileInfo) v.getTag();
                 if (info.isSelectable() && v.getVisibility() == View.VISIBLE) {
                     selectTile(v);
@@ -639,6 +646,10 @@
         };
     }
 
+    public void setWallpaperButtonEnabled(boolean enabled) {
+        mSetWallpaperButton.setEnabled(enabled);
+    }
+
     @Thunk void selectTile(View v) {
         if (mSelectedTile != null) {
             mSelectedTile.setSelected(false);
diff --git a/res/layout/apps_list_view.xml b/res/layout/apps_list_view.xml
index 595c46c..dfb7b58 100644
--- a/res/layout/apps_list_view.xml
+++ b/res/layout/apps_list_view.xml
@@ -20,7 +20,8 @@
     android:layout_height="match_parent"
     android:orientation="vertical"
     android:elevation="15dp"
-    android:visibility="gone">
+    android:visibility="gone"
+    android:focusableInTouchMode="true">
     <EditText
         android:id="@+id/app_search_box"
         android:layout_width="match_parent"
diff --git a/src/com/android/launcher3/AppsContainerView.java b/src/com/android/launcher3/AppsContainerView.java
index 559f6eb..52bc6b6 100644
--- a/src/com/android/launcher3/AppsContainerView.java
+++ b/src/com/android/launcher3/AppsContainerView.java
@@ -57,8 +57,11 @@
     private RecyclerView.Adapter mAdapter;
     private RecyclerView.LayoutManager mLayoutManager;
     private RecyclerView.ItemDecoration mItemDecoration;
-    @Thunk AppsContainerRecyclerView mAppsListView;
-    private EditText mSearchBar;
+
+    private LinearLayout mContentView;
+    @Thunk AppsContainerRecyclerView mAppsRecyclerView;
+    private EditText mSearchBarView;
+    
     private int mNumAppsPerRow;
     private Point mLastTouchDownPos = new Point();
     private Rect mInsets = new Rect();
@@ -140,7 +143,7 @@
      * Hides the search bar
      */
     public void hideSearchBar() {
-        mSearchBar.setVisibility(View.GONE);
+        mSearchBarView.setVisibility(View.GONE);
         updateBackgrounds();
         updatePaddings();
     }
@@ -149,14 +152,14 @@
      * Scrolls this list view to the top.
      */
     public void scrollToTop() {
-        mAppsListView.scrollToPosition(0);
+        mAppsRecyclerView.scrollToPosition(0);
     }
 
     /**
      * Returns the content view used for the launcher transitions.
      */
     public View getContentView() {
-        return findViewById(R.id.apps_list);
+        return mContentView;
     }
 
     /**
@@ -173,19 +176,31 @@
         if (USE_LAYOUT == GRID_LAYOUT) {
             ((AppsGridAdapter) mAdapter).setRtl(isRtl);
         }
-        mSearchBar = (EditText) findViewById(R.id.app_search_box);
-        if (mSearchBar != null) {
-            mSearchBar.addTextChangedListener(this);
-            mSearchBar.setOnEditorActionListener(this);
+
+        // Work around the search box getting first focus and showing the cursor by
+        // proxying the focus from the content view to the recycler view directly
+        mContentView = (LinearLayout) findViewById(R.id.apps_list);
+        mContentView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+            @Override
+            public void onFocusChange(View v, boolean hasFocus) {
+                if (v == mContentView && hasFocus) {
+                    mAppsRecyclerView.requestFocus();
+                }
+            }
+        });
+        mSearchBarView = (EditText) findViewById(R.id.app_search_box);
+        if (mSearchBarView != null) {
+            mSearchBarView.addTextChangedListener(this);
+            mSearchBarView.setOnEditorActionListener(this);
         }
-        mAppsListView = (AppsContainerRecyclerView) findViewById(R.id.apps_list_view);
-        mAppsListView.setApps(mApps);
-        mAppsListView.setNumAppsPerRow(mNumAppsPerRow);
-        mAppsListView.setLayoutManager(mLayoutManager);
-        mAppsListView.setAdapter(mAdapter);
-        mAppsListView.setHasFixedSize(true);
+        mAppsRecyclerView = (AppsContainerRecyclerView) findViewById(R.id.apps_list_view);
+        mAppsRecyclerView.setApps(mApps);
+        mAppsRecyclerView.setNumAppsPerRow(mNumAppsPerRow);
+        mAppsRecyclerView.setLayoutManager(mLayoutManager);
+        mAppsRecyclerView.setAdapter(mAdapter);
+        mAppsRecyclerView.setHasFixedSize(true);
         if (mItemDecoration != null) {
-            mAppsListView.addItemDecoration(mItemDecoration);
+            mAppsRecyclerView.addItemDecoration(mItemDecoration);
         }
         updateBackgrounds();
         updatePaddings();
@@ -207,7 +222,7 @@
             DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
             if (grid.updateAppsViewNumCols(context.getResources(), fixedBounds.width())) {
                 mNumAppsPerRow = grid.appsViewNumCols;
-                mAppsListView.setNumAppsPerRow(mNumAppsPerRow);
+                mAppsRecyclerView.setNumAppsPerRow(mNumAppsPerRow);
                 if (USE_LAYOUT == GRID_LAYOUT) {
                     ((AppsGridAdapter) mAdapter).setNumAppsPerRow(mNumAppsPerRow);
                 }
@@ -372,7 +387,7 @@
             for (int i = 0; i < items.size(); i++) {
                 AlphabeticalAppsList.AdapterItem item = items.get(i);
                 if (!item.isSectionHeader) {
-                    mAppsListView.getChildAt(i).performClick();
+                    mAppsRecyclerView.getChildAt(i).performClick();
                     InputMethodManager imm = (InputMethodManager)
                             getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                     imm.hideSoftInputFromWindow(getWindowToken(), 0);
@@ -390,12 +405,7 @@
 
     @Override
     public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
-        if (!toWorkspace) {
-            // Disable the focus so that the search bar doesn't get focus
-            if (mSearchBar != null) {
-                mSearchBar.setFocusableInTouchMode(false);
-            }
-        }
+        // Do nothing
     }
 
     @Override
@@ -410,12 +420,10 @@
 
     @Override
     public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
-        if (mSearchBar != null) {
+        if (mSearchBarView != null) {
             if (toWorkspace) {
                 // Clear the search bar
-                mSearchBar.setText("");
-            } else {
-                mSearchBar.setFocusableInTouchMode(true);
+                mSearchBarView.setText("");
             }
         }
     }
@@ -430,7 +438,8 @@
     private void updatePaddings() {
         boolean isRtl = (getResources().getConfiguration().getLayoutDirection() ==
                 LAYOUT_DIRECTION_RTL);
-        boolean hasSearchBar = (mSearchBar != null) && (mSearchBar.getVisibility() == View.VISIBLE);
+        boolean hasSearchBar = (mSearchBarView != null) &&
+                (mSearchBarView.getVisibility() == View.VISIBLE);
 
         if (mFixedBounds.isEmpty()) {
             // If there are no fixed bounds, then use the default padding and insets
@@ -446,14 +455,15 @@
         // Update the apps recycler view
         int inset = mFixedBounds.isEmpty() ? mContainerInset : mFixedBoundsContainerInset;
         if (isRtl) {
-            mAppsListView.setPadding(inset, inset, inset + mContentMarginStart, inset);
+            mAppsRecyclerView.setPadding(inset, inset, inset + mContentMarginStart, inset);
         } else {
-            mAppsListView.setPadding(inset + mContentMarginStart, inset, inset, inset);
+            mAppsRecyclerView.setPadding(inset + mContentMarginStart, inset, inset, inset);
         }
 
         // Update the search bar
         if (hasSearchBar) {
-            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mSearchBar.getLayoutParams();
+            LinearLayout.LayoutParams lp =
+                    (LinearLayout.LayoutParams) mSearchBarView.getLayoutParams();
             lp.leftMargin = lp.rightMargin = inset;
         }
     }
@@ -463,11 +473,12 @@
      */
     private void updateBackgrounds() {
         int inset = mFixedBounds.isEmpty() ? mContainerInset : mFixedBoundsContainerInset;
-        boolean hasSearchBar = (mSearchBar != null) && (mSearchBar.getVisibility() == View.VISIBLE);
+        boolean hasSearchBar = (mSearchBarView != null) &&
+                (mSearchBarView.getVisibility() == View.VISIBLE);
 
         // Update the background of the reveal view and list to be inset with the fixed bound
         // insets instead of the default insets
-        mAppsListView.setBackground(new InsetDrawable(
+        mAppsRecyclerView.setBackground(new InsetDrawable(
                 getContext().getResources().getDrawable(
                         hasSearchBar ? R.drawable.apps_list_search_bg : R.drawable.apps_list_bg),
                 inset, 0, inset, 0));
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 42e145b..5679dfc 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1003,7 +1003,7 @@
         super.onResume();
 
         // Restore the previous launcher state
-        if (mOnResumeState == State.WORKSPACE || mOnResumeState == State.NONE) {
+        if (mOnResumeState == State.WORKSPACE) {
             showWorkspace(false);
         } else if (mOnResumeState == State.APPS) {
             showAppsView(false /* animated */, false /* resetListToTop */);
diff --git a/src/com/android/launcher3/LauncherScroller.java b/src/com/android/launcher3/LauncherScroller.java
index 3bd0a78..a9b4955 100644
--- a/src/com/android/launcher3/LauncherScroller.java
+++ b/src/com/android/launcher3/LauncherScroller.java
@@ -20,7 +20,6 @@
 import android.content.Context;
 import android.hardware.SensorManager;
 import android.os.Build;
-import android.util.FloatMath;
 import android.view.ViewConfiguration;
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
@@ -409,7 +408,7 @@
 
             float dx = (float) (mFinalX - mStartX);
             float dy = (float) (mFinalY - mStartY);
-            float hyp = FloatMath.sqrt(dx * dx + dy * dy);
+            float hyp = (float) Math.hypot(dx, dy);
 
             float ndx = dx / hyp;
             float ndy = dy / hyp;
@@ -426,7 +425,7 @@
         mMode = FLING_MODE;
         mFinished = false;
 
-        float velocity = FloatMath.sqrt(velocityX * velocityX + velocityY * velocityY);
+        float velocity = (float) Math.hypot(velocityX, velocityY);
 
         mVelocity = velocity;
         mDuration = getSplineFlingDuration(velocity);
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index 57bd5b2..78272a8 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -184,11 +184,6 @@
         final WidgetsContainerView toView = mLauncher.getWidgetsView();
         PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
             @Override
-            public void onRevealViewVisible(View revealView, View contentView,
-                    View allAppsButtonView) {
-                revealView.setBackground(mLauncher.getDrawable(R.drawable.quantum_panel_dark));
-            }
-            @Override
             public float getMaterialRevealViewFinalAlpha(View revealView) {
                 return 0.3f;
             }
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 9173971..043ecb0 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1410,7 +1410,22 @@
         }
 
         private float wallpaperOffsetForCurrentScroll() {
+            // TODO: do different behavior if it's  a live wallpaper?
+            // Don't use up all the wallpaper parallax until you have at least
+            // MIN_PARALLAX_PAGE_SPAN pages
+            int numScrollingPages = getNumScreensExcludingEmptyAndCustom();
+            int parallaxPageSpan;
+            if (mWallpaperIsLiveWallpaper) {
+                parallaxPageSpan = numScrollingPages - 1;
+            } else {
+                parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1);
+            }
+            mNumPagesForWallpaperParallax = parallaxPageSpan;
+
             if (getChildCount() <= 1) {
+                if (isLayoutRtl()) {
+                    return 1 - 1.0f/mNumPagesForWallpaperParallax;
+                }
                 return 0;
             }
 
@@ -1430,28 +1445,20 @@
             if (scrollRange == 0) {
                 return 0;
             } else {
-                // TODO: do different behavior if it's  a live wallpaper?
                 // Sometimes the left parameter of the pages is animated during a layout transition;
                 // this parameter offsets it to keep the wallpaper from animating as well
                 int adjustedScroll =
                         getScrollX() - firstPageScrollX - getLayoutTransitionOffsetForPage(0);
                 float offset = Math.min(1, adjustedScroll / (float) scrollRange);
                 offset = Math.max(0, offset);
-                // Don't use up all the wallpaper parallax until you have at least
-                // MIN_PARALLAX_PAGE_SPAN pages
-                int numScrollingPages = getNumScreensExcludingEmptyAndCustom();
-                int parallaxPageSpan;
-                if (mWallpaperIsLiveWallpaper) {
-                    parallaxPageSpan = numScrollingPages - 1;
-                } else {
-                    parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1);
-                }
-                mNumPagesForWallpaperParallax = parallaxPageSpan;
 
                 // On RTL devices, push the wallpaper offset to the right if we don't have enough
                 // pages (ie if numScrollingPages < MIN_PARALLAX_PAGE_SPAN)
-                int padding = isLayoutRtl() ? parallaxPageSpan - numScrollingPages + 1 : 0;
-                return offset * (padding + numScrollingPages - 1) / parallaxPageSpan;
+                if (!mWallpaperIsLiveWallpaper && numScrollingPages < MIN_PARALLAX_PAGE_SPAN
+                        && isLayoutRtl()) {
+                    return offset * (parallaxPageSpan - numScrollingPages + 1) / parallaxPageSpan;
+                }
+                return offset * (numScrollingPages - 1) / parallaxPageSpan;
             }
         }