[2/2] OmniGears: allow config of double tap to home

Change-Id: I5c47ac98af0224f43b6a1317980ee5756393a1c7
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index 032bf2b..7a74107 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -217,6 +217,7 @@
     <string name="long_press_recents_action_title">Long press recents action</string>
     <string name="long_press_recents_action_split">Toggle splitscreen</string>
     <string name="long_press_home_action_title">Long press home action</string>
+    <string name="double_press_home_action_title">Double tap home action</string>
     <string name="keys_action_recents">Recents</string>
     <string name="keys_action_assist">Launch assist</string>
 
diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml
index 6612baf..d9abd60 100644
--- a/res/xml/button_settings.xml
+++ b/res/xml/button_settings.xml
@@ -106,6 +106,12 @@
             android:entries="@array/long_press_home_action_entries"
             android:entryValues="@array/long_press_home_action_values"
             android:persistent="false"/>
+        <ListPreference
+            android:key="double_press_home_action"
+            android:title="@string/double_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 eca3a1e..6685c3b 100644
--- a/src/org/omnirom/omnigears/ButtonSettings.java
+++ b/src/org/omnirom/omnigears/ButtonSettings.java
@@ -58,10 +58,12 @@
     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 static final String DOUBLE_PRESS_HOME_ACTION = "double_press_home_action";
 
     private ListPreference mNavbarRecentsStyle;
     private ListPreference mLongPressRecentsAction;
     private ListPreference mLongPressHomeAction;
+    private ListPreference mDoublePressHomeAction;
     private SwitchPreference mEnableNavBar;
     private SwitchPreference mDisabkeHWKeys;
 
@@ -127,6 +129,15 @@
         mLongPressHomeAction.setValue(Integer.toString(longPressHomeAction));
         mLongPressHomeAction.setSummary(mLongPressHomeAction.getEntry());
         mLongPressHomeAction.setOnPreferenceChangeListener(this);
+
+        int defaultDoublePressOnHomeBehavior = getResources().getInteger(com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
+        mDoublePressHomeAction = (ListPreference) findPreference(DOUBLE_PRESS_HOME_ACTION);
+        int doublePressHomeAction = Settings.System.getInt(resolver,
+                Settings.System.BUTTON_DOUBLE_PRESS_HOME, defaultDoublePressOnHomeBehavior);
+
+        mDoublePressHomeAction.setValue(Integer.toString(doublePressHomeAction));
+        mDoublePressHomeAction.setSummary(mDoublePressHomeAction.getEntry());
+        mDoublePressHomeAction.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -177,6 +188,12 @@
             mLongPressHomeAction.setSummary(mLongPressHomeAction.getEntries()[index]);
             Settings.System.putInt(getContentResolver(), Settings.System.BUTTON_LONG_PRESS_HOME, value);
             return true;
+        } else if (preference == mDoublePressHomeAction) {
+            int value = Integer.valueOf((String) newValue);
+            int index = mDoublePressHomeAction.findIndexOfValue((String) newValue);
+            mDoublePressHomeAction.setSummary(mDoublePressHomeAction.getEntries()[index]);
+            Settings.System.putInt(getContentResolver(), Settings.System.BUTTON_DOUBLE_PRESS_HOME, value);
+            return true;
         }
         return false;
     }