DetailsFragment: fix regression of missing title View

When title view and VideoFragment both exist, title view becomes
display only. When there is no VideoFragment, user can focus
to title view and do search, that is backward compatible with
behavior in 25.0.0

Bug: 33839988
Test: SupportLeanbackDemos DetailsFragmentTest

Change-Id: I52156993914a427d52b658ea10cd815632ca4fe3
diff --git a/samples/SupportLeanbackDemos/AndroidManifest.xml b/samples/SupportLeanbackDemos/AndroidManifest.xml
index 1dba568..ea3c1ee 100644
--- a/samples/SupportLeanbackDemos/AndroidManifest.xml
+++ b/samples/SupportLeanbackDemos/AndroidManifest.xml
@@ -43,6 +43,22 @@
             android:theme="@style/Theme.Example.Leanback.Details"
             android:exported="true" />
 
+        <activity android:name="DetailsVideoActivity"
+            android:theme="@style/Theme.Example.Leanback.Details"
+            android:exported="true" />
+
+        <activity android:name="DetailsVideoSupportActivity"
+            android:theme="@style/Theme.Example.Leanback.Details"
+            android:exported="true" />
+
+        <activity android:name="DetailsCustomTitleActivity"
+            android:theme="@style/Theme.Example.Leanback.Details.CustomTitle"
+            android:exported="true" />
+
+        <activity android:name="DetailsCustomTitleSupportActivity"
+            android:theme="@style/Theme.Example.Leanback.Details.CustomTitle"
+            android:exported="true" />
+
         <activity android:name="SearchDetailsActivity"
             android:theme="@style/Theme.Example.Leanback.SearchDetails"
             android:exported="true" />
diff --git a/samples/SupportLeanbackDemos/generatev4.py b/samples/SupportLeanbackDemos/generatev4.py
index d4b3f22..c79f1b1 100755
--- a/samples/SupportLeanbackDemos/generatev4.py
+++ b/samples/SupportLeanbackDemos/generatev4.py
@@ -134,8 +134,6 @@
     line = line.replace('DetailsActivity', 'DetailsSupportActivity')
     line = line.replace('android.app.Activity', 'android.support.v4.app.FragmentActivity')
     line = line.replace('extends Activity', 'extends FragmentActivity')
-    line = line.replace('R.layout.details', 'R.layout.details_support')
-    line = line.replace('R.layout.legacy_details', 'R.layout.legacy_details_support')
     line = line.replace('getFragmentManager()', 'getSupportFragmentManager()')
     line = line.replace('DetailsFragment', 'DetailsSupportFragment')
     line = line.replace('NewDetailsFragment', 'NewDetailsSupportFragment')
@@ -143,26 +141,6 @@
 file.close()
 outfile.close()
 
-file = open('res/layout/details.xml', 'r')
-outfile = open('res/layout/details_support.xml', 'w')
-for line in file:
-    line = replace_xml_head(line, "details")
-    line = line.replace('com.example.android.leanback.NewDetailsFragment', 'com.example.android.leanback.NewDetailsSupportFragment')
-    outfile.write(line)
-file.close()
-outfile.close()
-
-
-file = open('res/layout/legacy_details.xml', 'r')
-outfile = open('res/layout/legacy_details_support.xml', 'w')
-for line in file:
-    line = replace_xml_head(line, "legacy_details")
-    line = line.replace('com.example.android.leanback.DetailsFragment', 'com.example.android.leanback.DetailsSupportFragment')
-    outfile.write(line)
-file.close()
-outfile.close()
-
-
 file = open('src/com/example/android/leanback/SearchDetailsActivity.java', 'r')
 outfile = open('src/com/example/android/leanback/SearchDetailsSupportActivity.java', 'w')
 write_java_head(outfile, "SearchDetailsActivity")
diff --git a/samples/SupportLeanbackDemos/res/layout/custom_title.xml b/samples/SupportLeanbackDemos/res/layout/custom_title.xml
new file mode 100644
index 0000000..4a88021
--- /dev/null
+++ b/samples/SupportLeanbackDemos/res/layout/custom_title.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.example.android.leanback.CustomTitleView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/browse_title_group"
+    android:orientation="horizontal" android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+    <TextView
+        android:text="@string/custom_title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+</com.example.android.leanback.CustomTitleView>
\ No newline at end of file
diff --git a/samples/SupportLeanbackDemos/res/layout/details.xml b/samples/SupportLeanbackDemos/res/layout/details.xml
deleted file mode 100644
index 3159f54..0000000
--- a/samples/SupportLeanbackDemos/res/layout/details.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2014 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.
--->
-
-<fragment xmlns:android="http://schemas.android.com/apk/res/android"
-    android:name="com.example.android.leanback.NewDetailsFragment"
-    android:id="@+id/details_fragment"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-/>
diff --git a/samples/SupportLeanbackDemos/res/layout/legacy_details.xml b/samples/SupportLeanbackDemos/res/layout/details_activity.xml
similarity index 85%
rename from samples/SupportLeanbackDemos/res/layout/legacy_details.xml
rename to samples/SupportLeanbackDemos/res/layout/details_activity.xml
index 4af4e6a..7fc1400 100644
--- a/samples/SupportLeanbackDemos/res/layout/legacy_details.xml
+++ b/samples/SupportLeanbackDemos/res/layout/details_activity.xml
@@ -15,8 +15,7 @@
      limitations under the License.
 -->
 
