Fixing crash in FocusHelper and removing some old focus code for old Customize layout.

Change-Id: Ifd8a38174bbcf04c0ffeeefb4f42419e82a6ba95
diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java
index 94488a1..b765e17 100644
--- a/src/com/android/launcher2/AllAppsTabbed.java
+++ b/src/com/android/launcher2/AllAppsTabbed.java
@@ -81,7 +81,7 @@
         };
 
         // Create the tabs and wire them up properly
-        AllAppsTabKeyEventListener keyListener = new AllAppsTabKeyEventListener();
+        AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
         TextView tabView;
         TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
         tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index b5c6327..51db66c 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -25,6 +25,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TabHost;
+import android.widget.TabWidget;
 import android.widget.TextView;
 
 import com.android.launcher.R;
@@ -63,7 +64,7 @@
         // Setup the tab host
         setup();
 
-        final ViewGroup tabs = (ViewGroup) findViewById(com.android.internal.R.id.tabs);
+        final TabWidget tabs = (TabWidget) findViewById(com.android.internal.R.id.tabs);
         final AppsCustomizePagedView appsCustomizePane = (AppsCustomizePagedView)
                 findViewById(R.id.apps_customize_pane_content);
         mTabs = tabs;
@@ -87,6 +88,13 @@
         tabView.setText(mContext.getString(R.string.widgets_tab_label));
         addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
         setOnTabChangedListener(this);
+
+        // Setup the key listener to jump between the last tab view and the market icon
+        AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
+        View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
+        lastTab.setOnKeyListener(keyListener);
+        View shopButton = findViewById(R.id.market_button);
+        shopButton.setOnKeyListener(keyListener);
     }
 
     @Override
diff --git a/src/com/android/launcher2/FocusHelper.java b/src/com/android/launcher2/FocusHelper.java
index 861a70b..25d941b 100644
--- a/src/com/android/launcher2/FocusHelper.java
+++ b/src/com/android/launcher2/FocusHelper.java
@@ -16,10 +16,6 @@
 
 package com.android.launcher2;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-
 import android.content.res.Configuration;
 import android.view.KeyEvent;
 import android.view.View;
@@ -30,6 +26,10 @@
 
 import com.android.launcher.R;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
 /**
  * A keyboard listener we set on all the button bar buttons.
  */
@@ -62,13 +62,13 @@
 }
 
 /**
- * A keyboard listener we set on the last tab button in AllApps to jump to then
+ * A keyboard listener we set on the last tab button in AppsCustomize to jump to then
  * market icon and vice versa.
  */
-class AllAppsTabKeyEventListener implements View.OnKeyListener {
+class AppsCustomizeTabKeyEventListener implements View.OnKeyListener {
     @Override
     public boolean onKey(View v, int keyCode, KeyEvent event) {
-        return FocusHelper.handleAllAppsTabKeyEvent(v, keyCode, event);
+        return FocusHelper.handleAppsCustomizeTabKeyEvent(v, keyCode, event);
     }
 }
 
@@ -85,9 +85,9 @@
     }
 
     /**
-     * Handles key events in a AllApps tab between the last tab view and the shop button.
+     * Handles key events in a AppsCustomize tab between the last tab view and the shop button.
      */
