AdvancedDisplay: Re-integrate into Settings

 * Apply the default Oreo theme and inherit the layouts from Google
   for the Settings app, in order to keep UI consistency.

 * Get rid of SettingsDrawerActivity as it no longer fits in.

 * Add required appcompat and preference support libraries.

 * Integrate into display settings category using IA.

Change-Id: I8438e0ebec27085df2be4668f8f7170d2010fb20
diff --git a/AdvancedDisplay/Android.mk b/AdvancedDisplay/Android.mk
index d972dc4..e0d82fa 100644
--- a/AdvancedDisplay/Android.mk
+++ b/AdvancedDisplay/Android.mk
@@ -9,16 +9,19 @@
 LOCAL_CERTIFICATE := platform
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
-    android-support-v14-preference \
+    android-support-v4 \
     android-support-v7-appcompat \
     android-support-v7-preference \
     android-support-v7-recyclerview \
+    android-support-v13 \
+    android-support-v14-preference \
     org.lineageos.platform.internal
 
 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
 
 LOCAL_RESOURCE_DIR := \
     $(LOCAL_PATH)/res \
+    $(TOP)/packages/resources/devicesettings/res \
     frameworks/support/v14/preference/res \
     frameworks/support/v7/appcompat/res \
     frameworks/support/v7/preference/res \
@@ -31,8 +34,6 @@
     --extra-packages android.support.v7.preference \
     --extra-packages android.support.v7.recyclerview
 
-include frameworks/base/packages/SettingsLib/common.mk
-
 include $(BUILD_PACKAGE)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/AdvancedDisplay/AndroidManifest.xml b/AdvancedDisplay/AndroidManifest.xml
index 241b105..71b93b0 100644
--- a/AdvancedDisplay/AndroidManifest.xml
+++ b/AdvancedDisplay/AndroidManifest.xml
@@ -6,7 +6,8 @@
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 
     <application
-        android:label="@string/app_name">
+        android:label="@string/app_name"
+        android:theme="@style/Theme.Main">
         <receiver android:name="org.lineageos.settings.device.BootCompletedReceiver">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
@@ -16,17 +17,16 @@
 
         <activity
             android:name=".AdvancedDisplayActivity"
-            android:label="@string/app_name"
-            android:theme="@style/AdvancedDisplay">
+            android:label="@string/app_name">
             <intent-filter>
                 <action android:name="com.android.settings.action.EXTRA_SETTINGS" />
             </intent-filter>
             <meta-data
-                android:name="com.android.settings.icon"
-                android:resource="@drawable/ic_settings_advanced_display" />
-            <meta-data
                 android:name="com.android.settings.category"
-                android:value="com.android.settings.category.device" />
+                android:value="com.android.settings.category.ia.display" />
+            <meta-data
+                android:name="com.android.settings.summary"
+                android:value="@string/summary_empty" />
         </activity>
     </application>
 </manifest>
diff --git a/AdvancedDisplay/res/values/dimens.xml b/AdvancedDisplay/res/values/dimens.xml
index 62f1899..077adea 100644
--- a/AdvancedDisplay/res/values/dimens.xml
+++ b/AdvancedDisplay/res/values/dimens.xml
@@ -17,4 +17,6 @@
 <resources>
     <!-- ActionBar contentInsetStart -->
     <dimen name="actionbar_subsettings_contentInsetStart">72dp</dimen>
+
+    <dimen name="settings_side_margin">0dip</dimen>
 </resources>
diff --git a/AdvancedDisplay/res/values/strings.xml b/AdvancedDisplay/res/values/strings.xml
index 42cdc6c..89f55a9 100644
--- a/AdvancedDisplay/res/values/strings.xml
+++ b/AdvancedDisplay/res/values/strings.xml
@@ -26,4 +26,7 @@
     <string name="mdnie_scenario_summary_head">Set the mDNIe scenario</string>
     <string name="mdnie_negative_title_head">Negative mode</string>
     <string name="mdnie_negative_summary_head">Enable/disable inverted colors</string>
+
+    <!-- DO NOT TRANSLATE Empty summary for dynamic preferences -->
+    <string name="summary_empty" translatable="false"></string>
 </resources>
