Re-add support for the app shelf

Accidentally broken as a part of tuner customization of the nav bar.
Now supported for inflation.

Change-Id: Id097fb48d1d77aa37518246cca8c7a9494de2af2
diff --git a/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml b/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml
index dd559c5..38265f6 100644
--- a/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml
+++ b/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml
@@ -25,10 +25,9 @@
         android:layout_height="match_parent">
 
         <LinearLayout
-            android:id="@+id/start_group"
+            android:id="@+id/ends_group"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:gravity="start"
             android:orientation="horizontal" />
 
         <LinearLayout
@@ -38,13 +37,6 @@
             android:gravity="center"
             android:orientation="horizontal" />
 
-        <LinearLayout
-            android:id="@+id/end_group"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="end"
-            android:orientation="horizontal" />
-
     </FrameLayout>
 
     <FrameLayout
@@ -53,10 +45,9 @@
         android:layout_height="match_parent">
 
         <LinearLayout
-            android:id="@+id/start_group_lightsout"
+            android:id="@+id/ends_group_lightsout"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:gravity="start"
             android:orientation="horizontal" />
 
         <LinearLayout
@@ -66,13 +57,6 @@
             android:gravity="center"
             android:orientation="horizontal" />
 
-        <LinearLayout
-            android:id="@+id/end_group_lightsout"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="end"
-            android:orientation="horizontal" />
-
     </FrameLayout>
 
     <com.android.systemui.statusbar.policy.DeadZone
