Merge "OmniGears: FR translation" into android-4.4
diff --git a/res/values-cs/custom_strings.xml b/res/values-cs/custom_strings.xml
index b36e560..6df15db 100644
--- a/res/values-cs/custom_strings.xml
+++ b/res/values-cs/custom_strings.xml
@@ -117,7 +117,7 @@
     <string name="screen_auto_brighness_summary">Úrovně jasu obrazovky automatického režimu</string>
     <string name="button_auto_brightness">Automatické úrovně</string>
     <string name="button_auto_brighness_summary">Úrovně jasu tlačítka automatického režimu</string>
-    <string name="button_brightness_category">Tlačítka</string>
+    <string name="button_brightness_title">Tlačítka</string>
     <string name="button_no_brightness">Tmavý režim</string>
     <string name="button_no_brightness_summary">Nenastavovat jas tlačítka</string>
     <string name="button_link_brightness">Odkaz na obrazovce</string>
diff --git a/res/values-de/custom_strings.xml b/res/values-de/custom_strings.xml
index 4d0832c..d4b7840 100644
--- a/res/values-de/custom_strings.xml
+++ b/res/values-de/custom_strings.xml
@@ -118,7 +118,7 @@
     <string name="screen_auto_brighness_summary">Helligkeitsstufen für Automodus</string>
     <string name="button_auto_brightness">Automatische Stufen</string>
     <string name="button_auto_brighness_summary">Tastenhelligkeit im Automodus</string>
-    <string name="button_brightness_category">Tasten</string>
+    <string name="button_brightness_title">Tasten</string>
     <string name="button_no_brightness">Dunkler Modus</string>
     <string name="button_no_brightness_summary">Tastenhelligkeit nicht einstellen</string>
     <string name="button_link_brightness">Mit Bildschirm verknüpfen</string>
diff --git a/res/values-es/custom_strings.xml b/res/values-es/custom_strings.xml
index 19dccdd..a287c65 100644
--- a/res/values-es/custom_strings.xml
+++ b/res/values-es/custom_strings.xml
@@ -112,7 +112,7 @@
     <string name="screen_auto_brighness_summary">Niveles de brillo de la pantalla para el modo automático</string>
     <string name="button_auto_brightness">Niveles automáticos</string>
     <string name="button_auto_brighness_summary">Niveles de brillo del botón en modo automático</string>
-    <string name="button_brightness_category">Botones</string>
+    <string name="button_brightness_title">Botones</string>
     <string name="button_no_brightness">Modo oscuro</string>
     <string name="button_no_brightness_summary">No ajustar el brillo botón</string>
     <string name="button_link_brightness">Enlace a la pantalla</string>
diff --git a/res/values-fr/custom_strings.xml b/res/values-fr/custom_strings.xml
index 3df4554..2f2623b 100644
--- a/res/values-fr/custom_strings.xml
+++ b/res/values-fr/custom_strings.xml
@@ -97,7 +97,7 @@
     <string name="screen_auto_brighness_summary">Niveaux de luminosité de l\'écran pour le mode automatique</string>
     <string name="button_auto_brightness">Niveaux automatique</string>
     <string name="button_auto_brighness_summary">Niveaux de luminosité des boutons pour le mode automatique</string>
-    <string name="button_brightness_category">Boutons</string>
+    <string name="button_brightness_title">Boutons</string>
     <string name="button_no_brightness">Mode sombre</string>
     <string name="button_no_brightness_summary">Ne pas définir la luminosité du bouton</string>
     <string name="button_link_brightness">Lier à l\'écran</string>
diff --git a/res/values-it/custom_strings.xml b/res/values-it/custom_strings.xml
index b181958..e0160d8 100644
--- a/res/values-it/custom_strings.xml
+++ b/res/values-it/custom_strings.xml
@@ -116,7 +116,7 @@
     <string name="screen_auto_brighness_summary">I livelli di luminosità dello schermo sono in modalità automatica</string>
     <string name="button_auto_brightness">Livelli automatici</string>
     <string name="button_auto_brighness_summary">I livelli dei pusalti sono in modalità automatica</string>
-    <string name="button_brightness_category">Pulsanti</string>
+    <string name="button_brightness_title">Pulsanti</string>
     <string name="button_no_brightness">Modalità buia</string>
     <string name="button_no_brightness_summary">Non impostare la luminosità pulsanti</string>
     <string name="button_link_brightness">Passa a schermo</string>
diff --git a/res/values-nl/custom_strings.xml b/res/values-nl/custom_strings.xml
index b3504cc..9b25f1d 100644
--- a/res/values-nl/custom_strings.xml
+++ b/res/values-nl/custom_strings.xml
@@ -117,7 +117,7 @@
     <string name="screen_auto_brighness_summary">Schermhelderheid automatisch bepalen</string>
     <string name="button_auto_brightness">Automatische waardes</string>
     <string name="button_auto_brighness_summary">Knoppenhelderheid automatisch bepalen</string>
-    <string name="button_brightness_category">Knoppen</string>
+    <string name="button_brightness_title">Knoppen</string>
     <string name="button_no_brightness">Donkere modus</string>
     <string name="button_no_brightness_summary">Geen knoppenhelderheid</string>
     <string name="button_link_brightness">Link naar scherm</string>
diff --git a/res/values-pl/custom_strings.xml b/res/values-pl/custom_strings.xml
index ccd2a0a..a15ab8c 100644
--- a/res/values-pl/custom_strings.xml
+++ b/res/values-pl/custom_strings.xml
@@ -115,7 +115,7 @@
     <string name="screen_auto_brighness_summary">Poziomy jasności ekranu dla trybu automatycznego</string>
     <string name="button_auto_brightness">Automatyczne poziomy</string>
     <string name="button_auto_brighness_summary">Poziomy jasności przycisku dla trybu automatycznego</string>
-    <string name="button_brightness_category">Przyciski</string>
+    <string name="button_brightness_title">Przyciski</string>
     <string name="button_no_brightness">Tryb ciemny</string>
     <string name="button_no_brightness_summary">Nie ustawiaj jasnośći przycisków</string>
     <string name="button_link_brightness">Powiąż z ekranem</string>
diff --git a/res/values-pt/custom_strings.xml b/res/values-pt/custom_strings.xml
index ea87a3c..82adb39 100644
--- a/res/values-pt/custom_strings.xml
+++ b/res/values-pt/custom_strings.xml
@@ -112,7 +112,7 @@
     <string name="screen_auto_brighness_summary">Níveis de brilho da tela para modo automático</string>
     <string name="button_auto_brightness">Níveis automáticos</string>
     <string name="button_auto_brighness_summary">Níveis ade brilho do botão para modo automático</string>
