Merge "Add KitchenSink entry for window insets" into rvc-qpr-dev
diff --git a/tests/EmbeddedKitchenSinkApp/res/layout/window_insets_fragment.xml b/tests/EmbeddedKitchenSinkApp/res/layout/window_insets_fragment.xml
new file mode 100644
index 0000000..5533668
--- /dev/null
+++ b/tests/EmbeddedKitchenSinkApp/res/layout/window_insets_fragment.xml
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 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.
+  -->
+<ScrollView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/content"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:fadeScrollbars="false">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Control Status Bar Insets"/>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+
+            <Button
+                android:id="@+id/show_status_bar_insets"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Show Status Bar Insets"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/hide_status_bar_insets"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Hide Status Bar Insets"
+                android:textSize="30sp"/>
+
+        </LinearLayout>
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Control Navigation Bar Insets"/>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+
+            <Button
+                android:id="@+id/show_nav_bar_insets"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Show Navigation Bar Insets"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/hide_nav_bar_insets"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Hide Navigation Bar Insets"
+                android:textSize="30sp"/>
+
+        </LinearLayout>
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Control System Bar Insets (both Status and Navigation)"/>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+
+            <Button
+                android:id="@+id/show_system_bar_insets"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Show System Bar Insets"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/hide_system_bar_insets"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Hide System Bar Insets"
+                android:textSize="30sp"/>
+
+        </LinearLayout>
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Set System Bar Behavior"/>
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+
+            <Button
+                android:id="@+id/show_bars_by_touch"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Show By Touch"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/show_bars_by_swipe"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Show By Swipe"
+                android:textSize="30sp"/>
+
+            <Button
+                android:id="@+id/show_transient_bars_by_swipe"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_margin="10dp"
+                android:text="Show Transient By Swipe"
+                android:textSize="30sp"/>
+
+        </LinearLayout>
+
+    </LinearLayout>
+</ScrollView>
\ No newline at end of file
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
index 20dd9fc..e883501 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
@@ -56,6 +56,7 @@
 import com.google.android.car.kitchensink.displayinfo.DisplayInfoFragment;
 import com.google.android.car.kitchensink.experimental.ExperimentalFeatureTestFragment;
 import com.google.android.car.kitchensink.hvac.HvacTestFragment;
+import com.google.android.car.kitchensink.insets.WindowInsetsFragment;
 import com.google.android.car.kitchensink.notification.NotificationFragment;
 import com.google.android.car.kitchensink.orientation.OrientationTestFragment;
 import com.google.android.car.kitchensink.packageinfo.PackageInfoFragment;
@@ -198,7 +199,8 @@
             new FragmentMenuEntry("vehicle ctrl", VehicleCtrlFragment.class),
             new FragmentMenuEntry("vehicle hal", VehicleHalFragment.class),
             new FragmentMenuEntry("volume test", VolumeTestFragment.class),
-            new FragmentMenuEntry("web links", WebLinksTestFragment.class));
+            new FragmentMenuEntry("web links", WebLinksTestFragment.class),
+            new FragmentMenuEntry("window insets", WindowInsetsFragment.class));
 
     private Car mCarApi;
     private CarHvacManager mHvacManager;
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/insets/WindowInsetsFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/insets/WindowInsetsFragment.java
new file mode 100644
index 0000000..f4d52cf
--- /dev/null
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/insets/WindowInsetsFragment.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2020 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.google.android.car.kitchensink.insets;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowInsets;
+import android.view.WindowInsetsController;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
+import com.google.android.car.kitchensink.R;
+
+/** Test fragment for controlling window insets. */
+public final class WindowInsetsFragment extends Fragment {
+
+    private WindowInsetsController mWindowInsetsController;
+
+    @Nullable
+    @Override
+    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+            @Nullable Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.window_insets_fragment, container,
+                /* attachToRoot= */ false);
+    }
+
+    @Override
+    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        mWindowInsetsController = view.getWindowInsetsController();
+        initStatusBarInsetsButtons(view);
+        initNavigationBarInsetsButtons(view);
+        initSystemBarInsetsButtons(view);
+        initSystemBarBehaviorButtons(view);
+    }
+
+    private void initStatusBarInsetsButtons(View view) {
+        view.findViewById(R.id.show_status_bar_insets).setOnClickListener(
+                v -> mWindowInsetsController.show(WindowInsets.Type.statusBars()));
+        view.findViewById(R.id.hide_status_bar_insets).setOnClickListener(
+                v -> mWindowInsetsController.hide(WindowInsets.Type.statusBars()));
+    }
+
+    private void initNavigationBarInsetsButtons(View view) {
+        view.findViewById(R.id.show_nav_bar_insets).setOnClickListener(
+                v -> mWindowInsetsController.show(WindowInsets.Type.navigationBars()));
+        view.findViewById(R.id.hide_nav_bar_insets).setOnClickListener(
+                v -> mWindowInsetsController.hide(WindowInsets.Type.navigationBars()));
+    }
+
+    private void initSystemBarInsetsButtons(View view) {
+        view.findViewById(R.id.show_system_bar_insets).setOnClickListener(
+                v -> mWindowInsetsController.show(WindowInsets.Type.systemBars()));
+        view.findViewById(R.id.hide_system_bar_insets).setOnClickListener(
+                v -> mWindowInsetsController.hide(WindowInsets.Type.systemBars()));
+    }
+
+    private void initSystemBarBehaviorButtons(View view) {
+        view.findViewById(R.id.show_bars_by_touch).setOnClickListener(
+                v -> mWindowInsetsController.setSystemBarsBehavior(
+                        WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH));
+        view.findViewById(R.id.show_bars_by_swipe).setOnClickListener(
+                v -> mWindowInsetsController.setSystemBarsBehavior(
+                        WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE));
+        view.findViewById(R.id.show_transient_bars_by_swipe).setOnClickListener(
+                v -> mWindowInsetsController.setSystemBarsBehavior(
+                        WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE));
+    }
+}