android.database.MatrixCursor Java Examples

The following examples show how to use android.database.MatrixCursor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalStorageProvider.java    From filechooser with MIT License 6 votes vote down vote up
@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;
}
 
Example #2
Source File: StickerContentProvider.java    From flutter_whatsapp_stickers with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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;
}
 
Example #3
Source File: ExpandShrinkListViewActivity.java    From AndroidViewUtils with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: LocalStorageProvider.java    From Effects-Pro with MIT License 6 votes vote down vote up
@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;
}
 
Example #5
Source File: AccountsLoader.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: SearchCatalogProvider.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: DataUtils.java    From arca-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #8
Source File: LocalStorageProvider.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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;
}
 
Example #9
Source File: AlbumLoader.java    From Matisse with Apache License 2.0 6 votes vote down vote up
@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});
}
 
Example #10
Source File: RowsTest.java    From SMP with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #11
Source File: CrossProfileDocumentsProvider.java    From Shelter with Do What The F*ck You Want To Public License 6 votes vote down vote up
@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;
}
 
Example #12
Source File: ContactsCursorLoader.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
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();
  }
}
 
Example #13
Source File: SuntimesThemeProvider.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: HobbitProviderImplHashMap.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: ConversationListLoader.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
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]));
}
 
Example #16
Source File: NowPlayingFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@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);
  }
 
Example #17
Source File: AppStorageProvider.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: BelvedereFileProvider.java    From belvedere with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
                    final String[] selectionArgs, final String sortOrder) {
    final Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder);

    /*
        It's not necessary to overwrite
            public Cursor query(final Uri uri, final String[] projection, final String selection, final String[]
                selectionArgs, final String sortOrder, final CancellationSignal cancellationSignal);
        cause it calls this method.

        == What's happening here? ==
        Some apps rely on the MediaStore.MediaColumns.DATA column in the cursor. To prevent them
        from crashing, we have to copy the initial cursor and add the MediaStore.MediaColumns.DATA
        column. The values of this column will always be null, but we assume that they are able
        to handle that case.
    */

    if(source == null) {
        Log.w(Belvedere.LOG_TAG, "Not able to apply workaround, super.query(...) returned null");
        return null;
    }

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);

    final MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            row.add(source.getString(i));
        }
    }
    source.close();

    return cursor;
}
 
Example #19
Source File: ProgramTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
private static MatrixCursor getProgramCursor(ContentValues contentValues) {
    String[] rows = Program.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;
}
 
Example #20
Source File: ScienceJournalDocsProvider.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
  // Use a MatrixCursor to build a cursor
  // with either the requested fields, or the default
  // projection if "projection" is null.
  final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));

  final MatrixCursor.RowBuilder row = result.newRow();
  row.add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_PROJECTION);

  // TODO: Implement Root.FLAG_SUPPORTS_RECENTS and Root.FLAG_SUPPORTS_SEARCH.
  // This will mean documents will show up in the "recents" category and be searchable.

  // COLUMN_TITLE is the root title (e.g. Gallery, Drive).
  row.add(Root.COLUMN_TITLE, getContext().getString(R.string.app_name));

  // This document id cannot change after it's shared.
  row.add(Root.COLUMN_DOCUMENT_ID, ROOT_DIRECTORY_ID);

  // The child MIME types are used to filter the roots and only present to the
  // user those roots that contain the desired type somewhere in their file hierarchy.
  row.add(Root.COLUMN_MIME_TYPES, "image/*");

  row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher);

  return result;
}
 
Example #21
Source File: RecordedProgramTest.java    From xipl with Apache License 2.0 5 votes vote down vote up
private static MatrixCursor getRecordedProgramCursor(ContentValues contentValues) {
    String[] rows = RecordedProgram.PROJECTION;
    MatrixCursor cursor = new MatrixCursor(rows);
    MatrixCursor.RowBuilder builder = cursor.newRow();
    for (String row : rows) {
        builder.add(row, contentValues.get(row));
    }
    cursor.moveToFirst();
    return cursor;
}
 
