Support preference tidy

Update PreferenceFragmentCompat to match changes in PreferenceFragment
Remove unused constant
Fix up theme for material and leanback preference to eliminate undesired padding

Change-Id: I72c59b21efb41420091e497ad6b08a7638cc2569
diff --git a/v14/preference/res/values-v17/styles.xml b/v14/preference/res/values-v17/styles.xml
new file mode 100644
index 0000000..e0b478f
--- /dev/null
+++ b/v14/preference/res/values-v17/styles.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 The Android Open Source 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>
+    <style name="PreferenceFragmentList.Material">
+        <item name="android:paddingStart">0dp</item>
+        <item name="android:paddingEnd">0dp</item>
+    </style>
+
+</resources>
diff --git a/v14/preference/res/values/styles.xml b/v14/preference/res/values/styles.xml
index eb59c34..8e1f255 100644
--- a/v14/preference/res/values/styles.xml
+++ b/v14/preference/res/values/styles.xml
@@ -74,4 +74,9 @@
         <item name="android:textStyle">normal</item>
     </style>
 
+    <style name="PreferenceFragmentList.Material">
+        <item name="android:paddingLeft">0dp</item>
+        <item name="android:paddingRight">0dp</item>
+    </style>
+
 </resources>
diff --git a/v14/preference/res/values/themes.xml b/v14/preference/res/values/themes.xml
index 2bfe623..6c1c93f 100644
--- a/v14/preference/res/values/themes.xml
+++ b/v14/preference/res/values/themes.xml
@@ -30,5 +30,6 @@
         <item name="switchPreferenceStyle">@style/Preference.SwitchPreference.Material</item>
         <item name="dialogPreferenceStyle">@style/Preference.DialogPreference.Material</item>
         <item name="editTextPreferenceStyle">@style/Preference.DialogPreference.EditTextPreference.Material</item>
+        <item name="preferenceFragmentListStyle">@style/PreferenceFragmentList.Material</item>
     </style>
 </resources>
diff --git a/v14/preference/src/android/support/v14/preference/PreferenceFragment.java b/v14/preference/src/android/support/v14/preference/PreferenceFragment.java
index c65731b..106f62d 100644
--- a/v14/preference/src/android/support/v14/preference/PreferenceFragment.java
+++ b/v14/preference/src/android/support/v14/preference/PreferenceFragment.java
@@ -130,11 +130,6 @@
 
     private int mLayoutResId = R.layout.preference_list_fragment;
 
-    /**
-     * The starting request code given out to preference framework.
-     */
-    private static final int FIRST_REQUEST_CODE = 100;
-
     private static final int MSG_BIND_PREFERENCES = 1;
     private Handler mHandler = new Handler() {
         @Override
diff --git a/v17/preference-leanback/res/values/styles.xml b/v17/preference-leanback/res/values/styles.xml
index 56554a4..d52cd87 100644
--- a/v17/preference-leanback/res/values/styles.xml
+++ b/v17/preference-leanback/res/values/styles.xml
@@ -62,4 +62,9 @@
         <item name="android:dialogLayout">@layout/preference_dialog_edittext</item>
     </style>
 
+    <style name="PreferenceFragmentList.Leanback">
+        <item name="android:paddingStart">0dp</item>
+        <item name="android:paddingEnd">0dp</item>
+    </style>
+
 </resources>
diff --git a/v17/preference-leanback/res/values/themes.xml b/v17/preference-leanback/res/values/themes.xml
index b3060d9..a34bc20 100644
--- a/v17/preference-leanback/res/values/themes.xml
+++ b/v17/preference-leanback/res/values/themes.xml
@@ -26,5 +26,6 @@
         <item name="switchPreferenceStyle">@style/LeanbackPreference.SwitchPreference</item>
         <item name="dialogPreferenceStyle">@style/LeanbackPreference.DialogPreference</item>
         <item name="editTextPreferenceStyle">@style/LeanbackPreference.DialogPreference.EditTextPreference</item>
+        <item name="preferenceFragmentListStyle">@style/PreferenceFragmentList.Leanback</item>
     </style>
 </resources>
diff --git a/v7/preference/src/android/support/v7/preference/PreferenceFragmentCompat.java b/v7/preference/src/android/support/v7/preference/PreferenceFragmentCompat.java
index 8231d89..503fc9b 100644
--- a/v7/preference/src/android/support/v7/preference/PreferenceFragmentCompat.java
+++ b/v7/preference/src/android/support/v7/preference/PreferenceFragmentCompat.java
@@ -123,11 +123,6 @@
 
     private int mLayoutResId = R.layout.preference_list_fragment;
 
-    /**
-     * The starting request code given out to preference framework.
-     */
-    private static final int FIRST_REQUEST_CODE = 100;
-
     private static final int MSG_BIND_PREFERENCES = 1;
     private Handler mHandler = new Handler() {
         @Override
@@ -241,7 +236,15 @@
 
         a.recycle();
 
-        final View view = inflater.inflate(mLayoutResId, container, false);
+        // Need to theme the inflater to pick up the preferenceFragmentListStyle
+        final TypedValue tv = new TypedValue();
+        getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
+        final int theme = tv.resourceId;
+
+        final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
+        final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);
+
+        final View view = themedInflater.inflate(mLayoutResId, container, false);
 
         final View rawListContainer = view.findViewById(R.id.list_container);
         if (!(rawListContainer instanceof ViewGroup)) {
@@ -251,7 +254,7 @@
 
         final ViewGroup listContainer = (ViewGroup) rawListContainer;
 
-        final RecyclerView listView = onCreateRecyclerView(inflater, listContainer,
+        final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer,
                 savedInstanceState);
         if (listView == null) {
             throw new RuntimeException("Could not create RecyclerView");