Merge "Removing extraneous apps-customize page reset. (Bug 11027505)" into jb-ub-now-indigo-rose
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 07346f0..e3312d5 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -492,10 +492,12 @@
             int width, height;
             cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
             View child = getChildAt(fra.mCellX, fra.mCellY);
-            int centerX = mTempLocation[0] + mCellWidth / 2;
-            int centerY = mTempLocation[1] + previewOffset / 2 +
-                    child.getPaddingTop() + grid.folderBackgroundOffset;
+
             if (child != null) {
+                int centerX = mTempLocation[0] + mCellWidth / 2;
+                int centerY = mTempLocation[1] + previewOffset / 2 +
+                        child.getPaddingTop() + grid.folderBackgroundOffset;
+
                 // Draw outer ring, if it exists
                 if (FolderIcon.HAS_OUTER_RING) {
                     d = FolderRingAnimator.sSharedOuterRingDrawable;
diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java
index 3c955cb..89f8275 100644
--- a/src/com/android/launcher3/DragLayer.java
+++ b/src/com/android/launcher3/DragLayer.java
@@ -69,6 +69,8 @@
     public static final int ANIMATION_END_FADE_OUT = 1;
     public static final int ANIMATION_END_REMAIN_VISIBLE = 2;
 
+    private TouchCompleteListener mTouchCompleteListener;
+
     private final Rect mInsets = new Rect();
 
     /**
@@ -173,10 +175,17 @@
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
-        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+        int action = ev.getAction();
+
+        if (action == MotionEvent.ACTION_DOWN) {
             if (handleTouchDown(ev, true)) {
                 return true;
             }
+        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+            if (mTouchCompleteListener != null) {
+                mTouchCompleteListener.onTouchComplete();
+            }
+            mTouchCompleteListener = null;
         }
         clearAllResizeFrames();
         return mDragController.onInterceptTouchEvent(ev);
@@ -278,12 +287,15 @@
         int x = (int) ev.getX();
         int y = (int) ev.getY();
 
-        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-            if (ev.getAction() == MotionEvent.ACTION_DOWN) {
-                if (handleTouchDown(ev, false)) {
-                    return true;
-                }
+        if (action == MotionEvent.ACTION_DOWN) {
+            if (handleTouchDown(ev, false)) {
+                return true;
             }
+        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+            if (mTouchCompleteListener != null) {
+                mTouchCompleteListener.onTouchComplete();
+            }
+            mTouchCompleteListener = null;
         }
 
         if (mCurrentResizeFrame != null) {
@@ -818,4 +830,12 @@
             }
         }
     }
+
+    public void setTouchCompleteListener(TouchCompleteListener listener) {
+        mTouchCompleteListener = listener;
+    }
+
+    public interface TouchCompleteListener {
+        public void onTouchComplete();
+    }
 }
diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java
index 59bd307..83aef1a 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java
@@ -24,20 +24,24 @@
 import android.view.ViewGroup;
 import android.widget.RemoteViews;
 
+import com.android.launcher3.DragLayer.TouchCompleteListener;
+
 /**
  * {@inheritDoc}
  */
-public class LauncherAppWidgetHostView extends AppWidgetHostView {
+public class LauncherAppWidgetHostView extends AppWidgetHostView implements TouchCompleteListener {
     private CheckLongPressHelper mLongPressHelper;
     private LayoutInflater mInflater;
     private Context mContext;
     private int mPreviousOrientation;
+    private DragLayer mDragLayer;
 
     public LauncherAppWidgetHostView(Context context) {
         super(context);
         mContext = context;
         mLongPressHelper = new CheckLongPressHelper(this);
         mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        mDragLayer = ((Launcher) context).getDragLayer();
     }
 
     @Override
@@ -72,6 +76,7 @@
         switch (ev.getAction()) {
             case MotionEvent.ACTION_DOWN: {
                 mLongPressHelper.postCheckForLongPress();
+                mDragLayer.setTouchCompleteListener(this);
                 break;
             }
 
@@ -100,7 +105,11 @@
     @Override
     public void cancelLongPress() {
         super.cancelLongPress();
+        mLongPressHelper.cancelLongPress();
+    }
 
+    @Override
+    public void onTouchComplete() {
         mLongPressHelper.cancelLongPress();
     }
 
@@ -108,4 +117,6 @@
     public int getDescendantFocusability() {
         return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
     }
+
+
 }
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index d1819e1..7e1442d 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -1623,6 +1623,7 @@
 
                 final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
                 final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI;
+                if (DEBUG_LOADERS) Log.d(TAG, "loading model from " + contentUri);
                 final Cursor c = contentResolver.query(contentUri, null, null, null, null);
 
                 // +1 for the hotseat (it can be larger than the workspace)
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 39afe10..d0f6770 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -49,8 +49,8 @@
 import android.util.Log;
 import android.util.Xml;
 
-import com.android.launcher3.LauncherSettings.BaseLauncherColumns;
 import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.config.ProviderConfig;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -69,7 +69,7 @@
     private static final int DATABASE_VERSION = 15;
 
     static final String OLD_AUTHORITY = "com.android.launcher2.settings";
-    static final String AUTHORITY = "com.android.launcher3.settings";
+    static final String AUTHORITY = ProviderConfig.AUTHORITY;
 
     static final String TABLE_FAVORITES = "favorites";
     static final String TABLE_WORKSPACE_SCREENS = "workspaceScreens";
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index b209436..2a339c0 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -350,7 +350,11 @@
             }
 
             mPageIndicator.addMarkers(markers, mAllowPagedViewAnimations);
-            mPageIndicator.setOnClickListener(getPageIndicatorClickListener());
+
+            OnClickListener listener = getPageIndicatorClickListener();
+            if (listener != null) {
+                mPageIndicator.setOnClickListener(listener);
+            }
             mPageIndicator.setContentDescription(getPageIndicatorDescription());
         }
     }
@@ -1524,6 +1528,19 @@
         }
     }
 
