android.widget.SearchView.OnQueryTextListener#android.database.MatrixCursor源码实例Demo

下面列出了android.widget.SearchView.OnQueryTextListener#android.database.MatrixCursor 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Method called to handle query requests from client
 * applications.  This plays the role of the "concrete hook
 * method" in the Template Method pattern.
 */
@Override
public Cursor queryCharacters(Uri uri,
                              String[] projection,
                              String selection,
                              String[] selectionArgs,
                              String sortOrder) {
    final MatrixCursor cursor =
        new MatrixCursor(CharacterContract.CharacterEntry.sColumnsToDisplay);

    synchronized (this) {
        // Implement a simple query mechanism for the table.
        for (CharacterRecord cr : mCharacterMap.values())
            buildCursorConditionally(cursor,
                                     cr,
                                     selection,
                                     selectionArgs);
    }

    return cursor;
}
 
源代码2 项目: mollyim-android   文件: ContactsCursorLoader.java
private @NonNull Cursor filterNonPushContacts(@NonNull Cursor cursor) {
  try {
    final long startMillis = System.currentTimeMillis();
    final MatrixCursor matrix = new MatrixCursor(CONTACT_PROJECTION);
    while (cursor.moveToNext()) {
      final RecipientId id        = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ContactRepository.ID_COLUMN)));
      final Recipient   recipient = Recipient.resolved(id);

      if (recipient.resolve().getRegistered() != RecipientDatabase.RegisteredState.REGISTERED) {
        matrix.addRow(new Object[]{cursor.getLong(cursor.getColumnIndexOrThrow(ContactRepository.ID_COLUMN)),
                                   cursor.getString(cursor.getColumnIndexOrThrow(ContactRepository.NAME_COLUMN)),
                                   cursor.getString(cursor.getColumnIndexOrThrow(ContactRepository.NUMBER_COLUMN)),
                                   cursor.getString(cursor.getColumnIndexOrThrow(ContactRepository.NUMBER_TYPE_COLUMN)),
                                   cursor.getString(cursor.getColumnIndexOrThrow(ContactRepository.LABEL_COLUMN)),
                                   ContactRepository.NORMAL_TYPE});
      }
    }
    Log.i(TAG, "filterNonPushContacts() -> " + (System.currentTimeMillis() - startMillis) + "ms");
    return matrix;
  } finally {
    cursor.close();
  }
}
 
源代码3 项目: SMP   文件: RowsTest.java
@Override
public Cursor query(Uri uri,
                    String[] projection,
                    String selection,
                    String[] selectionArgs,
                    String sortOrder) {
    String[] columnNames = {MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.TRACK,
            MediaStore.MediaColumns.DATA,
            MediaStore.Audio.Media.IS_MUSIC
    };
    MatrixCursor matrixCursor = new MatrixCursor(columnNames);
    for(String[] row : data)
        matrixCursor.addRow(row);
    return matrixCursor;
}
 
源代码4 项目: Effects-Pro   文件: LocalStorageProvider.java
@Override
public Cursor queryChildDocuments(final String parentDocumentId, final String[] projection,
		final String sortOrder) throws FileNotFoundException {
	// Create a cursor with either the requested fields, or the default
	// projection if "projection" is null.
	final MatrixCursor result = new MatrixCursor(projection != null ? projection
			: DEFAULT_DOCUMENT_PROJECTION);
	final File parent = new File(parentDocumentId);
	for (File file : parent.listFiles()) {
		// Don't show hidden files/folders
		if (!file.getName().startsWith(".")) {
			// Adds the file's display name, MIME type, size, and so on.
			includeFile(result, file);
		}
	}
	return result;
}
 
private Cursor getHardCodedCursor()
{
    final String[] columns = new String[]
    { "_id", ExpandShrinkListViewActivity.COLUMN_NAME_TITLE, ExpandShrinkListViewActivity.COLUMN_NAME_TEXT }; //$NON-NLS-1$ 

    final MatrixCursor matrixCursor = new MatrixCursor(columns);
    this.startManagingCursor(matrixCursor);

    // Get String resources
    final String[] titles = this.getResources().getStringArray(R.array.expand_shrink_list_view_title);
    final String[] texts = this.getResources().getStringArray(R.array.expand_shrink_list_view_text);

    if (titles.length == texts.length)
    {
        for (int i = 0; i < titles.length; i++)
        {
            matrixCursor.addRow(new Object[]
            { i, titles[i], texts[i] });
        }
    }

    return matrixCursor;
}
 
