[2/3] omnigears: volume wake

PS3:
whitespace cleanup

PS5:
set volume wake support default to false

Change-Id: I78151f3f19a3bb9848aa49eabb0abc0ef51b6a4e
diff --git a/res/values/config.xml b/res/values/config.xml
index 33fef4f..5afa65b 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -19,4 +19,11 @@
     <!-- does the device have multi color led support or only
          a fixed set of led colors -->
     <bool name="config_has_multi_color_led" translatable="false">true</bool>
+
+    <!-- Volume Rocker Wake Support. Some devices do not support (PMU) this.
+         Setting to false will disable Volume Rocker Wake support -->
+    <bool name="config_show_volumeRockerWake">false</bool>
+
+    <!-- Volume rocker support. Some devices do not have a volume rocker. -->
+    <bool name="config_has_volume_rocker">true</bool>
 </resources>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index 0c2f4d5..952b00a 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -191,6 +191,11 @@
     <string name="auto_brightness_menu_remove">Remove</string>
     <string name="sensor_category">Sensor</string>
 
+    <!-- button settings -->
+    <string name="button_volume_keys_title">Volume</string>
+    <string name="button_volume_wake_title">Volume button wake</string>
+    <string name="button_volume_wake_summary">Pressing a volume button will wake your device</string>
+
 </resources>
 
 
diff --git a/res/xml/button_settings.xml b/res/xml/button_settings.xml
new file mode 100644
index 0000000..e4569ab
--- /dev/null
+++ b/res/xml/button_settings.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--  Copyright (C) 2013 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"
+        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+    <PreferenceCategory
+        android:key="button_volume_keys"
+        android:title="@string/button_volume_keys_title" >
+
+        <CheckBoxPreference
+            android:key="button_volume_wake_screen"
+            android:title="@string/button_volume_wake_title"
+            android:summary="@string/button_volume_wake_summary"
+            android:defaultValue="false" />
+
+    </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/src/org/omnirom/omnigears/ButtonSettings.java b/src/org/omnirom/omnigears/ButtonSettings.java
new file mode 100644
index 0000000..d17c86d
--- /dev/null
+++ b/src/org/omnirom/omnigears/ButtonSettings.java
@@ -0,0 +1,82 @@
+/*
+ *  Copyright (C) 2013 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;
+
+import android.content.ContentResolver;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
+
+public class ButtonSettings extends SettingsPreferenceFragment {
+
+    private static final String CATEGORY_VOLUME = "button_volume_keys";
+    private static final String BUTTON_VOLUME_WAKE = "button_volume_wake_screen";
+
+    private CheckBoxPreference mVolumeWake;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        addPreferencesFromResource(R.xml.button_settings);
+
+        final ContentResolver resolver = getActivity().getContentResolver();
+        final PreferenceScreen prefScreen = getPreferenceScreen();
+        final Resources res = getResources();
+
+        final PreferenceCategory volumeCategory =
+                (PreferenceCategory) prefScreen.findPreference(CATEGORY_VOLUME);
+
+        if (hasVolumeRocker()) {
+            if (!res.getBoolean(R.bool.config_show_volumeRockerWake)) {
+                prefScreen.removePreference(volumeCategory);
+            } else {
+                mVolumeWake = (CheckBoxPreference) findPreference(BUTTON_VOLUME_WAKE);
+                mVolumeWake.setChecked(Settings.System.getInt(resolver,
+                        Settings.System.VOLUME_WAKE_SCREEN, 0) != 0);
+            }
+        } else {
+            prefScreen.removePreference(volumeCategory);
+        }
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        if (preference == mVolumeWake) {
+            boolean checked = ((CheckBoxPreference)preference).isChecked();
+            Settings.System.putInt(getActivity().getContentResolver(),
+                    Settings.System.VOLUME_WAKE_SCREEN, checked ? 1:0);
+
+            return true;
+        }
+
+        return super.onPreferenceTreeClick(preferenceScreen, preference);
+    }
+
+    private boolean hasVolumeRocker() {
+        return getActivity().getResources().getBoolean(R.bool.config_has_volume_rocker);
+    }
+}