Example #22
Source File: TrayProviderHelperTest.java    From tray with Apache License 2.0 5 votes vote down vote up
public void testCursorToTrayItem() throws Exception {

        final MatrixCursor matrixCursor = new MatrixCursor(new String[]{
                TrayContract.Preferences.Columns.KEY,
                TrayContract.Preferences.Columns.VALUE,
                TrayContract.Preferences.Columns.MODULE,
                TrayContract.Preferences.Columns.CREATED,
                TrayContract.Preferences.Columns.UPDATED,
                TrayContract.Preferences.Columns.MIGRATED_KEY
        });
        final Date created = new Date();
        final Date updated = new Date();
        matrixCursor.addRow(new Object[]{
                "key",
                "value",
                "module",
                created.getTime(),
                updated.getTime(),
                "migratedKey"
        });
        assertTrue(matrixCursor.moveToFirst());

        final TrayItem item = TrayProviderHelper.cursorToTrayItem(matrixCursor);
        assertEquals("key", item.key());
        assertEquals("value", item.value());
        assertEquals("migratedKey", item.migratedKey());
        assertEquals("module", item.module());
        assertEquals(updated, item.updateTime());
        assertEquals(created, item.created());
    }
 
Example #23
Source File: ChannelTest.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: TaskListFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * prepares the update of the view after the group descriptor was changed
 */
public void prepareReload()
{
    mAdapter = new ExpandableGroupDescriptorAdapter(new MatrixCursor(new String[] { "_id" }), getActivity(), getLoaderManager(), mGroupDescriptor);
    mExpandableListView.setAdapter(mAdapter);
    mExpandableListView.setOnChildClickListener(mTaskItemClickListener);
    mExpandableListView.setOnGroupCollapseListener(mTaskListCollapseListener);
    mAdapter.setOnChildLoadedListener(this);
    mAdapter.setChildCursorFilter(COMPLETED_FILTER);
    restoreFilterState();

}
 
Example #25
Source File: PriorityCursorFactory.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor getCursor()
{
    MatrixCursor result = new MatrixCursor(DEFAULT_PROJECTION);
    result.addRow(ROW_PRIORITY_HIGH);
    result.addRow(ROW_PRIORITY_MEDIUM);
    result.addRow(ROW_PRIORITY_LOW);
    result.addRow(ROW_PRIORITY_NONE);
    return result;
}
 
Example #26
Source File: PrivacyProvider.java    From XPrivacy with GNU General Public License v3.0 5 votes vote down vote up
private void getUsage(int uid, String restrictionName, String methodName, MatrixCursor cursor) {
	SharedPreferences prefs = getContext().getSharedPreferences(PREF_USAGE + "." + restrictionName,
			Context.MODE_PRIVATE);
	String values = prefs.getString(getUsagePref(uid, methodName), null);
	if (values != null) {
		String[] value = values.split(":");
		long timeStamp = Long.parseLong(value[0]);
		boolean restricted = Boolean.parseBoolean(value[1]);
		cursor.addRow(new Object[] { uid, restrictionName, methodName, restricted, timeStamp });
	}
}
 
Example #27
Source File: LocalStorageProvider.java    From qiniu-lab-android with MIT License 5 votes vote down vote up
@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;
}
 
Example #28
Source File: TemplateProvider.java    From Dashboard with MIT License 5 votes vote down vote up
public Cursor query(Uri paramUri, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2) {
    MatrixCursor cursor = new MatrixCursor(new String[]{"string"});
    try {
        final String path = paramUri.getPath().substring(1);
        for (String s : getContext().getAssets().list(path)) {
            cursor.newRow().add(s);
            cursor.moveToNext();
        }
        cursor.moveToFirst();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return cursor;
}
 
Example #29
Source File: ConfigurationProvider.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
    selection = Uri.decode(uri.getLastPathSegment());
    if (selection == null) return null;
    return new MatrixCursor(new String[]{"key", "value"});
}
 
Example #30
Source File: DataUtilsTest.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testGetCursorWithNullList() throws Exception {
    final MatrixCursor cursor = DataUtils.getCursor(null);

    final String[] columnNames = cursor.getColumnNames();

    assertEquals(1, columnNames.length);
    assertEquals(columnNames[0], "_id");
}