Merge branch 'eclair' into eclair-release
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java
index a1760de..193914c 100644
--- a/src/com/android/launcher2/AllAppsView.java
+++ b/src/com/android/launcher2/AllAppsView.java
@@ -49,6 +49,7 @@
 import android.view.accessibility.AccessibilityEvent;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 
@@ -328,7 +329,7 @@
             }
         }
 
-        if (mArrowNavigation && iconCount > 0) {
+        if (iconCount > 0) {
             mArrowNavigation = true;
 
             int currentSelection = mRollo.mState.selectedIconIndex;
@@ -369,6 +370,8 @@
                     } else if (currentTopRow > 0) {
                         newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
                         mRollo.moveTo(newSelection / Defines.COLUMNS_PER_PAGE);
+                    } else {
+                        newSelection = Defines.COLUMNS_PER_PAGE * (Defines.ROWS_PER_PAGE-1);
                     }
                 }
                 handled = true;
@@ -381,7 +384,11 @@
                 if (mLastSelection != SELECTION_HOME) {
                     if (currentRow < rowCount-1) {
                         mRollo.setHomeSelected(SELECTED_NONE);
-                        newSelection = currentSelection + Defines.COLUMNS_PER_PAGE;
+                        if (currentSelection < 0) {
+                            newSelection = 0;
+                        } else {
+                            newSelection = currentSelection + Defines.COLUMNS_PER_PAGE;
+                        }
                         if (newSelection >= iconCount) {
                             // Go from D to G in this arrangement:
                             //     A B C D
@@ -608,7 +615,6 @@
                 break;
             }
             if (text != null) {
-                Log.d(TAG, "dispatchPopulateAccessibilityEvent setting text=" + text);
                 event.setEnabled(true);
                 event.getText().add(text);
                 //event.setContentDescription(text);
@@ -644,8 +650,6 @@
     }
 
     public boolean isVisible() {
-        Log.d(TAG, "isVisible mZoomDirty=" + mZoomDirty
-                + " mMessageProc=" + (mMessageProc == null ? "null" : mZoom));
         return mZoom > 0.001f;
     }
 
@@ -1344,7 +1348,6 @@
 
                 if (prev != index) {
                     if (info.title != null && info.title.length() > 0) {
-                        Log.d(TAG, "sendAccessibilityEvent SELECTION_ICONS " + info.title);
                         //setContentDescription(info.title);
                         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
                     }
@@ -1369,7 +1372,6 @@
                 mLastSelection = SELECTION_HOME;
                 mState.homeButtonId = mHomeButtonFocused.getID();
                 if (prev != SELECTION_HOME) {
-                    Log.d(TAG, "sendAccessibilityEvent SELECTION_HOME");
                     sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
                 }
                 break;
@@ -1378,6 +1380,69 @@
                 break;
             }
         }
+
+        public void dumpState() {
+            Log.d(TAG, "mRollo.mWidth=" + mWidth);
+            Log.d(TAG, "mRollo.mHeight=" + mHeight);
+            Log.d(TAG, "mRollo.mIcons=" + mIcons);
+            if (mIcons != null) {
+                Log.d(TAG, "mRollo.mIcons.length=" + mIcons.length);
+            }
+            if (mIconIds != null) {
+                Log.d(TAG, "mRollo.mIconIds.length=" + mIconIds.length);
+            }
+            Log.d(TAG, "mRollo.mIconIds=" +  Arrays.toString(mIconIds));
+            if (mLabelIds != null) {
+                Log.d(TAG, "mRollo.mLabelIds.length=" + mLabelIds.length);
+            }
+            Log.d(TAG, "mRollo.mLabelIds=" +  Arrays.toString(mLabelIds));
+            Log.d(TAG, "mRollo.mTouchXBorders=" +  Arrays.toString(mTouchXBorders));
+            Log.d(TAG, "mRollo.mTouchYBorders=" +  Arrays.toString(mTouchYBorders));
+            Log.d(TAG, "mRollo.mHasSurface=" + mHasSurface);
+            Log.d(TAG, "mRollo.mAppsDirty=" + mAppsDirty);
+            Log.d(TAG, "mRollo.mState.newPositionX=" + mState.newPositionX);
+            Log.d(TAG, "mRollo.mState.newTouchDown=" + mState.newTouchDown);
+            Log.d(TAG, "mRollo.mState.flingVelocity=" + mState.flingVelocity);
+            Log.d(TAG, "mRollo.mState.iconCount=" + mState.iconCount);
+            Log.d(TAG, "mRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
+            Log.d(TAG, "mRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
+            Log.d(TAG, "mRollo.mState.zoomTarget=" + mState.zoomTarget);
+            Log.d(TAG, "mRollo.mState.homeButtonId=" + mState.homeButtonId);
+            Log.d(TAG, "mRollo.mState.targetPos=" + mState.targetPos);
+            Log.d(TAG, "mRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
+            Log.d(TAG, "mRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
+            Log.d(TAG, "mRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
+            Log.d(TAG, "mRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
+            Log.d(TAG, "mRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
+            Log.d(TAG, "mRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
+            Log.d(TAG, "mRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
+            Log.d(TAG, "mRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
+        }
+    }
+
+    public void dumpState() {
+        Log.d(TAG, "mRS=" + mRS);
+        Log.d(TAG, "mRollo=" + mRollo);
+        ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
+        Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
+        Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
+        Log.d(TAG, "mLastSelection=" + mLastSelection);
+        Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
+        Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
+        Log.d(TAG, "mTouchTracking=" + mTouchTracking);
+        Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
+        Log.d(TAG, "mZoomDirty=" + mZoomDirty);
+        Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom);
+        Log.d(TAG, "mZoom=" + mZoom);
+        Log.d(TAG, "mPosX=" + mPosX);
+        Log.d(TAG, "mVelocity=" + mVelocity);
+        Log.d(TAG, "mMessageProc=" + mMessageProc);
+        if (mRollo != null) {
+            mRollo.dumpState();
+        }
+        if (mRS != null) {
+            mRS.contextDump(0);
+        }
     }
 }
 
diff --git a/src/com/android/launcher2/ApplicationInfo.java b/src/com/android/launcher2/ApplicationInfo.java
index db802c7..0fe84e7 100644
--- a/src/com/android/launcher2/ApplicationInfo.java
+++ b/src/com/android/launcher2/ApplicationInfo.java
@@ -21,6 +21,9 @@
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.drawable.Drawable;
+import android.util.Log;
+
+import java.util.ArrayList;
 
 /**
  * Represents a launchable application. An application is made of a name (or title),
@@ -140,4 +143,15 @@
         super.unbind();
         icon.setCallback(null);
     }
+
+
+    public static void dumpApplicationInfoList(String tag, String label,
+            ArrayList<ApplicationInfo> list) {
+        Log.d(tag, label + " size=" + list.size());
+        for (ApplicationInfo info: list) {
+            Log.d(tag, "   title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap
+                    + " icon=" + info.icon + " iconBitmap=" + info.iconBitmap
+                    + " filtered=" + info.filtered + " customIcon=" + info.customIcon);
+        }
+    }
 }
diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java
index 51e3f25..7ae9891 100644
--- a/src/com/android/launcher2/DragLayer.java
+++ b/src/com/android/launcher2/DragLayer.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.MotionEvent;
 import android.view.KeyEvent;
 import android.widget.FrameLayout;
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index c04176f..3e878d6 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -48,6 +48,7 @@
 import android.os.Parcelable;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.provider.LiveFolders;
 import android.text.Selection;
 import android.text.SpannableStringBuilder;
@@ -55,6 +56,7 @@
 import android.text.method.TextKeyListener;
 import android.util.Log;
 import android.view.Display;
+import android.view.HapticFeedbackConstants;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -563,7 +565,9 @@
         Drawable next = mNextView.getDrawable();
         mWorkspace.setIndicators(previous, next);
 
+        mPreviousView.setHapticFeedbackEnabled(false);
         mPreviousView.setOnLongClickListener(this);
+        mNextView.setHapticFeedbackEnabled(false);
         mNextView.setOnLongClickListener(this);
 
         workspace.setOnLongClickListener(this);
@@ -1318,6 +1322,12 @@
                     return true;
                 case KeyEvent.KEYCODE_HOME:
                     return true;
+                case KeyEvent.KEYCODE_VOLUME_DOWN:
+                    if (SystemProperties.getInt("launcher2.dumpstate", 0) != 0) {
+                        dumpState();
+                        return true;
+                    }
+                    break;
             }
         } else if (event.getAction() == KeyEvent.ACTION_UP) {
             switch (event.getKeyCode()) {
@@ -1469,10 +1479,18 @@
     public boolean onLongClick(View v) {
         switch (v.getId()) {
             case R.id.previous_screen:
-                showPreviousPreview(v);
+                if (!isAllAppsVisible()) {
+                    mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+                            HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+                    showPreviousPreview(v);
+                }
                 return true;
             case R.id.next_screen:
-                showNextPreview(v);
+                if (!isAllAppsVisible()) {
+                    mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+                            HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+                    showNextPreview(v);
+                }
                 return true;
         }
 
@@ -1501,6 +1519,8 @@
             } else {
                 if (!(cellInfo.cell instanceof Folder)) {
                     // User long pressed on an item
+                    mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+                            HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
                     mWorkspace.startDrag(cellInfo);
                 }
             }
@@ -2179,4 +2199,14 @@
         mWorkspace.removeShortcutsForPackage(packageName);
         mAllAppsGrid.removeApps(apps);
     }
+
+    /**
+     * Prints out out state for debugging.
+     */
+    public void dumpState() {
+        Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
+        mModel.dumpState();
+        mAllAppsGrid.dumpState();
+        Log.d(TAG, "END launcher2 dump state");
+    }
 }
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index a796831..85d47a9 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -616,6 +616,7 @@
 
                 mItems.clear();
                 mAppWidgets.clear();
+                mFolders.clear();
 
                 final Cursor c = contentResolver.query(
                         LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
@@ -999,6 +1000,27 @@
                     });
                 }
             }
+
+            public void dumpState() {
+                Log.d(TAG, "mLoader.mLoaderThread.mContext=" + mContext);
+                Log.d(TAG, "mLoader.mLoaderThread.mWaitThread=" + mWaitThread);
+                Log.d(TAG, "mLoader.mLoaderThread.mIsLaunching=" + mIsLaunching);
+                Log.d(TAG, "mLoader.mLoaderThread.mStopped=" + mStopped);
+                Log.d(TAG, "mLoader.mLoaderThread.mWorkspaceDoneBinding=" + mWorkspaceDoneBinding);
+            }
+        }
+
+        public void dumpState() {
+            Log.d(TAG, "mLoader.mLastWorkspaceSeq=" + mLoader.mLastWorkspaceSeq);
+            Log.d(TAG, "mLoader.mWorkspaceSeq=" + mLoader.mWorkspaceSeq);
+            Log.d(TAG, "mLoader.mLastAllAppsSeq=" + mLoader.mLastAllAppsSeq);
+            Log.d(TAG, "mLoader.mAllAppsSeq=" + mLoader.mAllAppsSeq);
+            Log.d(TAG, "mLoader.mItems size=" + mLoader.mItems.size());
+            if (mLoaderThread != null) {
+                mLoaderThread.dumpState();
+            } else {
+                Log.d(TAG, "mLoader.mLoaderThread=null");
+            }
         }
     }
 
@@ -1207,4 +1229,14 @@
             return sCollator.compare(a.title.toString(), b.title.toString());
         }
     };