+    // While layout transitions are occurring, a child's position may stray from its baseline
+    // position. This method returns the magnitude of this stray at any given time.
+    public int getLayoutTransitionOffsetForPage(int index) {
+        if (mPageScrolls == null || index >= mPageScrolls.length || index < 0) {
+            return 0;
+        } else {
+            View child = getChildAt(index);
+            int scrollOffset = (getViewportWidth() - child.getMeasuredWidth()) / 2;
+            int baselineX = mPageScrolls[index] + scrollOffset + getViewportOffsetX();
+            return (int) (child.getX() - baselineX);
+        }
+    }
+
     // This curve determines how the effect of scrolling over the limits of the page dimishes
     // as the user pulls further and further from the bounds
     private float overScrollInfluenceCurve(float f) {
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java
index 3992170..d3e1c7b 100644
--- a/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -616,11 +616,11 @@
             Log.e(TAG, "Error loading thumbnail for uri=" + uri);
         }
         mWallpapersView.addView(pickedImageThumbnail, 0);
-        updateTileIndices();
 
         UriWallpaperInfo info = new UriWallpaperInfo(uri);
         pickedImageThumbnail.setTag(info);
         info.setView(pickedImageThumbnail);
+        updateTileIndices();
         pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener);
         mThumbnailOnClickListener.onClick(pickedImageThumbnail);
     }
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index a23d7d0..4515b03 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1387,7 +1387,9 @@
         float progress = 0;
         if (hasCustomContent()) {
             int index = mScreenOrder.indexOf(CUSTOM_CONTENT_SCREEN_ID);
-            int scrollDelta = getScrollForPage(index + 1) - getScrollX();
+
+            int scrollDelta = getScrollForPage(index + 1) - getScrollX() +
+                    getLayoutTransitionOffsetForPage(index + 1);
             translationX = scrollDelta;
             progress = (1.0f * scrollDelta) /
                     (getScrollForPage(index + 1) - getScrollForPage(index));
diff --git a/src/com/android/launcher3/config/ProviderConfig.java b/src/com/android/launcher3/config/ProviderConfig.java
new file mode 100644
index 0000000..db25076
--- /dev/null
+++ b/src/com/android/launcher3/config/ProviderConfig.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2013 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.config;
+
+public class ProviderConfig {
+
+    public static final String AUTHORITY = "com.android.launcher3.settings";
+}