-    <string name="button_brightness_category">Botões</string>
+    <string name="button_brightness_title">Botões</string>
     <string name="button_no_brightness">Modo escuro</string>
     <string name="button_no_brightness_summary">"Não definir brilho do botão"</string>
     <string name="button_link_brightness">Link com a tela</string>
diff --git a/res/values-ru/custom_strings.xml b/res/values-ru/custom_strings.xml
index e81e3ef..6e106d6 100644
--- a/res/values-ru/custom_strings.xml
+++ b/res/values-ru/custom_strings.xml
@@ -118,7 +118,7 @@
     <string name="screen_auto_brighness_summary">Яркость экрана в автоматическом режиме</string>
     <string name="button_auto_brightness">Автоматическая яркость подсветки</string>
     <string name="button_auto_brighness_summary">Яркость подсветки кнопок в автоматическом режиме</string>
-    <string name="button_brightness_category">Кнопки</string>
+    <string name="button_brightness_title">Кнопки</string>
     <string name="button_no_brightness">Отключить подсветку</string>
     <string name="button_no_brightness_summary">Подсветка кнопок отключена</string>
     <string name="button_link_brightness">Ссылаться на яркость экрана</string>
diff --git a/res/values-sv/custom_strings.xml b/res/values-sv/custom_strings.xml
index 9df21f4..340bee6 100644
--- a/res/values-sv/custom_strings.xml
+++ b/res/values-sv/custom_strings.xml
@@ -96,7 +96,7 @@
     <string name="screen_auto_brighness_summary">Skärmljusnivåer för automatiskt läge</string>
     <string name="button_auto_brightness">Automatiska nivåer</string>
     <string name="button_auto_brighness_summary">Knappljusnivåer för automatiskt läge</string>
-    <string name="button_brightness_category">Knappar</string>
+    <string name="button_brightness_title">Knappar</string>
     <string name="button_no_brightness">Mörkt läge</string>
     <string name="button_no_brightness_summary">Ställ inte in knappljusstyrka</string>
     <string name="button_link_brightness">Sammanlänka med skärm</string>
diff --git a/res/values-zh-rCN/custom_strings.xml b/res/values-zh-rCN/custom_strings.xml
index f3f411b..7289bf5 100644
--- a/res/values-zh-rCN/custom_strings.xml
+++ b/res/values-zh-rCN/custom_strings.xml
@@ -117,7 +117,7 @@
     <string name="screen_auto_brighness_summary">自动模式下的屏幕亮度等级</string>
     <string name="button_auto_brightness">自动等级</string>
     <string name="button_auto_brighness_summary">自动模式下的按钮亮度等级</string>
-    <string name="button_brightness_category">按钮</string>
+    <string name="button_brightness_title">按钮</string>
     <string name="button_no_brightness">全黑模式</string>
     <string name="button_no_brightness_summary">不要设置按钮亮度</string>
     <string name="button_link_brightness">与屏幕同步</string>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index dabc9d1..33cbf5e 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -118,7 +118,6 @@
     <string name="screen_auto_brighness_summary">Screen brightness levels for automatic mode</string>
     <string name="button_auto_brightness">Automatic levels</string>
     <string name="button_auto_brighness_summary">Button brightness levels for automatic mode</string>
-    <string name="button_brightness_category">Buttons</string>
     <string name="button_no_brightness">Dark mode</string>
     <string name="button_no_brightness_summary">Don\'t set button brightness</string>
     <string name="button_link_brightness">Link to screen</string>
@@ -149,6 +148,8 @@
     <string name="sensor_category">Sensor</string>
     <string name="button_timeout_title">Timeout</string>
     <string name="button_timeout_summary">Disabled on value 0</string>
+    <string name="button_brightness_title">Button brightness</string>
+    <string name="button_brightness_summary">Button brightness settings</string>
 
     <!-- button settings -->
     <string name="button_volume_keys_title">Volume</string>
@@ -218,6 +219,10 @@
     <string name="no_home_key">You have no button assigned to the \"Home\" action! This can make your device unusable!</string>
     <string name="virtual_key_haptic_feedback_title">Vibrate on touch</string>
     <string name="virtual_key_haptic_feedback_summary">Enable depends on \"Vibrate on touch\" in sound settings</string>
+    <string name="navigation_bar_show_title">Show navigation bar</string>
+    <string name="navigation_bar_show_summary">Force enable navigation bar</string>
+    <string name="hardware_keys_disable_title">Disable keys</string>
+    <string name="hardware_keys_disable_summary">Force disable keys</string>
 
     <!-- Power Menu Options-->
     <string name="bars_and_menus_category_power_menu_title">Power menu</string>
@@ -342,6 +347,7 @@
 
     <!-- Navigation Bar customization-->
     <string name="navigation_bar_title">Buttons and layout</string>
+    <string name="navigation_bar_summary">Configure navigation bar buttons</string>
     <string name="navigation_bar_help_text">1 - To begin editing, tap the lock icon\n\n2 - Tap any button to assign or change functionality\n\n3 - Long press any button to rearrange the order\n\n4 - To save, tap the lock icon again\n\n5 - To restore system default, tap the reset button\n\n</string>
     <string name="navigation_bar_tips">\u2022 Actions can only be assigned to one button at a time\n\n\u2022 The home button cannot be re-assigned\n\n\u2022 Side buttons cannot be rearranged</string>
     <string name="navigation_bar_tips_title">Quick tips</string>
@@ -353,6 +359,7 @@
 
     <!-- Navigation ring shortcuts -->
     <string name="navigation_ring_title">Quick launch shortcuts</string>
+    <string name="navigation_ring_summary">Configure custom navigation bar shortcuts</string>
     <string name="navring_target_reset_message">Delete all user created navigation bar shortcuts and restore to default?</string>
     <string name="navring_target_reset">Navigation bar shortcuts reset to default</string>
     <string name="navring_action_open_ime_switcher">Open IME Switcher</string>
@@ -526,6 +533,7 @@
 
     <!-- Navigation bar height/width -->
     <string name="navbar_dimen_title">Dimensions</string>
+    <string name="navbar_dimen_summary">Configure width and height of navigation bar</string>
     <string name="navbar_dimensions_reset_message">Reset all dimensions entries to default?</string>
     <string name="navigation_bar_height_title">Navigation bar height</string>
     <string name="navigation_bar_height_summary">Navigation bar height while in portrait.</string>
diff --git a/res/xml/bars_settings.xml b/res/xml/bars_settings.xml
index 7c873e2..2dba831 100644
--- a/res/xml/bars_settings.xml
+++ b/res/xml/bars_settings.xml
@@ -114,16 +114,19 @@
         <PreferenceScreen
             android:key="navigation_bar"
             android:fragment="org.omnirom.omnigears.interfacesettings.NavBar"
+            android:summary="@string/navigation_bar_summary"
             android:title="@string/navigation_bar_title" />
 
         <PreferenceScreen
             android:key="navigation_bar_dimen"
             android:fragment="org.omnirom.omnigears.interfacesettings.NavBarDimen"
