[2/2] OmniGears: allow config of long press home

Change-Id: Ia993e5ca61f96d3ae1882b1dff8764cc35e6aa76
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index 281e25c..64451ee 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -450,15 +450,17 @@
         <item>@string/long_press_recents_action_split</item>
         <item>@string/keys_action_last_app</item>
         <item>@string/keys_action_sleep</item>
+        <!--<item>@string/keys_action_all_apps</item>-->
     </string-array>
 
     <string-array name="long_press_home_action_values" translatable="false">
         <item>0</item>
-        <item>1</item>
+        <item>7</item>
         <item>2</item>
         <item>3</item>
         <item>4</item>
         <item>5</item>
         <item>6</item>
+        <!--<item>1</item>-->
     </string-array>
 </resources>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index 91e3bd5..8b8f036 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -58,6 +58,7 @@
     <string name="keys_action_normal">Normal press</string>
     <string name="keys_action_long">Long press</string>
     <string name="keys_action_double">Double tap</string>
+    <string name="keys_action_all_apps">All apps</string>
     <string name="dialog_no_home_key_title">No home action</string>
     <string name="no_home_key">You have no button assigned to the \"Home\" action! This can make your device unusable!</string>
     <string name="button_volume_keys_title">Volume</string>
diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml
index 26e53d2..bb84d65 100644
--- a/res/xml/button_settings.xml
+++ b/res/xml/button_settings.xml
@@ -29,6 +29,18 @@
     </PreferenceCategory>
 
     <PreferenceCategory
+        android:key="button_power"
+        android:title="@string/global_actions_power_title" >
+        
+        <Preference
+            android:key="global_actions"
+            android:title="@string/global_actions_title"
+            android:summary="@string/global_actions_summary"
+            android:icon="@drawable/ic_settings_power"
+            android:fragment="org.omnirom.omnigears.interfacesettings.GlobalActionsSettings" />
+    </PreferenceCategory>
+
+    <PreferenceCategory
         android:key="button_other"
         android:title="@string/button_other_title" >
 
@@ -44,11 +56,12 @@
             android:entries="@array/long_press_recents_action_entries"
             android:entryValues="@array/long_press_recents_action_values"
             android:persistent="false"/>
-        <Preference
-            android:key="global_actions"
-            android:title="@string/global_actions_title"
-            android:summary="@string/global_actions_summary"
-            android:icon="@drawable/ic_settings_power"
-            android:fragment="org.omnirom.omnigears.interfacesettings.GlobalActionsSettings" />
+        <ListPreference
+            android:key="long_press_home_action"
+            android:title="@string/long_press_home_action_title"
+            android:entries="@array/long_press_home_action_entries"
+            android:entryValues="@array/long_press_home_action_values"
+            android:persistent="false"/>
     </PreferenceCategory>
+
 </PreferenceScreen>
diff --git a/src/org/omnirom/omnigears/ButtonSettings.java b/src/org/omnirom/omnigears/ButtonSettings.java
index ad70934..c2e1b84 100644
--- a/src/org/omnirom/omnigears/ButtonSettings.java
+++ b/src/org/omnirom/omnigears/ButtonSettings.java
@@ -47,9 +47,11 @@
 
     private static final String NAVIGATION_BAR_RECENTS_STYLE = "navbar_recents_style";
     private static final String LONG_PRESS_RECENTS_ACTION = "long_press_recents_action";
+    private static final String LONG_PRESS_HOME_ACTION = "long_press_home_action";
 
     private ListPreference mNavbarRecentsStyle;
     private ListPreference mLongPressRecentsAction;
+    private ListPreference mLongPressHomeAction;
 
     @Override
     public int getMetricsCategory() {
@@ -63,6 +65,8 @@
         addPreferencesFromResource(R.xml.button_settings);
 
         final ContentResolver resolver = getContentResolver();
+        final int deviceKeys = getResources().getInteger(
+                com.android.internal.R.integer.config_deviceHardwareKeys);
 
         mNavbarRecentsStyle = (ListPreference) findPreference(NAVIGATION_BAR_RECENTS_STYLE);
         int recentsStyle = Settings.System.getInt(resolver,
@@ -79,6 +83,16 @@
         mLongPressRecentsAction.setValue(Integer.toString(longPressRecentsAction));
         mLongPressRecentsAction.setSummary(mLongPressRecentsAction.getEntry());
         mLongPressRecentsAction.setOnPreferenceChangeListener(this);
+
+        // for navbar devices default is always assist LONG_PRESS_HOME_ASSIST = 2
+        int defaultLongPressOnHomeBehavior = (deviceKeys == 0) ? 2 : getResources().getInteger(com.android.internal.R.integer.config_longPressOnHomeBehavior);
+        mLongPressHomeAction = (ListPreference) findPreference(LONG_PRESS_HOME_ACTION);
+        int longPressHomeAction = Settings.System.getInt(resolver,
+                Settings.System.BUTTON_LONG_PRESS_HOME, defaultLongPressOnHomeBehavior);
+
+        mLongPressHomeAction.setValue(Integer.toString(longPressHomeAction));
+        mLongPressHomeAction.setSummary(mLongPressHomeAction.getEntry());
+        mLongPressHomeAction.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -106,6 +120,12 @@
             mLongPressRecentsAction.setSummary(mLongPressRecentsAction.getEntries()[index]);
             Settings.System.putInt(getContentResolver(), Settings.System.BUTTON_LONG_PRESS_RECENTS, value);
             return true;
+        } else if (preference == mLongPressHomeAction) {
+            int value = Integer.valueOf((String) newValue);
+            int index = mLongPressHomeAction.findIndexOfValue((String) newValue);
+            mLongPressHomeAction.setSummary(mLongPressHomeAction.getEntries()[index]);
+            Settings.System.putInt(getContentResolver(), Settings.System.BUTTON_LONG_PRESS_HOME, value);
+            return true;
         }
         return false;
     }