@NonNull
private MatrixCursor getStickersForAStickerPack(@NonNull final Uri uri) {
    final String identifier = uri.getLastPathSegment();
    final MatrixCursor cursor = new MatrixCursor(
            new String[] { STICKER_FILE_NAME_IN_QUERY, STICKER_FILE_EMOJI_IN_QUERY });

    for (final StickerPack stickerPack : getStickerPackList()) {
        if (identifier.equals(stickerPack.identifier)) {
            for (final Sticker sticker : stickerPack.getStickers()) {
                cursor.addRow(new Object[] { sticker.imageFileName, TextUtils.join(",", sticker.emojis) });
            }
        }
    }

    cursor.setNotificationUri(Objects.requireNonNull(getContext()).getContentResolver(), uri);
    return cursor;
}
 
源代码7 项目: filechooser   文件: LocalStorageProvider.java
@Override
public Cursor queryChildDocuments(final String parentDocumentId, final String[] projection,
        final String sortOrder) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_DOCUMENT_PROJECTION);
    final File parent = new File(parentDocumentId);
    for (File file : parent.listFiles()) {
        // Don't show hidden files/folders
        if (!file.getName().startsWith(".")) {
            // Adds the file's display name, MIME type, size, and so on.
            includeFile(result, file);
        }
    }
    return result;
}
 
源代码8 项目: SuntimesWidget   文件: SuntimesThemeProvider.java
/**
 * queryThemes
 */
private Cursor queryThemes(@NonNull Uri uri, @Nullable String[] projection, HashMap<String, String> selection, @Nullable String sortOrder)
{
    Context context = getContext();
    WidgetThemes.initThemes(context);

    String[] columns = (projection != null ? projection : QUERY_THEMES_PROJECTION);
    MatrixCursor retValue = new MatrixCursor(columns);

    if (context != null)
    {
        int i = 0;
        for (SuntimesTheme.ThemeDescriptor themeDesc : WidgetThemes.getValues()) {
            retValue.addRow(createRow(themeDesc, columns, i++));
        }
    }
    return retValue;
}
 
源代码9 项目: JPPF   文件: AppStorageProvider.java
/**
 * Add a row in the specified cursor for the specified file.
 * @param child the file for which to add a row.
 * @param cursor the cursor to add a row to.
 */
private void createRowForChild(File child, MatrixCursor cursor) {
  MatrixCursor.RowBuilder row = cursor.newRow();
  String type = getContext().getContentResolver().getType(Uri.fromFile(child));
  Log.v(LOG_TAG, "createRowForChild(child=" + child + ") type=" + type);
  if (type == null) type = child.isDirectory() ? Document.MIME_TYPE_DIR : "application/octet-stream";
  int flags = child.isDirectory()
    ? /*Document.FLAG_DIR_PREFERS_GRID |*/ Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_DIR_SUPPORTS_CREATE
    : /*Document.FLAG_SUPPORTS_WRITE*/ 0;
  row.add(Document.COLUMN_FLAGS, flags);
  row.add(Document.COLUMN_DISPLAY_NAME, child.getName());
  row.add(Document.COLUMN_DOCUMENT_ID, getDocumentId(child));
  row.add(Document.COLUMN_MIME_TYPE, type);
  row.add(Document.COLUMN_SIZE, child.isDirectory() ? child.getTotalSpace() - child.getFreeSpace() : child.length());
  row.add(Document.COLUMN_LAST_MODIFIED, null);
}
 