-    static boolean handleAllAppsTabKeyEvent(View v, int keyCode, KeyEvent e) {
+    static boolean handleAppsCustomizeTabKeyEvent(View v, int keyCode, KeyEvent e) {
         final TabHost tabHost = findTabHostParent(v);
         final ViewGroup contents = (ViewGroup)
                 tabHost.findViewById(com.android.internal.R.id.tabcontent);
@@ -129,124 +129,6 @@
 
     /**
      * Handles key events in a PageViewExtendedLayout containing PagedViewWidgets.
-     * To be deprecated.
-     */
-    static boolean handlePagedViewWidgetKeyEvent(PagedViewWidget w, int keyCode, KeyEvent e) {
-        if (!LauncherApplication.isScreenLarge()) return false;
-
-        final PagedViewExtendedLayout parent = (PagedViewExtendedLayout) w.getParent();
-        final ViewGroup container = (ViewGroup) parent.getParent();
-        final TabHost tabHost = findTabHostParent(container);
-        final TabWidget tabs = (TabWidget) tabHost.findViewById(com.android.internal.R.id.tabs);
-        final int widgetIndex = parent.indexOfChild(w);
-        final int widgetCount = parent.getChildCount();
-        final int pageIndex = container.indexOfChild(parent);
-        final int pageCount = container.getChildCount();
-
-        final int action = e.getAction();
-        final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
-        PagedViewExtendedLayout newParent = null;
-        boolean wasHandled = false;
-        switch (keyCode) {
-            case KeyEvent.KEYCODE_DPAD_LEFT:
-                if (handleKeyEvent) {
-                    // Select the previous widget or the last widget on the previous page
-                    if (widgetIndex > 0) {
-                        parent.getChildAt(widgetIndex - 1).requestFocus();
-                    } else {
-                        if (pageIndex > 0) {
-                            newParent = (PagedViewExtendedLayout)
-                                    container.getChildAt(pageIndex - 1);
-                            newParent.getChildAt(newParent.getChildCount() - 1).requestFocus();
-                        }
-                    }
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_DPAD_RIGHT:
-                if (handleKeyEvent) {
-                    // Select the next widget or the first widget on the next page
-                    if (widgetIndex < (widgetCount - 1)) {
-                        parent.getChildAt(widgetIndex + 1).requestFocus();
-                    } else {
-                        if (pageIndex < (pageCount - 1)) {
-                            newParent = (PagedViewExtendedLayout)
-                                    container.getChildAt(pageIndex + 1);
-                            newParent.getChildAt(0).requestFocus();
-                        }
-                    }
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_DPAD_UP:
-                if (handleKeyEvent) {
-                    // Select widgets tab on the tab bar
-                    tabs.requestFocus();
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_DPAD_DOWN:
-                if (handleKeyEvent) {
-                    // TODO: Should focus the global search bar
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_ENTER:
-            case KeyEvent.KEYCODE_DPAD_CENTER:
-                if (handleKeyEvent) {
-                    // Simulate a click on the widget
-                    View.OnClickListener clickListener = (View.OnClickListener) container;
-                    clickListener.onClick(w);
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_PAGE_UP:
-                if (handleKeyEvent) {
-                    // Select the first item on the previous page, or the first item on this page
-                    // if there is no previous page
-                    if (pageIndex > 0) {
-                        newParent = (PagedViewExtendedLayout) container.getChildAt(pageIndex - 1);
-                        newParent.getChildAt(0).requestFocus();
-                    } else {
-                        parent.getChildAt(0).requestFocus();
-                    }
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_PAGE_DOWN:
-                if (handleKeyEvent) {
-                    // Select the first item on the next page, or the last item on this page
-                    // if there is no next page
-                    if (pageIndex < (pageCount - 1)) {
-                        newParent = (PagedViewExtendedLayout) container.getChildAt(pageIndex + 1);
-                        newParent.getChildAt(0).requestFocus();
-                    } else {
-                        parent.getChildAt(widgetCount - 1).requestFocus();
-                    }
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_MOVE_HOME:
-                if (handleKeyEvent) {
-                    // Select the first item on this page
-                    parent.getChildAt(0).requestFocus();
-                }
-                wasHandled = true;
-                break;
-            case KeyEvent.KEYCODE_MOVE_END:
-                if (handleKeyEvent) {
-                    // Select the last item on this page
-                    parent.getChildAt(widgetCount - 1).requestFocus();
-                }
-                wasHandled = true;
-                break;
-            default: break;
-        }
-        return wasHandled;
-    }
-
-    /**
-     * Handles key events in a PageViewExtendedLayout containing PagedViewWidgets.
      */
     static boolean handlePagedViewGridLayoutWidgetKeyEvent(PagedViewWidget w, int keyCode,
             KeyEvent e) {
@@ -908,7 +790,7 @@
         final CellLayout layout = (CellLayout) parent.getParent();
         final Workspace workspace = (Workspace) layout.getParent();
         final ViewGroup launcher = (ViewGroup) workspace.getParent();
-        final ViewGroup tabs = (ViewGroup) launcher.findViewById(R.id.all_apps_button_cluster);
+        final ViewGroup tabs = (ViewGroup) launcher.findViewById(R.id.qsb_bar);
         int iconIndex = parent.indexOfChild(v);
         int iconCount = parent.getChildCount();
         int pageIndex = workspace.indexOfChild(layout);
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
index 2ffa398..6ddecf1 100644
--- a/src/com/android/launcher2/PagedViewWidget.java
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -257,24 +257,14 @@
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        if (LauncherApplication.isScreenLarge()) {
-            return FocusHelper.handlePagedViewWidgetKeyEvent(this, keyCode, event)
-                    || super.onKeyDown(keyCode, event);
-        } else {
-            return FocusHelper.handlePagedViewGridLayoutWidgetKeyEvent(this, keyCode, event)
-                    || super.onKeyDown(keyCode, event);
-        }
+        return FocusHelper.handlePagedViewGridLayoutWidgetKeyEvent(this, keyCode, event)
+                || super.onKeyDown(keyCode, event);
     }
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (LauncherApplication.isScreenLarge()) {
-            return FocusHelper.handlePagedViewWidgetKeyEvent(this, keyCode, event)
-                    || super.onKeyUp(keyCode, event);
-        } else {
-            return FocusHelper.handlePagedViewGridLayoutWidgetKeyEvent(this, keyCode, event)
-                    || super.onKeyUp(keyCode, event);
-        }
+        return FocusHelper.handlePagedViewGridLayoutWidgetKeyEvent(this, keyCode, event)
+                || super.onKeyUp(keyCode, event);
     }
 
     @Override