From 11c4b2c51ef2c6e215cc5838bf640868580ea59d Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Tue, 8 Jun 2021 16:55:51 +0800 Subject: [PATCH] Remove the large space when searching region list Collapse the tool bar when we're doing search for a better user experience. And we don't allow user can expand the tool bar at this moment since it will see a large space at this moment. Fix: 181741353 Test: Open the page and don't see a huge space now. Change-Id: Iec5ebe9b22a2aad15dc8cf90113a64c358ee447e --- .../datetime/timezone/BaseTimeZonePicker.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java index dca597f16dc..6032abd9b17 100644 --- a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java +++ b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java @@ -27,6 +27,7 @@ import android.widget.LinearLayout; import android.widget.SearchView; import android.widget.TextView; +import androidx.core.view.ViewCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -35,6 +36,8 @@ import com.android.settings.core.InstrumentedFragment; import com.android.settings.datetime.timezone.model.TimeZoneData; import com.android.settings.datetime.timezone.model.TimeZoneDataLoader; +import com.google.android.material.appbar.AppBarLayout; + import java.util.Locale; /** @@ -43,12 +46,15 @@ import java.util.Locale; * The search matches the prefix of words in the search text. */ public abstract class BaseTimeZonePicker extends InstrumentedFragment - implements SearchView.OnQueryTextListener { + implements SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener { public static final String EXTRA_RESULT_REGION_ID = "com.android.settings.datetime.timezone.result_region_id"; public static final String EXTRA_RESULT_TIME_ZONE_ID = "com.android.settings.datetime.timezone.result_time_zone_id"; + + protected AppBarLayout mAppBarLayout; + private final int mTitleResId; private final int mSearchHintResId; private final boolean mSearchEnabled; @@ -88,6 +94,7 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, /* reverseLayout */ false)); mRecyclerView.setAdapter(mAdapter); + mAppBarLayout = getActivity().findViewById(R.id.app_bar); // Initialize TimeZoneDataLoader only when mRecyclerView is ready to avoid race // during onDateLoaderReady callback. @@ -121,6 +128,7 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment inflater.inflate(R.menu.time_zone_base_search_menu, menu); final MenuItem searchMenuItem = menu.findItem(R.id.time_zone_search_menu); + searchMenuItem.setOnActionExpandListener(this); mSearchView = (SearchView) searchMenuItem.getActionView(); mSearchView.setQueryHint(getText(mSearchHintResId)); @@ -148,6 +156,21 @@ public abstract class BaseTimeZonePicker extends InstrumentedFragment } } + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + // To prevent a large space on tool bar. + mAppBarLayout.setExpanded(false /*expanded*/, false /*animate*/); + // To prevent user can expand the collpasing tool bar view. + ViewCompat.setNestedScrollingEnabled(mRecyclerView, false); + return true; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + ViewCompat.setNestedScrollingEnabled(mRecyclerView, true); + return true; + } + @Override public boolean onQueryTextSubmit(String query) { return false;