Search in sources :

Example 71 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by DirtyUnicorns.

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);
        }
    };
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Loader(android.content.Loader) Intent(android.content.Intent) RootInfo(com.android.documentsui.model.RootInfo) Collection(java.util.Collection)

Example 72 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RecentsLoader method loadInBackgroundLocked.

private DirectoryResult loadInBackgroundLocked() {
    if (mFirstPassLatch == null) {
        // First time through we kick off all the recent tasks, and wait
        // around to see if everyone finishes quickly.
        final Collection<RootInfo> roots = mRoots.getMatchingRootsBlocking(mState);
        for (RootInfo root : roots) {
            if (root.supportsRecents()) {
                mTasks.put(root, new RecentsTask(root.authority, root.rootId));
            }
        }
        mFirstPassLatch = new CountDownLatch(mTasks.size());
        for (RecentsTask task : mTasks.values()) {
            ProviderExecutor.forAuthority(task.authority).execute(task);
        }
        try {
            mFirstPassLatch.await(MAX_FIRST_PASS_WAIT_MILLIS, TimeUnit.MILLISECONDS);
            mFirstPassDone = true;
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    final long rejectBefore = System.currentTimeMillis() - REJECT_OLDER_THAN;
    // Collect all finished tasks
    boolean allDone = true;
    List<Cursor> cursors = new ArrayList<>();
    for (RecentsTask task : mTasks.values()) {
        if (task.isDone()) {
            try {
                final Cursor cursor = task.get();
                if (cursor == null)
                    continue;
                final FilteringCursorWrapper filtered = new FilteringCursorWrapper(cursor, mState.acceptMimes, RECENT_REJECT_MIMES, rejectBefore) {

                    @Override
                    public void close() {
                    // Ignored, since we manage cursor lifecycle internally
                    }
                };
                cursors.add(filtered);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
            // We already logged on other side
            } catch (Exception e) {
                Log.e(TAG, "Failed to query Recents for authority: " + task.authority + ". Skip this authority in Recents.", e);
            }
        } else {
            allDone = false;
        }
    }
    if (DEBUG) {
        Log.d(TAG, "Found " + cursors.size() + " of " + mTasks.size() + " recent queries done");
    }
    final DirectoryResult result = new DirectoryResult();
    result.sortOrder = SORT_ORDER_LAST_MODIFIED;
    final Cursor merged;
    if (cursors.size() > 0) {
        merged = new MergeCursor(cursors.toArray(new Cursor[cursors.size()]));
    } else {
        // Return something when nobody is ready
        merged = new MatrixCursor(new String[0]);
    }
    // Tell the UI if this is an in-progress result. When loading is complete, another update is
    // sent with EXTRA_LOADING set to false.
    Bundle extras = new Bundle();
    extras.putBoolean(DocumentsContract.EXTRA_LOADING, !allDone);
    merged.setExtras(extras);
    result.cursor = merged;
    return result;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MergeCursor(android.database.MergeCursor) CountDownLatch(java.util.concurrent.CountDownLatch) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) MatrixCursor(android.database.MatrixCursor) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MatrixCursor(android.database.MatrixCursor) RootInfo(com.android.documentsui.model.RootInfo) ExecutionException(java.util.concurrent.ExecutionException)

Example 73 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class RootsCache method isIconUniqueBlocking.

public boolean isIconUniqueBlocking(RootInfo root) {
    waitForFirstLoad();
    loadStoppedAuthorities();
    synchronized (mLock) {
        final int rootIcon = root.derivedIcon != 0 ? root.derivedIcon : root.icon;
        for (RootInfo test : mRoots.get(root.authority)) {
            if (Objects.equals(test.rootId, root.rootId)) {
                continue;
            }
            final int testIcon = test.derivedIcon != 0 ? test.derivedIcon : test.icon;
            if (testIcon == rootIcon) {
                return false;
            }
        }
        return true;
    }
}
Also used : RootInfo(com.android.documentsui.model.RootInfo)

Example 74 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

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 75 with RootInfo

use of com.android.documentsui.model.RootInfo in project android_frameworks_base by ResurrectionRemix.

the class FilesActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final RootInfo root = getCurrentRoot();
    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem pasteFromCb = menu.findItem(R.id.menu_paste_from_clipboard);
    final MenuItem settings = menu.findItem(R.id.menu_settings);
    final MenuItem newWindow = menu.findItem(R.id.menu_new_window);
    createDir.setVisible(true);
    createDir.setEnabled(canCreateDirectory());
    pasteFromCb.setEnabled(mClipper.hasItemsToPaste());
    settings.setVisible(root.hasSettings());
    newWindow.setVisible(Shared.shouldShowFancyFeatures(this));
    Menus.disableHiddenItems(menu, pasteFromCb);
    // It hides icon if searching in progress
    mSearchManager.updateMenu();
    return true;
}
Also used : RootInfo(com.android.documentsui.model.RootInfo) MenuItem(android.view.MenuItem)

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