List of usage examples for android.provider DocumentsContract buildChildDocumentsUri
public static Uri buildChildDocumentsUri(String authority, String parentDocumentId)
From source file:org.alfresco.mobile.android.application.providers.storage.StorageAccessDocumentsProvider.java
@Override public Cursor queryChildDocuments(final String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException { // Log.d(TAG, "Query Children : " + parentDocumentId); final DocumentFolderCursor docsCursor = new DocumentFolderCursor(resolveDocumentProjection(projection)); Uri uri = DocumentsContract.buildChildDocumentsUri(mAuthority, parentDocumentId); // Log.d(TAG, "Query Children : " + uri); EncodedQueryUri cUri = new EncodedQueryUri(parentDocumentId); // Dispatch value try {//from w ww .ja v a 2 s . c o m // Flag to detect loading in progress Boolean active = mLoadingUris.get(uri); switch (cUri.type) { case PREFIX_ACCOUNT: // First Rows after AlfrescoAccount selection // Display Top level Entry Points retrieveRootMenuChildren(uri, cUri, docsCursor); break; case PREFIX_ROOT_MENU: int id = Integer.parseInt(cUri.id); switch (id) { case R.string.menu_browse_sites: // List of Sites if (active != null && !active) { fillSitesChildren(uri, active, docsCursor); } else { retrieveSitesChildren(uri, cUri, docsCursor); } break; case R.string.menu_browse_favorites_folder: // List favorite folders if (active != null && !active) { fillNodeChildren(uri, active, docsCursor); } else { retrieveFavoriteFoldersChildren(uri, cUri, docsCursor); } break; default: break; } break; case PREFIX_SITE: // List children for a specific site // i.e Document Library Children if (active != null && !active) { fillNodeChildren(uri, active, docsCursor); } else { retrieveSiteDocumentLibraryChildren(uri, cUri, docsCursor); } break; case PREFIX_DOC: // Children browsing if (parentDocumentId == null) { return docsCursor; } if (active != null && !active) { fillNodeChildren(uri, active, docsCursor); } else { retrieveFolderChildren(uri, cUri, docsCursor); } break; default: break; } } catch (Exception e) { docsCursor.setErrorInformation("Error : " + e.getMessage()); docsCursor.setNotificationUri(getContext().getContentResolver(), uri); getContext().getContentResolver().notifyChange(uri, null); // Log.w(TAG, Log.getStackTraceString(e)); } return docsCursor; }
From source file:org.sufficientlysecure.privacybox.VaultProvider.java
@Override public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException { final ExtrasMatrixCursor result = new ExtrasMatrixCursor(resolveDocumentProjection(projection)); result.setNotificationUri(getContext().getContentResolver(), DocumentsContract.buildChildDocumentsUri(AUTHORITY, parentDocumentId)); // TODO: Extra inf below? not for special root folder! // result.putString(DocumentsContract.EXTRA_INFO, "bla"); try {/*from ww w . j a v a2s . c o m*/ final EncryptedDocument doc = getDocument(Long.parseLong(parentDocumentId)); final JSONObject meta = doc.readMetadata(); final JSONArray children = meta.getJSONArray(KEY_CHILDREN); for (int i = 0; i < children.length(); i++) { final long docId = children.getLong(i); includeDocument(result, docId); } } catch (IOException e) { throw new IllegalStateException(e); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (JSONException e) { throw new IllegalStateException(e); } return result; }
From source file:com.example.android.vault.VaultProvider.java
/** * Remove any references to the given document, usually when included as a * child of another directory.//from w ww. j a v a 2 s .c o m */ private void deleteDocumentReferences(long docId) { for (String name : mDocumentsDir.list()) { try { final long parentDocId = Long.parseLong(name); final EncryptedDocument parentDoc = getDocument(parentDocId); final JSONObject meta = parentDoc.readMetadata(); if (Document.MIME_TYPE_DIR.equals(meta.getString(Document.COLUMN_MIME_TYPE))) { final JSONArray children = meta.getJSONArray(KEY_CHILDREN); if (maybeRemove(children, docId)) { Log.d(TAG, "Removed " + docId + " reference from " + name); parentDoc.writeMetadataAndContent(meta, null); getContext().getContentResolver().notifyChange( DocumentsContract.buildChildDocumentsUri(AUTHORITY, name), null, false); } } } catch (NumberFormatException ignored) { } catch (IOException e) { Log.w(TAG, "Failed to examine " + name, e); } catch (GeneralSecurityException e) { Log.w(TAG, "Failed to examine " + name, e); } catch (JSONException e) { Log.w(TAG, "Failed to examine " + name, e); } } }
From source file:com.example.android.vault.VaultProvider.java
@Override public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException { final ExtrasMatrixCursor result = new ExtrasMatrixCursor(resolveDocumentProjection(projection)); result.setNotificationUri(getContext().getContentResolver(), DocumentsContract.buildChildDocumentsUri(AUTHORITY, parentDocumentId)); // Notify user in storage UI when key isn't hardware-backed if (!mHardwareBacked) { result.putString(DocumentsContract.EXTRA_INFO, getContext().getString(R.string.info_software_detail)); }/*from w w w .jav a 2 s.c o m*/ try { final EncryptedDocument doc = getDocument(Long.parseLong(parentDocumentId)); final JSONObject meta = doc.readMetadata(); final JSONArray children = meta.getJSONArray(KEY_CHILDREN); for (int i = 0; i < children.length(); i++) { final long docId = children.getLong(i); includeDocument(result, docId); } } catch (IOException e) { throw new IllegalStateException(e); } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (JSONException e) { throw new IllegalStateException(e); } return result; }
From source file:com.seafile.seadroid2.provider.SeafileProvider.java
/** * Fetches a dirent (list of entries of a directory) from Seafile asynchronously. * * This will return nothing. It will only signal the client over the MatrixCursor. The client * will then recall DocumentProvider.queryChildDocuments() again. * * @param dm the dataManager to be used. * @param repoId the Id of the repository * @param path the path of the directory. * @param result Cursor object over which to signal the client. *//*from w ww . j av a 2 s . c o m*/ private void fetchDirentAsync(final DataManager dm, final String repoId, final String path, MatrixCursor result) { final Uri uri = DocumentsContract.buildChildDocumentsUri(Utils.AUTHORITY, docIdParser.buildId(dm.getAccount(), repoId, path)); result.setNotificationUri(getContext().getContentResolver(), uri); ConcurrentAsyncTask.submit(new Runnable() { @Override public void run() { try { // fetch the dirents from the server dm.getDirentsFromServer(repoId, path); reachableAccounts.add(dm.getAccount()); } catch (SeafException e) { Log.e(DEBUG_TAG, "Exception while querying dirents", e); reachableAccounts.remove(dm.getAccount()); } // The notification has to be sent only *after* queryChildDocuments has // finished. To be safe, wait a bit. try { Thread.sleep(100); } catch (InterruptedException e1) { } // notify the SAF to to do a new queryChildDocuments getContext().getContentResolver().notifyChange(uri, null); } }); }
From source file:com.seafile.seadroid2.provider.SeafileProvider.java
/** * Fetches starred files from Seafile asynchronously. * * This will return nothing. It will only signal the client over the MatrixCursor. The client * will then recall DocumentProvider.queryChildDocuments() again. * * @param dm the dataManager to be used. * @param result Cursor object over which to signal the client. *///from ww w.j a va 2 s . co m private void fetchStarredAsync(final DataManager dm, MatrixCursor result) { final Uri uri = DocumentsContract.buildChildDocumentsUri(Utils.AUTHORITY, docIdParser.buildStarredFilesId(dm.getAccount())); result.setNotificationUri(getContext().getContentResolver(), uri); ConcurrentAsyncTask.submit(new Runnable() { @Override public void run() { try { dm.getStarredFiles(); reachableAccounts.add(dm.getAccount()); } catch (SeafException e) { Log.e(DEBUG_TAG, "Exception while querying starred files", e); reachableAccounts.remove(dm.getAccount()); } // The notification has to be sent only *after* queryChildDocuments has // finished. To be safe, wait a bit. try { Thread.sleep(100); } catch (InterruptedException e1) { } // notify the SAF to to do a new queryChildDocuments getContext().getContentResolver().notifyChange(uri, null); } }); }
From source file:com.seafile.seadroid2.provider.SeafileProvider.java
/** * Fetches a new list of repositories from Seafile asynchronously. * * This will return nothing. It will only signal the client over the MatrixCursor. The client * will then recall DocumentProvider.queryChildDocuments() again. * * @param dm the dataManager to be used. * @param result Cursor object over which to signal the client. *//*from w w w .j a va 2 s . c o m*/ private void fetchReposAsync(final DataManager dm, MatrixCursor result) { final Uri uri = DocumentsContract.buildChildDocumentsUri(Utils.AUTHORITY, docIdParser.buildId(dm.getAccount(), null, null)); result.setNotificationUri(getContext().getContentResolver(), uri); ConcurrentAsyncTask.submit(new Runnable() { @Override public void run() { try { // fetch new repositories from the server dm.getReposFromServer(); reachableAccounts.add(dm.getAccount()); } catch (SeafException e) { Log.e(DEBUG_TAG, "Exception while querying repos", e); reachableAccounts.remove(dm.getAccount()); } // The notification has to be sent only *after* queryChildDocuments has // finished. To be safe, wait a bit. try { Thread.sleep(100); } catch (InterruptedException e1) { } // notify the SAF to to do a new queryChildDocuments getContext().getContentResolver().notifyChange(uri, null); } }); }