Fixing various issues with the dock.

- Prevent crash due to no overlays in certain device configurations
- Fixing kb crash and adding content description for Apps button

Change-Id: Ie2a2bc29e7b9408a165f93d108fdd803193afc29
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
index 57a6584..476d063 100644
--- a/src/com/android/launcher2/BubbleTextView.java
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -330,16 +330,4 @@
         }
         return true;
     }
-
-    @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event) {
-        return FocusHelper.handleBubbleTextViewKeyEvent(this, keyCode, event)
-                || super.onKeyDown(keyCode, event);
-    }
-
-    @Override
-    public boolean onKeyUp(int keyCode, KeyEvent event) {
-        return FocusHelper.handleBubbleTextViewKeyEvent(this, keyCode, event)
-                || super.onKeyUp(keyCode, event);
-    }
 }
diff --git a/src/com/android/launcher2/FocusHelper.java b/src/com/android/launcher2/FocusHelper.java
index 233fd6f..3783d56 100644
--- a/src/com/android/launcher2/FocusHelper.java
+++ b/src/com/android/launcher2/FocusHelper.java
@@ -31,9 +31,19 @@
 import java.util.Comparator;
 
 /**
+ * A keyboard listener we set on all the workspace icons.
+ */
+class BubbleTextViewKeyEventListener implements View.OnKeyListener {
+    @Override
+    public boolean onKey(View v, int keyCode, KeyEvent event) {
+        return FocusHelper.handleBubbleTextViewKeyEvent((BubbleTextView) v, keyCode, event);
+    }
+}
+
+/**
  * A keyboard listener we set on all the hotseat buttons.
  */
-class HotseatKeyEventListener implements View.OnKeyListener {
+class HotseatBubbleTextViewKeyEventListener implements View.OnKeyListener {
     @Override
     public boolean onKey(View v, int keyCode, KeyEvent event) {
         final Configuration configuration = v.getResources().getConfiguration();
@@ -612,6 +622,7 @@
         final Workspace workspace = (Workspace) layout.getParent();
         final ViewGroup launcher = (ViewGroup) workspace.getParent();
         final ViewGroup tabs = (ViewGroup) launcher.findViewById(R.id.qsb_bar);
+        final ViewGroup hotseat = (ViewGroup) launcher.findViewById(R.id.hotseat);
         int iconIndex = parent.indexOfChild(v);
         int iconCount = parent.getChildCount();
         int pageIndex = workspace.indexOfChild(layout);
@@ -678,11 +689,13 @@
                 break;
             case KeyEvent.KEYCODE_DPAD_DOWN:
                 if (handleKeyEvent) {
-                    // Select the closest icon in the next line, otherwise select the tab bar
+                    // Select the closest icon in the next line, otherwise select the button bar
                     View newIcon = getClosestBubbleTextViewOnLine(layout, parent, v, 1);
                     if (newIcon != null) {
                         newIcon.requestFocus();
                         wasHandled = true;
+                    } else if (hotseat != null) {
+                        hotseat.requestFocus();
                     }
                 }
                 break;
diff --git a/src/com/android/launcher2/Hotseat.java b/src/com/android/launcher2/Hotseat.java
index deab131..491691e 100644
--- a/src/com/android/launcher2/Hotseat.java
+++ b/src/com/android/launcher2/Hotseat.java
@@ -57,6 +57,7 @@
 
     public void setup(Launcher launcher) {
         mLauncher = launcher;
+        setOnKeyListener(new HotseatBubbleTextViewKeyEventListener());
     }
 
     CellLayout getLayout() {
@@ -96,11 +97,14 @@
                 inflater.inflate(R.layout.application, mContent, false);
         allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null,
                 context.getResources().getDrawable(R.drawable.apps_hotseat_button), null, null);
-        // button.setText(context.getString(R.string.all_apps_button_label));
+        // allAppsButton.setText(context.getString(R.string.all_apps_button_label));
+        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
         allAppsButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(android.view.View v) {
-                mLauncher.showAllApps(true);
+                if (mLauncher != null) {
+                    mLauncher.showAllApps(true);
+                }
             }
         });
 
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 0abdec0..3050be4 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2874,6 +2874,13 @@
         final Workspace workspace = mWorkspace;
         for (int i=start; i<end; i++) {
             final ItemInfo item = shortcuts.get(i);
+
+            // Short circuit if we are loading dock items for a configuration which has no dock
+            if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
+                    mHotseat == null) {
+                continue;
+            }
+
             switch (item.itemType) {
                 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
                 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index b86fa41..e71e0f8 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -453,6 +453,7 @@
         final CellLayout layout;
         if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
             layout = mLauncher.getHotseat().getLayout();
+            child.setOnKeyListener(null);
 
             if (screen < 0) {
                 screen = mLauncher.getHotseat().getOrderInHotseat(x, y);
@@ -464,6 +465,7 @@
             }
         } else {
             layout = (CellLayout) getChildAt(screen);
+            child.setOnKeyListener(new BubbleTextViewKeyEventListener());
         }
 
         CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();