Example usage for android.database MatrixCursor setNotificationUri

List of usage examples for android.database MatrixCursor setNotificationUri

Introduction

In this page you can find the example usage for android.database MatrixCursor setNotificationUri.

Prototype

@Override
public void setNotificationUri(ContentResolver cr, Uri notifyUri) 

Source Link

Document

Specifies a content URI to watch for changes.

Usage

From source file:fr.seeks.SuggestionProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String query = uri.getLastPathSegment();

    if (query == null || query.equals("") || query.equals("search_suggest_query"))
        return null;

    Log.v(TAG, "Request '" + query + "' for '" + uri + "'");

    MatrixCursor matrix = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_TITLE, KEY_DESCRIPTION, KEY_QUERY, KEY_ACTION, KEY_URL });

    Boolean instant_suggest = mPrefs.getBoolean("instant_suggest", false);
    if (instant_suggest) {
        setCursorOfQuery(uri, query, matrix);
    } else {/*  w  w  w . jav  a  2s.c om*/
        perhapsSetCursorOfQuery(uri, query, matrix);
    }
    matrix.setNotificationUri(getContext().getContentResolver(), uri);

    return matrix;
}

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   www  .  ja v a 2  s  .  c o 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.
 *//*  w  ww  . j a  v  a  2  s.  com*/
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);
        }
    });
}

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  www  . j  a  v  a2s  .c  om
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.example.android.notepad.CMNotesProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    String[] keys = null;//from  w w  w  .  jav a2  s  .c  o  m

    switch (sUriMatcher.match(uri)) {
    case NOTES:
        //qb.setProjectionMap(sNotesProjectionMap);
        break;

    case NOTE_ID:
        //qb.setProjectionMap(sNotesProjectionMap);
        //qb.appendWhere(Notes._ID + "=" + uri.getPathSegments().get(1));
        keys = new String[] { uri.getPathSegments().get(1) };
        break;

    case LIVE_FOLDER_NOTES:
        //qb.setProjectionMap(sLiveFolderProjectionMap);
        break;

    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    // Get the database and run the query
    //SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    //Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);

    CMAdapter cmadapter = new CMAdapter();
    JSONObject objects = cmadapter.getValues(keys);
    MatrixCursor c = new MatrixCursor(projection);

    // objects is a map of key => value mappings, where key is the _id
    Iterator<String> note_ids = objects.keys();
    while (note_ids.hasNext()) {
        String id = note_ids.next();
        RowBuilder row = c.newRow();
        for (String field : projection) {
            if (field.equals(Notes._ID)) {
                row.add(id);
            } else {
                String val = "bad entry";
                try {
                    val = objects.getJSONObject(id).getString(field);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                row.add(val);
            }
        }
    }

    // Tell the cursor what uri to watch, so it knows when its source data changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

From source file:com.seafile.seadroid2.provider.SeafileProvider.java

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {

    String[] netProjection = netProjection(projection, SUPPORTED_ROOT_PROJECTION);
    MatrixCursor result = new MatrixCursor(netProjection);

    Log.d(DEBUG_TAG, "queryRoots()");

    // add a Root for every signed in Seafile account we have.
    for (Account a : accountManager.getAccountList()) {
        includeRoot(result, a);//from  w  w  w . j  a  v  a  2 s  .  co  m
    }

    // notification uri for the event, that the account list has changed
    result.setNotificationUri(getContext().getContentResolver(), NOTIFICATION_URI);

    return result;
}

From source file:net.sf.xfd.provider.PublicProvider.java

@Nullable
@Override/*from  ww  w . j  a  v a  2  s.c  o  m*/
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {
    String path = uri.getPath();

    if (TextUtils.isEmpty(uri.getPath())) {
        path = "/";
    }

    try {
        assertAbsolute(path);
    } catch (FileNotFoundException e) {
        return null;
    }

    path = canonString(path);

    if (!path.equals(uri.getPath())) {
        uri = uri.buildUpon().path(path).build();
    }

    if (!checkAccess(uri, "r")) {
        return null;
    }

    if (projection == null) {
        projection = COMMON_PROJECTION;
    }

    final OS os = base.getOS();
    if (os == null) {
        return null;
    }

    try {
        final MatrixCursor cursor = new MatrixCursor(projection, 1);

        final Object[] row = new Object[projection.length];

        final Stat stat = new Stat();
        final String name = extractName(path);
        final String mime = base.getTypeFast(path, name, stat);

        for (int i = 0; i < projection.length; ++i) {
            String col = projection[i];

            switch (col) {
            case BaseColumns._ID:
                row[i] = stat.st_ino;
                break;
            case COLUMN_DISPLAY_NAME:
                row[i] = name;
                break;
            case COLUMN_SIZE:
                row[i] = stat.st_size;
                break;
            case COLUMN_MIME_TYPE:
                row[i] = mime;
                break;
            default:
                row[i] = null;
            }
        }

        cursor.addRow(row);

        final Context context = getContext();
        assert context != null;

        final String packageName = context.getPackageName();

        cursor.setNotificationUri(context.getContentResolver(),
                DocumentsContract.buildDocumentUri(packageName + FileProvider.AUTHORITY_SUFFIX, path));

        return cursor;
    } catch (IOException e) {
        e.printStackTrace();

        return null;
    }
}