Java Code Examples for android.database.Cursor.setNotificationUri()

The following are Jave code examples for showing how to use setNotificationUri() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: SimpleEntityContentProvider.java   Source Code and License Vote up 6 votes
@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    int uriType = sURIMatcher.match(uri);
    switch (uriType) {
    case SIMPLEENTITY_DIR:
        queryBuilder.setTables(TABLENAME);
        break;
    case SIMPLEENTITY_ID:
        queryBuilder.setTables(TABLENAME);
        queryBuilder.appendWhere(PK + "="
                + uri.getLastPathSegment());
        break;
    default:
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    Database db = getDatabase();
    Cursor cursor = queryBuilder.query(((StandardDatabase) db).getSQLiteDatabase(), projection, selection,
            selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}
 
Example 2
Project: chuck   File: ChuckContentProvider.java   Source Code and License Vote up 6 votes
@Override
@Nullable
public Cursor query(@NonNull Uri uri, @Nullable String[] projection,
                    @Nullable String selection, @Nullable String[] selectionArgs,
                    @Nullable String sortOrder) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    Cursor cursor = null;
    switch (matcher.match(uri)) {
        case TRANSACTIONS:
            cursor = LocalCupboard.getInstance().withDatabase(db).query(HttpTransaction.class).
                    withProjection(projection).
                    withSelection(selection, selectionArgs).
                    orderBy(sortOrder).
                    getCursor();
            break;
        case TRANSACTION:
            cursor = LocalCupboard.getInstance().withDatabase(db).query(HttpTransaction.class).
                    byId(ContentUris.parseId(uri)).
                    getCursor();
            break;
    }
    if (cursor != null) {
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
    }
    return cursor;
}
 
Example 3
Project: odoo-work   File: BaseContentProvider.java   Source Code and License Vote up 6 votes
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String order) {
    OModel model = getModel(getContext(), uri);
    setMatcher(model);
    SQLiteDatabase db = model.getWritableDatabase();
    Cursor cr = db.query(model.getTableName(), projection, selection, selectionArgs, null, null, order);
    Context ctx = getContext();
    if (cr != null && ctx != null)
        cr.setNotificationUri(ctx.getContentResolver(), uri);
    return cr;
}
 
Example 4
Project: Melophile   File: MusicProvider.java   Source Code and License Vote up 6 votes
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
                    @Nullable String[] selectionArgs, @Nullable String sortOrder) {

    final SQLiteDatabase db=database.getReadableDatabase();
    final MusicMatchEnum matchEnum=matcher.match(uri);

    SqlQueryBuilder builder=buildQuery(uri,matchEnum);
    Cursor cursor=builder
            .where(selection,selectionArgs)
            .query(db,projection,sortOrder);

    Context context = getContext();
    if (null != context) {
        cursor.setNotificationUri(context.getContentResolver(), uri);
    }
    return cursor;
}
 
Example 5
Project: androidtv-sample   File: VideoProvider.java   Source Code and License Vote up 5 votes
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
        case SEARCH_SUGGEST: {
            String rawQuery = "";
            if (selectionArgs != null && selectionArgs.length > 0) {
                rawQuery = selectionArgs[0];
            }
            retCursor = getSuggestions(rawQuery);
            break;
        }
        case VIDEO: {
            retCursor = mOpenHelper.getReadableDatabase().query(
                    VideoContract.VideoEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder
            );
            break;
        }
        default: {
            throw new UnsupportedOperationException("Unknown uri: " + uri);
        }
    }

    retCursor.setNotificationUri(mContentResolver, uri);
    return retCursor;
}
 