-<fragment xmlns:android="http://schemas.android.com/apk/res/android"
-    android:name="com.example.android.leanback.DetailsFragment"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/details_fragment"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
diff --git a/samples/SupportLeanbackDemos/res/layout/details_support.xml b/samples/SupportLeanbackDemos/res/layout/details_support.xml
deleted file mode 100644
index 103dc25..0000000
--- a/samples/SupportLeanbackDemos/res/layout/details_support.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This file is auto-generated from details.xml.  DO NOT MODIFY. -->
-
-<!--
-     Copyright (C) 2014 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.
--->
-
-<fragment xmlns:android="http://schemas.android.com/apk/res/android"
-    android:name="com.example.android.leanback.NewDetailsSupportFragment"
-    android:id="@+id/details_fragment"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-/>
diff --git a/samples/SupportLeanbackDemos/res/layout/legacy_details_support.xml b/samples/SupportLeanbackDemos/res/layout/legacy_details_support.xml
deleted file mode 100644
index 8146f9b..0000000
--- a/samples/SupportLeanbackDemos/res/layout/legacy_details_support.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This file is auto-generated from legacy_details.xml.  DO NOT MODIFY. -->
-
-<!--
-     Copyright (C) 2014 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.
--->
-
-<fragment xmlns:android="http://schemas.android.com/apk/res/android"
-    android:name="com.example.android.leanback.DetailsSupportFragment"
-    android:id="@+id/details_fragment"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-/>
diff --git a/samples/SupportLeanbackDemos/res/values/strings.xml b/samples/SupportLeanbackDemos/res/values/strings.xml
index 3774ebf..6de7d7b 100644
--- a/samples/SupportLeanbackDemos/res/values/strings.xml
+++ b/samples/SupportLeanbackDemos/res/values/strings.xml
@@ -29,8 +29,17 @@
     <string name="search_support_description">SearchSupportFragment test</string>
     <string name="details">Details</string>
     <string name="details_description">DetailsFragment test</string>
+    <string name="details_video">Details with Video</string>
+    <string name="details_video_description">DetailsFragment with Video test</string>
+    <string name="details_custom_title">Details with custom title</string>
+    <string name="details_custom_title_description">DetailsFragment with custom title test</string>
     <string name="details_support">Details(support version)</string>
     <string name="details_support_description">DetailsSupportFragment test</string>
+    <string name="details_video_support">Details with Video(support version)</string>
+    <string name="details_video_support_description">DetailsFragment with Video test(support version)</string>
+    <string name="details_custom_title_support">Details with custom title(support version)</string>
+    <string name="details_custom_title_support_description">DetailsSupportFragment with custom title test</string>
+    <string name="custom_title">Custom Title</string>
     <string name="search_details">Search Details</string>
     <string name="search_details_description">Search style DetailsFragment test</string>
     <string name="search_details_support">Search Details(support version)</string>
diff --git a/samples/SupportLeanbackDemos/res/values/themes.xml b/samples/SupportLeanbackDemos/res/values/themes.xml
index 458c5c0..58ae373 100644
--- a/samples/SupportLeanbackDemos/res/values/themes.xml
+++ b/samples/SupportLeanbackDemos/res/values/themes.xml
@@ -23,6 +23,9 @@
     </style>
     <style name="Theme.Example.Leanback.Details" parent="Theme.Leanback.Details">
     </style>
+    <style name="Theme.Example.Leanback.Details.CustomTitle">
+        <item name="browseTitleViewLayout">@layout/custom_title</item>.
+    </style>
     <style name="Theme.Example.Leanback.VerticalGrid" parent="Theme.Leanback.VerticalGrid">
     </style>
     <style name="Theme.Example.Leanback.Rows" parent="Theme.Leanback">
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/CustomTitleView.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/CustomTitleView.java
new file mode 100644
index 0000000..3ceb17d
--- /dev/null
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/CustomTitleView.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2016 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 com.example.android.leanback;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.support.v17.leanback.widget.SearchOrbView;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.support.v17.leanback.widget.TitleViewAdapter;
+
+public class CustomTitleView extends LinearLayout implements TitleViewAdapter.Provider {
+
+    private final TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() {
+        @Override
+        public View getSearchAffordanceView() {
+            return null;
+        }
+
+        @Override
+        public void setOnSearchClickedListener(View.OnClickListener listener) {
+        }
+
+        @Override
+        public void setAnimationEnabled(boolean enable) {
+        }
+
+        @Override
+        public Drawable getBadgeDrawable() {
+            return null;
+        }
+
+        @Override
+        public SearchOrbView.Colors getSearchAffordanceColors() {
+            return null;
+        }
+
+        @Override
+        public CharSequence getTitle() {
+            return null;
+        }
+
+        @Override
+        public void setBadgeDrawable(Drawable drawable) {
+        }
+
+        @Override
+        public void setSearchAffordanceColors(SearchOrbView.Colors colors) {
+        }
+
+        @Override
+        public void setTitle(CharSequence titleText) {
+        }
+
+        @Override
+        public void updateComponentsVisibility(int flags) {
+        }
+    };
+
+    public CustomTitleView(Context context) {
+        this(context, null);
+    }
+
+    public CustomTitleView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public CustomTitleView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    @Override
+    public TitleViewAdapter getTitleViewAdapter() {
+        return mTitleViewAdapter;
+    }
+}
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java
index 43c6910..6e2cbb4 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsActivity.java
@@ -26,22 +26,41 @@
                 && !(this instanceof SearchDetailsActivity));
     }
 
