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

Commit 0a8ab3a5 authored by Tsung-Mao Fang's avatar Tsung-Mao Fang Committed by Android (Google) Code Review
Browse files

Merge "Remove the large space when searching region list" into sc-dev

parents b62dedf9 11c4b2c5
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -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;