Example 6
Project: mobile-store   File: RepoProvider.java   Source Code and License Vote up 5 votes
@Override
public Cursor query(Uri uri, String[] projection,
                    String selection, String[] selectionArgs, String sortOrder) {

    if (TextUtils.isEmpty(sortOrder)) {
        sortOrder = Cols.PRIORITY + " ASC";
    }

    switch (MATCHER.match(uri)) {
        case CODE_LIST:
            // Do nothing (don't restrict query)
            break;

        case CODE_SINGLE:
            selection = (selection == null ? "" : selection + " AND ") +
                    Cols._ID + " = " + uri.getLastPathSegment();
            break;

        case CODE_ALL_EXCEPT_SWAP:
            selection = "COALESCE(" + Cols.IS_SWAP + ", 0) = 0 ";
            break;

        default:
            Log.e(TAG, "Invalid URI for repo content provider: " + uri);
            throw new UnsupportedOperationException("Invalid URI for repo content provider: " + uri);
    }

    Cursor cursor = db().query(getTableName(), projection,
            selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
 
Example 7
Project: PeSanKita-android   File: RecipientPreferenceDatabase.java   Source Code and License Vote up 5 votes
public Cursor getBlocked() {
  SQLiteDatabase database = databaseHelper.getReadableDatabase();

  Cursor cursor = database.query(TABLE_NAME, new String[] {ID, RECIPIENT_IDS}, BLOCK + " = 1",
                                 null, null, null, null, null);
  cursor.setNotificationUri(context.getContentResolver(), Uri.parse(RECIPIENT_PREFERENCES_URI));

  return cursor;
}
 
Example 8
Project: android-dev-challenge   File: TaskContentProvider.java   Source Code and License Vote up 5 votes
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {

    // Get access to underlying database (read-only for query)
    final SQLiteDatabase db = mTaskDbHelper.getReadableDatabase();

    // Write URI match code and set a variable to return a Cursor
    int match = sUriMatcher.match(uri);
    Cursor retCursor;

    // Query for the tasks directory and write a default case
    switch (match) {
        // Query for the tasks directory
        case TASKS:
            retCursor =  db.query(TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
            break;
        // Default exception
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    // Set a notification URI on the Cursor and return that Cursor
    retCursor.setNotificationUri(getContext().getContentResolver(), uri);

    // Return the desired Cursor
    return retCursor;
}
 
Example 9
Project: Java-9-Programming-Blueprints   File: SunagoContentProvider.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {
    switch (URI_MATCHER.match(uri)) {
        case 2:
            selection = selection + "_ID = " + uri.getLastPathSegment();
            break;
    }
    SQLiteDatabase db = openHelper.getReadableDatabase();
    Cursor cursor = db.query("items", projection, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
 
Example 10
Project: Cable-Android   File: Database.java   Source Code and License Vote up 4 votes
protected void setNotifyConverationListeners(Cursor cursor, long threadId) {
  cursor.setNotificationUri(context.getContentResolver(), Uri.parse(CONVERSATION_URI + threadId));
}
 
Example 11
Project: pets   File: PetProvider.java   Source Code and License Vote up 4 votes
/**
 * ********** QUERY ***********
 *
 * @param uri
 * @param projection
 * @param selection
 * @param selectionArgs
 * @param sortOrder
 * @return
 */
@Nullable
@Override
public Cursor query(@NonNull Uri uri,
                    @Nullable String[] projection,
                    @Nullable String selection,
                    @Nullable String[] selectionArgs,
                    @Nullable String sortOrder) {

    // read the database
    SQLiteDatabase database = mPetDbHelper.getReadableDatabase();

    // Declare the Cursor to be returned in the end
    Cursor cursor;

    // Run the Uri Matcher
    final int matcher = sUriMathcer.match(uri);

    // Select between PETS or PETS_ID case
    switch (matcher) {
        case PETS:
            cursor = database.query(
                    PetEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);

            break;
        case PETS_ID:
            selection = PetEntry._ID + "=?";
            selectionArgs = new String[]{String.valueOf(ContentUris.parseId(uri))};
            cursor = database.query(
                    PetEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);

            break;
        default:
            throw new IllegalArgumentException("Cannot query unknown URI " + uri);
    }

    // Set notification URI to the cursor
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}
 
Example 12
Project: Udacity_Sunshine   File: WeatherProvider.java   Source Code and License Vote up 4 votes
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {
    // Here's the switch statement that, given a URI, will determine what kind of request it is,
    // and query the database accordingly.
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
        // "weather/*/*"
        case WEATHER_WITH_LOCATION_AND_DATE:
        {
            retCursor = getWeatherByLocationSettingAndDate(uri, projection, sortOrder);
            break;
        }
        // "weather/*"
        case WEATHER_WITH_LOCATION: {
            retCursor = getWeatherByLocationSetting(uri, projection, sortOrder);
            break;
        }
        // "weather"
        case WEATHER: {
            retCursor = mOpenHelper.getReadableDatabase().query(
                    WeatherContract.WeatherEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder
            );
            break;
        }
        // "location"
        case LOCATION: {
            retCursor = mOpenHelper.getReadableDatabase().query(
                    WeatherContract.LocationEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder
            );
            break;
        }

        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
}
 
Example 13
Project: MovieGuide   File: FavoritesProvider.java   Source Code and License Vote up 4 votes
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {

    SQLiteDatabase db = helper.getReadableDatabase();
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();

    switch (sUriMatcher.match(uri)) {
        case MOVIES:
            builder.setTables(FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL);
            break;
        case MOVIE_ID:
            builder.setTables(FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL);
            builder.appendWhere(FavoritesContract.FavoriteColumns.COLUMN_MOVIE_ID
                    + " = " + uri.getLastPathSegment());
            break;
        case TV_SHOWS:
            builder.setTables(FavoritesContract.FavoriteColumns.FAVORITE_TV_SHOWS_TBL);
            break;
        case TV_SHOW_ID:
            builder.setTables(FavoritesContract.FavoriteColumns.FAVORITE_TV_SHOWS_TBL);
            builder.appendWhere(FavoritesContract.FavoriteColumns.COLUMN_TV_SHOW_ID
                    + " = " + uri.getLastPathSegment());
            break;
        case PERSONS:
            builder.setTables(FavoritesContract.FavoriteColumns.FAVORITE_PERSON_TBL);
            break;
        case PERSON_ID:
            builder.setTables(FavoritesContract.FavoriteColumns.FAVORITE_PERSON_TBL);
            builder.appendWhere(FavoritesContract.FavoriteColumns.COLUMN_PERSON_ID
                    + " = " + uri.getLastPathSegment());
            break;
        default:
            throw new IllegalArgumentException("Unsupported URI: " + uri);
    }

    Cursor returnCursor =
            builder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
    returnCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return returnCursor;
}
 
Example 14
Project: TVGuide   File: TvContentProvider.java   Source Code and License Vote up 4 votes
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
        // "category"
        case CATEGORY: {
            retCursor = openHelper.getReadableDatabase().query(
                    sCategoryQueryBuilder.getTables(),
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder
            );
            break;
        }
        // "category/*"
        case CATEGORY_WITH_ID: {
            retCursor = getCategoryById(uri, projection, sortOrder);
            break;
        }
        // "channel"
        case CHANNEL: {
            retCursor = openHelper.getReadableDatabase().query(
                    sChannelQueryBuilder.getTables(),
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder
            );
            break;
        }
        // "channel/*"
        case CHANNEL_WITH_ID: {
            retCursor = getChannelById(uri, projection, sortOrder);
            break;
        }
        // "program"
        case PROGRAM: {
            retCursor = openHelper.getReadableDatabase().query(
                    ProgramEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder
            );
            break;
        }
        // "program/*"
        case PROGRAM_WITH_ID: {
            retCursor = getProgramById(uri, projection, sortOrder);
            break;
        }
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
}
 
Example 15
Project: Android-DownloadManager   File: DownloadProvider.java   Source Code and License Vote up 4 votes
/**
 * Starts a database query
 */
@Override
public Cursor query(final Uri uri, String[] projection,
         final String selection, final String[] selectionArgs,
         final String sort) {

    Helpers.validateSelection(selection, sAppReadableColumnsSet);

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    int match = sURIMatcher.match(uri);
    if (match == -1) {
        if (Constants.LOGV) {
            Log.v(Constants.TAG, "querying unknown URI: " + uri);
        }
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    if (match == REQUEST_HEADERS_URI) {
        if (projection != null || selection != null || sort != null) {
            throw new UnsupportedOperationException("Request header queries do not support "
                                                    + "projections, selections or sorting");
        }
        return queryRequestHeaders(db, uri);
    }

    SqlSelection fullSelection = getWhereClause(uri, selection, selectionArgs, match);

    if (shouldRestrictVisibility()) {
        if (projection == null) {
            projection = sAppReadableColumnsArray.clone();
        } else {
            // check the validity of the columns in projection 
            for (int i = 0; i < projection.length; ++i) {
                if (!sAppReadableColumnsSet.contains(projection[i])) {
                    throw new IllegalArgumentException("column " + projection[i] + " is not allowed in queries");
                }
            }
        }

        for (int i = 0; i < projection.length; i++) {
            final String newColumn = sColumnsMap.get(projection[i]);
            if (newColumn != null) {
                projection[i] = newColumn;
            }
        }
    }

    if (Constants.LOGVV) {
        logVerboseQueryInfo(projection, selection, selectionArgs, sort, db);
    }

    Cursor ret = db.query(DB_TABLE, projection, fullSelection.getSelection(),
            fullSelection.getParameters(), null, null, sort);

    if (ret != null) {
        ret.setNotificationUri(getContext().getContentResolver(), uri);
        if (Constants.LOGVV) {
            Log.v(Constants.TAG,
                    "created cursor " + ret + " on behalf of " + Binder.getCallingPid());
        }
    } else {
        if (Constants.LOGV) {
            Log.v(Constants.TAG, "query failed in downloads database");
        }
    }

    return ret;
}
 
Example 16
Project: Shush   File: PlacesContentProvider.java   Source Code and License Vote up 4 votes
/**
 * Handles requests to query data by uri.
 * @param uri
 * @param projection
 * @param selection
 * @param selectionArgs
 * @param sortOrder
 * @return A cursor object
 */
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {

    //Get access to underlying database (read only for query)
    final SQLiteDatabase db = mPlacesDbHelper.getReadableDatabase();

    //Add a variable for uri matching and a cursor that can be returned
    int match = sUriMatcher.match(uri);
    Cursor retCursor;


    switch (match){
        //query for the places directory.
        case PLACES:
            retCursor = db.query(PlacesContract.PlaceEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
            break;
        //query for the time directory.
        case TIME:
            retCursor = db.query(PlacesContract.TimeEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
            break;
        //query for a single time.
        case SINGLE_TIME_WITH_ID:
            String id = uri.getPathSegments().get(1);
            retCursor = db.query(PlacesContract.TimeEntry.TABLE_NAME,
                    projection,
                    "id =?",
                    new String[]{id},
                    null,
                    null,
                    sortOrder);
            break;
        //default exception
        default:
            throw new UnsupportedOperationException("Cannot access Uri : " + uri);

            }

    //Set a notification uri to the cursor so that it gets updated
    // id there is any change in the uri and return it.
    retCursor.setNotificationUri(getContext().getContentResolver(),uri);

    return retCursor;
}
 
Example 17
Project: downloadmanager   File: DownloadProvider.java   Source Code and License Vote up 4 votes
/**
     * Starts a database query
     */
    @Override
    public Cursor query(final Uri uri, String[] projection,
                        final String selection, final String[] selectionArgs,
                        final String sort) {

//        Helpers.validateSelection(selection, sAppReadableColumnsSet);

        SQLiteDatabase db = mOpenHelper.getReadableDatabase();

        int match = sURIMatcher.match(uri);
        if (match == -1) {
            if (Constants.LOGV) {
                Log.v(Constants.TAG, "querying unknown URI: " + uri);
            }
            throw new IllegalArgumentException("Unknown URI: " + uri);
        }

        if (match == REQUEST_HEADERS_URI) {
            if (projection != null || selection != null || sort != null) {
                throw new UnsupportedOperationException("Request header queries do not support "
                        + "projections, selections or sorting");
            }
            return queryRequestHeaders(db, uri);
        }

        SqlSelection fullSelection = getWhereClause(uri, selection, selectionArgs, match);

        if (shouldRestrictVisibility()) {
            if (projection == null) {
                projection = sAppReadableColumnsArray.clone();
            } else {
                // check the validity of the columns in projection 
                for (int i = 0; i < projection.length; ++i) {
                    if (!sAppReadableColumnsSet.contains(projection[i])) {
                        throw new IllegalArgumentException("column " + projection[i] + " is not allowed in queries");
                    }
                }
            }

            for (int i = 0; i < projection.length; i++) {
                final String newColumn = sColumnsMap.get(projection[i]);
                if (newColumn != null) {
                    projection[i] = newColumn;
                }
            }
        }

        if (Constants.LOGVV) {
            logVerboseQueryInfo(projection, selection, selectionArgs, sort, db);
        }

        Cursor ret = db.query(DB_TABLE, projection, fullSelection.getSelection(),
                fullSelection.getParameters(), null, null, sort);

        if (ret != null) {
            ret.setNotificationUri(getContext().getContentResolver(), uri);
            if (Constants.LOGVV) {
                Log.v(Constants.TAG,
                        "created cursor " + ret + " on behalf of " + Binder.getCallingPid());
            }
        } else {
            if (Constants.LOGV) {
                Log.v(Constants.TAG, "query failed in downloads database");
            }
        }

        return ret;
    }
 
Example 18
Project: keepass2android   File: HistoryProvider.java   Source Code and License Vote up 4 votes
@Override
public synchronized Cursor query(Uri uri, String[] projection,
        String selection, String[] selectionArgs, String sortOrder) {
    if (Utils.doLog())
        Log.d(CLASSNAME, String.format(
                "query() >> uri = %s, selection = %s, sortOrder = %s", uri,
                selection, sortOrder));

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(HistoryContract.TABLE_NAME);
    qb.setProjectionMap(MAP_COLUMNS);

    SQLiteDatabase db = null;
    Cursor cursor = null;

    /*
     * Choose the projection and adjust the "where" clause based on URI
     * pattern-matching.
     */
    switch (URI_MATCHER.match(uri)) {
    case URI_HISTORY: {
        if (Arrays.equals(projection,
                new String[] { HistoryContract._COUNT })) {
            db = mHistoryHelper.getReadableDatabase();
            cursor = db.rawQuery(
                    String.format(
                            "SELECT COUNT(*) AS %s FROM %s %s",
                            HistoryContract._COUNT,
                            HistoryContract.TABLE_NAME,
                            selection != null ? String.format("WHERE %s",
                                    selection) : "").trim(), null);
        }

        break;
    }// URI_HISTORY

    /*
     * If the incoming URI is for a single history item identified by its
     * ID, chooses the history item ID projection, and appends
     * "_ID = <history-item-ID>" to the where clause, so that it selects
     * that single history item.
     */
    case URI_HISTORY_ID: {
        qb.appendWhere(DbUtils.SQLITE_FTS_COLUMN_ROW_ID + " = "
                + uri.getLastPathSegment());

        break;
    }// URI_HISTORY_ID

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

    if (TextUtils.isEmpty(sortOrder))
        sortOrder = HistoryContract.DEFAULT_SORT_ORDER;

    /*
     * Opens the database object in "read" mode, since no writes need to be
     * done.
     */
    if (Utils.doLog())
        Log.d(CLASSNAME,
                String.format("Going to SQLiteQueryBuilder >> db = %s", db));
    if (db == null) {
        db = mHistoryHelper.getReadableDatabase();
        /*
         * Performs the query. If no problems occur trying to read the
         * database, then a Cursor object is returned; otherwise, the cursor
         * variable contains null. If no records were selected, then the
         * Cursor object is empty, and Cursor.getCount() returns 0.
         */
        cursor = qb.query(db, projection, selection, selectionArgs, null,
                null, sortOrder);
    }

    cursor = appendNameAndRealUri(cursor);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
 
Example 19
Project: Monolith   File: DataProvider.java   Source Code and License Vote up 4 votes
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {
    final SQLiteDatabase db_g = mOpenHelper_gallery.getReadableDatabase();
    final SQLiteDatabase db_a = mOpenHelper_article.getReadableDatabase();
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
        case IMAGE:
            retCursor = db_g.query(TABLE_NAME_GALLERY,
                    projection,
                    selection,
                    selectionArgs,
                    null, null,
                    sortOrder);
            break;
        case IMAGE_ID:
            retCursor = db_g.query(TABLE_NAME_GALLERY,
                    projection,
                    selection,
                    selectionArgs,
                    null, null,
                    sortOrder);
            break;

        case ARTICLE:
            retCursor = db_a.query(TABLE_NAME_ARTICLE,
                    projection,
                    selection,
                    selectionArgs,
                    null, null,
                    sortOrder);
            break;

        case ARTICLE_ID:
            retCursor = db_a.query(TABLE_NAME_ARTICLE,
                    projection,
                    selection,
                    selectionArgs,
                    null, null,
                    sortOrder);
            break;

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

    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
}
 
Example 20
Project: letv   File: LetvContentProvider.java   Source Code and License Vote up 4 votes
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    int match = URI_MATCHER.match(uri);
    SQLiteDatabase db = this.sqliteDataBase.getWritableDatabase();
    String targetTable = "";
    switch (match) {
        case 100:
            targetTable = SearchTrace.TABLE_NAME;
            break;
        case 101:
            targetTable = FavoriteRecord.TABLE_NAME;
            break;
        case 102:
            targetTable = PlayRecord.TABLE_NAME;
            break;
        case 103:
            targetTable = DownloadTrace.TABLE_NAME;
            break;
        case 104:
            targetTable = FestivalImageTrace.TABLE_NAME;
            break;
        case 105:
            targetTable = LocalVideoTrace.TABLE_NAME;
            break;
        case 106:
            targetTable = LiveBookTrace.TABLE_NAME;
            break;
        case 107:
            targetTable = DialogMsgTrace.TABLE_NAME;
            break;
        case 108:
            targetTable = LocalCacheTrace.TABLE_NAME;
            break;
        case 109:
            targetTable = TopChannelsTrace.TABLE_NAME;
            break;
        case 110:
            targetTable = WorldCupTrace.TABLE_NAME;
            break;
        case 111:
            targetTable = ChannelListTrace.TABLE_NAME;
            break;
        case 112:
            targetTable = ChannelHisListTrace.TABLE_NAME;
            break;
        case 113:
            targetTable = PlayRecordWatched.TABLE_NAME;
            break;
        case 114:
            targetTable = HotTopTrace.TABLE_NAME;
            break;
        case 115:
            targetTable = Emoji.TABLE_NAME;
            break;
        case 116:
            targetTable = LanguageSettingsTrace.TABLE_NAME;
            break;
        default:
            throw new UnsupportedOperationException("缺少URL matcher,请添加..." + uri.toString());
    }
    Cursor cursor = db.query(targetTable, null, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}