源代码10 项目: Silence   文件: ConversationListLoader.java
private Cursor getUnarchivedConversationList() {
  List<Cursor> cursorList = new LinkedList<>();
  cursorList.add(DatabaseFactory.getThreadDatabase(context).getConversationList());

  int archivedCount = DatabaseFactory.getThreadDatabase(context)
                                     .getArchivedConversationListCount();

  if (archivedCount > 0) {
    MatrixCursor switchToArchiveCursor = new MatrixCursor(new String[] {
        ThreadDatabase.ID, ThreadDatabase.DATE, ThreadDatabase.MESSAGE_COUNT,
        ThreadDatabase.RECIPIENT_IDS, ThreadDatabase.SNIPPET, ThreadDatabase.READ,
        ThreadDatabase.TYPE, ThreadDatabase.SNIPPET_TYPE, ThreadDatabase.SNIPPET_URI,
        ThreadDatabase.ARCHIVED, ThreadDatabase.STATUS, ThreadDatabase.LAST_SEEN}, 1);

    switchToArchiveCursor.addRow(new Object[] {-1L, System.currentTimeMillis(), archivedCount,
                                               "-1", null, 1, ThreadDatabase.DistributionTypes.ARCHIVE,
                                               0, null, 0, -1, 0});

    cursorList.add(switchToArchiveCursor);
  }

  return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
 
源代码11 项目: Shelter   文件: CrossProfileDocumentsProvider.java
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) {
    ensureServiceBound();
    List<Map<String, Serializable>> files;
    try {
        files = mService.loadFiles(parentDocumentId);
    } catch (RemoteException e) {
        return null;
    }
    final MatrixCursor result = new MatrixCursor(projection == null ? DEFAULT_DOCUMENT_PROJECTION : projection);
    // Allow receiving notification on create / delete
    result.setNotificationUri(getContext().getContentResolver(),
            DocumentsContract.buildDocumentUri(AUTHORITY, parentDocumentId));

    for (Map<String, Serializable> file : files) {
        includeFile(result, file);
    }
    return result;
}
 
@Override
public Cursor queryChildDocuments(final String parentDocumentId, final String[] projection,
                                  final String sortOrder) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_DOCUMENT_PROJECTION);
    final File parent = new File(parentDocumentId);
    for (File file : parent.listFiles()) {
        // Don't show hidden files/folders
        if (!file.getName().startsWith(".")) {
            // Adds the file's display name, MIME type, size, and so on.
            includeFile(result, file);
        }
    }
    return result;
}
 
源代码13 项目: arca-android   文件: DataUtils.java
public static <T> MatrixCursor getCursor(final List<T> list) {
    if (list == null || list.isEmpty())
        return new MatrixCursor(new String[] { "_id" });

    final String[] titles = getFieldTitlesFromObject(list.get(0));

    final MatrixCursor cursor = new MatrixCursor(titles);

    try {
        addFieldValuesFromList(cursor, list);
    } catch (final IllegalAccessException e) {
        Logger.ex(e);
    }

    return cursor;
}
 
源代码14 项目: CSipSimple   文件: AccountsLoader.java
/**
 * Creates a cursor that contains a single row and maps the section to the
 * given value.
 */
private Cursor createCursorForAccount(FilteredProfile fa) {
    MatrixCursor matrixCursor = new MatrixCursor(COLUMN_HEADERS);
    
    
    matrixCursor.addRow(new Object[] {
            fa.account.id,
            fa.account.id,
            fa.account.display_name,
            fa.account.wizard,
            fa.isForceCall ? 1 : 0,
            fa.rewriteNumber(numberToCall),
            fa.getStatusForOutgoing() ? 1 : 0,
            fa.getStatusColor()
    });
    return matrixCursor;
}
 
源代码15 项目: YiBo   文件: SearchCatalogProvider.java
@Override
public Cursor query(Uri uri, String[] projection, String selection,
		String[] selectionArgs, String sortOrder) {
	if (selectionArgs == null
		|| selectionArgs.length == 0
		|| StringUtil.isEmpty(selectionArgs[0])) {
		return null;
	}
	
	MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES);
	Object[] row1 = new Object[]{
		new Integer(SEARCH_CATALOG_STATUS), 
		getContext().getString(R.string.lable_search_suggest_status, selectionArgs[0]),
		SEARCH_CATALOG_STATUS, selectionArgs[0]};
	Object[] row2 = new Object[]{
		new Integer(SEARCH_CATALOG_USER), 
		getContext().getString(R.string.lable_search_suggest_user, selectionArgs[0]),
		SEARCH_CATALOG_USER, selectionArgs[0]};
	
	cursor.addRow(row1);
	cursor.addRow(row2);
	return cursor;
}
 
源代码16 项目: Matisse   文件: AlbumLoader.java
@Override
public Cursor loadInBackground() {
    Cursor albums = super.loadInBackground();
    MatrixCursor allAlbum = new MatrixCursor(COLUMNS);
    int totalCount = 0;
    String allAlbumCoverPath = "";
    if (albums != null) {
        while (albums.moveToNext()) {
            totalCount += albums.getInt(albums.getColumnIndex(COLUMN_COUNT));
        }
        if (albums.moveToFirst()) {
            allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA));
        }
    }
    allAlbum.addRow(new String[]{Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath,
            String.valueOf(totalCount)});

    return new MergeCursor(new Cursor[]{allAlbum, albums});
}
 
