AOSP_Q版本设置-搜索流程

本文详细介绍了AOSP Q版本的设置搜索流程,包括界面、实现原理、添加搜索项和跳转方法。搜索界面在SettingsIntelligence项目中,初始化候选项涉及多个类和数据库操作。点击搜索项后,通过Intent启动对应界面,并使用动画效果进行平滑过渡。
摘要由CSDN通过智能技术生成

Q版本设置-搜索流程

前言

借鉴下面三篇O版本设置搜索流程的介绍排版,从界面,实现原理,如何新增搜索项和跳转方法这4个方面介绍Q版本的搜索流程。方便对比Q版本和O版本的区别
https://blog.csdn.net/qq_34149526/article/details/83341195
https://blog.csdn.net/qq_34149526/article/details/83378184
https://blog.csdn.net/qq_34149526/article/details/83414364

界面

位于Settings主界面布局文件settings_homepage_container.xml中:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/settings_homepage_container"
    ...>
...
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include layout="@layout/search_bar"/>
    </com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

搜索栏是否显示的逻辑:
SettingsHomepageActivity.java
——>onCreate():

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

...
        final Toolbar toolbar = findViewById(R.id.search_action_bar);
        FeatureFactory.getFactory(this).getSearchFeatureProvider()
                .initSearchToolbar(this /* activity */, toolbar, SettingsEnums.SETTINGS_HOMEPAGE);
...
    }

SearchFeatureProvider

    /**
     * Initializes the search toolbar.
     */
    default void initSearchToolbar(Activity activity, Toolbar toolbar, int pageId) {
   
  ...
        if (!Utils.isDeviceProvisioned(activity) ||
                !Utils.isPackageEnabled(activity, getSettingsIntelligencePkgName(activity))) {
   
            final ViewGroup parent = (ViewGroup) toolbar.getParent();
            if (parent != null) {
   
                parent.setVisibility(View.GONE);
            }
            return;
        }
        // Please forgive me for what I am about to do.
        //
        // Need to make the navigation icon non-clickable so that the entire card is clickable
        // and goes to the search UI. Also set the background to null so there's no ripple.
        final View navView = toolbar.getNavigationView();
        navView.setClickable(false);
        navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
        navView.setBackground(null);

        toolbar.setOnClickListener(tb -> {
   
            final Context context = activity.getApplicationContext();
            final Intent intent = buildSearchIntent(context, pageId);

            if (activity.getPackageManager().queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
   
                return;
            }

            FeatureFactory.getFactory(context).getSlicesFeatureProvider()
                    .indexSliceDataAsync(context);
            FeatureFactory.getFactory(context).getMetricsFeatureProvider()
                    .action(context, SettingsEnums.ACTION_SEARCH_RESULTS);
            activity.startActivityForResult(intent, REQUEST_CODE);
        });
    }



此处仅仅是按钮作用,实际是没有编辑框的。Q版本把搜索模块分出去了,不在Settings这个项目里面,分到了SettingsIntelligence(P版本之前都是在Settings项目内,版本之间改动都不大)

ps:这个模块还包含设置建议的功能

当点击搜索栏时会跳转到
packages/apps/SettingsIntelligence/src/com/android/settings/intelligence/search/SearchActivity.java

界面的显示在SearchFragment.java中实现:

布对应的布局文件search_panel.xml(与历史版本几乎一样):


                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值