Merge "Extend FragmentActivity instead of AppCompatActivity in CarSettingActivity." into pi-car-dev
diff --git a/res/layout/add_wifi.xml b/res/layout/add_wifi.xml
index 0786fd2..c7edf03 100644
--- a/res/layout/add_wifi.xml
+++ b/res/layout/add_wifi.xml
@@ -30,8 +30,7 @@
             style="@style/TextAppearance.Car.Body1.SingleLine" />
         <com.google.android.material.textfield.TextInputLayout
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:theme="@style/Theme.AppCompat.Light">
+            android:layout_height="wrap_content">
             <EditText
                 android:id="@+id/wifi_name_input"
                 android:layout_width="match_parent"
@@ -44,8 +43,7 @@
     <com.google.android.material.textfield.TextInputLayout
         android:id="@+id/wifi_password_wrapper"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:theme="@style/Theme.AppCompat.Light">
+        android:layout_height="wrap_content">
         <EditText
             android:id="@+id/wifi_password"
             android:layout_width="match_parent"
diff --git a/res/layout/app_compat_activity.xml b/res/layout/car_setting_activity.xml
similarity index 87%
rename from res/layout/app_compat_activity.xml
rename to res/layout/car_setting_activity.xml
index d186653..8189cd8 100644
--- a/res/layout/app_compat_activity.xml
+++ b/res/layout/car_setting_activity.xml
@@ -17,16 +17,13 @@
 
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
-    <androidx.appcompat.widget.Toolbar
-        android:id="@+id/toolbar"
+    <FrameLayout
+        android:id="@+id/action_bar"
         android:layout_width="match_parent"
-        android:layout_height="@dimen/car_app_bar_height"
-        app:contentInsetStart="0dp"
-        style="@style/ActionBarStyle.Car" />
+        android:layout_height="@dimen/car_app_bar_height"/>
     <View
         android:layout_width="match_parent"
         android:layout_height="@dimen/car_list_divider_height"
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0f9c792..3aa586e 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -52,10 +52,6 @@
         <item name="android:windowExitAnimation">@anim/trans_fade_out</item>
     </style>
 
-    <style name="ActionBarStyle.Car" parent="Widget.Car.Toolbar">
-        <item name="actionBarSize">@dimen/car_app_bar_height</item>
-    </style>
-
     <style name="TrimmedHorizontalProgressBar" parent="android:Widget.Material.ProgressBar.Horizontal">
         <item name="android:indeterminateDrawable">@drawable/progress_indeterminate_horizontal_material_trimmed</item>
         <item name="android:minHeight">3dp</item>
diff --git a/src/com/android/car/settings/common/BaseFragment.java b/src/com/android/car/settings/common/BaseFragment.java
index ac37a77..360fc64 100644
--- a/src/com/android/car/settings/common/BaseFragment.java
+++ b/src/com/android/car/settings/common/BaseFragment.java
@@ -22,14 +22,12 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.FrameLayout;
 import android.widget.TextView;
 
 import androidx.annotation.LayoutRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.StringRes;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar;
 import androidx.fragment.app.Fragment;
 
 import com.android.car.settings.R;
@@ -59,7 +57,6 @@
 
         /**
          * Pops the top off the fragment stack.
-         * @return {@code false} if there's no stack to pop, {@code true} otherwise
          */
         void goBack();
 
