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

Commit d3b8e520 authored by Aga Wronska's avatar Aga Wronska Committed by Android (Google) Code Review
Browse files

Merge "Keep Search View visible after search completed Improve Search View...

Merge "Keep Search View visible after search completed Improve Search View behavior Add Search View background color"
parents 04fc3542 97831485
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -15,11 +15,19 @@
-->
-->


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- showAsAction flag impacts the behavior of SearchView.
     When set to collapseActionView, collapsing SearchView to icon is the
     default behavior. It would fit UX, however after expanding SearchView is
     shown on the left site of the toolbar (replacing title). Since no way to
     prevent this behavior was found, the flag is set to always. SearchView is
     always visible by default and it is being collapse manually by calling
     setIconified() method
-->
    <item
    <item
        android:id="@+id/menu_search"
        android:id="@+id/menu_search"
        android:title="@string/menu_search"
        android:title="@string/menu_search"
        android:icon="@drawable/ic_menu_search"
        android:icon="@drawable/ic_menu_search"
        android:showAsAction="always|collapseActionView"
        android:showAsAction="always"
        android:actionViewClass="android.widget.SearchView"
        android:actionViewClass="android.widget.SearchView"
        android:imeOptions="actionSearch" />
        android:imeOptions="actionSearch" />
    <item
    <item
+2 −0
Original line number Original line Diff line number Diff line
@@ -33,4 +33,6 @@
    <color name="item_doc_background">#fffafafa</color>
    <color name="item_doc_background">#fffafafa</color>
    <color name="item_doc_background_selected">#ffe0f2f1</color>
    <color name="item_doc_background_selected">#ffe0f2f1</color>


    <color name="menu_search_background">#ff676f74</color>

