Adds RecyclerView in a CoordinatorLayout w/ a collapsing app bar.

Bug: 330062053
Test: No tests, just sample
Change-Id: If659f93e8c2fcde9e50c47500a8d84e5e23fef16
diff --git a/samples/Support4Demos/src/main/AndroidManifest.xml b/samples/Support4Demos/src/main/AndroidManifest.xml
index 59c0a48..c3cfdba 100644
--- a/samples/Support4Demos/src/main/AndroidManifest.xml
+++ b/samples/Support4Demos/src/main/AndroidManifest.xml
@@ -449,6 +449,17 @@
         </activity>
 
         <activity
+            android:name=".widget.RecyclerViewWithCollapsingToolbarActivity"
+            android:exported="true"
+            android:theme="@style/Theme.AppCompat.Light"
+            android:label="@string/recycler_view_with_collapsing_toolbar">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
+        <activity
             android:name=".graphics.RoundedBitmapDrawableActivity"
             android:exported="true"
             android:label="Graphics/RoundedBitmapDrawable">
diff --git a/samples/Support4Demos/src/main/java/com/example/android/supportv4/widget/RecyclerViewWithCollapsingToolbarActivity.java b/samples/Support4Demos/src/main/java/com/example/android/supportv4/widget/RecyclerViewWithCollapsingToolbarActivity.java
new file mode 100644
index 0000000..dbcd566
--- /dev/null
+++ b/samples/Support4Demos/src/main/java/com/example/android/supportv4/widget/RecyclerViewWithCollapsingToolbarActivity.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2024 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.supportv4.widget;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.example.android.supportv4.R;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
+
+import org.jspecify.annotations.NonNull;
+import org.jspecify.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Demonstrates the use of recycler view in nested scrolling (testing scrolling with a keyboard).
+ * See the associated layout file for details.
+ */
+public class RecyclerViewWithCollapsingToolbarActivity extends AppCompatActivity {
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_recycler_view_with_collapsing_toolbar);
+
+        CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar_layout);
+        collapsingToolbar.setTitle(
+                getResources().getString(R.string.preference_screen_collapsing_appbar_title)
+        );
+        collapsingToolbar.setContentScrimColor(getResources().getColor(R.color.color1));
+
+        RecyclerView recyclerView = findViewById(R.id.recycler_view);
+        recyclerView.setLayoutManager(new LinearLayoutManager(this));
+
+        List<String> data = new ArrayList<String>();
+        for (int index = 0; index < 14; index++) {
+            data.add(String.valueOf(index));
+        }
+
+        MyAdapter adapter = new MyAdapter(data);
+        recyclerView.setAdapter(adapter);
+    }
+
+    public static class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
+        private final List<String> mDataForItems;
+
+        public MyAdapter(@NonNull List<String> items) {
+            this.mDataForItems = items;
+        }
+
+        public static class ViewHolder extends RecyclerView.ViewHolder {
+            @NonNull public TextView textViewHeader;
+            @NonNull public TextView textViewSubHeader;
+
+            public ViewHolder(@NonNull View itemView) {
+                super(itemView);
+                textViewHeader = itemView.findViewById(R.id.textViewHeader);
+                textViewSubHeader = itemView.findViewById(R.id.textViewSubHeader);
+            }
+        }
+
+        @Override
+        public MyAdapter.@NonNull ViewHolder onCreateViewHolder(
+                @NonNull ViewGroup parent,
+                int viewType
+        ) {
+            View itemView = LayoutInflater.from(parent.getContext()).inflate(
+                    R.layout.recycler_view_with_collapsing_toolbar_list_item,
+                    parent,
+                    false
+            );
+            return new ViewHolder(itemView);
+        }
+
+        @Override
+        public void onBindViewHolder(
+                MyAdapter.@NonNull ViewHolder holder,
+                int position
+        ) {
+            String number = mDataForItems.get(position);
+
+            holder.textViewHeader.setText(number);
+            holder.textViewSubHeader.setText("Sub Header for " + number);
+        }
+
+        @Override
+        public int getItemCount() {
+            return mDataForItems.size();
+        }
+    }
+}
diff --git a/samples/Support4Demos/src/main/res/layout/activity_recycler_view_with_collapsing_toolbar.xml b/samples/Support4Demos/src/main/res/layout/activity_recycler_view_with_collapsing_toolbar.xml
new file mode 100644
index 0000000..7078a3d
--- /dev/null
+++ b/samples/Support4Demos/src/main/res/layout/activity_recycler_view_with_collapsing_toolbar.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright 2024 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.
+-->
+<androidx.coordinatorlayout.widget.CoordinatorLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:fitsSystemWindows="true"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".widget.RecyclerViewWithCollapsingToolbarActivity">
+
+    <!-- App Bar -->
+    <com.google.android.material.appbar.AppBarLayout
+        android:layout_width="match_parent"
+        android:layout_height="200dp">
+
+        <com.google.android.material.appbar.CollapsingToolbarLayout
+            android:id="@+id/collapsing_toolbar_layout"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            app:expandedTitleMarginStart="48dp"
+            app:expandedTitleMarginEnd="64dp"
+            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
+
+            <View android:layout_width="match_parent"
+                android:layout_height="200dp"
+                android:background="@color/color2"/>
+
+            <androidx.appcompat.widget.Toolbar
+                android:id="@+id/toolbar"
+                android:layout_width="match_parent"
+                android:layout_height="?attr/actionBarSize"
+                app:layout_collapseMode="pin" />
+        </com.google.android.material.appbar.CollapsingToolbarLayout>
+    </com.google.android.material.appbar.AppBarLayout>
+
+    <!-- Content -->
+    <FrameLayout
+        android:layout_height="match_parent"
+        android:layout_width="match_parent"
+        android:orientation="vertical"
+        app:layout_behavior="@string/appbar_scrolling_view_behavior">
+
+            <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/recycler_view"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+            </androidx.recyclerview.widget.RecyclerView>
+    </FrameLayout>
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/samples/Support4Demos/src/main/res/layout/recycler_view_with_collapsing_toolbar_list_item.xml b/samples/Support4Demos/src/main/res/layout/recycler_view_with_collapsing_toolbar_list_item.xml
new file mode 100644
index 0000000..675980c
--- /dev/null
+++ b/samples/Support4Demos/src/main/res/layout/recycler_view_with_collapsing_toolbar_list_item.xml
@@ -0,0 +1,34 @@
+<!--
+  Copyright (C) 2024 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:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:padding="16dp"
+    android:focusable="true">
+
+    <TextView
+        android:id="@+id/textViewHeader"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="24sp" />
+
+    <TextView
+        android:id="@+id/textViewSubHeader"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="14sp" />
+</LinearLayout>
diff --git a/samples/Support4Demos/src/main/res/values/strings.xml b/samples/Support4Demos/src/main/res/values/strings.xml
index e9624cb..08b2848 100644
--- a/samples/Support4Demos/src/main/res/values/strings.xml
+++ b/samples/Support4Demos/src/main/res/values/strings.xml
@@ -244,6 +244,9 @@
     <string name="regular">regular</string>
     <string name="round">round</string>
 
+    <string name="recycler_view_with_collapsing_toolbar">Widget/RecyclerView with Collapsing Appbar</string>
+    <string name="recycler_view_with_collapsing_toolbar_title">Header</string>
+
     <string name="drawable_compat_no_tint">Not tint</string>
     <string name="drawable_compat_color_tint">Color tint</string>
     <string name="drawable_compat_color_list_tint">Color state list</string>