Loading res/layout-sw720dp/activity.xml +2 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ android:layout_height="match_parent" android:orientation="vertical"> <Toolbar <com.android.documentsui.DocumentsToolBar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?android:attr/actionBarSize" Loading @@ -34,7 +34,7 @@ android:layout_marginStart="4dp" android:overlapAnchor="true" /> </Toolbar> </com.android.documentsui.DocumentsToolBar> <LinearLayout android:layout_width="match_parent" Loading res/layout/activity.xml +2 −2 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ android:layout_height="match_parent" android:orientation="vertical"> <Toolbar <com.android.documentsui.DocumentsToolBar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?android:attr/actionBarSize" Loading @@ -39,7 +39,7 @@ android:layout_marginStart="4dp" android:overlapAnchor="true" /> </Toolbar> </com.android.documentsui.DocumentsToolBar> <com.android.documentsui.DirectoryContainerView android:id="@+id/container_directory" Loading src/com/android/documentsui/BaseActivity.java +28 −6 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ abstract class BaseActivity extends Activity { boolean showMenu = super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.activity, menu); mSearchManager.install(menu.findItem(R.id.menu_search)); mSearchManager.install((DocumentsToolBar) findViewById(R.id.toolbar)); return showMenu; } Loading Loading @@ -690,19 +690,24 @@ abstract class BaseActivity extends Activity { * Facade over the various search parts in the menu. */ final class SearchManager implements SearchView.OnCloseListener, OnActionExpandListener, OnQueryTextListener { SearchView.OnCloseListener, OnActionExpandListener, OnQueryTextListener, DocumentsToolBar.OnActionViewCollapsedListener { private boolean mSearchExpanded; private boolean mIgnoreNextClose; private boolean mIgnoreNextCollapse; private DocumentsToolBar mActionBar; private MenuItem mMenu; private SearchView mView; public void install(MenuItem menu) { mMenu = menu; mView = (SearchView) menu.getActionView(); public void install(DocumentsToolBar actionBar) { assert(mActionBar == null); mActionBar = actionBar; mMenu = actionBar.getSearchMenu(); mView = (SearchView) mMenu.getActionView(); mActionBar.setOnActionViewCollapsedListener(this); mMenu.setOnActionExpandListener(this); mView.setOnQueryTextListener(this); mView.setOnCloseListener(this); Loading Loading @@ -753,6 +758,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() { return getDisplayState().currentSearch != null; } Loading Loading @@ -788,7 +806,6 @@ abstract class BaseActivity extends Activity { mIgnoreNextCollapse = false; return true; } getDisplayState().currentSearch = null; onCurrentDirectoryChanged(ANIM_NONE); return true; Loading @@ -807,5 +824,10 @@ abstract class BaseActivity extends Activity { public boolean onQueryTextChange(String newText) { return false; } @Override public void onActionViewCollapsed() { updateActionBar(); } } } src/com/android/documentsui/DocumentsActivity.java +10 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,11 @@ import static com.android.documentsui.DirectoryFragment.ANIM_DOWN; import static com.android.documentsui.DirectoryFragment.ANIM_NONE; import static com.android.documentsui.DirectoryFragment.ANIM_UP; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import android.app.ActionBar; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; Loading Loading @@ -499,6 +504,11 @@ public class DocumentsActivity extends BaseActivity { @Override public void onBackPressed() { // While action bar is expanded, the state stack UI is hidden. if (mSearchManager.cancelSearch()) { return; } if (!mState.stackTouched) { super.onBackPressed(); return; Loading src/com/android/documentsui/DocumentsToolBar.java 0 → 100644 +72 −0 Original line number 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); } } Loading
res/layout-sw720dp/activity.xml +2 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ android:layout_height="match_parent" android:orientation="vertical"> <Toolbar <com.android.documentsui.DocumentsToolBar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?android:attr/actionBarSize" Loading @@ -34,7 +34,7 @@ android:layout_marginStart="4dp" android:overlapAnchor="true" /> </Toolbar> </com.android.documentsui.DocumentsToolBar> <LinearLayout android:layout_width="match_parent" Loading
res/layout/activity.xml +2 −2 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ android:layout_height="match_parent" android:orientation="vertical"> <Toolbar <com.android.documentsui.DocumentsToolBar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?android:attr/actionBarSize" Loading @@ -39,7 +39,7 @@ android:layout_marginStart="4dp" android:overlapAnchor="true" /> </Toolbar> </com.android.documentsui.DocumentsToolBar> <com.android.documentsui.DirectoryContainerView android:id="@+id/container_directory" Loading
src/com/android/documentsui/BaseActivity.java +28 −6 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ abstract class BaseActivity extends Activity { boolean showMenu = super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.activity, menu); mSearchManager.install(menu.findItem(R.id.menu_search)); mSearchManager.install((DocumentsToolBar) findViewById(R.id.toolbar)); return showMenu; } Loading Loading @@ -690,19 +690,24 @@ abstract class BaseActivity extends Activity { * Facade over the various search parts in the menu. */ final class SearchManager implements SearchView.OnCloseListener, OnActionExpandListener, OnQueryTextListener { SearchView.OnCloseListener, OnActionExpandListener, OnQueryTextListener, DocumentsToolBar.OnActionViewCollapsedListener { private boolean mSearchExpanded; private boolean mIgnoreNextClose; private boolean mIgnoreNextCollapse; private DocumentsToolBar mActionBar; private MenuItem mMenu; private SearchView mView; public void install(MenuItem menu) { mMenu = menu; mView = (SearchView) menu.getActionView(); public void install(DocumentsToolBar actionBar) { assert(mActionBar == null); mActionBar = actionBar; mMenu = actionBar.getSearchMenu(); mView = (SearchView) mMenu.getActionView(); mActionBar.setOnActionViewCollapsedListener(this); mMenu.setOnActionExpandListener(this); mView.setOnQueryTextListener(this); mView.setOnCloseListener(this); Loading Loading @@ -753,6 +758,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() { return getDisplayState().currentSearch != null; } Loading Loading @@ -788,7 +806,6 @@ abstract class BaseActivity extends Activity { mIgnoreNextCollapse = false; return true; } getDisplayState().currentSearch = null; onCurrentDirectoryChanged(ANIM_NONE); return true; Loading @@ -807,5 +824,10 @@ abstract class BaseActivity extends Activity { public boolean onQueryTextChange(String newText) { return false; } @Override public void onActionViewCollapsed() { updateActionBar(); } } }
src/com/android/documentsui/DocumentsActivity.java +10 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,11 @@ import static com.android.documentsui.DirectoryFragment.ANIM_DOWN; import static com.android.documentsui.DirectoryFragment.ANIM_NONE; import static com.android.documentsui.DirectoryFragment.ANIM_UP; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import android.app.ActionBar; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; Loading Loading @@ -499,6 +504,11 @@ public class DocumentsActivity extends BaseActivity { @Override public void onBackPressed() { // While action bar is expanded, the state stack UI is hidden. if (mSearchManager.cancelSearch()) { return; } if (!mState.stackTouched) { super.onBackPressed(); return; Loading
src/com/android/documentsui/DocumentsToolBar.java 0 → 100644 +72 −0 Original line number 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); } }