diff --git a/packages/SystemUI/res/layout/apps_bar.xml b/packages/SystemUI/res/layout/apps_bar.xml
new file mode 100644
index 0000000..e226805
--- /dev/null
+++ b/packages/SystemUI/res/layout/apps_bar.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2016, 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.
+-->
+
+<!-- Container for the app shelf. -->
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/app_shelf"
+    android:orientation="horizontal"
+    android:layout_height="match_parent"
+    android:layout_width="0dp"
+    android:layout_weight="1">
+    <com.android.systemui.statusbar.phone.NavigationBarApps
+        android:id="@+id/navigation_bar_apps"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent" />
+</LinearLayout>
diff --git a/packages/SystemUI/res/layout/navigation_bar_with_apps.xml b/packages/SystemUI/res/layout/navigation_bar_with_apps.xml
deleted file mode 100644
index ac95b5e..0000000
--- a/packages/SystemUI/res/layout/navigation_bar_with_apps.xml
+++ /dev/null
@@ -1,331 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-**
-** Copyright 2012, 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.
--->
-
-<!-- Navigation bar with app shortcuts. See also navigation_bar.xml. -->
-<com.android.systemui.statusbar.phone.NavigationBarView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:systemui="http://schemas.android.com/apk/res-auto"
-    android:layout_height="match_parent"
-    android:layout_width="match_parent"
-    android:background="@drawable/system_bar_background"
-    >
-
-    <!-- Portrait layout. -->
-    <FrameLayout android:id="@+id/rot0"
-        android:layout_height="match_parent"
-        android:layout_width="match_parent"
-        >
-
-        <LinearLayout
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            android:orientation="horizontal"
-            android:clipChildren="false"
-            android:clipToPadding="false"
-            android:id="@+id/nav_buttons"
-            android:animateLayoutChanges="true"
-            >
-
-            <!-- Back button is flush left. -->
-            <com.android.systemui.statusbar.policy.KeyButtonView
-                android:id="@+id/back"
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_back"
-                android:scaleType="centerInside"
-                systemui:keyCode="4"
-                android:layout_weight="0"
-                android:contentDescription="@string/accessibility_back"
-                />
-
-            <com.android.systemui.statusbar.policy.KeyButtonView
-                android:id="@+id/home"
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_home"
-                android:scaleType="centerInside"
-                systemui:keyCode="3"
-                systemui:keyRepeat="true"
-                android:layout_weight="0"
-                android:contentDescription="@string/accessibility_home"
-                />
-
-            <!-- Container for the app shelf. -->
-            <LinearLayout
-                android:id="@+id/app_shelf"
-                android:orientation="horizontal"
-                android:layout_height="match_parent"
-                android:layout_width="0dp"
-                android:layout_weight="1"
-                >
-                <com.android.systemui.statusbar.phone.NavigationBarApps
-                    android:id="@+id/navigation_bar_apps"
-                    android:layout_width="wrap_content"
-                    android:layout_height="match_parent"
-                    />
-            </LinearLayout>
-
-            <FrameLayout
-                android:layout_width="@dimen/navigation_extra_key_width"
-                android:layout_height="match_parent"
-                android:layout_weight="0"
-                android:layout_marginEnd="2dp" >
-                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/menu"
-                    android:layout_width="@dimen/navigation_extra_key_width"
-                    android:layout_height="match_parent"
-                    android:src="@drawable/ic_sysbar_menu"
-                    android:scaleType="centerInside"
-                    android:layout_marginEnd="2dp"
-                    systemui:keyCode="82"
-                    android:visibility="invisible"
-                    android:contentDescription="@string/accessibility_menu"
-                    />
-                <com.android.systemui.statusbar.policy.KeyButtonView
-                    android:id="@+id/ime_switcher"
-                    android:layout_width="@dimen/navigation_extra_key_width"
-                    android:layout_height="match_parent"
-                    android:layout_marginEnd="2dp"
-                    android:scaleType="centerInside"
-                    android:src="@drawable/ic_ime_switcher_default"
-                    android:visibility="invisible"
-                    android:contentDescription="@string/accessibility_ime_switch_button" />
-            </FrameLayout>
-
-            <!-- Recents always at the far right. -->
-            <com.android.systemui.statusbar.policy.KeyButtonView
-                android:id="@+id/recent_apps"
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_recent"
-                android:scaleType="centerInside"
-                android:layout_weight="0"
-                android:contentDescription="@string/accessibility_recent"
-                />
-        </LinearLayout>
-
-        <!-- lights out layout to match exactly -->
-        <LinearLayout
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            android:orientation="horizontal"
-            android:id="@+id/lights_out"
-            android:visibility="gone"
-            >
-            <ImageView
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_lights_out_dot_small"
-                android:scaleType="center"
-                android:layout_weight="0"
-                />
-            <ImageView
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_lights_out_dot_large"
-                android:scaleType="center"
-                android:layout_weight="0"
-                />
-            <Space
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:layout_weight="1"
-                />
-            <ImageView
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_lights_out_dot_small"
-                android:scaleType="center"
-                android:layout_weight="0"
-                />
-        </LinearLayout>
-
-        <com.android.systemui.statusbar.policy.DeadZone
-            android:id="@+id/deadzone"
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            systemui:minSize="@dimen/navigation_bar_deadzone_size"
-            systemui:maxSize="@dimen/navigation_bar_deadzone_size_max"
-            systemui:holdTime="@integer/navigation_bar_deadzone_hold"
-            systemui:decayTime="@integer/navigation_bar_deadzone_decay"
-            systemui:orientation="horizontal"
-            android:layout_gravity="top"
-            />
-    </FrameLayout>
-
-    <!-- Landscape layout. -->
-    <FrameLayout android:id="@+id/rot90"
-        android:layout_height="match_parent"
-        android:layout_width="match_parent"
-        android:visibility="gone"
-        android:paddingTop="0dp"
-        >
-
-        <LinearLayout
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            android:orientation="horizontal"
-            android:clipChildren="false"
-            android:clipToPadding="false"
-            android:id="@+id/nav_buttons"
-            android:animateLayoutChanges="true"
-            >
-
-            <!-- Back button is flush left. -->
-            <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_back"
-                android:scaleType="centerInside"
-                systemui:keyCode="4"
-                android:layout_weight="0"
-                android:contentDescription="@string/accessibility_back"
-                />
-            <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
-                android:layout_width="64dp" android:paddingStart="4dp" android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_home"
-                android:scaleType="centerInside"
-                systemui:keyCode="3"
-                systemui:keyRepeat="true"
-                android:layout_weight="0"
-                android:contentDescription="@string/accessibility_home"
-                />
-
-            <!-- Container for the app shelf. -->
-            <LinearLayout
-                android:id="@+id/app_shelf"
-                android:orientation="horizontal"
-                android:layout_height="match_parent"
-                android:layout_width="0dp"
-                android:layout_weight="1"
-                >
-                <com.android.systemui.statusbar.phone.NavigationBarApps
-                    android:id="@+id/navigation_bar_apps"
-                    android:layout_width="wrap_content"
-                    android:layout_height="match_parent"
-                    />
-            </LinearLayout>
-
-            <FrameLayout
-                android:layout_width="@dimen/navigation_extra_key_width"
-                android:layout_height="match_parent"
-                android:layout_marginEnd="2dp"
-                android:layout_weight="0"
-                android:visibility="gone" >
-                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/menu"
-                    android:layout_width="@dimen/navigation_extra_key_width"
-                    android:layout_height="match_parent"
-                    android:layout_marginEnd="2dp"
-                    android:src="@drawable/ic_sysbar_menu"
-                    android:scaleType="centerInside"
-                    systemui:keyCode="82"
-                    android:visibility="invisible"
-                    android:contentDescription="@string/accessibility_menu" />
-                <com.android.systemui.statusbar.policy.KeyButtonView
-                    android:id="@+id/ime_switcher"
-                    android:layout_width="@dimen/navigation_extra_key_width"
-                    android:layout_height="match_parent"
-                    android:layout_marginEnd="2dp"
-                    android:src="@drawable/ic_ime_switcher_default"
-                    android:visibility="invisible"
-                    android:contentDescription="@string/accessibility_ime_switch_button"
-                    android:scaleType="centerInside" />
-            </FrameLayout>
-
-            <!-- Recents always at the far right. -->
-            <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_recent"
-                android:scaleType="centerInside"
-                android:layout_weight="0"
-                android:contentDescription="@string/accessibility_recent"
-                />
-        </LinearLayout>
-
-        <!-- lights out layout to match exactly -->
-        <LinearLayout
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            android:orientation="horizontal"
-            android:id="@+id/lights_out"
-            android:visibility="gone"
-            >
-            <ImageView
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_lights_out_dot_small"
-                android:scaleType="center"
-                android:layout_weight="0"
-                />
-            <ImageView
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_lights_out_dot_large"
-                android:scaleType="center"
-                android:layout_weight="0"
-                />
-            <Space
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:layout_weight="1"
-                />
-            <ImageView
-                android:layout_width="64dp"
-                android:paddingStart="4dp"
-                android:paddingEnd="4dp"
-                android:layout_height="match_parent"
-                android:src="@drawable/ic_sysbar_lights_out_dot_small"
-                android:scaleType="center"
-                android:layout_weight="0"
-                />
-        </LinearLayout>
-
-        <com.android.systemui.statusbar.policy.DeadZone
-            android:id="@+id/deadzone"
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            systemui:minSize="@dimen/navigation_bar_deadzone_size"
-            systemui:maxSize="@dimen/navigation_bar_deadzone_size_max"
-            systemui:holdTime="@integer/navigation_bar_deadzone_hold"
-            systemui:decayTime="@integer/navigation_bar_deadzone_decay"
-            systemui:orientation="horizontal"
-            android:layout_gravity="top"
-            />
-    </FrameLayout>
-</com.android.systemui.statusbar.phone.NavigationBarView>
diff --git a/packages/SystemUI/res/layout/navigation_layout.xml b/packages/SystemUI/res/layout/navigation_layout.xml
index 7ebf4ed..f9a3653 100644
--- a/packages/SystemUI/res/layout/navigation_layout.xml
+++ b/packages/SystemUI/res/layout/navigation_layout.xml
@@ -26,10 +26,9 @@
         android:layout_height="match_parent">
 
         <LinearLayout
