Split Connectivity fragment to multiple pages/tabs

This also changes KS theme to material/androidx, what's required to use tabs.

Bug: 131323542
Test: open KS app and click around
Change-Id: Ia9b4a6920972ab2361c3b63efab5b552a65316cd
diff --git a/tests/EmbeddedKitchenSinkApp/Android.mk b/tests/EmbeddedKitchenSinkApp/Android.mk
index a0b27ab..c39fa9f 100644
--- a/tests/EmbeddedKitchenSinkApp/Android.mk
+++ b/tests/EmbeddedKitchenSinkApp/Android.mk
@@ -42,6 +42,8 @@
 
 LOCAL_STATIC_ANDROID_LIBRARIES += \
     car-service-lib-for-test \
+    com.google.android.material_material \
+    androidx.appcompat_appcompat \
     androidx.car_car-cluster
 
 LOCAL_STATIC_JAVA_LIBRARIES += \
diff --git a/tests/EmbeddedKitchenSinkApp/res/layout/connectivity_fragment.xml b/tests/EmbeddedKitchenSinkApp/res/layout/connectivity_fragment.xml
index dc2d01a..245ba03 100644
--- a/tests/EmbeddedKitchenSinkApp/res/layout/connectivity_fragment.xml
+++ b/tests/EmbeddedKitchenSinkApp/res/layout/connectivity_fragment.xml
@@ -14,122 +14,134 @@
      limitations under the License.
 -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:orientation="vertical"
-              android:layout_width="match_parent"
-              android:layout_height="match_parent">
+<androidx.viewpager.widget.ViewPager
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/connectivity_pager"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <com.google.android.material.tabs.TabLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="top" />
 
     <LinearLayout
+        android:tag="WiFi Control"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <LinearLayout
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_margin="4dp">
 
-        <TextView
+            <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="20dp"
                 android:text="Wifi:" />
 
-        <Button android:id="@+id/startWifi"
+            <Button android:id="@+id/startWifi"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="5dp"
                 android:text="Start" />
 
-        <Button android:id="@+id/stopWifi"
+            <Button android:id="@+id/stopWifi"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="20dp"
                 android:text="Stop" />
 
-        <TextView
+            <TextView
                 android:id="@+id/wifiStatusPolled"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" />
-    </LinearLayout>
+        </LinearLayout>
 
-    <LinearLayout
+        <LinearLayout
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_margin="4dp">
 
-        <TextView
+            <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="20dp"
                 android:text="Tethering:" />
 
-        <Button android:id="@+id/startTethering"
+            <Button android:id="@+id/startTethering"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="5dp"
                 android:text="Start" />
 
-        <Button android:id="@+id/stopTethering"
+            <Button android:id="@+id/stopTethering"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="20dp"
                 android:text="Stop" />
 
-        <TextView
+            <TextView
                 android:id="@+id/tetheringStatus"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="5dp" />
 
-        <TextView
+            <TextView
                 android:id="@+id/tetheringStatusPolled"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" />
-    </LinearLayout>
+        </LinearLayout>
 
-    <LinearLayout
+        <LinearLayout
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_margin="4dp">
 
-        <TextView
+            <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="20dp"
                 android:text="LocalOnly:" />
 
-        <Button android:id="@+id/startLocalOnly"
+            <Button android:id="@+id/startLocalOnly"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="5dp"
                 android:text="Start" />
 
-        <Button android:id="@+id/stopLocalOnly"
+            <Button android:id="@+id/stopLocalOnly"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="20dp"
                 android:text="Stop" />
 
-        <TextView
+            <TextView
                 android:id="@+id/localOnlyStatus"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" />
+        </LinearLayout>
     </LinearLayout>
 
-    <!-- List(s) of networks (right now only have view all, may do a search UI)
-    -->
     <LinearLayout
-            android:orientation="vertical"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent">
+        android:tag="Network list"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
 
         <!-- Header for table -->
         <LinearLayout
-                android:orientation="horizontal"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:paddingLeft="4dp"
-                android:background="#3C3F41"
-                android:weightSum="12">
+            android:orientation="horizontal"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingLeft="4dp"
+            android:background="#3C3F41"
+            android:weightSum="12">
 
             <TextView
                 android:layout_width="0dp"
@@ -138,8 +150,7 @@
                 android:textSize="32sp"
                 android:textColor="#d4d4d4"
                 android:textStyle="bold"
-                android:text="Net ID">
-            </TextView>
+                android:text="Net ID" />
 
             <TextView
                 android:layout_width="0dp"
@@ -148,8 +159,7 @@
                 android:textSize="32sp"
                 android:textColor="#d4d4d4"
                 android:textStyle="bold"
-                android:text="Details">
-            </TextView>
+                android:text="Details" />
 
             <TextView
                 android:layout_width="0dp"
@@ -158,8 +168,7 @@
                 android:textSize="32sp"
                 android:textColor="#d4d4d4"
                 android:textStyle="bold"
-                android:text="Functions">
-            </TextView>
+                android:text="Functions" />
 
         </LinearLayout>
 