+    protected boolean hasBackgroundVideo() {
+        return false;
+    }
+
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         getFragmentManager().enableDebugLogging(true);
-        setContentView(useLegacyFragment() ? R.layout.legacy_details : R.layout.details);
+        setContentView(R.layout.details_activity);
         if (savedInstanceState == null) {
-            // Only pass object to fragment when activity is first time created,
-            // later object is modified and persisted with fragment state.
             if (useLegacyFragment()) {
-                ((DetailsFragment)getFragmentManager().findFragmentById(R.id.details_fragment))
-                    .setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                DetailsFragment fragment = new DetailsFragment();
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                getFragmentManager().beginTransaction()
+                        .replace(R.id.details_fragment, fragment)
+                        .commit();
             } else {
-                ((NewDetailsFragment)getFragmentManager().findFragmentById(R.id.details_fragment))
-                    .setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                NewDetailsFragment fragment = new NewDetailsFragment();
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                fragment.setBackgroundVideo(hasBackgroundVideo());
+                getFragmentManager().beginTransaction()
+                        .replace(R.id.details_fragment, fragment)
+                        .commit();
+            }
+        } else {
+            if (useLegacyFragment()) {
+                DetailsFragment fragment = (DetailsFragment) getFragmentManager()
+                        .findFragmentById(R.id.details_fragment);
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+            } else {
+                NewDetailsFragment fragment = (NewDetailsFragment) getFragmentManager()
+                        .findFragmentById(R.id.details_fragment);
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
             }
         }
     }
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsCustomTitleActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsCustomTitleActivity.java
new file mode 100644
index 0000000..0796fb7
--- /dev/null
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsCustomTitleActivity.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 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 com.example.android.leanback;
+
+/**
+ * Same function as DetailsActivity, using different theme in AndroidManifest.
+ */
+public class DetailsCustomTitleActivity extends DetailsActivity {
+}
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsCustomTitleSupportActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsCustomTitleSupportActivity.java
new file mode 100644
index 0000000..4ad2f7a
--- /dev/null
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsCustomTitleSupportActivity.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 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 com.example.android.leanback;
+
+/**
+ * Same function as DetailsSupportActivity, using different theme in AndroidManifest.
+ */
+public class DetailsCustomTitleSupportActivity extends DetailsSupportActivity {
+}
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java
index 09d9526..56acc05 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsFragment.java
@@ -126,12 +126,7 @@
         ps.addClassPresenter(ListRow.class, new ListRowPresenter());
 
         mRowsAdapter = new ArrayObjectAdapter(ps);
