[2/3] OmniGears: power menu settings

Change-Id: I3395cc3d177cef4044bfdd72c6879cd2c7e970ed
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index f8ac1a1..a24503b 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -338,7 +338,7 @@
 
     <!-- global acions config -->
     <string name="global_actions_power_title">Power</string>
-    <string name="global_actions_reboot_title">Reboot</string>
+    <string name="global_actions_reboot_title">Restart</string>
     <string name="global_actions_lockdown_title">Lock</string>
     <string name="global_actions_settings_title">Settings</string>
     <string name="global_actions_airplane_title">Airplane mode</string>
@@ -353,8 +353,8 @@
     <string name="global_actions_summary">Actions shown in power menu</string>
     <string name="global_actions_header">Some actions are only visible depending on the setup or only if the device is unlocked</string>
     <string name="global_actions_anim">Appearance</string>
-    <string name="global_actions_advanced_reboot_summary">Show more options in reboot menu</string>
-    <string name="global_actions_advanced_reboot_title">Enable advanced reboot</string>
+    <string name="global_actions_advanced_reboot_summary">Show more options in restart menu</string>
+    <string name="global_actions_advanced_reboot_title">Enable advanced restart</string>
 
     <string name="font_sample_text">11:57</string>
 
diff --git a/res/xml/global_actions.xml b/res/xml/global_actions.xml
new file mode 100644
index 0000000..6da6518
--- /dev/null
+++ b/res/xml/global_actions.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--  Copyright (C) 2016 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:key="global_actions"
+    android:title="@string/global_actions_title">
+
+    <PreferenceCategory
+        android:key="global_actions_anim"
+        android:title="@string/global_actions_anim" >
+
+       <org.omnirom.omnigears.preference.SecureSettingSwitchPreference
+            android:key="advanced_reboot"
+            android:title="@string/global_actions_advanced_reboot_title"
+            android:summary="@string/global_actions_advanced_reboot_summary" />
+       <ListPreference
+            android:key="power_menu_animations"
+            android:title="@string/power_menu_animation_title"
+            android:dialogTitle="@string/power_menu_animation_dialog_title"
+            android:entries="@array/power_menu_animations_entries"
+            android:entryValues="@array/power_menu_animations_values"
+            android:summary="@string/power_menu_animation_summary"
+            android:persistent="false" />
+    </PreferenceCategory>
+</PreferenceScreen>
diff --git a/src/org/omnirom/omnigears/interfacesettings/GlobalActionsSettings.java b/src/org/omnirom/omnigears/interfacesettings/GlobalActionsSettings.java
new file mode 100644
index 0000000..8b9f111
--- /dev/null
+++ b/src/org/omnirom/omnigears/interfacesettings/GlobalActionsSettings.java
@@ -0,0 +1,131 @@
+/*
+ *  Copyright (C) 2016 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.interfacesettings;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.support.v7.preference.ListPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.support.v14.preference.SwitchPreference;
+import android.provider.SearchIndexableResource;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+
+import java.util.List;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+
+import org.omnirom.omnigears.preference.SecureSettingSwitchPreference;
+import org.omnirom.omnigears.OmniDashboardFragment;
+
+public class GlobalActionsSettings extends SettingsPreferenceFragment implements
+        Preference.OnPreferenceChangeListener, Indexable {
+    private static final String TAG = "GlobalActionsSettings";
+    private static final String POWER_MENU_ANIMATIONS = "power_menu_animations";
+
+    private ListPreference mPowerMenuAnimations;
+    private SecureSettingSwitchPreference mAdvancedReboot;
+
+    @Override
+    public int getMetricsCategory() {
+        return OmniDashboardFragment.ACTION_SETTINGS_OMNI;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.global_actions);
+
+        final PreferenceScreen prefScreen = getPreferenceScreen();
+        final ContentResolver contentResolver = getContext().getContentResolver();
+
+        mPowerMenuAnimations = (ListPreference) findPreference(POWER_MENU_ANIMATIONS);
+        mPowerMenuAnimations.setValue(String.valueOf(Settings.System.getInt(
+                getContentResolver(), Settings.System.POWER_MENU_ANIMATIONS, 0)));
+        mPowerMenuAnimations.setSummary(mPowerMenuAnimations.getEntry());
+        mPowerMenuAnimations.setOnPreferenceChangeListener(this);
+
+        mAdvancedReboot = (SecureSettingSwitchPreference)
+                findPreference(Settings.Secure.ADVANCED_REBOOT);
+        mAdvancedReboot.setOnPreferenceChangeListener(this);
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(Preference preference) {
+        return super.onPreferenceTreeClick(preference);
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object objValue) {
+         boolean result = false;
+         if (preference instanceof ListPreference) {
+             if (preference == mPowerMenuAnimations) {
+                Settings.System.putInt(getContentResolver(), Settings.System.POWER_MENU_ANIMATIONS,
+                        Integer.valueOf((String) objValue));
+                mPowerMenuAnimations.setValue(String.valueOf(objValue));
+                mPowerMenuAnimations.setSummary(mPowerMenuAnimations.getEntry());
+                return true;
+             }
+         } else if (preference instanceof SecureSettingSwitchPreference) {
+             if (preference == mAdvancedReboot) {
+                boolean value = (Boolean) objValue;
+                Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADVANCED_REBOOT,
+                        value ? 1:0);
+                Settings.Secure.putInt(getContentResolver(), Settings.Secure.GLOBAL_ACTION_DNAA,
+                        value ? 1:0);
+             }
+             return true;
+         }
+         return result;
+    }
+
+    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    ArrayList<SearchIndexableResource> result =
+                            new ArrayList<SearchIndexableResource>();
+
+                    SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.global_actions;
+                    result.add(sir);
+
+                    return result;
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    ArrayList<String> result = new ArrayList<String>();
+                    return result;
+                }
+            };
+}