Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 084b6b03 authored by Alex Stetson's avatar Alex Stetson Committed by Automerger Merge Worker
Browse files

Merge "Car Settings Search Bar UI" into rvc-dev am: a0a1a9f9

Change-Id: I63b087cbfdbb345f935708c6266cd75da0d82fd2
parents 4df2aa74 a0a1a9f9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ android_app {
    privileged: true,
    required: ["privapp_whitelist_com.android.settings.intelligence"],

    libs: ["android.car-stubs"],
    static_libs: [
        "androidx.legacy_legacy-support-v4",
        "androidx.legacy_legacy-support-v13",
@@ -30,6 +31,7 @@ android_app {
        "androidx.preference_preference",
        "androidx.recyclerview_recyclerview",
        "androidx.legacy_legacy-preference-v14",
        "car-ui-lib",
    ],
    resource_dirs: ["res"],
    srcs: [
+2 −1
Original line number Diff line number Diff line
## People who can approve changes

# Android auto
rlagos@google.com
rlagos@google.com # OWNER for SUW related code
ericberglund@google.com # OWNER for Car Settings related code

# TV Settings
leifhendrik@google.com
+2 −0
Original line number Diff line number Diff line
@@ -22,4 +22,6 @@
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="Theme.CarSettings" parent="@style/Theme.CarUi.WithToolbar"/>
</resources>
 No newline at end of file
+21 −0
Original line number Diff line number Diff line
<?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.
  -->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:title="@string/app_name_settings_intelligence"/>
+90 −0
Original line number Diff line number Diff line
/*
 * 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.android.settings.intelligence.search;

import static com.android.car.ui.core.CarUi.requireInsets;
import static com.android.car.ui.core.CarUi.requireToolbar;

import android.os.Bundle;

import com.android.car.ui.preference.PreferenceFragment;
import com.android.car.ui.toolbar.ToolbarController;
import com.android.settings.intelligence.R;
import com.android.car.ui.toolbar.MenuItem;
import com.android.car.ui.toolbar.Toolbar;

import java.util.Collections;
import java.util.List;

/**
 * Search fragment for car settings
 */
public class CarSearchFragment extends PreferenceFragment {

    private MenuItem mClearHistoryButton;

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.car_search_fragment, rootKey);
    }

    protected ToolbarController getToolbar() {
        return requireToolbar(requireActivity());
    }

    protected List<MenuItem> getToolbarMenuItems() {
        return Collections.singletonList(mClearHistoryButton);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mClearHistoryButton = new MenuItem.Builder(getContext())
                .setTitle(R.string.search_clear_history)
                .setDisplayBehavior(MenuItem.DisplayBehavior.NEVER)
                .setOnClickListener(i -> onClearHistoryButtonClicked())
                .build();
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ToolbarController toolbar = getToolbar();
        if (toolbar != null) {
            List<MenuItem> items = getToolbarMenuItems();
            toolbar.setTitle(getPreferenceScreen().getTitle());
            toolbar.setMenuItems(items);
            toolbar.setNavButtonMode(Toolbar.NavButtonMode.BACK);
            toolbar.setState(Toolbar.State.SUBPAGE);
            toolbar.setState(Toolbar.State.SEARCH);
            toolbar.setSearchHint(R.string.abc_search_hint);
            toolbar.registerOnSearchListener(this::onQueryTextChange);
            toolbar.setShowMenuItemsWhileSearching(true);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        onCarUiInsetsChanged(requireInsets(requireActivity()));
    }

    private void onQueryTextChange(String query) {}

    private void onClearHistoryButtonClicked() {}
}
Loading