コード例 #1
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    SelectionBuilder builder = new SelectionBuilder();
    Context ctx = getContext();
    assert ctx != null;
    Cursor c;

    int uriMatch = sUriMatcher.match(uri);
    switch (uriMatch) {
      case ROUTE_EMOTES_ID:
        // Return a single entry, by ID
        String id = uri.getLastPathSegment();
        builder.where(EmotesContract.Emote._ID + "=?", id);
      case ROUTE_EMOTES:
        // Return all known entries
        builder.table(EmotesContract.Emote.TABLE_NAME).where(selection, selectionArgs);

        c = builder.query(db, projection, sortOrder);

        // Note: Notification URI must be manually set here for loaders to
        // correctly register ContentObservers.
        c.setNotificationUri(ctx.getContentResolver(), uri);

        return c;
      case ROUTE_EMOTES_DISTINCT:
        // Return all known entries
        builder.table(EmotesContract.Emote.TABLE_NAME).where(selection, selectionArgs);

        c = builder.query(true, db, projection, sortOrder);

        // Note: Notification URI must be manually set here for loaders to
        // correctly register ContentObservers.
        c.setNotificationUri(ctx.getContentResolver(), uri);

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