+            android:summary="@string/navbar_dimen_summary"
             android:title="@string/navbar_dimen_title" />
 
         <PreferenceScreen
             android:key="navigation_ring"
             android:fragment="org.omnirom.omnigears.interfacesettings.NavRing"
+            android:summary="@string/navigation_ring_summary"
             android:title="@string/navigation_ring_title" />
 
         <CheckBoxPreference
diff --git a/res/xml/brightness_settings.xml b/res/xml/brightness_settings.xml
index 6c8d0a7..6a02d70 100644
--- a/res/xml/brightness_settings.xml
+++ b/res/xml/brightness_settings.xml
@@ -17,7 +17,6 @@
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
         android:title="@string/brightness"
-        android:key="backlight_settings"
         xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
 
         <PreferenceCategory
@@ -28,46 +27,13 @@
                         android:title="@string/brightness"
                         android:persistent="false"/>
 
-                <Preference
+                <PreferenceScreen
                         android:key="screen_auto_brightness"
                         android:title="@string/screen_auto_brightness"
                         android:summary="@string/screen_auto_brighness_summary"/>
         </PreferenceCategory>
 
         <PreferenceCategory
-                android:key="button_brightness_category"
-                android:title="@string/button_brightness_category">
-
-                <Preference
-                        android:key="button_auto_brightness"
-                        android:title="@string/button_auto_brightness"
-                        android:summary="@string/button_auto_brighness_summary"/>
-                <Preference
-                        android:key="button_manual_brightness"
-                        android:title="@string/button_manual_brightness"
-                        android:summary="@string/button_manual_brightness_summary"/>
-                <CheckBoxPreference
-                        android:key="button_no_brightness"
-                        android:title="@string/button_no_brightness"
-                        android:summary="@string/button_no_brightness_summary"
-                        android:persistent="false"/>
-                <CheckBoxPreference
-                        android:key="button_link_brightness"
-                        android:title="@string/button_link_brightness"
-                        android:summary="@string/button_link_brightness_summary"
-                        android:persistent="false"/>
-                <org.omnirom.omnigears.chameleonos.SeekBarPreference
-                        android:key="button_timeout"
-                        android:title="@string/button_timeout_title"
-                        android:summary="@string/button_timeout_summary"
-                        android:max="30"
-                        settings:min="0"
-                        settings:unitsLeft=""
-                        settings:unitsRight="@string/unit_sec"
-                        android:persistent="false" />
-        </PreferenceCategory>
-
-        <PreferenceCategory
                 android:key="sensor_category"
                 android:title="@string/sensor_category">
 
diff --git a/res/xml/button_brightness_settings.xml b/res/xml/button_brightness_settings.xml
new file mode 100644
index 0000000..60d0095
--- /dev/null
+++ b/res/xml/button_brightness_settings.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--  Copyright (C) 2014 The OmniROM Project
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        android:title="@string/button_brightness_title"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+        <Preference
+                android:key="button_auto_brightness"
+                android:title="@string/button_auto_brightness"
+                android:summary="@string/button_auto_brighness_summary"/>
+        <Preference
+                android:key="button_manual_brightness"
+                android:title="@string/button_manual_brightness"
+                android:summary="@string/button_manual_brightness_summary"/>
+        <CheckBoxPreference
+                android:key="button_no_brightness"
+                android:title="@string/button_no_brightness"
+                android:summary="@string/button_no_brightness_summary"
+                android:persistent="false"/>
+        <CheckBoxPreference
+                android:key="button_link_brightness"
+                android:title="@string/button_link_brightness"
+                android:summary="@string/button_link_brightness_summary"
+                android:persistent="false"/>
+        <org.omnirom.omnigears.chameleonos.SeekBarPreference
+                android:key="button_timeout"
+                android:title="@string/button_timeout_title"
+                android:summary="@string/button_timeout_summary"
+                android:max="30"
+                settings:min="0"
+                settings:unitsLeft=""
+                settings:unitsRight="@string/unit_sec"
+                android:persistent="false" />
+</PreferenceScreen>
diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml
index 8e3b781..c3396e2 100644
--- a/res/xml/button_settings.xml
+++ b/res/xml/button_settings.xml
@@ -69,6 +69,17 @@
         android:key="button_keys"
         android:title="@string/button_keys_title" >
 
+        <org.omnirom.omnigears.preference.SystemCheckBoxPreference
+            android:key="navigation_bar_show"
+            android:title="@string/navigation_bar_show_title"
+            android:summary="@string/navigation_bar_show_summary" />
+
+        <CheckBoxPreference
+            android:key="hardware_keys_disable"
+            android:title="@string/hardware_keys_disable_title"
+            android:summary="@string/hardware_keys_disable_summary"
+            android:persistent="false"/>
+
         <CheckBoxPreference
             android:key="virtual_key_haptic_feedback"
             android:title="@string/virtual_key_haptic_feedback_title"
@@ -81,6 +92,12 @@
             android:summary="@string/force_show_overflow_menu_summary"
             android:persistent="false"/>
 
+        <PreferenceScreen
+            android:key="button_brightness"
+            android:title="@string/brightness"
+            android:summary="@string/button_brightness_summary"
+            android:fragment="org.omnirom.omnigears.brightness.ButtonBrightnessSettings" />
+
         <SwitchPreference
             android:key="keys_enable_custom"
             android:title="@string/keys_enable_custom_title"
diff --git a/src/org/omnirom/omnigears/ButtonSettings.java b/src/org/omnirom/omnigears/ButtonSettings.java
index 3fd001a..34b1b4b 100644
--- a/src/org/omnirom/omnigears/ButtonSettings.java
+++ b/src/org/omnirom/omnigears/ButtonSettings.java
@@ -93,6 +93,9 @@
     private static final String KEYS_APP_SWITCH_LONG_PRESS = "keys_app_switch_long_press";
     private static final String VIRTUAL_KEY_HAPTIC_FEEDBACK = "virtual_key_haptic_feedback";
     private static final String FORCE_SHOW_OVERFLOW_MENU = "force_show_overflow_menu";
+    private static final String KEYS_BRIGHTNESS_KEY = "button_brightness";
+    private static final String KEYS_SHOW_NAVBAR_KEY = "navigation_bar_show";
+    private static final String KEYS_DISABLE_HW_KEY = "hardware_keys_disable";
 
     // Available custom actions to perform on a key press.
     private static final int ACTION_NOTHING = 0;
@@ -135,6 +138,13 @@
     private CheckBoxPreference mHeadsetHookLaunchVoice;
     private CheckBoxPreference mVirtualKeyHapticFeedback;
     private CheckBoxPreference mForceShowOverflowMenu;