源代码17 项目: mobile-manager-tool   文件: NowPlayingFragment.java
@Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
      if (data == null) {
          return;
      }
      long[] mNowPlaying = MusicUtils.getQueue();
  	String[] audioCols = new String[] { BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ARTIST, AudioColumns.ALBUM};
      MatrixCursor playlistCursor = new MatrixCursor(audioCols);
  	for(int i = 0; i < mNowPlaying.length; i++){
  		data.moveToPosition(-1);
  		while (data.moveToNext()) {
              long audioid = data.getLong(data.getColumnIndexOrThrow(BaseColumns._ID));
          	if( audioid == mNowPlaying[i]) {
                  String trackName = data.getString(data.getColumnIndexOrThrow(MediaColumns.TITLE));
                  String artistName = data.getString(data.getColumnIndexOrThrow(AudioColumns.ARTIST));
                  String albumName = data.getString(data.getColumnIndexOrThrow(AudioColumns.ALBUM));
          		playlistCursor.addRow(new Object[] {audioid, trackName, artistName, albumName });
          	}
          }
  	}
      data.close();
mCursor = playlistCursor;
      super.onLoadFinished(loader, playlistCursor);
  }
 
源代码18 项目: androidtv-sample-inputs   文件: ChannelTest.java
private static MatrixCursor getChannelCursor(ContentValues contentValues) {
    String[] rows = Channel.PROJECTION;
    MatrixCursor cursor = new MatrixCursor(rows);
    MatrixCursor.RowBuilder builder = cursor.newRow();
    for(String row: rows) {
        if (row != null) {
            builder.add(row, contentValues.get(row));
        }
    }
    cursor.moveToFirst();
    return cursor;
}
 
源代码19 项目: mobile-manager-tool   文件: AddIdCursorLoader.java
@Override
  public Cursor loadInBackground() {

      Cursor mediaCursor = getContext().getContentResolver().query(mUri, mProjection, mSelection,
              mSelectionArgs, mSortOrder);
      //Get cursor filled with Audio Id's
      String [] projection =  new String[] {
              BaseColumns._ID, AlbumColumns.ALBUM
      };
      Uri uri = Audio.Albums.EXTERNAL_CONTENT_URI;
      String sortOrder = Audio.Albums.DEFAULT_SORT_ORDER;
      Cursor albumCursor = getContext().getContentResolver().query(uri, projection, null, null, sortOrder);

      //Matrix cursor to hold final data to be returned to calling context
      MatrixCursor cursor = new MatrixCursor( new String[]
      		{ BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ARTIST, AudioColumns.ALBUM, AudioColumns.ALBUM_ID});
      //Map data from Audio Id cursor to the ALbumName Colum
      ContentQueryMap mQueryMap = new ContentQueryMap(albumCursor, AlbumColumns.ALBUM, false, null);

Map<String, ContentValues> data = mQueryMap.getRows();
      if (mediaCursor != null) {
          while(mediaCursor.moveToNext()) {
		String id = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(BaseColumns._ID));
		String title = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(MediaColumns.TITLE));
		String artist = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(AudioColumns.ARTIST));
		String album = mediaCursor.getString(mediaCursor.getColumnIndexOrThrow(AudioColumns.ALBUM));

		ContentValues tData = data.get(album);
		String albumid = (String) tData.get(BaseColumns._ID);
		cursor.addRow(new String[] {id, title, artist, album, albumid});
          }
          mediaCursor.close();
      }

      if (cursor != null) {
          // Ensure the cursor window is filled
          registerContentObserver(cursor, mObserver);
      }
      return cursor;
  }
 
源代码20 项目: mollyim-android   文件: ContactsCursorLoader.java
private Cursor getPhoneNumberSearchHeaderCursor() {
  MatrixCursor contactsHeader = new MatrixCursor(CONTACT_PROJECTION, 1);
  contactsHeader.addRow(new Object[] { null,
                                       getContext().getString(R.string.ContactsCursorLoader_phone_number_search),
                                       "",
                                       ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE,
                                       "",
                                       ContactRepository.DIVIDER_TYPE });
  return contactsHeader;
}
 