@@ -171,12 +180,12 @@
 
             <!-- Filled in code with network_item.xml -->
             <ListView
-                    android:id="@+id/networks"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content">
-            </ListView>
+                android:id="@+id/networks"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content" />
 
         </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
 
     </LinearLayout>
-</LinearLayout>
+
+</androidx.viewpager.widget.ViewPager>
diff --git a/tests/EmbeddedKitchenSinkApp/res/layout/kitchen_activity.xml b/tests/EmbeddedKitchenSinkApp/res/layout/kitchen_activity.xml
index f0439c4..e6de221 100644
--- a/tests/EmbeddedKitchenSinkApp/res/layout/kitchen_activity.xml
+++ b/tests/EmbeddedKitchenSinkApp/res/layout/kitchen_activity.xml
@@ -26,7 +26,6 @@
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_marginBottom="10dp"
-        android:background="@android:color/background_light"
         android:text="Hide KitchenSink Menu"
         android:textSize="30sp"
         android:padding="15dp"/>
diff --git a/tests/EmbeddedKitchenSinkApp/res/values/styles.xml b/tests/EmbeddedKitchenSinkApp/res/values/styles.xml
index 908c051..65bdab1 100644
--- a/tests/EmbeddedKitchenSinkApp/res/values/styles.xml
+++ b/tests/EmbeddedKitchenSinkApp/res/values/styles.xml
@@ -34,6 +34,6 @@
         <item name="android:clickable">true</item>
     </style>
 
-    <style name="KitchenSinkActivityTheme" parent="android:Theme.DeviceDefault.NoActionBar">
+    <style name="KitchenSinkActivityTheme" parent="Theme.AppCompat.NoActionBar">
     </style>
 </resources>
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 a80c3b4..3bbc99e 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
@@ -159,8 +159,8 @@
             new FragmentMenuEntry("alert window", AlertDialogTestFragment.class),
             new FragmentMenuEntry("assistant", CarAssistantFragment.class),
             new FragmentMenuEntry("audio", AudioTestFragment.class),
-            new FragmentMenuEntry("bluetooth headset", BluetoothHeadsetFragment.class),
-            new FragmentMenuEntry("bluetooth messaging test", MapMceTestFragment.class),
+            new FragmentMenuEntry("BT headset", BluetoothHeadsetFragment.class),
+            new FragmentMenuEntry("BT messaging", MapMceTestFragment.class),
             new FragmentMenuEntry("carboard", KeyboardTestFragment.class),
             new FragmentMenuEntry("connectivity", ConnectivityFragment.class),
             new FragmentMenuEntry("cubes test", CubesTestFragment.class),
@@ -238,7 +238,7 @@
 
         mMenu = findViewById(R.id.menu);
         mMenu.setAdapter(new MenuAdapter(this));
-        mMenu.setLayoutManager(new GridLayoutManager(this, 3));
+        mMenu.setLayoutManager(new GridLayoutManager(this, 4));
 
         mMenuButton = findViewById(R.id.menu_button);
         mMenuButton.setOnClickListener(view -> toggleMenuVisibility());
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/SimplePagerAdapter.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/SimplePagerAdapter.java
new file mode 100644
index 0000000..aedd3dd
--- /dev/null
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/SimplePagerAdapter.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 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;
+
+import android.util.Pair;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.viewpager.widget.PagerAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SimplePagerAdapter extends PagerAdapter {
+    private final List<Pair<View, String>> mPages = new ArrayList<>();
+
+    public SimplePagerAdapter(ViewGroup container) {
+        for (int i = 0; i < container.getChildCount(); i++) {
+            final View child = container.getChildAt(i);
+            final Object tag = child.getTag();
+            if (!(tag instanceof String)) continue;
+            mPages.add(new Pair<>(child, (String) tag));
+        }
+    }
+
+    @Override
+    public Object instantiateItem(ViewGroup container, int position) {
+        return mPages.get(position).first;
+    }
+
+    @Override
+    public int getCount() {
+        return mPages.size();
+    }
+
+    @Override
+    public CharSequence getPageTitle(int position) {
+        return mPages.get(position).second;
+    }
+
+    @Override
+    public boolean isViewFromObject(View view, Object object) {
+        return view == object;
+    }
+}
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java
index 31b83cc..0306698 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/connectivity/ConnectivityFragment.java
@@ -45,8 +45,10 @@
 
 import androidx.fragment.app.Fragment;
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+import androidx.viewpager.widget.ViewPager;
 
 import com.google.android.car.kitchensink.R;
+import com.google.android.car.kitchensink.SimplePagerAdapter;
 
 import java.net.NetworkInterface;
 import java.net.SocketException;
@@ -468,6 +470,9 @@
             @Nullable Bundle savedInstanceState) {
         View view = inflater.inflate(R.layout.connectivity_fragment, container, false);
 
+        ViewPager pager = view.findViewById(R.id.connectivity_pager);
+        pager.setAdapter(new SimplePagerAdapter(pager));
+
         // Create the ListView of all networks
         ListView networksView = view.findViewById(R.id.networks);
         mNetworksAdapter = new NetworkListAdapter(getContext(), mNetworkItems, this);