+    private boolean mButtonBrightnessSupport;
+    private CheckBoxPreference mEnableNavBar;
+    private CheckBoxPreference mDisabkeHWKeys;
+    private PreferenceScreen mButtonBrightness;
+    private PreferenceCategory mKeysBackCategory;
+    private PreferenceCategory mKeysHomeCategory;
+    private PreferenceCategory mKeysMenuCategory;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -149,6 +159,8 @@
         final PreferenceCategory volumeCategory =
                 (PreferenceCategory) prefScreen.findPreference(CATEGORY_VOLUME);
 
+        mButtonBrightnessSupport = getResources().getBoolean(com.android.internal.R.bool.config_button_brightness_support);
+
         if (hasVolumeRocker()) {
             mVolumeWake = (CheckBoxPreference) findPreference(BUTTON_VOLUME_WAKE);
             mVolumeDefault = (ListPreference) findPreference(BUTTON_VOLUME_DEFAULT);
@@ -194,11 +206,11 @@
 
         final PreferenceCategory keysCategory =
                 (PreferenceCategory) prefScreen.findPreference(CATEGORY_KEYS);
-        final PreferenceCategory keysBackCategory =
+        mKeysBackCategory =
                 (PreferenceCategory) prefScreen.findPreference(CATEGORY_BACK);
-        final PreferenceCategory keysHomeCategory =
+        mKeysHomeCategory =
                 (PreferenceCategory) prefScreen.findPreference(CATEGORY_HOME);
-        final PreferenceCategory keysMenuCategory =
+        mKeysMenuCategory =
                 (PreferenceCategory) prefScreen.findPreference(CATEGORY_MENU);
         final PreferenceCategory keysAssistCategory =
                 (PreferenceCategory) prefScreen.findPreference(CATEGORY_ASSIST);
@@ -207,9 +219,9 @@
 
         if (!res.getBoolean(R.bool.config_has_hardware_buttons)) {
             prefScreen.removePreference(keysCategory);
-            prefScreen.removePreference(keysBackCategory);
-            prefScreen.removePreference(keysHomeCategory);
-            prefScreen.removePreference(keysMenuCategory);
+            prefScreen.removePreference(mKeysBackCategory);
+            prefScreen.removePreference(mKeysHomeCategory);
+            prefScreen.removePreference(mKeysMenuCategory);
             prefScreen.removePreference(keysAssistCategory);
             prefScreen.removePreference(keysAppSwitchCategory);
         } else {
@@ -241,6 +253,12 @@
                     VIRTUAL_KEY_HAPTIC_FEEDBACK);
             mForceShowOverflowMenu = (CheckBoxPreference) prefScreen.findPreference(
                     FORCE_SHOW_OVERFLOW_MENU);
+            mEnableNavBar = (CheckBoxPreference) prefScreen.findPreference(
+                    KEYS_SHOW_NAVBAR_KEY);
+            mDisabkeHWKeys = (CheckBoxPreference) prefScreen.findPreference(
+                    KEYS_DISABLE_HW_KEY);
+            mButtonBrightness = (PreferenceScreen) prefScreen.findPreference(
+                    KEYS_BRIGHTNESS_KEY);
 
             if (hasBackKey) {
                 int backPressAction = Settings.System.getInt(resolver,
@@ -261,7 +279,7 @@
                 
                 mKeySettings.put(Settings.System.KEY_BACK_LONG_PRESS_ACTION, backLongPressAction);
             } else {
-                prefScreen.removePreference(keysBackCategory);
+                prefScreen.removePreference(mKeysBackCategory);
             }
 
             if (hasHomeKey) {
@@ -313,7 +331,7 @@
 
                 mKeySettings.put(Settings.System.KEY_HOME_DOUBLE_TAP_ACTION, homeDoubleTapAction);
             } else {
-                prefScreen.removePreference(keysHomeCategory);
+                prefScreen.removePreference(mKeysHomeCategory);
             }
 
             if (hasMenuKey) {
@@ -339,7 +357,7 @@
 
                 mKeySettings.put(Settings.System.KEY_MENU_LONG_PRESS_ACTION, menuLongPressAction);
             } else {
-                prefScreen.removePreference(keysMenuCategory);
+                prefScreen.removePreference(mKeysMenuCategory);
             }
 
             if (hasAssistKey) {
@@ -395,9 +413,18 @@
             }
 
             boolean hasNavBar = getResources().getBoolean(
-                com.android.internal.R.bool.config_showNavigationBar);
+                    com.android.internal.R.bool.config_showNavigationBar);
             mForceShowOverflowMenu.setChecked(Settings.System.getInt(resolver,
-                        Settings.System.FORCE_SHOW_OVERFLOW_MENU, (!hasNavBar && hasMenuKey) ? 0 : 1) == 1);
+                    Settings.System.FORCE_SHOW_OVERFLOW_MENU, (!hasNavBar && hasMenuKey) ? 0 : 1) == 1);
+
+            boolean harwareKeysDisable = Settings.System.getInt(resolver,
+                        Settings.System.HARDWARE_KEYS_DISABLE, 0) == 1;
+            mDisabkeHWKeys.setChecked(harwareKeysDisable);
+
+            if (!mButtonBrightnessSupport){
+                keysCategory.removePreference(mButtonBrightness);
+            }
+            updateDisableHWKeyEnablement(harwareKeysDisable);
         }
 
         final PreferenceCategory headsethookCategory =
@@ -437,6 +464,12 @@
             Settings.System.putInt(getContentResolver(),
                     Settings.System.FORCE_SHOW_OVERFLOW_MENU, checked ? 1:0);
             return true;
+        } else if (preference == mDisabkeHWKeys){
+            boolean checked = ((CheckBoxPreference)preference).isChecked();
+            Settings.System.putInt(getContentResolver(),
+                    Settings.System.HARDWARE_KEYS_DISABLE, checked ? 1:0);
+            updateDisableHWKeyEnablement(checked);
+            return true;
         }
 
         return super.onPreferenceTreeClick(preferenceScreen, preference);
@@ -621,4 +654,16 @@
         list.setEntries(entries.toArray(new CharSequence[entries.size()]));
         list.setEntryValues(values.toArray(new CharSequence[values.size()]));
     }
+
+    private void updateDisableHWKeyEnablement(boolean harwareKeysDisable) {
+        boolean enableHWKeyRebinding = Settings.System.getInt(getContentResolver(),
+                    Settings.System.HARDWARE_KEY_REBINDING, 0) == 1;
+
+        mVirtualKeyHapticFeedback.setEnabled(!harwareKeysDisable);
+        mForceShowOverflowMenu.setEnabled(!harwareKeysDisable);
+        mButtonBrightness.setEnabled(!harwareKeysDisable);
+        mKeysHomeCategory.setEnabled(!harwareKeysDisable && enableHWKeyRebinding);
+        mKeysBackCategory.setEnabled(!harwareKeysDisable && enableHWKeyRebinding);
+        mKeysMenuCategory.setEnabled(!harwareKeysDisable && enableHWKeyRebinding);
+    }
 }
