Loading src/com/android/documentsui/BaseActivity.java +6 −9 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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()); } } Loading src/com/android/documentsui/queries/SearchFragment.java +5 −26 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); } } Loading Loading @@ -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, ""); Loading @@ -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); } Loading @@ -161,7 +151,6 @@ public class SearchFragment extends Fragment{ mSearchViewManager.setHistorySearch(); mSearchViewManager.setCurrentSearch(item); mSearchViewManager.restoreSearch(true); dismissNextFrame(); } private void dismiss() { Loading @@ -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) { Loading src/com/android/documentsui/queries/SearchViewManager.java +17 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading Loading @@ -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. Loading Loading @@ -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; } Loading Loading
src/com/android/documentsui/BaseActivity.java +6 −9 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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()); } } Loading
src/com/android/documentsui/queries/SearchFragment.java +5 −26 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); } } Loading Loading @@ -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, ""); Loading @@ -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); } Loading @@ -161,7 +151,6 @@ public class SearchFragment extends Fragment{ mSearchViewManager.setHistorySearch(); mSearchViewManager.setCurrentSearch(item); mSearchViewManager.restoreSearch(true); dismissNextFrame(); } private void dismiss() { Loading @@ -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) { Loading
src/com/android/documentsui/queries/SearchViewManager.java +17 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading Loading @@ -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. Loading Loading @@ -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; } Loading