@@ -165,15 +162,16 @@
     }
 
     /**
-     * Should be used to override fragment's title.
-     * Should be called after {@code super.onActivityCreated}, so that it's called AFTER the default title
-     * setter.
+     * Should be used to override fragment's title. Should be called after
+     * {@link #onActivityCreated}, so that it's called after the default title setter.
      *
      * @param title CharSequence to set as the new title.
      */
     protected final void setTitle(CharSequence title) {
-        TextView titleView = getActivity().findViewById(R.id.title);
-        titleView.setText(title);
+        TextView titleView = requireActivity().findViewById(R.id.title);
+        if (titleView != null) {
+            titleView.setText(title);
+        }
     }
 
     /**
@@ -192,20 +190,15 @@
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        // Soon AppCompatActivity will no longer be used in Settings
-        if (getActivity() instanceof AppCompatActivity) {
-            ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
-            actionBar.setDisplayHomeAsUpEnabled(false);
-            actionBar.setCustomView(mActionBarLayout);
-            actionBar.setDisplayShowCustomEnabled(true);
-            // make the toolbar take the whole width.
-            Toolbar toolbar = (Toolbar) actionBar.getCustomView().getParent();
-            toolbar.setPadding(0, 0, 0, 0);
-        }
+        FrameLayout actionBarContainer = requireActivity().findViewById(R.id.action_bar);
+        if (actionBarContainer != null) {
+            actionBarContainer.removeAllViews();
+            getLayoutInflater().inflate(mActionBarLayout, actionBarContainer);
 
-        getActivity().findViewById(R.id.action_bar_icon_container).setOnClickListener(
-                v -> onBackPressed());
-        TextView titleView = getActivity().findViewById(R.id.title);
-        titleView.setText(mTitleId);
+            TextView titleView = actionBarContainer.requireViewById(R.id.title);
+            titleView.setText(mTitleId);
+            actionBarContainer.requireViewById(R.id.action_bar_icon_container).setOnClickListener(
+                    v -> onBackPressed());
+        }
     }
 }
diff --git a/src/com/android/car/settings/common/CarSettingActivity.java b/src/com/android/car/settings/common/CarSettingActivity.java
index b4b2c31..8ccd66a 100644
--- a/src/com/android/car/settings/common/CarSettingActivity.java
+++ b/src/com/android/car/settings/common/CarSettingActivity.java
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License
  */
+
 package com.android.car.settings.common;
 
 import android.annotation.Nullable;
@@ -26,8 +27,7 @@
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Toast;
 
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar;
+import androidx.fragment.app.FragmentActivity;
 import androidx.fragment.app.FragmentManager.OnBackStackChangedListener;
 
 import com.android.car.settings.R;
@@ -39,8 +39,9 @@
  * Base activity class for car settings, provides a action bar with a back button that goes to
  * previous activity.
  */
-public class CarSettingActivity extends AppCompatActivity implements
-        BaseFragment.FragmentController, UXRestrictionsProvider, OnBackStackChangedListener{
+public class CarSettingActivity extends FragmentActivity implements BaseFragment.FragmentController,
+        UXRestrictionsProvider, OnBackStackChangedListener {
+
     private CarUxRestrictionsHelper mUxRestrictionsHelper;
     private View mRestrictedMessage;
     // Default to minimum restriction.
@@ -53,9 +54,7 @@
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.app_compat_activity);
-        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
-        setSupportActionBar(toolbar);
+        setContentView(R.layout.car_setting_activity);
         if (mUxRestrictionsHelper == null) {
             mUxRestrictionsHelper =
                     new CarUxRestrictionsHelper(this, carUxRestrictions -> {
@@ -125,7 +124,7 @@
         getSupportFragmentManager()
                 .beginTransaction()
                 .setCustomAnimations(
-                        R.animator.trans_right_in ,
+                        R.animator.trans_right_in,
                         R.animator.trans_left_out,
                         R.animator.trans_left_in,
                         R.animator.trans_right_out)
@@ -160,7 +159,7 @@
     }
 
     private void hideKeyboard() {
-        InputMethodManager imm = (InputMethodManager)this.getSystemService(
+        InputMethodManager imm = (InputMethodManager) this.getSystemService(
                 Context.INPUT_METHOD_SERVICE);
         imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
     }
diff --git a/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java b/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java
index 9e9929a..e963ef8 100644
--- a/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java
+++ b/tests/robotests/src/com/android/car/settings/testutils/BaseTestActivity.java
@@ -19,17 +19,15 @@
 import android.car.drivingstate.CarUxRestrictions;
 import android.os.Bundle;
 
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar;
+import androidx.fragment.app.FragmentActivity;
 
 import com.android.car.settings.R;
 import com.android.car.settings.common.BaseFragment;
 
 /**
- * Test activity that extends {@link AppCompatActivity}.
- * Used for testing {@code BaseFragment} instances.
+ * Test activity used for testing {@code BaseFragment} instances.
  */
-public class BaseTestActivity extends AppCompatActivity implements
+public class BaseTestActivity extends FragmentActivity implements
         BaseFragment.FragmentController,
         BaseFragment.UXRestrictionsProvider {
     private boolean mOnBackPressedFlag;
@@ -37,9 +35,7 @@
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.app_compat_activity);
-        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
-        setSupportActionBar(toolbar);
+        setContentView(R.layout.car_setting_activity);
     }
 
     /**