diff --git a/src/org/omnirom/omnigears/brightness/AutoBrightnessDialog.java b/src/org/omnirom/omnigears/brightness/AutoBrightnessDialog.java
index 801609f..672767a 100644
--- a/src/org/omnirom/omnigears/brightness/AutoBrightnessDialog.java
+++ b/src/org/omnirom/omnigears/brightness/AutoBrightnessDialog.java
@@ -266,12 +266,19 @@
 
         if (lux == null || values == null) {
             final Resources res = getContext().getResources();
-            lux = res.getIntArray(com.android.internal.R.array.config_autoBrightnessLevels);
-            if (mScreenMode){
-                values = res.getIntArray(com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
-            } else {
-                values = res.getIntArray(com.android.internal.R.array.config_autoBrightnessButtonBacklightValues);
+            if (lux == null){
+                lux = res.getIntArray(com.android.internal.R.array.config_autoBrightnessLevels);
             }
+            if (values == null){
+                if (mScreenMode){
+                    values = res.getIntArray(com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
+                } else {
+                    values = res.getIntArray(com.android.internal.R.array.config_autoBrightnessButtonBacklightValues);
+                }
+            }
+        }
+
+        if (lux == null && values == null) {
             mIsDefault = true;
         } else {
             mIsDefault = false;
diff --git a/src/org/omnirom/omnigears/brightness/BrightnessSettings.java b/src/org/omnirom/omnigears/brightness/BrightnessSettings.java
index 1283f27..58f9c89 100644
--- a/src/org/omnirom/omnigears/brightness/BrightnessSettings.java
+++ b/src/org/omnirom/omnigears/brightness/BrightnessSettings.java
@@ -40,39 +40,22 @@
 import android.app.AlertDialog;
 import android.text.TextWatcher;
 import android.text.Editable;
-import android.widget.Button;
 import android.widget.EditText;
 import android.widget.SeekBar;
 import android.widget.TextView;
 
 import org.omnirom.omnigears.R;
-import org.omnirom.omnigears.chameleonos.SeekBarPreference;
 
 public class BrightnessSettings extends SettingsPreferenceFragment implements
         Preference.OnPreferenceChangeListener {
     private static final String TAG = "BrightnessSettings";
 
     private static final String KEY_AUTOMATIC_SENSITIVITY = "auto_brightness_sensitivity";
-    private static final String KEY_BUTTON_BRIGHTNESS_CATEGORY = "button_brightness_category";
-    private static final String KEY_BUTTON_NO_BRIGHTNESS = "button_no_brightness";
-    private static final String KEY_BUTTON_LINK_BRIGHTNESS = "button_link_brightness";
     private static final String KEY_SCREEN_AUTO_BRIGHTNESS = "screen_auto_brightness";
-    private static final String KEY_BUTTON_AUTO_BRIGHTNESS = "button_auto_brightness";
-    private static final String KEY_BUTTON_MANUAL_BRIGHTNESS = "button_manual_brightness";
-    private static final String KEY_BUTTON_TIMEOUT = "button_timeout";
 
     private ListPreference mAutomaticSensitivity;
-    private CheckBoxPreference mNoButtonBrightness;
-    private CheckBoxPreference mLinkButtonBrightness;
     private Preference mAutomaticScreenBrightness;
-    private Preference mAutomaticButtonBrightness;
-    private Preference mManualButtonBrightness;
     private AutoBrightnessDialog mScreenBrightnessDialog;
-    private AutoBrightnessDialog mButtonBrightnessDialog;
-    private ManualButtonBrightnessDialog mManualBrightnessDialog;
-    private boolean mButtonBrightnessSupport;
-    private IPowerManager mPowerService;
-    private SeekBarPreference mButtonTimoutBar;
 
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -81,8 +64,6 @@
         PreferenceScreen prefSet = getPreferenceScreen();
         ContentResolver resolver = getActivity().getContentResolver();
 
-        mButtonBrightnessSupport = getResources().getBoolean(com.android.internal.R.bool.config_button_brightness_support);
-
         mAutomaticSensitivity = (ListPreference) findPreference(KEY_AUTOMATIC_SENSITIVITY);
         float currentSensitivity = Settings.System.getFloat(resolver,
             Settings.System.AUTO_BRIGHTNESS_RESPONSIVENESS, 1.0f);
@@ -93,52 +74,6 @@
         mAutomaticSensitivity.setOnPreferenceChangeListener(this);
 
         mAutomaticScreenBrightness = (Preference) findPreference(KEY_SCREEN_AUTO_BRIGHTNESS);
-
-        if (!mButtonBrightnessSupport){
-            removePreference(KEY_BUTTON_BRIGHTNESS_CATEGORY);
-        } else {
-            mNoButtonBrightness = (CheckBoxPreference) findPreference(KEY_BUTTON_NO_BRIGHTNESS);
-            mNoButtonBrightness.setChecked(Settings.System.getInt(resolver,
-                    Settings.System.CUSTOM_BUTTON_DISABLE_BRIGHTNESS, 0) != 0);
-
-            mLinkButtonBrightness = (CheckBoxPreference) findPreference(KEY_BUTTON_LINK_BRIGHTNESS);
-            mLinkButtonBrightness.setChecked(Settings.System.getInt(resolver,
-                    Settings.System.CUSTOM_BUTTON_USE_SCREEN_BRIGHTNESS, 0) != 0);
-
-            mAutomaticButtonBrightness = (Preference) findPreference(KEY_BUTTON_AUTO_BRIGHTNESS);
-            mManualButtonBrightness = (Preference) findPreference(KEY_BUTTON_MANUAL_BRIGHTNESS);
-
-            mButtonTimoutBar = (SeekBarPreference) findPreference(KEY_BUTTON_TIMEOUT);
-            int currentTimeout = Settings.System.getInt(resolver,
-                            Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 0);
-            mButtonTimoutBar.setValue(currentTimeout);
-            mButtonTimoutBar.setOnPreferenceChangeListener(this);
-
-            mPowerService = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
-
-            updateEnablement();
-        }
-    }
-
-    private void updateEnablement() {
-        if (mButtonBrightnessSupport){
-            if (mNoButtonBrightness.isChecked()){
-                mLinkButtonBrightness.setEnabled(false);
-                mButtonTimoutBar.setEnabled(false);
-                mAutomaticButtonBrightness.setEnabled(false);
-                mManualButtonBrightness.setEnabled(false);
-            } else if (mLinkButtonBrightness.isChecked()){
-                mNoButtonBrightness.setEnabled(false);
-                mAutomaticButtonBrightness.setEnabled(false);
-                mManualButtonBrightness.setEnabled(false);
-            } else {
-                mNoButtonBrightness.setEnabled(true);
-                mLinkButtonBrightness.setEnabled(true);
-                mButtonTimoutBar.setEnabled(true);
-                mAutomaticButtonBrightness.setEnabled(true);
-                mManualButtonBrightness.setEnabled(true);
-            }
-        }
     }
 
     @Override
@@ -153,36 +88,15 @@
         if (mScreenBrightnessDialog != null) {
             mScreenBrightnessDialog.dismiss();
         }
-        if (mButtonBrightnessDialog != null) {
-            mButtonBrightnessDialog.dismiss();
-        }
-        if (mManualBrightnessDialog != null) {
-            mManualBrightnessDialog.dismiss();
-        }
     }
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
         if (preference == mAutomaticScreenBrightness) {
             showScreenAutoBrightnessDialog();
-        } else if (preference == mAutomaticButtonBrightness) {
-            showButtonAutoBrightnessDialog();
-        } else if (preference == mManualButtonBrightness) {
-            showButtonManualBrightnessDialog();
-        } else if (preference == mNoButtonBrightness) {
-            boolean checked = ((CheckBoxPreference)preference).isChecked();
-            Settings.System.putInt(getActivity().getContentResolver(),
-                    Settings.System.CUSTOM_BUTTON_DISABLE_BRIGHTNESS, checked ? 1:0);
-            updateEnablement();
-        } else if (preference == mLinkButtonBrightness) {
-            boolean checked = ((CheckBoxPreference)preference).isChecked();
-            Settings.System.putInt(getActivity().getContentResolver(),
-                    Settings.System.CUSTOM_BUTTON_USE_SCREEN_BRIGHTNESS, checked ? 1:0);
-            updateEnablement();
-        } else {
-            return false;
+            return true;
         }
-        return true;
+        return super.onPreferenceTreeClick(preferenceScreen, preference);
     }
 
     @Override
@@ -197,10 +111,6 @@
                         Settings.System.AUTO_BRIGHTNESS_RESPONSIVENESS, sensitivity);
 
             updateAutomaticSensityDescription(value);
-        } else if (preference == mButtonTimoutBar) {
-            int buttonTimeout = (Integer) objValue;
-            Settings.System.putInt(getContentResolver(),
-                    Settings.System.BUTTON_BACKLIGHT_TIMEOUT, buttonTimeout);
         } else {
             return false;
         }