-            android:id="@+id/start_group"
+            android:id="@+id/ends_group"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:gravity="start"
             android:orientation="horizontal" />
 
         <LinearLayout
@@ -39,13 +38,6 @@
             android:gravity="center"
             android:orientation="horizontal" />
 
-        <LinearLayout
-            android:id="@+id/end_group"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="end"
-            android:orientation="horizontal" />
-
     </FrameLayout>
 
     <FrameLayout
@@ -54,10 +46,9 @@
         android:layout_height="match_parent">
 
         <LinearLayout
-            android:id="@+id/start_group_lightsout"
+            android:id="@+id/ends_group_lightsout"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:gravity="start"
             android:orientation="horizontal" />
 
         <LinearLayout
@@ -67,13 +58,6 @@
             android:gravity="center"
             android:orientation="horizontal" />
 
-        <LinearLayout
-            android:id="@+id/end_group_lightsout"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="end"
-            android:orientation="horizontal" />
-
     </FrameLayout>
 
     <com.android.systemui.statusbar.policy.DeadZone
diff --git a/packages/SystemUI/res/layout/navigation_layout_rot90.xml b/packages/SystemUI/res/layout/navigation_layout_rot90.xml
index 46df973..df32911 100644
--- a/packages/SystemUI/res/layout/navigation_layout_rot90.xml
+++ b/packages/SystemUI/res/layout/navigation_layout_rot90.xml
@@ -26,10 +26,9 @@
         android:layout_height="match_parent">
 
         <com.android.systemui.statusbar.phone.ReverseLinearLayout
