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

Commit 787106c0 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6484268 from 44fd2c85 to sc-d1-release

Change-Id: Id606d4639ef65e7c09aa5728e72486b06e4ca005
parents 27fe3b38 44fd2c85
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -175,10 +175,6 @@ public abstract class BaseActivity
             */
            @Override
            public void onSearchChanged(@Nullable String query) {
                if (query != null) {
                    SearchFragment.dismissFragmentNextFrame(getSupportFragmentManager());
                }

                if (mSearchManager.isSearching()) {
                    Metrics.logSearchMode(query != null, mSearchManager.hasCheckedChip());
                    if (mInjector.pickResult != null) {
@@ -227,12 +223,13 @@ public abstract class BaseActivity
                final boolean isInitailSearch
                        = !TextUtils.isEmpty(mSearchManager.getCurrentSearch())
                        && TextUtils.isEmpty(mSearchManager.getSearchViewText());
                if (hasFocus && (SearchFragment.get(getSupportFragmentManager()) == null)
                        && !isInitailSearch) {
                if (hasFocus) {
                    if (!isInitailSearch) {
                        SearchFragment.showFragment(getSupportFragmentManager(),
                                mSearchManager.getSearchViewText());
                    }
                } else {
                    SearchFragment.dismissFragmentNextFrame(getSupportFragmentManager());
                    SearchFragment.dismissFragment(getSupportFragmentManager());
                }
            }

+5 −26
Original line number Diff line number Diff line
@@ -17,11 +17,7 @@
package com.android.documentsui.queries;

import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -74,16 +70,10 @@ public class SearchFragment extends Fragment{
        ft.commitNow();
    }

    /**
     * Posts the dismissal of the dialog to the next frame of the main looper thread. This method
     * should be used in cases where the user is still searching, since it can avoid other elements
     * from flashing for a frame when they are reacting to the same state change (e.g.
     * http://b/153094528).
     */
    public static void dismissFragmentNextFrame(FragmentManager fm) {
    public static void dismissFragment(FragmentManager fm) {
        SearchFragment fragment = get(fm);
        if (fragment != null) {
            fragment.dismissNextFrame();
            fragment.dismiss();
        }
    }

@@ -113,6 +103,7 @@ public class SearchFragment extends Fragment{
        final BaseActivity activity = (BaseActivity) getActivity();
        final Injector injector = activity.getInjector();
        mSearchViewManager = injector.searchManager;
        mSearchViewManager.setFragmentManager(this.getParentFragmentManager());

        final String currentQuery = getArguments().getString(KEY_QUERY, "");

@@ -133,12 +124,11 @@ public class SearchFragment extends Fragment{
        View toolbar = getActivity().findViewById(R.id.toolbar_background_layout);
        if (toolbar != null) {
            // Align top with the bottom of search bar.
            Rect rect = new Rect();
            toolbar.getGlobalVisibleRect(rect);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
            layoutParams.setMargins(0, rect.height(), 0, 0);
            layoutParams.setMargins(0, getResources().getDimensionPixelSize(
                    R.dimen.action_bar_space_height), 0, 0);
            getView().setLayoutParams(layoutParams);
        }

@@ -161,7 +151,6 @@ public class SearchFragment extends Fragment{
        mSearchViewManager.setHistorySearch();
        mSearchViewManager.setCurrentSearch(item);
        mSearchViewManager.restoreSearch(true);
        dismissNextFrame();
    }

    private void dismiss() {
@@ -184,16 +173,6 @@ public class SearchFragment extends Fragment{
        }
    }

    /**
     * Posts the dismissal of the dialog to the next frame of the main looper thread. This method
     * should be used in cases where the user is still searching, since it can avoid other elements
     * from flashing for a frame when they are reacting to the same state change (e.g.
     * http://b/153094528).
     */
    private void dismissNextFrame() {
        new Handler(Looper.getMainLooper()).post(this::dismiss);
    }

    private class HistoryListAdapter extends ArrayAdapter<String> {

        public HistoryListAdapter(Context context, List<String> list) {
+17 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.SearchView.OnQueryTextListener;
import androidx.fragment.app.FragmentManager;

import com.android.documentsui.MetricConsts;
import com.android.documentsui.Metrics;
@@ -89,6 +90,7 @@ public class SearchViewManager implements
    private @Nullable Menu mMenu;
    private @Nullable MenuItem mMenuItem;
    private @Nullable SearchView mSearchView;
    private @Nullable FragmentManager mFragmentManager;

    public SearchViewManager(
            SearchManagerListener listener,
@@ -244,6 +246,10 @@ public class SearchViewManager implements
        restoreSearch(true);
    }

    public void setFragmentManager(FragmentManager fragmentManager) {
        mFragmentManager = fragmentManager;
    }

    /**
     * Used to hide menu icons, when the search is being restored. Needed because search restoration
     * is done before onPrepareOptionsMenu(Menu menu) that is overriding the icons visibility.
@@ -511,8 +517,17 @@ public class SearchViewManager implements
    @Override
    public boolean onQueryTextChange(String newText) {
        //Skip first search when search expanded
        if (!(mCurrentSearch == null && newText.isEmpty())) {
        if (mCurrentSearch == null && newText.isEmpty()) {
            return true;
        }

        performSearch(newText);
        if (mFragmentManager != null) {
            if (!newText.isEmpty()) {
                SearchFragment.dismissFragment(mFragmentManager);
            } else {
                SearchFragment.showFragment(mFragmentManager, "");
            }
        }
        return true;
    }