[2/2] OmniGears: Adds ability to answer call with hardware HOME button

Change-Id: I70871fd3a6168af76e309d310237e98fea33c4b5
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index 10cc2a9..1223f69 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -60,6 +60,8 @@
     <string name="keys_action_omniswitch">OmniSwitch recents</string>
     <string name="button_home_wake_title">Button wake</string>
     <string name="button_home_wake_summary">Pressing the home button will wake the device</string>
+    <string name="button_home_answers_call_title">Button answers call</string>
+    <string name="button_home_answers_call_summary">Pressing the home button will answer incoming call</string>
 
     <!-- Swap volume buttons when the screen is rotated -->
     <string name="swap_volume_buttons_title">Match rotation</string>
diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml
index 28749c0..ac77426 100644
--- a/res/xml/button_settings.xml
+++ b/res/xml/button_settings.xml
@@ -171,6 +171,12 @@
             android:summary="@string/button_home_wake_summary"
             android:persistent="false"/>
 
+        <CheckBoxPreference
+            android:key="button_home_answers_call"
+            android:title="@string/button_home_answers_call_title"
+            android:summary="@string/button_home_answers_call_summary"
+            android:persistent="false" />
+
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/org/omnirom/omnigears/ButtonSettings.java b/src/org/omnirom/omnigears/ButtonSettings.java
index 8e36537..da2ddd9 100644
--- a/src/org/omnirom/omnigears/ButtonSettings.java
+++ b/src/org/omnirom/omnigears/ButtonSettings.java
@@ -74,6 +74,7 @@
 
     private static final String BUTTON_VOLUME_WAKE = "button_volume_wake_screen";
     private static final String BUTTON_HOME_WAKE = "button_home_wake_screen";
+    private static final String BUTTON_HOME_ANSWERS_CALL = "button_home_answers_call";
 //    private static final String BUTTON_VOLUME_DEFAULT = "button_volume_default_screen";
 //    private static final String BUTTON_VOLUME_MUSIC_CONTROL = "button_volume_music_control";
 //    private static final String VOLUME_KEY_CURSOR_CONTROL = "volume_key_cursor_control";
@@ -125,6 +126,7 @@
 
     private CheckBoxPreference mVolumeWake;
     private CheckBoxPreference mHomeWake;
+    private CheckBoxPreference mHomeAnswerCall;
 //    private CheckBoxPreference mVolumeMusicControl;
     private CheckBoxPreference mSwapVolumeButtons;
 //    private ListPreference mVolumeKeyCursorControl;
@@ -351,6 +353,14 @@
                     mHomeWake.setChecked(Settings.System.getInt(resolver,
                         Settings.System.HOME_BUTTON_WAKE, 0) != 0);
                 }
+
+                mHomeAnswerCall = (CheckBoxPreference) findPreference(BUTTON_HOME_ANSWERS_CALL);
+                if (!Utils.isVoiceCapable(getActivity())) {
+                    mKeysHomeCategory.removePreference(mHomeAnswerCall);
+                } else {
+                    mHomeAnswerCall.setChecked(Settings.System.getInt(resolver,
+                        Settings.System.HOME_BUTTON_ANSWER, 0) != 0);
+                }
             } else {
                 prefScreen.removePreference(mKeysHomeCategory);
             }
@@ -499,6 +509,11 @@
             Settings.System.putInt(getContentResolver(),
                     Settings.System.HOME_BUTTON_WAKE, checked ? 1:0);
             return true;
+        } else if (preference == mHomeAnswerCall) {
+            boolean checked = ((CheckBoxPreference)preference).isChecked();
+            Settings.System.putInt(getContentResolver(),
+                    Settings.System.HOME_BUTTON_ANSWER, checked ? 1:0);
+            return true;
         }
 
         return super.onPreferenceTreeClick(preferenceScreen, preference);