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

Commit e577ef07 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Update visibility of the stack dropdown list after the search view is collapsed.

Previously we hid the stack dropdown list just before the action bar is
collapsed. Then the dropdown list gets back to be visible when the action bar is
collapsed.

The CL updates visibility of the stack dropdown list just after the action bar
is collapsed.

BUG=20945584
Change-Id: Iaf5055bce101f8134accd311829e50f441ddc98b
parent 584aeaa6
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@
    android:layout_height="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    android:orientation="vertical">


    <Toolbar
    <com.android.documentsui.DocumentsToolBar
        android:id="@+id/toolbar"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_height="?android:attr/actionBarSize"
@@ -34,7 +34,7 @@
            android:layout_marginStart="4dp"
            android:layout_marginStart="4dp"
            android:overlapAnchor="true" />
            android:overlapAnchor="true" />


    </Toolbar>
    </com.android.documentsui.DocumentsToolBar>


    <LinearLayout
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_width="match_parent"
+2 −2
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@
        android:layout_height="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        android:orientation="vertical">


        <Toolbar
        <com.android.documentsui.DocumentsToolBar
            android:id="@+id/toolbar"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:layout_height="?android:attr/actionBarSize"
@@ -39,7 +39,7 @@
                android:layout_marginStart="4dp"
                android:layout_marginStart="4dp"
                android:overlapAnchor="true" />
                android:overlapAnchor="true" />


        </Toolbar>
        </com.android.documentsui.DocumentsToolBar>


        <com.android.documentsui.DirectoryContainerView
        <com.android.documentsui.DirectoryContainerView
            android:id="@+id/container_directory"
            android:id="@+id/container_directory"
+28 −7
Original line number Original line Diff line number Diff line
@@ -101,7 +101,7 @@ abstract class BaseActivity extends Activity {
        boolean showMenu = super.onCreateOptionsMenu(menu);
        boolean showMenu = super.onCreateOptionsMenu(menu);


        getMenuInflater().inflate(R.menu.activity, menu);
        getMenuInflater().inflate(R.menu.activity, menu);
        mSearchManager.install(menu.findItem(R.id.menu_search));
        mSearchManager.install((DocumentsToolBar) findViewById(R.id.toolbar));


        return showMenu;
        return showMenu;
    }
    }
@@ -666,20 +666,24 @@ 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, OnActionExpandListener, OnQueryTextListener,
            DocumentsToolBar.OnActionViewCollapsedListener {


        private boolean mSearchExpanded;
        private boolean mSearchExpanded;
        private boolean mIgnoreNextClose;
        private boolean mIgnoreNextClose;
        private boolean mIgnoreNextCollapse;
        private boolean mIgnoreNextCollapse;


        private DocumentsToolBar mActionBar;
        private MenuItem mMenu;
        private MenuItem mMenu;
        private SearchView mView;
        private SearchView mView;


        public void install(MenuItem menu) {
        public void install(DocumentsToolBar actionBar) {
            assert(mMenu == null);
            assert(mActionBar == null);
            mMenu = menu;
            mActionBar = actionBar;
            mView = (SearchView) menu.getActionView();
            mMenu = actionBar.getSearchMenu();
            mView = (SearchView) mMenu.getActionView();


            mActionBar.setOnActionViewCollapsedListener(this);
            mMenu.setOnActionExpandListener(this);
            mMenu.setOnActionExpandListener(this);
            mView.setOnQueryTextListener(this);
            mView.setOnQueryTextListener(this);
            mView.setOnCloseListener(this);
            mView.setOnCloseListener(this);
@@ -730,6 +734,19 @@ abstract class BaseActivity extends Activity {
            }
            }
        }
        }


        /**
         * Cancels current search operation.
         * @return True if it cancels search. False if it does not operate
         *     search currently.
         */
        boolean cancelSearch() {
            if (mActionBar.hasExpandedActionView()) {
                mActionBar.collapseActionView();
                return true;
            }
            return false;
        }

        boolean isSearching() {
        boolean isSearching() {
            return getDisplayState().currentSearch != null;
            return getDisplayState().currentSearch != null;
        }
        }
@@ -765,7 +782,6 @@ abstract class BaseActivity extends Activity {
                mIgnoreNextCollapse = false;
                mIgnoreNextCollapse = false;
                return true;
                return true;
            }
            }

            getDisplayState().currentSearch = null;
            getDisplayState().currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
            return true;
@@ -784,5 +800,10 @@ abstract class BaseActivity extends Activity {
        public boolean onQueryTextChange(String newText) {
        public boolean onQueryTextChange(String newText) {
            return false;
            return false;
        }
        }

        @Override
        public void onActionViewCollapsed() {
            updateActionBar();
        }
    }
    }
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;
import java.util.List;


import android.app.ActionBar;
import android.app.Activity;
import android.app.Activity;
import android.app.Fragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentManager;
@@ -508,6 +509,11 @@ public class DocumentsActivity extends BaseActivity {


    @Override
    @Override
    public void onBackPressed() {
    public void onBackPressed() {
        // While action bar is expanded, the state stack UI is hidden.
        if (mSearchManager.cancelSearch()) {
            return;
        }

        if (!mState.stackTouched) {
        if (!mState.stackTouched) {
            super.onBackPressed();
            super.onBackPressed();
            return;
            return;
+72 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MenuItem;
import android.widget.Toolbar;

/**
 * ToolBar of Documents UI.
 */
public class DocumentsToolBar extends Toolbar {
    interface OnActionViewCollapsedListener {
        void onActionViewCollapsed();
    }

    private OnActionViewCollapsedListener mOnActionViewCollapsedListener;

    public DocumentsToolBar(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public DocumentsToolBar(Context context, AttributeSet attrs,
            int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DocumentsToolBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DocumentsToolBar(Context context) {
        super(context);
    }

    @Override
    public void collapseActionView() {
        super.collapseActionView();
        if (mOnActionViewCollapsedListener != null) {
            mOnActionViewCollapsedListener.onActionViewCollapsed();
        }
    }

    /**
     * Adds a listener that is invoked after collapsing the action view.
     * @param listener
     */
    public void setOnActionViewCollapsedListener(
            OnActionViewCollapsedListener listener) {
        mOnActionViewCollapsedListener = listener;
    }

    public MenuItem getSearchMenu() {
        return getMenu().findItem(R.id.menu_search);
    }
}