源代码21 项目: droidddle   文件: LocalStorageProvider.java
@Override
public Cursor queryDocument(final String documentId, final String[] projection) throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_DOCUMENT_PROJECTION);
    includeFile(result, new File(documentId));
    return result;
}
 
源代码22 项目: coursera-android   文件: StringsContentProvider.java
@Override
public synchronized Cursor query(Uri uri, String[] projection,
		String selection, String[] selectionArgs, String sortOrder) {

	// Create simple cursor
	MatrixCursor cursor = new MatrixCursor(DataContract.ALL_COLUMNS);

	if (isTableUri(uri)) {

		// Add all rows to cursor
		for (int idx = 0; idx < db.size(); idx++) {

			DataRecord dataRecord = db.get(db.keyAt(idx));
			cursor.addRow(new Object[] { dataRecord.getID(),
					dataRecord.getData() });

		}
	} else if (isItemUri(uri)){

		// Add single row to cursor
		Integer requestId = Integer.parseInt(uri.getLastPathSegment());

		if (null != db.get(requestId)) {

			DataRecord dr = db.get(requestId);
			cursor.addRow(new Object[] { dr.getID(), dr.getData() });

		}
	}
	return cursor;
}
 
源代码23 项目: telescope   文件: FileProvider.java
/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
 * managed by the FileProvider.
 * FileProvider reports the column names defined in {@link android.provider.OpenableColumns}:
 * <ul>
 * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link android.provider.OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri A content URI returned by {@link #getUriForFile}.
 * @param projection The list of columns to put into the {@link Cursor}. If null all columns are
 * included.
 * @param selection Selection criteria to apply. If null then all data that matches the content
 * URI is returned.
 * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to
 * the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 * right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 * <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 * values are bound to <i>selection</i> as {@link java.lang.String} values.
 * @param sortOrder A {@link java.lang.String} containing the column name(s) on which to sort
 * the resulting {@link Cursor}.
 * @return A {@link Cursor} containing the results of the query.
 */
@Override public Cursor query(Uri uri, String[] projection, String selection,
    String[] selectionArgs, String sortOrder) {
  // ContentProvider has already checked granted permissions
  final File file = mStrategy.getFileForUri(uri);

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

  String[] cols = new String[projection.length];
  Object[] values = new Object[projection.length];
  int i = 0;
  for (String col : projection) {
    if (OpenableColumns.DISPLAY_NAME.equals(col)) {
      cols[i] = OpenableColumns.DISPLAY_NAME;
      values[i++] = file.getName();
    } else if (OpenableColumns.SIZE.equals(col)) {
      cols[i] = OpenableColumns.SIZE;
      values[i++] = file.length();
    }
  }

  cols = copyOf(cols, i);
  values = copyOf(values, i);

  final MatrixCursor cursor = new MatrixCursor(cols, 1);
  cursor.addRow(values);
  return cursor;
}
 
源代码24 项目: sprinkles   文件: DateSerializerTest.java
@Test
public void serialize() {
    DateSerializer serializer = new DateSerializer();
    String name = "date";

    Date obj = new Date(100);
    ContentValues cv = new ContentValues();
    serializer.pack(obj, cv, name);

    MatrixCursor c = new MatrixCursor(new String[]{name});
    c.addRow(new Object[]{cv.getAsLong(name)});

    c.moveToFirst();
    assertTrue(serializer.unpack(c, name).equals(new Date(100)));
}
 
源代码25 项目: AndroidComponentPlugin   文件: ContentProvider.java
@Override
public Cursor query(String callingPkg, Uri uri, @Nullable String[] projection,
        @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) {
    validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    if (enforceReadPermission(callingPkg, uri, null) != AppOpsManager.MODE_ALLOWED) {
        // The caller has no access to the data, so return an empty cursor with
        // the columns in the requested order. The caller may ask for an invalid
        // column and we would not catch that but this is not a problem in practice.
        // We do not call ContentProvider#query with a modified where clause since
        // the implementation is not guaranteed to be backed by a SQL database, hence
        // it may not handle properly the tautology where clause we would have created.
        if (projection != null) {
            return new MatrixCursor(projection, 0);
        }

        // Null projection means all columns but we have no idea which they are.
        // However, the caller may be expecting to access them my index. Hence,
        // we have to execute the query as if allowed to get a cursor with the
        // columns. We then use the column names to return an empty cursor.
        Cursor cursor = ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
        if (cursor == null) {
            return null;
        }

        // Return an empty cursor for all columns.
        return new MatrixCursor(cursor.getColumnNames(), 0);
    }
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
源代码26 项目: XPrivacy   文件: XContentResolver.java
private void copyColumns(Cursor cursor, MatrixCursor result, int count) {
	try {
		Object[] columns = new Object[count];
		for (int i = 0; i < count; i++)
			switch (cursor.getType(i)) {
			case Cursor.FIELD_TYPE_NULL:
				columns[i] = null;
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				columns[i] = cursor.getInt(i);
				break;
			case Cursor.FIELD_TYPE_FLOAT:
				columns[i] = cursor.getFloat(i);
				break;
			case Cursor.FIELD_TYPE_STRING:
				columns[i] = cursor.getString(i);
				break;
			case Cursor.FIELD_TYPE_BLOB:
				columns[i] = cursor.getBlob(i);
				break;
			default:
				Util.log(this, Log.WARN, "Unknown cursor data type=" + cursor.getType(i));
			}
		result.addRow(columns);
	} catch (Throwable ex) {
		Util.bug(this, ex);
	}
}
 
源代码27 项目: android_9.0.0_r45   文件: ContentProvider.java
@Override
public Cursor query(String callingPkg, Uri uri, @Nullable String[] projection,
        @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) {
    uri = validateIncomingUri(uri);
    uri = maybeGetUriWithoutUserId(uri);
    if (enforceReadPermission(callingPkg, uri, null) != AppOpsManager.MODE_ALLOWED) {
        // The caller has no access to the data, so return an empty cursor with
        // the columns in the requested order. The caller may ask for an invalid
        // column and we would not catch that but this is not a problem in practice.
        // We do not call ContentProvider#query with a modified where clause since
        // the implementation is not guaranteed to be backed by a SQL database, hence
        // it may not handle properly the tautology where clause we would have created.
        if (projection != null) {
            return new MatrixCursor(projection, 0);
        }

        // Null projection means all columns but we have no idea which they are.
        // However, the caller may be expecting to access them my index. Hence,
        // we have to execute the query as if allowed to get a cursor with the
        // columns. We then use the column names to return an empty cursor.
        Cursor cursor = ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
        if (cursor == null) {
            return null;
        }

        // Return an empty cursor for all columns.
        return new MatrixCursor(cursor.getColumnNames(), 0);
    }
    final String original = setCallingPackage(callingPkg);
    try {
        return ContentProvider.this.query(
                uri, projection, queryArgs,
                CancellationSignal.fromTransport(cancellationSignal));
    } finally {
        setCallingPackage(original);
    }
}
 
源代码28 项目: sprinkles   文件: CursorListTest.java
@Before
public void initList() {
    MatrixCursor c = new MatrixCursor(new String[]{"title", "id"});
    c.addRow(new Object[]{"title1", 1});
    c.addRow(new Object[]{"title2", 2});
    c.addRow(new Object[]{"title3", 3});
    list = new CursorList<TestModel>(c, TestModel.class);
}
 
源代码29 项目: Study_Android_Demo   文件: SettingsProvider.java
private Cursor getAllSystemSettings(int userId, String[] projection) {
    if (DEBUG) {
        Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")");
    }

    // Resolve the userId on whose behalf the call is made.
    final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);

    synchronized (mLock) {
        List<String> names = getSettingsNamesLocked(SETTINGS_TYPE_SYSTEM, callingUserId);

        final int nameCount = names.size();

        String[] normalizedProjection = normalizeProjection(projection);
        MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);

        for (int i = 0; i < nameCount; i++) {
            String name = names.get(i);

            // Determine the owning user as some profile settings are cloned from the parent.
            final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId,
                    name);

            Setting setting = mSettingsRegistry.getSettingLocked(
                    SETTINGS_TYPE_SYSTEM, owningUserId, name);
            appendSettingToCursor(result, setting);
        }

        return result;
    }
}
 
源代码30 项目: filechooser   文件: LocalStorageProvider.java
@Override
public Cursor queryDocument(final String documentId, final String[] projection)
        throws FileNotFoundException {
    // Create a cursor with either the requested fields, or the default
    // projection if "projection" is null.
    final MatrixCursor result = new MatrixCursor(projection != null ? projection
            : DEFAULT_DOCUMENT_PROJECTION);
    includeFile(result, new File(documentId));
    return result;
}