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

Commit d36445c3 authored by Tony Huang's avatar Tony Huang
Browse files

Fine tune search history UX and a11y

1. Show search history after the user clicked clear button on SearchView
2. Add content description on history delete button.
3. Add test and also fix related UI test fail.

Fix: 128889445
Test: manual
Test: atest DocumentsUIGoogleTests:
      com.android.documentsui.SearchViewUiTest#testSearch_NoResults
Change-Id: Id91bebca9f1eba6a8b890519f2f83b4348ca8538
parent 558cdbd2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -454,4 +454,7 @@

    <!-- Search hint on search view. [CHAR LIMIT=48] -->
    <string name="search_bar_hint">Search this phone</string>

    <!-- Content description for deleting search history. [CHAR_LIMIT=60] -->
    <string name="delete_search_history">Delete the search history <xliff:g id="text" example="image">%1$s</xliff:g></string>
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -211,6 +211,14 @@ public abstract class BaseActivity
                            mSearchManager.getSearchViewText());
                }
            }

            @Override
            public void onSearchViewClearClicked() {
                if (SearchFragment.get(getSupportFragmentManager()) == null) {
                    SearchFragment.showFragment(getSupportFragmentManager(),
                            mSearchManager.getSearchViewText());
                }
            }
        };

        // "Commands" are meta input for controlling system behavior.
+16 −5
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public class SearchFragment extends DialogFragment
    private SearchView mSearchView;
    private ViewGroup mSearchChipGroup;
    private ListView mListView;
    private ArrayAdapter<String> mAdapter;

    private List<String> mHistoryList;

@@ -121,7 +122,7 @@ public class SearchFragment extends DialogFragment
        mSearchView.setQuery(currentQuery, false);
        mSearchView.setOnQueryTextListener(this);
        mHistoryList = SearchHistoryManager.getInstance(
                mSearchView.getContext().getApplicationContext()).getHistoryList(currentQuery);
                getContext().getApplicationContext()).getHistoryList(currentQuery);

        mSearchViewManager.bindChips(mSearchChipGroup);
        if (mSearchChipGroup.getVisibility() == View.VISIBLE) {
@@ -130,7 +131,8 @@ public class SearchFragment extends DialogFragment
            }
        }

        mListView.setAdapter(new HistoryListAdapter(getContext(), mHistoryList));
        mAdapter = new HistoryListAdapter(getContext(), mHistoryList);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(this::onHistoryItemClicked);
    }

@@ -169,9 +171,16 @@ public class SearchFragment extends DialogFragment

    @Override
    public boolean onQueryTextChange(String s) {
        if (!TextUtils.isEmpty(mSearchView.getQuery())) {
            mSearchViewManager.setCurrentSearch(s);
            mSearchViewManager.restoreSearch(true);
            dismiss();
        } else {
            mHistoryList = SearchHistoryManager.getInstance(
                    mSearchView.getContext().getApplicationContext()).getHistoryList("");
            mAdapter.clear();
            mAdapter.addAll(mHistoryList);
        }
        return true;
    }

@@ -196,6 +205,8 @@ public class SearchFragment extends DialogFragment
                mHistoryList.remove(history);
                notifyDataSetChanged();
            });
            button.setContentDescription(
                    getContext().getString(R.string.delete_search_history, history));

            return convertView;
        }
+12 −0
Original line number Diff line number Diff line
@@ -215,6 +215,13 @@ public class SearchViewManager implements
        mSearchView.setOnCloseListener(this);
        mSearchView.setOnSearchClickListener(this);
        mSearchView.setOnQueryTextFocusChangeListener(this);
        final View clearButton = mSearchView.findViewById(R.id.search_close_btn);
        if (clearButton != null) {
            clearButton.setOnClickListener(v -> {
                mSearchView.setQuery("", false);
                mListener.onSearchViewClearClicked();
            });
        }

        mFullBar = isFullBarSearch;
        mSearchView.setMaxWidth(Integer.MAX_VALUE);
@@ -588,5 +595,10 @@ public class SearchViewManager implements
        void onSearchChipStateChanged(View v);

        void onSearchViewFocusChanged(boolean hasFocus);

        /**
         * Call back when search view clear button clicked
         */
        void onSearchViewClearClicked();
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;

import androidx.test.InstrumentationRegistry;

/**
 * Handy collection of bots for working with Files app.
 */
@@ -69,11 +71,15 @@ public final class Bots {
        public final UiDevice mDevice;
        final Context mContext;
        final int mTimeout;
        public final String mTargetPackage;

        BaseBot(UiDevice device, Context context, int timeout) {
            mDevice = device;
            mContext = context;
            mTimeout = timeout;
            mTargetPackage =
                    InstrumentationRegistry.getInstrumentation()
                            .getTargetContext().getPackageName();
        }

        /**
Loading