-            android:id="@+id/start_group"
+            android:id="@+id/ends_group"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:gravity="bottom"
             android:orientation="vertical" />
 
         <com.android.systemui.statusbar.phone.ReverseLinearLayout
@@ -39,13 +38,6 @@
             android:gravity="center"
             android:orientation="vertical" />
 
-        <com.android.systemui.statusbar.phone.ReverseLinearLayout
-            android:id="@+id/end_group"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="top"
-            android:orientation="vertical" />
-
     </FrameLayout>
 
     <FrameLayout
@@ -54,10 +46,9 @@
         android:layout_height="match_parent">
 
         <com.android.systemui.statusbar.phone.ReverseLinearLayout
-            android:id="@+id/start_group_lightsout"
+            android:id="@+id/ends_group_lightsout"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:gravity="bottom"
             android:orientation="vertical" />
 
         <com.android.systemui.statusbar.phone.ReverseLinearLayout
@@ -67,13 +58,6 @@
             android:gravity="center"
             android:orientation="vertical" />
 
-        <com.android.systemui.statusbar.phone.ReverseLinearLayout
-            android:id="@+id/end_group_lightsout"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:gravity="top"
-            android:orientation="vertical" />
-
     </FrameLayout>
 
     <com.android.systemui.statusbar.policy.DeadZone
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
index b8ae81f..beeee0b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
@@ -24,6 +24,7 @@
 import android.view.ViewGroup;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.Space;
 import com.android.systemui.R;
 import com.android.systemui.tuner.TunerService;
@@ -42,6 +43,8 @@
     private static final String RECENT = "recent";
     private static final String NAVSPACE = "space";
 
+    private static final String APP_SHELF = "app_shelf";
+
     public static final String GRAVITY_SEPARATOR = ";";
     public static final String BUTTON_SEPARATOR = ",";
 
@@ -108,12 +111,10 @@
     }
 
     private void initiallyFill(ButtonDispatcher buttonDispatcher) {
-        addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.start_group));
+        addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.ends_group));
         addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.center_group));
-        addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.end_group));
-        addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.start_group));
+        addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.ends_group));
         addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.center_group));