@@ -228,155 +138,4 @@
         mScreenBrightnessDialog = new AutoBrightnessDialog(getActivity(), true);
         mScreenBrightnessDialog.show();
     }
-
-    private void showButtonAutoBrightnessDialog() {
-        if (mButtonBrightnessDialog != null && mButtonBrightnessDialog.isShowing()) {
-            return;
-        }
-
-        mButtonBrightnessDialog = new AutoBrightnessDialog(getActivity(), false);
-        mButtonBrightnessDialog.show();
-    }
-
-    private void showButtonManualBrightnessDialog() {
-        if (mManualBrightnessDialog != null && mManualBrightnessDialog.isShowing()) {
-            return;
-        }
-
-        mManualBrightnessDialog = new ManualButtonBrightnessDialog(getActivity());
-        mManualBrightnessDialog.show();
-    }
-
-    private class ManualButtonBrightnessDialog extends AlertDialog implements DialogInterface.OnClickListener {
-
-        private SeekBar mBacklightBar;
-        private EditText mBacklightInput;
-        private int mCurrentBrightness;
-        private boolean mIsDragging = false;
-
-        public ManualButtonBrightnessDialog(Context context) {
-            super(context);
-        }
-
-        @Override
-        protected void onCreate(Bundle savedInstanceState) {
-            final View v = getLayoutInflater().inflate(R.layout.dialog_manual_brightness, null);
-            final Context context = getContext();
-
-            mBacklightBar = (SeekBar) v.findViewById(R.id.backlight);
-            mBacklightInput = (EditText) v.findViewById(R.id.backlight_input);
-
-            setTitle(R.string.dialog_manual_brightness_title);
-            setCancelable(true);
-            setView(v);
-
-            try {
-                mCurrentBrightness = mPowerService.getCurrentButtonBrightnessValue();
-            } catch(Exception e){
-            }
-
-            mBacklightBar.setMax(brightnessToProgress(PowerManager.BRIGHTNESS_ON));
-            initListeners();
-            init();
-
-            setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.ok), this);
-            setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.cancel), this);
-
-            super.onCreate(savedInstanceState);
-        }
-
-        private int brightnessToProgress(int brightness) {
-            return brightness * 100;
-        }
-
-        private int progressToBrightness(int progress) {
-            int brightness = progress / 100;
-            return brightness;
-        }
-
-        @Override
-        public void onClick(DialogInterface dialog, int which) {
-            if (which == DialogInterface.BUTTON_POSITIVE) {
-                try {
-                    int newBacklight = Integer.valueOf(mBacklightInput.getText().toString());
-                    Settings.System.putInt(getContext().getContentResolver(),
-                            Settings.System.CUSTOM_BUTTON_BRIGHTNESS, newBacklight);
-                } catch (NumberFormatException e) {
-                    Log.d(TAG, "NumberFormatException " + e);
-                }
-            }
-        }
-
-        private void init() {
-            int currentValue = Settings.System.getInt(getContext().getContentResolver(),
-                            Settings.System.CUSTOM_BUTTON_BRIGHTNESS, 100);
-
-            mBacklightBar.setProgress(brightnessToProgress(currentValue));
-            mBacklightInput.setText(String.valueOf(currentValue));
-        }
-
-        private void initListeners() {
-            mBacklightBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
-                @Override
-                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-                    if (mIsDragging) {
-                        int brightness = progressToBrightness(seekBar.getProgress());
-                        mBacklightInput.setText(String.valueOf(brightness));
-                        try {
-                            mPowerService.setButtonBrightness(brightness);
-                        } catch(Exception e){
-                        }
-                    }
-                }
-                @Override
-                public void onStartTrackingTouch(SeekBar seekBar) {
-                    int brightness = progressToBrightness(seekBar.getProgress());
-                    try {
-                        mPowerService.setButtonBrightness(brightness);
-                    } catch(Exception e){
-                    }
-                    mIsDragging = true;
-                }
-                @Override
-                public void onStopTrackingTouch(SeekBar seekBar) {
-                    try {
-                        mPowerService.setButtonBrightness(mCurrentBrightness);
-                    } catch(Exception e){
-                    }
-                    mIsDragging = false;
-                }
-            });
-
-            mBacklightInput.addTextChangedListener(new TextWatcher() {
-                @Override
-                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-                }
-                @Override
-                public void onTextChanged(CharSequence s, int start, int before, int count) {
-                }
-                @Override
-                public void afterTextChanged(Editable s) {
-                    boolean ok = false;
-                    try {
-                        int minValue = 0;
-                        int maxValue = PowerManager.BRIGHTNESS_ON;
-                        int newBrightness = Integer.valueOf(s.toString());
-
-                        if (newBrightness >= minValue && newBrightness <= maxValue) {
-                            ok = true;
-                            mBacklightBar.setProgress(brightnessToProgress(newBrightness));
-                        }
-                    } catch (NumberFormatException e) {
-                        //ignored, ok is false ayway
-                    }
-
-                    Button okButton = mManualBrightnessDialog.getButton(DialogInterface.BUTTON_POSITIVE);
-                    if (okButton != null) {
-                        okButton.setEnabled(ok);
-                    }
-                }
-            });
-        }
-    }
 }
