diff options
Diffstat (limited to 'packages/DocumentsUI/src')
5 files changed, 155 insertions, 11 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index cb21131..bba33be 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.concurrent.Executor; @@ -32,6 +33,10 @@ import libcore.io.IoUtils; import android.app.Activity; import android.app.Fragment; import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.ProviderInfo; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; @@ -96,7 +101,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; } @@ -232,9 +237,38 @@ abstract class BaseActivity extends Activity { invalidateOptionsMenu(); } + final List<String> getExcludedAuthorities() { + List<String> authorities = new ArrayList<>(); + if (getIntent().getBooleanExtra(DocumentsContract.EXTRA_EXCLUDE_SELF, false)) { + // Exclude roots provided by the calling package. + String packageName = getCallingPackageMaybeExtra(); + try { + PackageInfo pkgInfo = getPackageManager().getPackageInfo(packageName, + PackageManager.GET_PROVIDERS); + for (ProviderInfo provider: pkgInfo.providers) { + authorities.add(provider.authority); + } + } catch (PackageManager.NameNotFoundException e) { + Log.e(mTag, "Calling package name does not resolve: " + packageName); + } + } + return authorities; + } + final String getCallingPackageMaybeExtra() { - final String extra = getIntent().getStringExtra(DocumentsContract.EXTRA_PACKAGE_NAME); - return (extra != null) ? extra : getCallingPackage(); + String callingPackage = getCallingPackage(); + // System apps can set the calling package name using an extra. + try { + ApplicationInfo info = getPackageManager().getApplicationInfo(callingPackage, 0); + if (info.isSystemApp() || info.isUpdatedSystemApp()) { + final String extra = getIntent().getStringExtra(DocumentsContract.EXTRA_PACKAGE_NAME); + if (extra != null) { + callingPackage = extra; + } + } + } finally { + return callingPackage; + } } public static BaseActivity get(Fragment fragment) { @@ -287,6 +321,9 @@ abstract class BaseActivity extends Activity { /** Currently copying file */ public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>(); + /** Name of the package that started DocsUI */ + public List<String> excludedAuthorities = new ArrayList<>(); + public static final int ACTION_OPEN = 1; public static final int ACTION_CREATE = 2; public static final int ACTION_GET_CONTENT = 3; @@ -327,6 +364,7 @@ abstract class BaseActivity extends Activity { out.writeString(currentSearch); out.writeMap(dirState); out.writeList(selectedDocumentsForCopy); + out.writeList(excludedAuthorities); } public static final Creator<State> CREATOR = new Creator<State>() { @@ -348,6 +386,7 @@ abstract class BaseActivity extends Activity { state.currentSearch = in.readString(); in.readMap(state.dirState, null); in.readList(state.selectedDocumentsForCopy, null); + in.readList(state.excludedAuthorities, null); return state; } @@ -627,20 +666,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) { - assert(mMenu == null); - 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); @@ -691,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() { return getDisplayState().currentSearch != null; } @@ -726,7 +782,6 @@ abstract class BaseActivity extends Activity { mIgnoreNextCollapse = false; return true; } - getDisplayState().currentSearch = null; onCurrentDirectoryChanged(ANIM_NONE); return true; @@ -745,5 +800,10 @@ abstract class BaseActivity extends Activity { public boolean onQueryTextChange(String newText) { return false; } + + @Override + public void onActionViewCollapsed() { + updateActionBar(); + } } } diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java index da59d0e..90ccf91 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java @@ -31,6 +31,7 @@ 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; @@ -256,6 +257,8 @@ public class DocumentsActivity extends BaseActivity { BaseActivity.DocumentsIntent.EXTRA_DIRECTORY_COPY, false); } + state.excludedAuthorities = getExcludedAuthorities(); + return state; } @@ -506,6 +509,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; diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsToolBar.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsToolBar.java new file mode 100644 index 0000000..36b7646 --- /dev/null +++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsToolBar.java @@ -0,0 +1,72 @@ +/* + * 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); + } +} diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java index 27e8f20..fbcb938 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +++ b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java @@ -383,6 +383,12 @@ public class RootsCache { continue; } + // Exclude roots from the calling package. + if (state.excludedAuthorities.contains(root.authority)) { + if (LOGD) Log.d(TAG, "Excluding root " + root.authority + " from calling package."); + continue; + } + matching.add(root); } return matching; diff --git a/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java b/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java index 97d8ed0..ecf4d6c 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java +++ b/packages/DocumentsUI/src/com/android/documentsui/model/RootInfo.java @@ -55,7 +55,6 @@ public class RootInfo implements Durable, Parcelable { public String mimeTypes; /** Derived fields that aren't persisted */ - public String derivedPackageName; public String[] derivedMimeTypes; public int derivedIcon; @@ -75,7 +74,6 @@ public class RootInfo implements Durable, Parcelable { availableBytes = -1; mimeTypes = null; - derivedPackageName = null; derivedMimeTypes = null; derivedIcon = 0; } |