-        addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.end_group));
     }
 
     private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) {
@@ -135,18 +136,41 @@
         String[] start = sets[0].split(BUTTON_SEPARATOR);
         String[] center = sets[1].split(BUTTON_SEPARATOR);
         String[] end = sets[2].split(BUTTON_SEPARATOR);
-        inflateButtons(start, (ViewGroup) mRot0.findViewById(R.id.start_group),
-                (ViewGroup) mRot0.findViewById(R.id.start_group_lightsout), false);
-        inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.start_group),
-                (ViewGroup) mRot90.findViewById(R.id.start_group_lightsout), true);
-        inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group),
-                (ViewGroup) mRot0.findViewById(R.id.start_group_lightsout), false);
-        inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group),
-                (ViewGroup) mRot90.findViewById(R.id.start_group_lightsout), true);
-        inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.end_group),
-                (ViewGroup) mRot0.findViewById(R.id.start_group_lightsout), false);
-        inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.end_group),
-                (ViewGroup) mRot90.findViewById(R.id.start_group_lightsout), true);
+        inflateButtons(start, (ViewGroup) mRot0.findViewById(R.id.ends_group),
+                (ViewGroup) mRot0.findViewById(R.id.ends_group_lightsout), false);
+        inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.ends_group),
+                (ViewGroup) mRot90.findViewById(R.id.ends_group_lightsout), true);
+
+        if (center.length == 1 && APP_SHELF.equals(center[0])) {
+            inflateShelf((LinearLayout) mRot0.findViewById(R.id.ends_group),
+                    (LinearLayout) mRot0.findViewById(R.id.ends_group_lightsout), false);
+            inflateShelf((LinearLayout) mRot90.findViewById(R.id.ends_group),
+                    (LinearLayout) mRot90.findViewById(R.id.ends_group_lightsout), true);
+        } else {
+            inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group),
+                    (ViewGroup) mRot0.findViewById(R.id.center_group_lightsout), false);
+            inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group),
+                    (ViewGroup) mRot90.findViewById(R.id.center_group_lightsout), true);
+            addGravitySpacer((LinearLayout) mRot0.findViewById(R.id.ends_group));
+            addGravitySpacer((LinearLayout) mRot90.findViewById(R.id.ends_group));
+        }
+
+        inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.ends_group),
+                (ViewGroup) mRot0.findViewById(R.id.ends_group_lightsout), false);
+        inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.ends_group),
+                (ViewGroup) mRot90.findViewById(R.id.ends_group_lightsout), true);
+    }
+
+    private void inflateShelf(LinearLayout layout, LinearLayout lightsOut, boolean landscape) {
+        View v = (landscape ? mLandscapeInflater : mLayoutInflater)
+                .inflate(R.layout.apps_bar, layout, false);
+        layout.addView(v);
+        addToDispatchers(v);
+        copyToLightsout(v, lightsOut);
+    }
+
+    private void addGravitySpacer(LinearLayout layout) {
+        layout.addView(new Space(mContext), new LinearLayout.LayoutParams(0, 0, 1));
     }
 
     private void inflateButtons(String[] buttons, ViewGroup parent, ViewGroup lightsOutParent,
@@ -187,6 +211,10 @@
     }
 
     private ViewGroup.LayoutParams copy(ViewGroup.LayoutParams layoutParams) {
+        if (layoutParams instanceof LinearLayout.LayoutParams) {
+            return new LinearLayout.LayoutParams(layoutParams.width, layoutParams.height,
+                    ((LinearLayout.LayoutParams) layoutParams).weight);
+        }
         return new LayoutParams(layoutParams.width, layoutParams.height);
     }
 
@@ -220,13 +248,17 @@
             throw new IllegalArgumentException("Unknown button " + button);
         }
         parent.addView(v);
+        addToDispatchers(v);
+        return v;
+    }
+
+    private void addToDispatchers(View v) {
         if (mButtonDispatchers != null) {
             final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId());
             if (indexOfKey >= 0) {
                 mButtonDispatchers.valueAt(indexOfKey).addView(v);
             }
         }
-        return v;
     }
 
     private boolean isSw600Dp() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index ffc836c7..3a41832 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -962,14 +962,8 @@
     }
 
     protected void inflateNavigationBarView(Context context) {
-        // Optionally show app shortcuts in the nav bar "shelf" area.
-        if (shouldShowAppShelf()) {
-            mNavigationBarView = (NavigationBarView) View.inflate(
-                    context, R.layout.navigation_bar_with_apps, null);
-        } else {
-            mNavigationBarView = (NavigationBarView) View.inflate(
-                    context, R.layout.navigation_bar, null);
-        }
+        mNavigationBarView = (NavigationBarView) View.inflate(
+                context, R.layout.navigation_bar, null);
     }
 
     protected void initSignalCluster(View containerView) {
@@ -982,21 +976,6 @@
         }
     }
 
-    /** Returns true if the app shelf should be shown in the nav bar. */
-    private boolean shouldShowAppShelf() {
-        // Allow adb to override the default shelf behavior:
-        // adb shell settings put system demo_app_shelf 0  # Zero forces it off.
-        // adb shell settings put system demo_app_shelf 1  # Non-zero forces it on.
-        final int DEFAULT = -1;
-        final int shelfOverride =
-                Settings.System.getInt(mContext.getContentResolver(), "demo_app_shelf", DEFAULT);
-        if (shelfOverride != DEFAULT) {
-            return shelfOverride != 0;
-        }
-        // Otherwise default to the platform feature.
-        return FREEFORM_WINDOW_MANAGEMENT;
-    }
-
     private void clearAllNotifications() {
 
         // animate-swipe all dismissable notifications, then animate the shade closed