</resources>
</resources>
+54 −33
Original line number Original line Diff line number Diff line
@@ -38,12 +38,14 @@ import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Root;
import android.provider.DocumentsContract.Root;
import android.support.annotation.LayoutRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem;
import android.view.MenuItem.OnActionExpandListener;
import android.view.View;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView.OnItemSelectedListener;
@@ -218,6 +220,7 @@ public abstract class BaseActivity extends Activity {
                case R.id.menu_advanced:
                case R.id.menu_advanced:
                case R.id.menu_file_size:
                case R.id.menu_file_size:
                case R.id.menu_new_window:
                case R.id.menu_new_window:
                case R.id.menu_search:
                    break;
                    break;
                default:
                default:
                    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
@@ -318,6 +321,8 @@ public abstract class BaseActivity extends Activity {
     * the (abstract) directoryChanged method will be called.
     * the (abstract) directoryChanged method will be called.
     * @param anim
     * @param anim
     */
     */
    // TODO: Refactor the usage of the method - now it is called not only when the directory
    // changed, but also to refresh the content of the directory while searching
    final void onCurrentDirectoryChanged(int anim) {
    final void onCurrentDirectoryChanged(int anim) {
        mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
        mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
        onDirectoryChanged(anim);
        onDirectoryChanged(anim);
@@ -328,8 +333,12 @@ public abstract class BaseActivity extends Activity {
        }
        }


        updateActionBar();
        updateActionBar();

        // Prevents searchView from being recreated while searching
        if (!mSearchManager.isSearching()) {
            invalidateOptionsMenu();
            invalidateOptionsMenu();
        }
        }
    }


    final List<String> getExcludedAuthorities() {
    final List<String> getExcludedAuthorities() {
        List<String> authorities = new ArrayList<>();
        List<String> authorities = new ArrayList<>();
@@ -720,7 +729,7 @@ public abstract class BaseActivity extends Activity {
     * Facade over the various search parts in the menu.
     * Facade over the various search parts in the menu.
     */
     */
    final class SearchManager implements
    final class SearchManager implements
            SearchView.OnCloseListener, OnActionExpandListener, OnQueryTextListener,
            SearchView.OnCloseListener, OnQueryTextListener, OnClickListener, OnFocusChangeListener,
            DocumentsToolBar.OnActionViewCollapsedListener {
            DocumentsToolBar.OnActionViewCollapsedListener {


        private boolean mSearchExpanded;
        private boolean mSearchExpanded;
@@ -738,9 +747,10 @@ public abstract class BaseActivity extends Activity {
            mView = (SearchView) mMenu.getActionView();
            mView = (SearchView) mMenu.getActionView();


            mActionBar.setOnActionViewCollapsedListener(this);
            mActionBar.setOnActionViewCollapsedListener(this);
            mMenu.setOnActionExpandListener(this);
            mView.setOnQueryTextListener(this);
            mView.setOnQueryTextListener(this);
            mView.setOnCloseListener(this);
            mView.setOnCloseListener(this);
            mView.setOnSearchClickListener(this);
            mView.setOnQueryTextFocusChangeListener(this);
        }
        }


        /**
        /**
@@ -793,19 +803,13 @@ public abstract class BaseActivity extends Activity {
         *     search currently.
         *     search currently.
         */
         */
        boolean cancelSearch() {
        boolean cancelSearch() {
            boolean collapsed = false;
            boolean closed = false;

            if (mActionBar.hasExpandedActionView()) {
                mActionBar.collapseActionView();
                collapsed = true;
            }

            if (isExpanded() || isSearching()) {
            if (isExpanded() || isSearching()) {
                onClose();
                // If the query string is not empty search view won't get iconified
                closed = true;
                mView.setQuery("", false);
                mView.setIconified(true);
                return true;
            }
            }
            return collapsed || closed;
            return false;
        }
        }


        boolean isSearching() {
        boolean isSearching() {
@@ -816,6 +820,11 @@ public abstract class BaseActivity extends Activity {
            return mSearchExpanded;
            return mSearchExpanded;
        }
        }


        /**
         * Clears the search.
         * @return True if the default behavior of clearing/dismissing SearchView should be
         *      overridden. False otherwise.
         */
        @Override
        @Override
        public boolean onClose() {
        public boolean onClose() {
            mSearchExpanded = false;
            mSearchExpanded = false;
@@ -824,33 +833,33 @@ public abstract class BaseActivity extends Activity {
                return false;
                return false;
            }
            }


            mView.setBackgroundColor(
                    getResources().getColor(android.R.color.transparent, null));

            // Refresh the directory if a search was done
            if(mState.currentSearch != null) {
                mState.currentSearch = null;
                mState.currentSearch = null;
                onCurrentDirectoryChanged(ANIM_NONE);
                onCurrentDirectoryChanged(ANIM_NONE);
            return false;
            }
            }


        @Override
            return false;
        public boolean onMenuItemActionExpand(MenuItem item) {
            mSearchExpanded = true;
            updateActionBar();
            return true;
        }
        }


        /**
         * Sets mSearchExpanded.
         * Called when search icon is clicked to start search.
         * Used to detect when the view expanded instead of onMenuItemActionExpand, because
         * SearchView has showAsAction set to always and onMenuItemAction* methods are not called.
         */
        @Override
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
        public void onClick (View v) {
            mSearchExpanded = false;
            mSearchExpanded = true;
            if (mIgnoreNextCollapse) {
            mView.setBackgroundColor(
                mIgnoreNextCollapse = false;
                    getResources().getColor(R.color.menu_search_background, null));
                return true;
            }
            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }
        }


        @Override
        @Override
        public boolean onQueryTextSubmit(String query) {
        public boolean onQueryTextSubmit(String query) {
            mSearchExpanded = true;
            mState.currentSearch = query;
            mState.currentSearch = query;
            mView.clearFocus();
            mView.clearFocus();
            onCurrentDirectoryChanged(ANIM_NONE);
            onCurrentDirectoryChanged(ANIM_NONE);
@@ -862,6 +871,18 @@ public abstract class BaseActivity extends Activity {
            return false;
            return false;
        }
        }


        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(!hasFocus) {
                if(mState.currentSearch == null) {
                    mView.setIconified(true);
                }
                else if(TextUtils.isEmpty(mView.getQuery())) {
                    cancelSearch();
                }
            }
        }

        @Override
        @Override
        public void onActionViewCollapsed() {
        public void onActionViewCollapsed() {
            updateActionBar();
            updateActionBar();
+0 −1
Original line number Original line Diff line number Diff line
@@ -407,7 +407,6 @@ public class DirectoryFragment extends Fragment implements DocumentsAdapter.Envi
                    state.derivedMode = result.mode;
                    state.derivedMode = result.mode;
                }
                }
                state.derivedSortOrder = result.sortOrder;
                state.derivedSortOrder = result.sortOrder;
                ((BaseActivity) context).onStateChanged();


                updateDisplayState();
                updateDisplayState();