-
diff --git a/src/org/omnirom/omnigears/brightness/ButtonBrightnessSettings.java b/src/org/omnirom/omnigears/brightness/ButtonBrightnessSettings.java
new file mode 100644
index 0000000..1948fc9
--- /dev/null
+++ b/src/org/omnirom/omnigears/brightness/ButtonBrightnessSettings.java
@@ -0,0 +1,323 @@
+/*
+ *  Copyright (C) 2014 The OmniROM Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package org.omnirom.omnigears.brightness;
+
+import com.android.settings.SettingsPreferenceFragment;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.PowerManager;
+import android.os.IPowerManager;
+import android.os.ServiceManager;
+import android.preference.Preference;
+import android.preference.PreferenceGroup;
+import android.preference.PreferenceScreen;
+import android.preference.ListPreference;
+import android.preference.CheckBoxPreference;
+import android.preference.PreferenceCategory;
+import android.provider.Settings;
+import android.view.View;
+import android.util.Log;
+import android.app.AlertDialog;
+import android.text.TextWatcher;
+import android.text.Editable;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import org.omnirom.omnigears.R;
+import org.omnirom.omnigears.chameleonos.SeekBarPreference;
+
+public class ButtonBrightnessSettings extends SettingsPreferenceFragment implements
+        Preference.OnPreferenceChangeListener {
+    private static final String TAG = "ButtonBrightnessSettings";
+
+    private static final String KEY_BUTTON_NO_BRIGHTNESS = "button_no_brightness";
+    private static final String KEY_BUTTON_LINK_BRIGHTNESS = "button_link_brightness";
+    private static final String KEY_BUTTON_AUTO_BRIGHTNESS = "button_auto_brightness";
+    private static final String KEY_BUTTON_MANUAL_BRIGHTNESS = "button_manual_brightness";
+    private static final String KEY_BUTTON_TIMEOUT = "button_timeout";
+
+    private CheckBoxPreference mNoButtonBrightness;
+    private CheckBoxPreference mLinkButtonBrightness;
+    private Preference mAutomaticButtonBrightness;
+    private Preference mManualButtonBrightness;
+    private AutoBrightnessDialog mButtonBrightnessDialog;
+    private ManualButtonBrightnessDialog mManualBrightnessDialog;
+    private IPowerManager mPowerService;
+    private SeekBarPreference mButtonTimoutBar;
+
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.button_brightness_settings);
+
+        PreferenceScreen prefSet = getPreferenceScreen();
+        ContentResolver resolver = getActivity().getContentResolver();
+
+        mNoButtonBrightness = (CheckBoxPreference) findPreference(KEY_BUTTON_NO_BRIGHTNESS);
+        mNoButtonBrightness.setChecked(Settings.System.getInt(resolver,
+                Settings.System.CUSTOM_BUTTON_DISABLE_BRIGHTNESS, 0) != 0);
+
+        mLinkButtonBrightness = (CheckBoxPreference) findPreference(KEY_BUTTON_LINK_BRIGHTNESS);
+        mLinkButtonBrightness.setChecked(Settings.System.getInt(resolver,
+                Settings.System.CUSTOM_BUTTON_USE_SCREEN_BRIGHTNESS, 0) != 0);
+
+        mAutomaticButtonBrightness = (Preference) findPreference(KEY_BUTTON_AUTO_BRIGHTNESS);
+        mManualButtonBrightness = (Preference) findPreference(KEY_BUTTON_MANUAL_BRIGHTNESS);
+
+        mButtonTimoutBar = (SeekBarPreference) findPreference(KEY_BUTTON_TIMEOUT);
+        int currentTimeout = Settings.System.getInt(resolver,
+                        Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 0);
+        mButtonTimoutBar.setValue(currentTimeout);
+        mButtonTimoutBar.setOnPreferenceChangeListener(this);
+
+        mPowerService = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
+
+        updateEnablement();
+    }
+
+    private void updateEnablement() {
+        if (mNoButtonBrightness.isChecked()){
+            mLinkButtonBrightness.setEnabled(false);
+            mButtonTimoutBar.setEnabled(false);
+            mAutomaticButtonBrightness.setEnabled(false);
+            mManualButtonBrightness.setEnabled(false);
+        } else if (mLinkButtonBrightness.isChecked()){
+            mNoButtonBrightness.setEnabled(false);
+            mAutomaticButtonBrightness.setEnabled(false);
+            mManualButtonBrightness.setEnabled(false);
+        } else {
+            mNoButtonBrightness.setEnabled(true);
+            mLinkButtonBrightness.setEnabled(true);
+            mButtonTimoutBar.setEnabled(true);
+            mAutomaticButtonBrightness.setEnabled(true);
+            mManualButtonBrightness.setEnabled(true);
+        }
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+
+        if (mButtonBrightnessDialog != null) {
+            mButtonBrightnessDialog.dismiss();
+        }
+        if (mManualBrightnessDialog != null) {
+            mManualBrightnessDialog.dismiss();
+        }
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        if (preference == mAutomaticButtonBrightness) {
+            showButtonAutoBrightnessDialog();
+            return true;
+        } else if (preference == mManualButtonBrightness) {
+            showButtonManualBrightnessDialog();
+            return true;
+        } else if (preference == mNoButtonBrightness) {
+            boolean checked = ((CheckBoxPreference)preference).isChecked();
+            Settings.System.putInt(getActivity().getContentResolver(),
+                    Settings.System.CUSTOM_BUTTON_DISABLE_BRIGHTNESS, checked ? 1:0);
+            updateEnablement();
+            return true;
+        } else if (preference == mLinkButtonBrightness) {
+            boolean checked = ((CheckBoxPreference)preference).isChecked();
+            Settings.System.putInt(getActivity().getContentResolver(),
+                    Settings.System.CUSTOM_BUTTON_USE_SCREEN_BRIGHTNESS, checked ? 1:0);
+            updateEnablement();
+            return true;
+        }
+        return super.onPreferenceTreeClick(preferenceScreen, preference);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object objValue) {
+        final String key = preference.getKey();
+
+        if (preference == mButtonTimoutBar) {
+            int buttonTimeout = (Integer) objValue;
+            Settings.System.putInt(getContentResolver(),
+                    Settings.System.BUTTON_BACKLIGHT_TIMEOUT, buttonTimeout);
+        } else {
+            return false;
+        }
+        return true;
+    }
+
+    private void showButtonAutoBrightnessDialog() {
+        if (mButtonBrightnessDialog != null && mButtonBrightnessDialog.isShowing()) {
+            return;
+        }
+
+        mButtonBrightnessDialog = new AutoBrightnessDialog(getActivity(), false);
+        mButtonBrightnessDialog.show();
+    }
+
+    private void showButtonManualBrightnessDialog() {
+        if (mManualBrightnessDialog != null && mManualBrightnessDialog.isShowing()) {
+            return;
+        }
+
+        mManualBrightnessDialog = new ManualButtonBrightnessDialog(getActivity());
+        mManualBrightnessDialog.show();
+    }
+
+    private class ManualButtonBrightnessDialog extends AlertDialog implements DialogInterface.OnClickListener {
+
+        private SeekBar mBacklightBar;
+        private EditText mBacklightInput;
+        private int mCurrentBrightness;
+        private boolean mIsDragging = false;
+
+        public ManualButtonBrightnessDialog(Context context) {
+            super(context);
+        }
+
+        @Override
+        protected void onCreate(Bundle savedInstanceState) {
+            final View v = getLayoutInflater().inflate(R.layout.dialog_manual_brightness, null);
+            final Context context = getContext();
+
+            mBacklightBar = (SeekBar) v.findViewById(R.id.backlight);
+            mBacklightInput = (EditText) v.findViewById(R.id.backlight_input);
+
+            setTitle(R.string.dialog_manual_brightness_title);
+            setCancelable(true);
+            setView(v);
+
+            try {
+                mCurrentBrightness = mPowerService.getCurrentButtonBrightnessValue();
+            } catch(Exception e){
+            }
+
+            mBacklightBar.setMax(brightnessToProgress(PowerManager.BRIGHTNESS_ON));
+            initListeners();
+            init();
+
+            setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.ok), this);
+            setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.cancel), this);
+
+            super.onCreate(savedInstanceState);
+        }
+
+        private int brightnessToProgress(int brightness) {
+            return brightness * 100;
+        }
+
+        private int progressToBrightness(int progress) {
+            int brightness = progress / 100;
+            return brightness;
+        }
+
+        @Override
+        public void onClick(DialogInterface dialog, int which) {
+            if (which == DialogInterface.BUTTON_POSITIVE) {
+                try {
+                    int newBacklight = Integer.valueOf(mBacklightInput.getText().toString());
+                    Settings.System.putInt(getContext().getContentResolver(),
+                            Settings.System.CUSTOM_BUTTON_BRIGHTNESS, newBacklight);
+                } catch (NumberFormatException e) {
+                    Log.d(TAG, "NumberFormatException " + e);
+                }
+            }
+        }
+
+        private void init() {
+            int currentValue = Settings.System.getInt(getContext().getContentResolver(),
+                            Settings.System.CUSTOM_BUTTON_BRIGHTNESS, 100);
+
+            mBacklightBar.setProgress(brightnessToProgress(currentValue));
+            mBacklightInput.setText(String.valueOf(currentValue));
+        }
+
+        private void initListeners() {
+            mBacklightBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+                @Override
+                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                    if (mIsDragging) {
+                        int brightness = progressToBrightness(seekBar.getProgress());
+                        mBacklightInput.setText(String.valueOf(brightness));
+                        try {
+                            mPowerService.setButtonBrightness(brightness);
+                        } catch(Exception e){
+                        }
+                    }
+                }
+                @Override
+                public void onStartTrackingTouch(SeekBar seekBar) {
+                    int brightness = progressToBrightness(seekBar.getProgress());
+                    try {
+                        mPowerService.setButtonBrightness(brightness);
+                    } catch(Exception e){
+                    }
+                    mIsDragging = true;
+                }
+                @Override
+                public void onStopTrackingTouch(SeekBar seekBar) {
+                    try {
+                        mPowerService.setButtonBrightness(mCurrentBrightness);
+                    } catch(Exception e){
+                    }
+                    mIsDragging = false;
+                }
+            });
+
+            mBacklightInput.addTextChangedListener(new TextWatcher() {
+                @Override
+                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+                }
+                @Override
+                public void onTextChanged(CharSequence s, int start, int before, int count) {
+                }
+                @Override
+                public void afterTextChanged(Editable s) {
+                    boolean ok = false;
+                    try {
+                        int minValue = 0;
+                        int maxValue = PowerManager.BRIGHTNESS_ON;
+                        int newBrightness = Integer.valueOf(s.toString());
+
+                        if (newBrightness >= minValue && newBrightness <= maxValue) {
+                            ok = true;
+                            mBacklightBar.setProgress(brightnessToProgress(newBrightness));
+                        }
+                    } catch (NumberFormatException e) {
+                        //ignored, ok is false ayway
+                    }
+
+                    Button okButton = mManualBrightnessDialog.getButton(DialogInterface.BUTTON_POSITIVE);
+                    if (okButton != null) {
+                        okButton.setEnabled(ok);
+                    }
+                }
+            });
+        }
+    }
+}
+
diff --git a/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java b/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
index 81a8f6d..c1ffc63 100644
--- a/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
+++ b/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
@@ -38,6 +38,7 @@
 import android.provider.Settings.SettingNotFoundException;
 
 import com.android.internal.util.omni.DeviceUtils;
+import com.android.settings.Utils;
 
 public class BarsSettings extends SettingsPreferenceFragment implements
         Preference.OnPreferenceChangeListener {
@@ -107,7 +108,7 @@
         mQuickPulldown = (ListPreference) findPreference(QUICK_PULLDOWN);
         mSmartPulldown = (ListPreference) findPreference(SMART_PULLDOWN);
 
-        if (DeviceUtils.isPhone(getActivity())) {
+        if (Utils.isPhone(getActivity())) {
             int quickPulldown = Settings.System.getInt(resolver,
                     Settings.System.QS_QUICK_PULLDOWN, 0);
             mQuickPulldown.setValue(String.valueOf(quickPulldown));
@@ -168,10 +169,7 @@
             prefSet.removePreference(findPreference(NETWORK_TRAFFIC_PERIOD));
         }
 
-        boolean hasNavBar = getResources().getBoolean(
-                com.android.internal.R.bool.config_showNavigationBar);
-        // Also check, if users without navigation bar force enabled it.
-        hasNavBar = hasNavBar || (SystemProperties.getInt("qemu.hw.mainkeys", 1) == 0);
+        boolean hasNavBar = DeviceUtils.deviceSupportNavigationBar(getActivity());
 
         // Hide navigation bar category on devices without navigation bar
         if (!hasNavBar) {