Merge "Add BaseLeanbackPreferenceFragment to preference-v17"
diff --git a/v17/preference/res/layout/leanback_preference_fragment.xml b/v17/preference/res/layout/leanback_preference_fragment.xml
new file mode 100644
index 0000000..3279a42
--- /dev/null
+++ b/v17/preference/res/layout/leanback_preference_fragment.xml
@@ -0,0 +1,40 @@
+<?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
+  -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/main_frame"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/lb_preference_decor_list_background"
+    android:orientation="vertical"
+    >
+
+    <TextView android:id="@+id/decor_title"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/lb_preference_decor_title_text_height"
+        android:background="?attr/defaultBrandColor"
+        android:fontFamily="sans-serif-condensed"
+        android:gravity="center_vertical"
+        android:paddingTop="@dimen/lb_preference_decor_title_padding_top"
+        android:paddingStart="@dimen/lb_preference_decor_title_padding_start"
+        android:paddingEnd="@dimen/lb_preference_decor_title_padding_end"
+        android:singleLine="true"
+        android:textSize="@dimen/lb_preference_decor_title_text_size"
+        android:textColor="?android:attr/textColorPrimary"
+        />
+
+</LinearLayout>
diff --git a/v17/preference/res/values/colors.xml b/v17/preference/res/values/colors.xml
new file mode 100644
index 0000000..de6c888
--- /dev/null
+++ b/v17/preference/res/values/colors.xml
@@ -0,0 +1,19 @@
+<?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>
+    <color name="lb_preference_decor_list_background">#263238</color>
+</resources>
diff --git a/v17/preference/res/values/dimens.xml b/v17/preference/res/values/dimens.xml
new file mode 100644
index 0000000..ff4e537
--- /dev/null
+++ b/v17/preference/res/values/dimens.xml
@@ -0,0 +1,23 @@
+<?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>
+  <dimen name="lb_preference_decor_title_text_height">64dp</dimen>
+  <dimen name="lb_preference_decor_title_padding_top">27dp</dimen>
+  <dimen name="lb_preference_decor_title_padding_start">24dp</dimen>
+  <dimen name="lb_preference_decor_title_padding_end">56dp</dimen>
+  <dimen name="lb_preference_decor_title_text_size">20sp</dimen>
+</resources>
diff --git a/v17/preference/src/android/support/v17/preference/BaseLeanbackPreferenceFragment.java b/v17/preference/src/android/support/v17/preference/BaseLeanbackPreferenceFragment.java
new file mode 100644
index 0000000..40d9607
--- /dev/null
+++ b/v17/preference/src/android/support/v17/preference/BaseLeanbackPreferenceFragment.java
@@ -0,0 +1,41 @@
+/*
+ * 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
+ */
+
+package android.support.v17.preference;
+
+import android.os.Bundle;
+import android.support.v14.preference.PreferenceFragment;
+import android.support.v17.leanback.widget.VerticalGridView;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+/**
+ * This fragment provides a preference fragment with leanback-style behavior, suitable for
+ * embedding into broader UI elements.
+ */
+public abstract class BaseLeanbackPreferenceFragment extends PreferenceFragment {
+
+    @Override
+    public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
+            Bundle savedInstanceState) {
+        VerticalGridView verticalGridView = (VerticalGridView) inflater
+                .inflate(R.layout.leanback_preferences_list, parent, false);
+        verticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE);
+        verticalGridView.setFocusScrollStrategy(VerticalGridView.FOCUS_SCROLL_ALIGNED);
+        return verticalGridView;
+    }
+}
diff --git a/v17/preference/src/android/support/v17/preference/LeanbackPreferenceFragment.java b/v17/preference/src/android/support/v17/preference/LeanbackPreferenceFragment.java
index 9559f04..73ce174 100644
--- a/v17/preference/src/android/support/v17/preference/LeanbackPreferenceFragment.java
+++ b/v17/preference/src/android/support/v17/preference/LeanbackPreferenceFragment.java
@@ -17,21 +17,33 @@
 package android.support.v17.preference;
 
 import android.os.Bundle;
-import android.support.v14.preference.PreferenceFragment;
-import android.support.v17.leanback.widget.VerticalGridView;
-import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
+import android.view.View;
 import android.view.ViewGroup;
+import android.widget.TextView;
 
-public abstract class LeanbackPreferenceFragment extends PreferenceFragment {
+/**
+ * This fragment provides a fully decorated leanback-style preference fragment, including a
+ * list background and header.
+ */
+public abstract class LeanbackPreferenceFragment extends BaseLeanbackPreferenceFragment {
 
     @Override
-    public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
-        VerticalGridView verticalGridView = (VerticalGridView) inflater
-                .inflate(R.layout.leanback_preferences_list, parent, false);
-        verticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE);
-        verticalGridView.setFocusScrollStrategy(VerticalGridView.FOCUS_SCROLL_ALIGNED);
-        return verticalGridView;
+        final View view = inflater.inflate(R.layout.leanback_preference_fragment, container, false);
+        final ViewGroup innerContainer = (ViewGroup) view.findViewById(R.id.main_frame);
+        final View innerView = super.onCreateView(inflater, innerContainer, savedInstanceState);
+        if (innerView != null) {
+            innerContainer.addView(innerView);
+        }
+        return view;
+    }
+
+    @Override
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        final TextView decorTitle = (TextView) view.findViewById(R.id.decor_title);
+        decorTitle.setText(getPreferenceScreen().getTitle());
     }
 }