+
+    public void dumpState() {
+        Log.d(TAG, "mBeforeFirstLoad=" + mBeforeFirstLoad);
+        Log.d(TAG, "mCallbacks=" + mCallbacks);
+        ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
+        ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
+        ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
+        ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
+        mLoader.dumpState();
+    }
 }
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 8853158..d0cec8a 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -139,6 +139,7 @@
         mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);
         a.recycle();
 
+        setHapticFeedbackEnabled(false);
         initWorkspace();
     }
 
@@ -352,6 +353,7 @@
         }
         group.addView(child, insert ? 0 : -1, lp);
         if (!(child instanceof Folder)) {
+            child.setHapticFeedbackEnabled(false);
             child.setOnLongClickListener(mLongClickListener);
         }
         if (child instanceof DropTarget) {
@@ -426,10 +428,8 @@
         if (vacant) {
             group.addView(child,
                     new CellLayout.LayoutParams(mTempCell[0], mTempCell[1], spanX, spanY));
+            child.setHapticFeedbackEnabled(false);
             child.setOnLongClickListener(mLongClickListener);
-            if (!(child instanceof Folder)) {
-                child.setOnLongClickListener(mLongClickListener);
-            }
             if (child instanceof DropTarget) {
                 mDragController.addDropTarget((DropTarget)child);
             }
@@ -1094,6 +1094,7 @@
         }
 
         cellLayout.addView(view, insertAtFirst ? 0 : -1);
+        view.setHapticFeedbackEnabled(false);
         view.setOnLongClickListener(mLongClickListener);
         if (view instanceof DropTarget) {
             mDragController.addDropTarget((DropTarget) view);