Search in sources :

Example 1 with RootInfo

use of com.android.documentsui.model.RootInfo in project platform_frameworks_base by android.

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;
}
Also used : RootInfo(com.android.documentsui.model.RootInfo) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentProviderClient(android.content.ContentProviderClient)

Example 2 with RootInfo

use of com.android.documentsui.model.RootInfo in project platform_frameworks_base by android.

the class RootsCache method getRootOneshot.

/**
     * Return the requested {@link RootInfo}, but only loading the roots for the
     * requested authority. This is useful when we want to load fast without
     * waiting for all the other roots to come back.
     */
public RootInfo getRootOneshot(String authority, String rootId) {
    synchronized (mLock) {
        RootInfo root = getRootLocked(authority, rootId);
        if (root == null) {
            mRoots.putAll(authority, loadRootsForAuthority(mContext.getContentResolver(), authority, false));
            root = getRootLocked(authority, rootId);
        }
        return root;
    }
}
Also used : RootInfo(com.android.documentsui.model.RootInfo)

Example 3 with RootInfo

use of com.android.documentsui.model.RootInfo in project platform_frameworks_base by android.

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;
            }
        }
    }
}
Also used : RootInfo(com.android.documentsui.model.RootInfo)

Example 4 with RootInfo

use of com.android.documentsui.model.RootInfo in project platform_frameworks_base by android.

the class DocumentsActivity method refreshDirectory.

@Override
void refreshDirectory(int anim) {
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();
    if (cwd == null) {
        // No directory means recents
        if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION) {
            RecentsCreateFragment.show(fm);
        } else {
            DirectoryFragment.showRecentsOpen(fm, anim);
            // In recents we pick layout mode based on the mimetype,
            // picking GRID for visual types. We intentionally don't
            // consult a user's saved preferences here since they are
            // set per root (not per root and per mimetype).
            boolean visualMimes = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mState.acceptMimes);
            mState.derivedMode = visualMimes ? State.MODE_GRID : State.MODE_LIST;
        }
    } else {
        // Normal boring directory
        DirectoryFragment.showDirectory(fm, root, cwd, anim);
    }
    // Forget any replacement target
    if (mState.action == ACTION_CREATE) {
        final SaveFragment save = SaveFragment.get(fm);
        if (save != null) {
            save.setReplaceTarget(null);
        }
    }
    if (mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION) {
        final PickFragment pick = PickFragment.get(fm);
        if (pick != null) {
            pick.setPickTarget(mState.action, mState.copyOperationSubType, cwd);
        }
    }
}
Also used : FragmentManager(android.app.FragmentManager) RootInfo(com.android.documentsui.model.RootInfo) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 5 with RootInfo

use of com.android.documentsui.model.RootInfo in project platform_frameworks_base by android.

the class BaseActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            return true;
        case R.id.menu_create_dir:
            showCreateDirectoryDialog();
            return true;
        case R.id.menu_search:
            // SearchViewManager listens for this directly.
            return false;
        case R.id.menu_sort_name:
            setUserSortOrder(State.SORT_ORDER_DISPLAY_NAME);
            return true;
        case R.id.menu_sort_date:
            setUserSortOrder(State.SORT_ORDER_LAST_MODIFIED);
            return true;
        case R.id.menu_sort_size:
            setUserSortOrder(State.SORT_ORDER_SIZE);
            return true;
        case R.id.menu_grid:
            setViewMode(State.MODE_GRID);
            return true;
        case R.id.menu_list:
            setViewMode(State.MODE_LIST);
            return true;
        case R.id.menu_paste_from_clipboard:
            DirectoryFragment dir = getDirectoryFragment();
            if (dir != null) {
                dir.pasteFromClipboard();
            }
            return true;
        case R.id.menu_advanced:
            setDisplayAdvancedDevices(!mState.showAdvanced);
            return true;
        case R.id.menu_file_size:
            setDisplayFileSize(!LocalPreferences.getDisplayFileSize(this));
            return true;
        case R.id.menu_settings:
            Metrics.logUserAction(this, Metrics.USER_ACTION_SETTINGS);
            final RootInfo root = getCurrentRoot();
            final Intent intent = new Intent(DocumentsContract.ACTION_DOCUMENT_ROOT_SETTINGS);
            intent.setDataAndType(root.getUri(), DocumentsContract.Root.MIME_TYPE_ITEM);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : RootInfo(com.android.documentsui.model.RootInfo) Intent(android.content.Intent) DirectoryFragment(com.android.documentsui.dirlist.DirectoryFragment)

Aggregations

RootInfo (com.android.documentsui.model.RootInfo)85 DocumentInfo (com.android.documentsui.model.DocumentInfo)20 FragmentManager (android.app.FragmentManager)15 Bundle (android.os.Bundle)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)10 Cursor (android.database.Cursor)10 ContentProviderClient (android.content.ContentProviderClient)5 Context (android.content.Context)5 Loader (android.content.Loader)5 MatrixCursor (android.database.MatrixCursor)5 MergeCursor (android.database.MergeCursor)5 Uri (android.net.Uri)5 VisibleForTesting (android.support.annotation.VisibleForTesting)5 MenuItem (android.view.MenuItem)5 DirectoryFragment (com.android.documentsui.dirlist.DirectoryFragment)5 IOException (java.io.IOException)5 Collection (java.util.Collection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutionException (java.util.concurrent.ExecutionException)5