implements View.OnClickListener, OnItemSelectedListener, SearchView.OnQueryTextListener {
static final String TAG = "ManageApplications";
- static final boolean DEBUG = true;
+ static final boolean DEBUG = false;
// Intent extras.
public static final String EXTRA_CLASSNAME = "classname";
private static final String EXTRA_HAS_ENTRIES = "hasEntries";
private static final String EXTRA_HAS_BRIDGE = "hasBridge";
private static final String EXTRA_FILTER_TYPE = "filterType";
+ private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
// attributes used as keys when passing values to AppInfoDashboardFragment activity
public static final String APP_CHG = "chg";
FilterSpinnerAdapter mFilterAdapter;
@VisibleForTesting
RecyclerView mRecyclerView;
+ // Whether or not search view is expanded.
+ @VisibleForTesting
+ boolean mExpandSearch;
private View mRootView;
private Spinner mFilterSpinner;
mFilter = appFilterRegistry.get(appFilterRegistry.getDefaultFilterType(mListType));
mIsWorkOnly = args != null ? args.getBoolean(EXTRA_WORK_ONLY) : false;
mWorkUserId = args != null ? args.getInt(EXTRA_WORK_ID) : NO_USER_SPECIFIED;
+ mExpandSearch = activity.getIntent().getBooleanExtra(EXTRA_EXPAND_SEARCH_VIEW, false);
if (savedInstanceState != null) {
mSortOrder = savedInstanceState.getInt(EXTRA_SORT_ORDER, mSortOrder);
mShowSystem = savedInstanceState.getBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
mFilterType =
savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL);
+ mExpandSearch = savedInstanceState.getBoolean(EXTRA_EXPAND_SEARCH_VIEW);
}
mInvalidSizeStr = activity.getText(R.string.invalid_size_value);
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
outState.putBoolean(EXTRA_HAS_BRIDGE, mApplications.mHasReceivedBridgeCallback);
+ outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
outState.putInt(EXTRA_FILTER_TYPE, mFilter.getFilterType());
if (mApplications != null) {
mApplications.onSaveInstanceState(outState);
mSearchView = (SearchView) searchMenuItem.getActionView();
mSearchView.setQueryHint(getText(R.string.search_settings));
mSearchView.setOnQueryTextListener(this);
+ if (mExpandSearch) {
+ searchMenuItem.expandActionView();
+ }
}
updateOptionsMenu();
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_DRAGGING;
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
-import static com.android.settings.applications.manageapplications.AppFilterRegistry
- .FILTER_APPS_ALL;
-import static com.android.settings.applications.manageapplications.ManageApplications
- .LIST_TYPE_MAIN;
-import static com.android.settings.applications.manageapplications.ManageApplications
- .LIST_TYPE_NOTIFICATION;
+import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL;
+import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
+import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_NOTIFICATION;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
when(searchMenu.getActionView()).thenReturn(searchView);
when(mMenu.findItem(R.id.search_app_list_menu)).thenReturn(searchMenu);
when(mMenu.add(anyInt() /* groupId */, anyInt() /* itemId */, anyInt() /* order */,
- anyInt() /* titleRes */)).thenReturn(helpMenu);
+ anyInt() /* titleRes */)).thenReturn(helpMenu);
doReturn("Test").when(mFragment).getText(anyInt() /* resId */);
doNothing().when(mFragment).updateOptionsMenu();
}
@Test
+ public void onCreateOptionsMenu_hasExpandSearchFlag_shouldExpandSearchView() {
+ final SearchView searchView = mock(SearchView.class);
+ final MenuItem searchMenu = mock(MenuItem.class);
+ final MenuItem helpMenu = mock(MenuItem.class);
+ when(searchMenu.getActionView()).thenReturn(searchView);
+ when(mMenu.findItem(R.id.search_app_list_menu)).thenReturn(searchMenu);
+ when(mMenu.add(anyInt() /* groupId */, anyInt() /* itemId */, anyInt() /* order */,
+ anyInt() /* titleRes */)).thenReturn(helpMenu);
+ doReturn("Test").when(mFragment).getText(anyInt() /* resId */);
+ doNothing().when(mFragment).updateOptionsMenu();
+
+ mFragment.mExpandSearch = true;
+ mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));
+
+ verify(searchMenu).expandActionView();
+ }
+
+ @Test
public void onQueryTextChange_shouldFilterSearchInApplicationsAdapter() {
final ManageApplications.ApplicationsAdapter adapter =
- mock(ManageApplications.ApplicationsAdapter.class);
+ mock(ManageApplications.ApplicationsAdapter.class);
final String query = "Test App";
ReflectionHelpers.setField(mFragment, "mApplications", adapter);
when(listContainer.getVisibility()).thenReturn(View.VISIBLE);
ReflectionHelpers.setField(mFragment, "mListContainer", listContainer);
ReflectionHelpers.setField(
- mFragment, "mFilterAdapter", mock(ManageApplications.FilterSpinnerAdapter.class));
+ mFragment, "mFilterAdapter", mock(ManageApplications.FilterSpinnerAdapter.class));
final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
appList.add(mock(ApplicationsState.AppEntry.class));
final ManageApplications.ApplicationsAdapter adapter =
- spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
- AppFilterRegistry.getInstance().get(FILTER_APPS_ALL),
- null /* savedInstanceState */));
+ spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
+ AppFilterRegistry.getInstance().get(FILTER_APPS_ALL),
+ null /* savedInstanceState */));
adapter.onRebuildComplete(appList);
ReflectionHelpers.setField(holder, "itemView", mock(View.class));
ManageApplications.ApplicationsAdapter adapter =
new ManageApplications.ApplicationsAdapter(mState,
- mFragment, mock(AppFilterItem.class),
+ mFragment, mock(AppFilterItem.class),
mock(Bundle.class));
final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
@Test
public void applicationsAdapter_filterSearch_emptyQuery_shouldShowFullList() {
final ManageApplications.ApplicationsAdapter adapter =
- new ManageApplications.ApplicationsAdapter(
- mState, mFragment, mock(AppFilterItem.class), Bundle.EMPTY);
+ new ManageApplications.ApplicationsAdapter(
+ mState, mFragment, mock(AppFilterItem.class), Bundle.EMPTY);
final String[] appNames = {"Apricot", "Banana", "Cantaloupe", "Fig", "Mango"};
ReflectionHelpers.setField(adapter, "mOriginalEntries", getTestAppList(appNames));
@Test
public void applicationsAdapter_filterSearch_noMatch_shouldShowEmptyList() {
final ManageApplications.ApplicationsAdapter adapter =
- new ManageApplications.ApplicationsAdapter(
- mState, mFragment, mock(AppFilterItem.class), Bundle.EMPTY);
+ new ManageApplications.ApplicationsAdapter(
+ mState, mFragment, mock(AppFilterItem.class), Bundle.EMPTY);
final String[] appNames = {"Apricot", "Banana", "Cantaloupe", "Fig", "Mango"};
ReflectionHelpers.setField(adapter, "mOriginalEntries", getTestAppList(appNames));
@Test
public void applicationsAdapter_filterSearch_shouldShowMatchedItemsOnly() {
final ManageApplications.ApplicationsAdapter adapter =
- new ManageApplications.ApplicationsAdapter(
- mState, mFragment, mock(AppFilterItem.class), Bundle.EMPTY);
+ new ManageApplications.ApplicationsAdapter(
+ mState, mFragment, mock(AppFilterItem.class), Bundle.EMPTY);
final String[] appNames = {"Apricot", "Banana", "Cantaloupe", "Fig", "Mango"};
ReflectionHelpers.setField(adapter, "mOriginalEntries", getTestAppList(appNames));