diff --git a/AdvancedDisplay/res/values/styles.xml b/AdvancedDisplay/res/values/styles.xml
index ee2d0a5..01f8dae 100644
--- a/AdvancedDisplay/res/values/styles.xml
+++ b/AdvancedDisplay/res/values/styles.xml
@@ -16,7 +16,42 @@
      limitations under the License.
 -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <style name="AdvancedDisplay" parent="@android:style/Theme.Material.Settings">
-        <item name="preferenceTheme">@android:style/Theme.Material.Settings</item>
+    <style name="Theme.Main" parent="@android:style/Theme.DeviceDefault.Settings">
+        <item name="preferenceCategoryStyle">@style/Theme.Main.PreferenceCategoryStyle</item>
+        <item name="preferenceFragmentStyle">@style/Theme.Main.PreferenceFragmentStyle</item>
+        <item name="preferenceStyle">@style/Theme.Main.PreferenceStyle</item>
+        <item name="preferenceTheme">@style/Theme.Main.PreferenceTheme</item>
+        <item name="dialogPreferenceStyle">@style/Theme.Main.DialogPreferenceStyle</item>
+        <item name="switchPreferenceStyle">@style/Theme.Main.SwitchPreferenceStyle</item>
+    </style>
+
+    <style name="Theme.Main.PreferenceCategoryStyle" parent="@*android:style/Preference.DeviceDefault.Category">
+        <item name="allowDividerAbove">true</item>
+        <item name="android:layout">@layout/preference_category_material_settings</item>
+    </style>
+
+    <style name="Theme.Main.PreferenceFragmentStyle" parent="@*android:style/PreferenceFragment.Material">
+        <item name="allowDividerAfterLastItem">false</item>
+    </style>
+
+    <style name="Theme.Main.PreferenceStyle" parent="@*android:style/Preference.DeviceDefault">
+        <item name="allowDividerAbove">false</item>
+        <item name="allowDividerBelow">true</item>
+        <item name="singleLineTitle">false</item>
+        <item name="android:layout">@layout/preference_material_settings</item>
+    </style>
+
+    <style name="Theme.Main.PreferenceTheme">
+    </style>
+
+    <style name="Theme.Main.DialogPreferenceStyle" parent="@*android:style/Preference.DeviceDefault.DialogPreference">
+        <item name="allowDividerAbove">false</item>
+        <item name="allowDividerBelow">true</item>
+        <item name="singleLineTitle">false</item>
+        <item name="android:iconSpaceReserved">true</item>
+    </style>
+
+    <style name="Theme.Main.SwitchPreferenceStyle" parent="@style/Theme.Main.PreferenceStyle">
+        <item name="widgetLayout">@*android:layout/preference_widget_switch</item>
     </style>
 </resources>
diff --git a/AdvancedDisplay/src/org/lineageos/settings/device/AdvancedDisplayActivity.java b/AdvancedDisplay/src/org/lineageos/settings/device/AdvancedDisplayActivity.java
index 82ce158..92397c3 100644
--- a/AdvancedDisplay/src/org/lineageos/settings/device/AdvancedDisplayActivity.java
+++ b/AdvancedDisplay/src/org/lineageos/settings/device/AdvancedDisplayActivity.java
@@ -17,15 +17,14 @@
 package org.lineageos.settings.device;
 
 import android.os.Bundle;
+import android.preference.PreferenceActivity;
 
-import com.android.settingslib.drawer.SettingsDrawerActivity;
-
-public class AdvancedDisplayActivity extends SettingsDrawerActivity {
+public class AdvancedDisplayActivity extends PreferenceActivity {
 
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        getFragmentManager().beginTransaction().replace(R.id.content_frame,
+        getFragmentManager().beginTransaction().replace(android.R.id.content,
                 new AdvancedDisplayFragment()).commit();
     }
 }
diff --git a/lineage.dependencies b/lineage.dependencies
new file mode 100644
index 0000000..c423969
--- /dev/null
+++ b/lineage.dependencies
@@ -0,0 +1,6 @@
+[
+  {
+    "repository": "android_packages_resources_devicesettings",
+    "target_path": "packages/resources/devicesettings"
+  }
+]