samsung:  doze: Integrate with Settings

Bring this up to speed on the Settings changes in N:
 * Use support libs for preferences
 * Hook up to Settings drawer through SettingsDrawerActivity

Change-Id: I9365b3ebd1bbfed2936302e30da50e3f9af06665
diff --git a/doze/Android.mk b/doze/Android.mk
index 015d801..07b7cac 100644
--- a/doze/Android.mk
+++ b/doze/Android.mk
@@ -10,10 +10,31 @@
 LOCAL_PRIVILEGED_MODULE := true
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-v14-preference \
+    android-support-v7-appcompat \
+    android-support-v7-preference \
+    android-support-v7-recyclerview \
     org.cyanogenmod.platform.internal
 
 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
 
+LOCAL_RESOURCE_DIR := \
+    $(LOCAL_PATH)/res \
+    frameworks/support/v14/preference/res \
+    frameworks/support/v7/appcompat/res \
+    frameworks/support/v7/preference/res \
+    frameworks/support/v7/recyclerview/res
+
+LOCAL_AAPT_FLAGS := --auto-add-overlay \
+    --extra-packages android.support.v14.preference:android.support.v7.appcompat:android.support.v7.preference:android.support.v7.recyclerview
+
+ifneq ($(INCREMENTAL_BUILDS),)
+    LOCAL_PROGUARD_ENABLED := disabled
+    LOCAL_JACK_ENABLED := incremental
+endif
+
+include frameworks/base/packages/SettingsLib/common.mk
+
 include $(BUILD_PACKAGE)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/doze/AndroidManifest.xml b/doze/AndroidManifest.xml
index fe2cfe4..b14e9e0 100644
--- a/doze/AndroidManifest.xml
+++ b/doze/AndroidManifest.xml
@@ -30,9 +30,9 @@
         </service>
 
         <activity
-            android:name=".TouchscreenGestureSettings"
+            android:name=".SamsungDozeActivity"
             android:label="@string/screen_gestures_panel_title"
-            android:theme="@android:style/Theme.Material.Settings">
+            android:theme="@style/SamsungDozeSettings">
             <intent-filter>
                 <action android:name="com.android.settings.action.EXTRA_SETTINGS" />
             </intent-filter>
diff --git a/doze/proguard.flags b/doze/proguard.flags
index 3bb1f2c..0a62941 100644
--- a/doze/proguard.flags
+++ b/doze/proguard.flags
@@ -1,3 +1,9 @@
 -keep class com.cyanogenmod.settings.device.* {
   *;
 }
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keep class ** extends android.support.v14.preference.PreferenceFragment
diff --git a/doze/res/values/styles.xml b/doze/res/values/styles.xml
new file mode 100644
index 0000000..69e4ff3
--- /dev/null
+++ b/doze/res/values/styles.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2016 The CyanogenMod Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <style name="SamsungDozeSettings" parent="@android:style/Theme.Material.Settings">
+        <item name="preferenceTheme">@android:style/Theme.Material.Settings</item>
+    </style>
+</resources>
diff --git a/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java b/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java
new file mode 100644
index 0000000..45ac530
--- /dev/null
+++ b/doze/src/com/cyanogenmod/settings/device/SamsungDozeActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.cyanogenmod.settings.device;
+
+import android.app.Fragment;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+
+import com.android.settingslib.drawer.SettingsDrawerActivity;
+
+public class SamsungDozeActivity extends SettingsDrawerActivity {
+
+    private static final String TAG = "samsung_doze";
+
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        getFragmentManager().beginTransaction().replace(R.id.content_frame,
+                new TouchscreenGestureSettings(), TAG).commit();
+    }
+}
diff --git a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java
index 30bbcf4..c9ffce0 100644
--- a/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java
+++ b/doze/src/com/cyanogenmod/settings/device/TouchscreenGestureSettings.java
@@ -17,14 +17,14 @@
 package com.cyanogenmod.settings.device;
 
 import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.preference.SwitchPreference;
+import android.support.v14.preference.PreferenceFragment;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
 import android.provider.Settings;
 
 import org.cyanogenmod.internal.util.ScreenType;
 
-public class TouchscreenGestureSettings extends PreferenceActivity {
+public class TouchscreenGestureSettings extends PreferenceFragment {
 
     private static final String KEY_AMBIENT_DISPLAY_ENABLE = "ambient_display_enable";
     private static final String KEY_HAND_WAVE = "gesture_hand_wave";
@@ -37,8 +37,7 @@
     private SwitchPreference mProximityWakePreference;
 
     @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
+    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         addPreferencesFromResource(R.xml.gesture_panel);
         boolean dozeEnabled = isDozeEnabled();
         mAmbientDisplayPreference =
@@ -59,22 +58,22 @@
     }
 
     @Override
-    protected void onResume() {
+    public void onResume() {
         super.onResume();
 
         // If running on a phone, remove padding around the listview
-        if (!ScreenType.isTablet(this)) {
+        if (!ScreenType.isTablet(getContext())) {
             getListView().setPadding(0, 0, 0, 0);
         }
     }
 
     private boolean enableDoze(boolean enable) {
-        return Settings.Secure.putInt(getContentResolver(),
+        return Settings.Secure.putInt(getContext().getContentResolver(),
                 Settings.Secure.DOZE_ENABLED, enable ? 1 : 0);
     }
 
     private boolean isDozeEnabled() {
-        return Settings.Secure.getInt(getContentResolver(),
+        return Settings.Secure.getInt(getContext().getContentResolver(),
                 Settings.Secure.DOZE_ENABLED, 1) != 0;
     }