-
-        PhotoItem item = (PhotoItem) (savedInstanceState != null ?
-                savedInstanceState.getParcelable(ITEM) : null);
-        if (item != null) {
-            setItem(item);
-        }
+        updateAdapter();
 
         setOnItemViewClickedListener(new OnItemViewClickedListener() {
             @Override
@@ -179,7 +174,13 @@
 
     public void setItem(PhotoItem photoItem) {
         mPhotoItem = photoItem;
+        updateAdapter();
+    }
 
+    void updateAdapter() {
+        if (mRowsAdapter == null) {
+            return;
+        }
         mRowsAdapter.clear();
         new Handler().postDelayed(new Runnable() {
             public void run() {
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportActivity.java
index 3ebf101..48d15e5 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportActivity.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportActivity.java
@@ -29,22 +29,41 @@
                 && !(this instanceof SearchDetailsSupportActivity));
     }
 
+    protected boolean hasBackgroundVideo() {
+        return false;
+    }
+
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         getSupportFragmentManager().enableDebugLogging(true);
-        setContentView(useLegacyFragment() ? R.layout.legacy_details_support : R.layout.details_support);
+        setContentView(R.layout.details_activity);
         if (savedInstanceState == null) {
-            // Only pass object to fragment when activity is first time created,
-            // later object is modified and persisted with fragment state.
             if (useLegacyFragment()) {
-                ((DetailsSupportFragment)getSupportFragmentManager().findFragmentById(R.id.details_fragment))
-                    .setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                DetailsSupportFragment fragment = new DetailsSupportFragment();
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                getSupportFragmentManager().beginTransaction()
+                        .replace(R.id.details_fragment, fragment)
+                        .commit();
             } else {
-                ((NewDetailsSupportFragment)getSupportFragmentManager().findFragmentById(R.id.details_fragment))
-                    .setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                NewDetailsSupportFragment fragment = new NewDetailsSupportFragment();
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+                fragment.setBackgroundVideo(hasBackgroundVideo());
+                getSupportFragmentManager().beginTransaction()
+                        .replace(R.id.details_fragment, fragment)
+                        .commit();
+            }
+        } else {
+            if (useLegacyFragment()) {
+                DetailsSupportFragment fragment = (DetailsSupportFragment) getSupportFragmentManager()
+                        .findFragmentById(R.id.details_fragment);
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
+            } else {
+                NewDetailsSupportFragment fragment = (NewDetailsSupportFragment) getSupportFragmentManager()
+                        .findFragmentById(R.id.details_fragment);
+                fragment.setItem((PhotoItem) getIntent().getParcelableExtra(EXTRA_ITEM));
             }
         }
     }
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportFragment.java
index 28a61d9..e58e2e7 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsSupportFragment.java
@@ -129,12 +129,7 @@
         ps.addClassPresenter(ListRow.class, new ListRowPresenter());
 
         mRowsAdapter = new ArrayObjectAdapter(ps);
-
-        PhotoItem item = (PhotoItem) (savedInstanceState != null ?
-                savedInstanceState.getParcelable(ITEM) : null);
-        if (item != null) {
-            setItem(item);
-        }
+        updateAdapter();
 
         setOnItemViewClickedListener(new OnItemViewClickedListener() {
             @Override
@@ -182,7 +177,13 @@
 
     public void setItem(PhotoItem photoItem) {
         mPhotoItem = photoItem;
+        updateAdapter();
+    }
 
+    void updateAdapter() {
+        if (mRowsAdapter == null) {
+            return;
+        }
         mRowsAdapter.clear();
         new Handler().postDelayed(new Runnable() {
             public void run() {
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsVideoActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsVideoActivity.java
new file mode 100644
index 0000000..06b65b7
--- /dev/null
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsVideoActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2016 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 com.example.android.leanback;
+
+public class DetailsVideoActivity extends DetailsActivity {
+
+    @Override
+    protected boolean hasBackgroundVideo() {
+        return true;
+    }
+
+}
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsVideoSupportActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsVideoSupportActivity.java
new file mode 100644
index 0000000..0c31d36
--- /dev/null
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/DetailsVideoSupportActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2016 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 com.example.android.leanback;
+
+public class DetailsVideoSupportActivity extends DetailsSupportActivity {
+
+    @Override
+    protected boolean hasBackgroundVideo() {
+        return true;
+    }
+
+}
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java
index 83e56d6..fcd8e65 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/MainActivity.java
@@ -61,12 +61,35 @@
                     R.string.browse_support_description);
             addAction(actions, SearchActivity.class, R.string.search, R.string.search_description);
             addAction(actions, SearchSupportActivity.class, R.string.search_support, R.string.search_support_description);
-            addAction(actions, DetailsActivity.class, R.string.details, R.string.details_description);
+
+            addAction(actions, DetailsActivity.class, R.string.details,
+                    R.string.details_description);
             actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
                     new PhotoItem("Hello world", R.drawable.gallery_photo_1));
-            addAction(actions, DetailsSupportActivity.class, R.string.details_support, R.string.details_support_description);
+            addAction(actions, DetailsSupportActivity.class, R.string.details_support,
+                    R.string.details_support_description);
             actions.get(actions.size()-1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
                     new PhotoItem("Hello world", R.drawable.gallery_photo_1));
+
+            addAction(actions, DetailsVideoActivity.class, R.string.details_video,
+                    R.string.details_video_description);
+            actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
+                    new PhotoItem("Hello world", R.drawable.gallery_photo_1));
+            addAction(actions, DetailsVideoSupportActivity.class, R.string.details_video_support,
+                    R.string.details_video_support_description);
+            actions.get(actions.size()-1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
+                    new PhotoItem("Hello world", R.drawable.gallery_photo_1));
+
+            addAction(actions, DetailsCustomTitleActivity.class, R.string.details_custom_title,
+                    R.string.details_custom_title_description);
+            actions.get(actions.size()-1).getIntent().putExtra(DetailsActivity.EXTRA_ITEM,
+                    new PhotoItem("Hello world", R.drawable.gallery_photo_1));
+            addAction(actions, DetailsCustomTitleSupportActivity.class,
+                    R.string.details_custom_title_support,
+                    R.string.details_custom_title_support_description);
+            actions.get(actions.size()-1).getIntent().putExtra(DetailsSupportActivity.EXTRA_ITEM,
+                    new PhotoItem("Hello world", R.drawable.gallery_photo_1));
+
             addAction(actions, SearchDetailsActivity.class, R.string.search_details,
                     R.string.search_details_description);
             actions.get(actions.size()-1).getIntent().putExtra(SearchDetailsActivity.EXTRA_ITEM,
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsFragment.java
index 75fa941..395d557 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsFragment.java
@@ -20,7 +20,6 @@
 import android.os.Handler;
 import android.support.v17.leanback.app.DetailsBackgroundParallaxHelper;
 import android.support.v17.leanback.app.DetailsFragmentVideoHelper;
-import android.support.v17.leanback.app.VideoFragment;
 import android.support.v17.leanback.media.MediaPlayerGlue;
 import android.support.v17.leanback.widget.Action;
 import android.support.v17.leanback.widget.ArrayObjectAdapter;
@@ -63,6 +62,7 @@
     private boolean TEST_OVERVIEW_ROW_ON_SECOND;
     private boolean TEST_SHARED_ELEMENT_TRANSITION;
     private boolean TEST_ENTRANCE_TRANSITION;
+    private boolean TEST_BACKGROUND_PLAYER;
 
     private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000;
     private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000;
@@ -77,7 +77,6 @@
     private BackgroundHelper mBackgroundHelper;
     private int mBitmapMinVerticalOffset = -100;
     private MediaPlayerGlue mMediaPlayerGlue;
-    private VideoFragment mVideoFragment;
 
     private void initializeTest() {
         TEST_SHARED_ELEMENT_TRANSITION = null != getActivity().getWindow()
@@ -97,27 +96,32 @@
                 getActivity(), getParallaxManager())
                 .setCoverImageMinVerticalOffset(mBitmapMinVerticalOffset)
                 .build();
-        mMediaPlayerGlue = new MediaPlayerGlue(getActivity());
-        mMediaPlayerGlue.setHost(createPlaybackGlueHost());
-        mVideoHelper = new DetailsFragmentVideoHelper(mMediaPlayerGlue, getParallaxManager());
-        mVideoHelper.setBackgroundDrawable(mParallaxHelper.getCoverImageDrawable());
+        if (TEST_BACKGROUND_PLAYER) {
+            mMediaPlayerGlue = new MediaPlayerGlue(getActivity());
+            mMediaPlayerGlue.setHost(createPlaybackGlueHost());
+            mVideoHelper = new DetailsFragmentVideoHelper(mMediaPlayerGlue, getParallaxManager());
+            mVideoHelper.setBackgroundDrawable(mParallaxHelper.getCoverImageDrawable());
 
-        mMediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ALL);
-        mMediaPlayerGlue.setArtist("A Googleer");
-        mMediaPlayerGlue.setTitle("Diving with Sharks");
-        mMediaPlayerGlue.setVideoUrl("http://techslides.com/demos/sample-videos/small.mp4");
+            mMediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ALL);
+            mMediaPlayerGlue.setArtist("A Googleer");
+            mMediaPlayerGlue.setTitle("Diving with Sharks");
+            mMediaPlayerGlue.setVideoUrl("http://techslides.com/demos/sample-videos/small.mp4");
+
+        }
 
         final Context context = getActivity();
         setBadgeDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_title,
                 context.getTheme()));
         setTitle("Leanback Sample App");
-        setOnSearchClickedListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                Intent intent = new Intent(getActivity(), SearchActivity.class);
-                startActivity(intent);
-            }
-        });
+        if (!TEST_BACKGROUND_PLAYER) {
+            setOnSearchClickedListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    Intent intent = new Intent(getActivity(), SearchActivity.class);
+                    startActivity(intent);
+                }
+            });
+        }
 
         mActionPlay = new Action(ACTION_PLAY, "Play");
         mActionRent = new Action(ACTION_RENT, "Rent", "$3.99", ResourcesCompat.getDrawable(
@@ -165,12 +169,7 @@
         ps.addClassPresenter(ListRow.class, new ListRowPresenter());
 
         mRowsAdapter = new ArrayObjectAdapter(ps);
-
-        PhotoItem item = (PhotoItem) (savedInstanceState != null ?
-                savedInstanceState.getParcelable(ITEM) : null);
-        if (item != null) {
-            setItem(item);
-        }
+        updateAdapter();
 
         setOnItemViewClickedListener(new OnItemViewClickedListener() {
             @Override
@@ -223,9 +222,19 @@
         return view;
     }
 
+    public void setBackgroundVideo(boolean backgroundVideo) {
+        TEST_BACKGROUND_PLAYER = backgroundVideo;
+    }
+
     public void setItem(PhotoItem photoItem) {
         mPhotoItem = photoItem;
+        updateAdapter();
+    }
 
+    void updateAdapter() {
+        if (mRowsAdapter == null) {
+            return;
+        }
         mRowsAdapter.clear();
         new Handler().postDelayed(new Runnable() {
             public void run() {
@@ -295,6 +304,8 @@
     @Override
     public void onStop() {
         super.onStop();
-        mMediaPlayerGlue.pause();
+        if (TEST_BACKGROUND_PLAYER) {
+            mMediaPlayerGlue.pause();
+        }
     }
 }
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsSupportFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsSupportFragment.java
index 11d8b7e..ba482b1 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsSupportFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/NewDetailsSupportFragment.java
@@ -23,7 +23,6 @@
 import android.os.Handler;
 import android.support.v17.leanback.app.DetailsBackgroundParallaxHelper;
 import android.support.v17.leanback.app.DetailsFragmentVideoHelper;
-import android.support.v17.leanback.app.VideoSupportFragment;
 import android.support.v17.leanback.media.MediaPlayerGlue;
 import android.support.v17.leanback.widget.Action;
 import android.support.v17.leanback.widget.ArrayObjectAdapter;
@@ -66,6 +65,7 @@
     private boolean TEST_OVERVIEW_ROW_ON_SECOND;
     private boolean TEST_SHARED_ELEMENT_TRANSITION;
     private boolean TEST_ENTRANCE_TRANSITION;
+    private boolean TEST_BACKGROUND_PLAYER;
 
     private static final long TIME_TO_LOAD_OVERVIEW_ROW_MS = 1000;
     private static final long TIME_TO_LOAD_RELATED_ROWS_MS = 2000;
@@ -80,7 +80,6 @@
     private BackgroundHelper mBackgroundHelper;
     private int mBitmapMinVerticalOffset = -100;
     private MediaPlayerGlue mMediaPlayerGlue;
-    private VideoSupportFragment mVideoSupportFragment;
 
     private void initializeTest() {
         TEST_SHARED_ELEMENT_TRANSITION = null != getActivity().getWindow()
@@ -100,27 +99,32 @@
                 getActivity(), getParallaxManager())
                 .setCoverImageMinVerticalOffset(mBitmapMinVerticalOffset)
                 .build();
-        mMediaPlayerGlue = new MediaPlayerGlue(getActivity());
-        mMediaPlayerGlue.setHost(createPlaybackGlueHost());
-        mVideoHelper = new DetailsFragmentVideoHelper(mMediaPlayerGlue, getParallaxManager());
-        mVideoHelper.setBackgroundDrawable(mParallaxHelper.getCoverImageDrawable());
+        if (TEST_BACKGROUND_PLAYER) {
+            mMediaPlayerGlue = new MediaPlayerGlue(getActivity());
+            mMediaPlayerGlue.setHost(createPlaybackGlueHost());
+            mVideoHelper = new DetailsFragmentVideoHelper(mMediaPlayerGlue, getParallaxManager());
+            mVideoHelper.setBackgroundDrawable(mParallaxHelper.getCoverImageDrawable());
 
-        mMediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ALL);
-        mMediaPlayerGlue.setArtist("A Googleer");
-        mMediaPlayerGlue.setTitle("Diving with Sharks");
-        mMediaPlayerGlue.setVideoUrl("http://techslides.com/demos/sample-videos/small.mp4");
+            mMediaPlayerGlue.setMode(MediaPlayerGlue.REPEAT_ALL);
+            mMediaPlayerGlue.setArtist("A Googleer");
+            mMediaPlayerGlue.setTitle("Diving with Sharks");
+            mMediaPlayerGlue.setVideoUrl("http://techslides.com/demos/sample-videos/small.mp4");
+
+        }
 
         final Context context = getActivity();
         setBadgeDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_title,
                 context.getTheme()));
         setTitle("Leanback Sample App");
-        setOnSearchClickedListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
-                startActivity(intent);
-            }
-        });
+        if (!TEST_BACKGROUND_PLAYER) {
+            setOnSearchClickedListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View view) {
+                    Intent intent = new Intent(getActivity(), SearchSupportActivity.class);
+                    startActivity(intent);
+                }
+            });
+        }
 
         mActionPlay = new Action(ACTION_PLAY, "Play");
         mActionRent = new Action(ACTION_RENT, "Rent", "$3.99", ResourcesCompat.getDrawable(
@@ -168,12 +172,7 @@
         ps.addClassPresenter(ListRow.class, new ListRowPresenter());
 
         mRowsAdapter = new ArrayObjectAdapter(ps);
-
-        PhotoItem item = (PhotoItem) (savedInstanceState != null ?
-                savedInstanceState.getParcelable(ITEM) : null);
-        if (item != null) {
-            setItem(item);
-        }
+        updateAdapter();
 
         setOnItemViewClickedListener(new OnItemViewClickedListener() {
             @Override
@@ -226,9 +225,19 @@
         return view;
     }
 
+    public void setBackgroundVideo(boolean backgroundVideo) {
+        TEST_BACKGROUND_PLAYER = backgroundVideo;
+    }
+
     public void setItem(PhotoItem photoItem) {
         mPhotoItem = photoItem;
+        updateAdapter();
+    }
 
+    void updateAdapter() {
+        if (mRowsAdapter == null) {
+            return;
+        }
         mRowsAdapter.clear();
         new Handler().postDelayed(new Runnable() {
             public void run() {
@@ -298,6 +307,8 @@
     @Override
     public void onStop() {
         super.onStop();
-        mMediaPlayerGlue.pause();
+        if (TEST_BACKGROUND_PLAYER) {
+            mMediaPlayerGlue.pause();
+        }
     }
 }
diff --git a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java
index f51513c..b806a9a 100644
--- a/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java
+++ b/samples/SupportLeanbackDemos/src/com/example/android/leanback/PlaybackOverlaySupportFragment.java
@@ -140,7 +140,6 @@
                 mGlue.setInitialized(true);
             }
         }, MEDIA_PREPARATION_DELAY);
-
         mGlue.setOnItemViewClickedListener(mOnItemViewClickedListener);
 
         mPlaybackControlsRowPresenter = mGlue.createControlsRowAndPresenter();
diff --git a/v17/leanback/src/android/support/v17/leanback/app/DetailsFragment.java b/v17/leanback/src/android/support/v17/leanback/app/DetailsFragment.java
index 214ae64..fcb3fa9 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/DetailsFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/DetailsFragment.java
@@ -191,6 +191,7 @@
             getChildFragmentManager().beginTransaction()
                     .replace(R.id.details_rows_dock, mRowsFragment).commit();
         }
+        installTitleView(inflater, mRootView, savedInstanceState);
         mRowsFragment.setAdapter(mAdapter);
         mRowsFragment.setOnItemViewSelectedListener(mOnItemViewSelectedListener);
         mRowsFragment.setOnItemViewClickedListener(mOnItemViewClickedListener);
@@ -378,8 +379,11 @@
 
     void onRowSelected(int selectedPosition, int selectedSubPosition) {
         ObjectAdapter adapter = getAdapter();
-        if (adapter == null || adapter.size() == 0
-                || (selectedPosition == 0 && selectedSubPosition == 0)) {
+        if (( mRowsFragment != null && mRowsFragment.getView() != null
+                && mRowsFragment.getView().hasFocus())
+                && (adapter == null || adapter.size() == 0
+                || (getVerticalGridView().getSelectedPosition() == 0
+                && getVerticalGridView().getSelectedSubPosition() == 0))) {
             showTitle(true);
         } else {
             showTitle(false);
@@ -548,20 +552,31 @@
         mRootView.setOnFocusSearchListener(new BrowseFrameLayout.OnFocusSearchListener() {
             @Override
             public View onFocusSearch(View focused, int direction) {
-                if (mVideoFragment == null) {
-                    return null;
-                }
                 if (mRowsFragment.getVerticalGridView() != null
                         && mRowsFragment.getVerticalGridView().hasFocus()) {
                     if (direction == View.FOCUS_UP) {
-                        slideOutGridView();
-                        return mVideoFragment.getView();
+                        if (mVideoFragment != null && mVideoFragment.getView() != null) {
+                            slideOutGridView();
+                            showTitle(false);
+                            return mVideoFragment.getView();
+                        } else if (getTitleView() != null) {
+                            return getTitleView();
+                        }
                     }
-                } else if (mVideoFragment.getView() != null
+                } else if (mVideoFragment != null && mVideoFragment.getView() != null
                         && mVideoFragment.getView().hasFocus()) {
                     if (direction == View.FOCUS_DOWN) {
-                        slideInGridView();
-                        return mRowsFragment.getVerticalGridView();
+                        if (mRowsFragment.getVerticalGridView() != null) {
+                            showTitle(true);
+                            slideInGridView();
+                            return mRowsFragment.getVerticalGridView();
+                        }
+                    }
+                } else if (getTitleView() != null && getTitleView().hasFocus()) {
+                    if (direction == View.FOCUS_DOWN) {
+                        if (mRowsFragment.getVerticalGridView() != null) {
+                            return mRowsFragment.getVerticalGridView();
+                        }
                     }
                 }
                 return focused;
@@ -579,6 +594,7 @@
                 if (mVideoFragment != null && mVideoFragment.getView() != null
                         && mVideoFragment.getView().hasFocus()) {
                     if (keyCode == KeyEvent.KEYCODE_BACK) {
+                        showTitle(true);
                         slideInGridView();
                         getVerticalGridView().requestFocus();
                         return true;
diff --git a/v17/leanback/src/android/support/v17/leanback/app/DetailsSupportFragment.java b/v17/leanback/src/android/support/v17/leanback/app/DetailsSupportFragment.java
index a969f1c..a9bbf28 100644
--- a/v17/leanback/src/android/support/v17/leanback/app/DetailsSupportFragment.java
+++ b/v17/leanback/src/android/support/v17/leanback/app/DetailsSupportFragment.java
@@ -194,6 +194,7 @@
             getChildFragmentManager().beginTransaction()
                     .replace(R.id.details_rows_dock, mRowsSupportFragment).commit();
         }
+        installTitleView(inflater, mRootView, savedInstanceState);
         mRowsSupportFragment.setAdapter(mAdapter);
         mRowsSupportFragment.setOnItemViewSelectedListener(mOnItemViewSelectedListener);
         mRowsSupportFragment.setOnItemViewClickedListener(mOnItemViewClickedListener);
@@ -381,8 +382,11 @@
 
     void onRowSelected(int selectedPosition, int selectedSubPosition) {
         ObjectAdapter adapter = getAdapter();
-        if (adapter == null || adapter.size() == 0
-                || (selectedPosition == 0 && selectedSubPosition == 0)) {
+        if (( mRowsSupportFragment != null && mRowsSupportFragment.getView() != null
+                && mRowsSupportFragment.getView().hasFocus())
+                && (adapter == null || adapter.size() == 0
+                || (getVerticalGridView().getSelectedPosition() == 0
+                && getVerticalGridView().getSelectedSubPosition() == 0))) {
             showTitle(true);
         } else {
             showTitle(false);
@@ -551,20 +555,31 @@
         mRootView.setOnFocusSearchListener(new BrowseFrameLayout.OnFocusSearchListener() {
             @Override
             public View onFocusSearch(View focused, int direction) {
-                if (mVideoSupportFragment == null) {
-                    return null;
-                }
                 if (mRowsSupportFragment.getVerticalGridView() != null
                         && mRowsSupportFragment.getVerticalGridView().hasFocus()) {
                     if (direction == View.FOCUS_UP) {
-                        slideOutGridView();
-                        return mVideoSupportFragment.getView();
+                        if (mVideoSupportFragment != null && mVideoSupportFragment.getView() != null) {
+                            slideOutGridView();
+                            showTitle(false);
+                            return mVideoSupportFragment.getView();
+                        } else if (getTitleView() != null) {
+                            return getTitleView();
+                        }
                     }
-                } else if (mVideoSupportFragment.getView() != null
+                } else if (mVideoSupportFragment != null && mVideoSupportFragment.getView() != null
                         && mVideoSupportFragment.getView().hasFocus()) {
                     if (direction == View.FOCUS_DOWN) {
-                        slideInGridView();
-                        return mRowsSupportFragment.getVerticalGridView();
+                        if (mRowsSupportFragment.getVerticalGridView() != null) {
+                            showTitle(true);
+                            slideInGridView();
+                            return mRowsSupportFragment.getVerticalGridView();
+                        }
+                    }
+                } else if (getTitleView() != null && getTitleView().hasFocus()) {
+                    if (direction == View.FOCUS_DOWN) {
+                        if (mRowsSupportFragment.getVerticalGridView() != null) {
+                            return mRowsSupportFragment.getVerticalGridView();
+                        }
                     }
                 }
                 return focused;
@@ -582,6 +597,7 @@
                 if (mVideoSupportFragment != null && mVideoSupportFragment.getView() != null
                         && mVideoSupportFragment.getView().hasFocus()) {
                     if (keyCode == KeyEvent.KEYCODE_BACK) {
+                        showTitle(true);
                         slideInGridView();
                         getVerticalGridView().requestFocus();
                         return true;
diff --git a/v17/leanback/tests/java/android/support/v17/leanback/app/DetailsFragmentTest.java b/v17/leanback/tests/java/android/support/v17/leanback/app/DetailsFragmentTest.java
index c6662ab..c24a7e5 100644
--- a/v17/leanback/tests/java/android/support/v17/leanback/app/DetailsFragmentTest.java
+++ b/v17/leanback/tests/java/android/support/v17/leanback/app/DetailsFragmentTest.java
@@ -16,6 +16,7 @@
 package android.support.v17.leanback.app;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import android.content.Intent;
 import android.graphics.Rect;
@@ -87,6 +88,9 @@
                 bitmapDrawable.getBounds().height());
         assertEquals(0, bitmapDrawable.getVerticalOffset());
 
+        assertTrue("TitleView is visible", detailsFragment.getView()
+                .findViewById(R.id.browse_title_group).getVisibility() == View.VISIBLE);
+
         activityTestRule.runOnUiThread(new Runnable() {
             @Override
             public void run() {
@@ -97,7 +101,9 @@
         PollingCheck.waitFor(4000, new PollingCheck.PollingCheckCondition() {
             @Override
             public boolean canProceed() {
-                return bitmapDrawable.getVerticalOffset() == mDefaultVerticalOffset;
+                return bitmapDrawable.getVerticalOffset() == mDefaultVerticalOffset
+                        && detailsFragment.getView()
+                        .findViewById(R.id.browse_title_group).getVisibility() != View.VISIBLE;
             }
         });