use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.
the class RootsFragment method onCurrentRootChanged.
public void onCurrentRootChanged() {
if (mAdapter == null) {
return;
}
final RootInfo root = ((BaseActivity) getActivity()).getCurrentRoot();
for (int i = 0; i < mAdapter.getCount(); i++) {
final Object item = mAdapter.getItem(i);
if (item instanceof RootItem) {
final RootInfo testRoot = ((RootItem) item).root;
if (Objects.equals(testRoot, root)) {
mList.setItemChecked(i, true);
mList.setSelection(i);
return;
}
}
}
}
use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.
the class RootsFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Context context = getActivity();
final RootsCache roots = DocumentsApplication.getRootsCache(context);
final State state = ((BaseActivity) context).getDisplayState();
mCallbacks = new LoaderCallbacks<Collection<RootInfo>>() {
@Override
public Loader<Collection<RootInfo>> onCreateLoader(int id, Bundle args) {
return new RootsLoader(context, roots, state);
}
@Override
public void onLoadFinished(Loader<Collection<RootInfo>> loader, Collection<RootInfo> result) {
if (!isAdded()) {
return;
}
Intent handlerAppIntent = getArguments().getParcelable(EXTRA_INCLUDE_APPS);
mAdapter = new RootsAdapter(context, result, handlerAppIntent, state);
mList.setAdapter(mAdapter);
onCurrentRootChanged();
}
@Override
public void onLoaderReset(Loader<Collection<RootInfo>> loader) {
mAdapter = null;
mList.setAdapter(null);
}
};
}
use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.
the class RootsCache method loadRootsForAuthority.
/**
* Bring up requested provider and query for all active roots.
*/
private Collection<RootInfo> loadRootsForAuthority(ContentResolver resolver, String authority, boolean forceRefresh) {
if (DEBUG)
Log.d(TAG, "Loading roots for " + authority);
synchronized (mObservedAuthorities) {
if (mObservedAuthorities.add(authority)) {
// Watch for any future updates
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
mContext.getContentResolver().registerContentObserver(rootsUri, true, mObserver);
}
}
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
if (!forceRefresh) {
// Look for roots data that we might have cached for ourselves in the
// long-lived system process.
final Bundle systemCache = resolver.getCache(rootsUri);
if (systemCache != null) {
if (DEBUG)
Log.d(TAG, "System cache hit for " + authority);
return systemCache.getParcelableArrayList(TAG);
}
}
final ArrayList<RootInfo> roots = new ArrayList<>();
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
cursor = client.query(rootsUri, null, null, null, null);
while (cursor.moveToNext()) {
final RootInfo root = RootInfo.fromRootsCursor(authority, cursor);
roots.add(root);
}
} catch (Exception e) {
Log.w(TAG, "Failed to load some roots from " + authority + ": " + e);
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
// Cache these freshly parsed roots over in the long-lived system
// process, in case our process goes away. The system takes care of
// invalidating the cache if the package or Uri changes.
final Bundle systemCache = new Bundle();
systemCache.putParcelableArrayList(TAG, roots);
resolver.putCache(rootsUri, systemCache);
return roots;
}
use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.
the class RootsCache method getMatchingRoots.
@VisibleForTesting
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
final List<RootInfo> matching = new ArrayList<>();
for (RootInfo root : roots) {
if (DEBUG)
Log.d(TAG, "Evaluating " + root);
if (state.action == State.ACTION_CREATE && !root.supportsCreate()) {
if (DEBUG)
Log.d(TAG, "Excluding read-only root because: ACTION_CREATE.");
continue;
}
if (state.action == State.ACTION_PICK_COPY_DESTINATION && !root.supportsCreate()) {
if (DEBUG)
Log.d(TAG, "Excluding read-only root because: ACTION_PICK_COPY_DESTINATION.");
continue;
}
if (state.action == State.ACTION_OPEN_TREE && !root.supportsChildren()) {
if (DEBUG)
Log.d(TAG, "Excluding root !supportsChildren because: ACTION_OPEN_TREE.");
continue;
}
if (!state.showAdvanced && root.isAdvanced()) {
if (DEBUG)
Log.d(TAG, "Excluding root because: unwanted advanced device.");
continue;
}
if (state.localOnly && !root.isLocalOnly()) {
if (DEBUG)
Log.d(TAG, "Excluding root because: unwanted non-local device.");
continue;
}
if (state.directoryCopy && root.isDownloads()) {
if (DEBUG)
Log.d(TAG, "Excluding downloads root because: unsupported directory copy.");
continue;
}
if (state.action == State.ACTION_OPEN && root.isEmpty()) {
if (DEBUG)
Log.d(TAG, "Excluding empty root because: ACTION_OPEN.");
continue;
}
if (state.action == State.ACTION_GET_CONTENT && root.isEmpty()) {
if (DEBUG)
Log.d(TAG, "Excluding empty root because: ACTION_GET_CONTENT.");
continue;
}
final boolean overlap = MimePredicate.mimeMatches(root.derivedMimeTypes, state.acceptMimes) || MimePredicate.mimeMatches(state.acceptMimes, root.derivedMimeTypes);
if (!overlap) {
if (DEBUG)
Log.d(TAG, "Excluding root because: unsupported content types > " + state.acceptMimes);
continue;
}
if (state.excludedAuthorities.contains(root.authority)) {
if (DEBUG)
Log.d(TAG, "Excluding root because: owned by calling package.");
continue;
}
if (DEBUG)
Log.d(TAG, "Including " + root);
matching.add(root);
}
return matching;
}
use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.
the class FilesActivity method refreshDirectory.
@Override
void refreshDirectory(int anim) {
final FragmentManager fm = getFragmentManager();
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
assert (!mSearchManager.isSearching());
if (cwd == null) {
DirectoryFragment.showRecentsOpen(fm, anim);
} else {
// Normal boring directory
DirectoryFragment.showDirectory(fm, root, cwd, anim);
}
}
Aggregations