Java 类android.database.MatrixCursor 实例源码

项目:keepass2android    文件:LocalFileProvider.java   
/**
 * Checks ancestor with {@link BaseFile#CMD_IS_ANCESTOR_OF},
 * {@link BaseFile#PARAM_SOURCE} and {@link BaseFile#PARAM_TARGET}.
 * 
 * @param uri
 *            the original URI from client.
 * @return {@code null} if source is not ancestor of target; or a
 *         <i>non-null but empty</i> cursor if the source is.
 */
private MatrixCursor doCheckAncestor(Uri uri) {
    File source = new File(Uri.parse(
            uri.getQueryParameter(BaseFile.PARAM_SOURCE)).getPath());
    File target = new File(Uri.parse(
            uri.getQueryParameter(BaseFile.PARAM_TARGET)).getPath());
    if (source == null || target == null)
        return null;

    boolean validate = ProviderUtils.getBooleanQueryParam(uri,
            BaseFile.PARAM_VALIDATE, true);
    if (validate) {
        if (!source.isDirectory() || !target.exists())
            return null;
    }

    if (source.equals(target.getParentFile())
            || (target.getParent() != null && target.getParent()
                    .startsWith(source.getAbsolutePath())))
        return BaseFileProviderUtils.newClosedCursor();

    return null;
}
项目:keepass2android    文件:Kp2aFileProvider.java   
private MatrixCursor getCheckConnectionCursor(Uri uri) {
    try
    {
        checkConnection(uri);
        Log.d("KP2A_FC_P", "checking connection for " + uri + " ok.");
        return null;
    }
    catch (Exception e)
    {
        Log.d("KP2A_FC_P","Check connection failed with: " + e.toString());

        MatrixCursor matrixCursor = new MatrixCursor(BaseFileProviderUtils.CONNECTION_CHECK_CURSOR_COLUMNS);
        RowBuilder newRow = matrixCursor.newRow();
        String message = e.getLocalizedMessage();
        if (message == null)
            message = e.getMessage();
        if (message == null)
            message = e.toString();
        newRow.add(message);
        return matrixCursor;
    }
}
项目:keepass2android    文件:Kp2aFileProvider.java   
private RowBuilder addFileInfo(MatrixCursor matrixCursor, int id,
        FileEntry f) {
    int type = !f.isDirectory ? BaseFile.FILE_TYPE_FILE : BaseFile.FILE_TYPE_DIRECTORY;
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(id);// _ID
    newRow.add(BaseFile
            .genContentIdUriBase(
                    getAuthority())
            .buildUpon().appendPath(f.path)
            .build().toString());
    newRow.add(f.path);
    if (f.displayName == null)
        Log.w("KP2AJ", "displayName is null for " + f.path);
    newRow.add(f.displayName);
    newRow.add(f.canRead ? 1 : 0);
    newRow.add(f.canWrite ? 1 : 0);
    newRow.add(f.sizeInBytes);
    newRow.add(type);
    if (f.lastModifiedTime > 0)
        newRow.add(f.lastModifiedTime);
    else 
        newRow.add(null);
    newRow.add(FileUtils.getResIcon(type, f.displayName));
    return newRow;
}
项目:keepass2android    文件:Kp2aFileProvider.java   
private void addDeletedFileInfo(MatrixCursor matrixCursor, String filename) {
    int type = BaseFile.FILE_TYPE_NOT_EXISTED;
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(0);// _ID
    newRow.add(BaseFile
            .genContentIdUriBase(
                    getAuthority())
            .buildUpon().appendPath(filename)
            .build().toString());
    newRow.add(filename);
    newRow.add(filename);
    newRow.add(0);
    newRow.add(0);
    newRow.add(0);
    newRow.add(type);
    newRow.add(null);
    newRow.add(FileUtils.getResIcon(type, filename));
}
项目:PeSanKita-android    文件: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.RECEIPT_COUNT,
        ThreadDatabase.EXPIRES_IN, ThreadDatabase.LAST_SEEN}, 1);

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

    cursorList.add(switchToArchiveCursor);
  }

  return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
项目: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;
}
项目:CSipSimple    文件:FavLoader.java   
/**
 * Creates a cursor that contains contacts group corresponding to an sip
 * account.
 */
private Cursor createContentCursorFor(SipProfile account) {
    Cursor c = null;
    if(!TextUtils.isEmpty(account.android_group)) {
        c = ContactsWrapper.getInstance().getContactsByGroup(getContext(), account.android_group);
    }
    if(c != null) {
        return c;
    }
    MatrixCursor mc = new MatrixCursor (new String[] {
            BaseColumns._ID, 
            ContactsWrapper.FIELD_TYPE
    });
    mc.addRow(new Object[] {account.id, ContactsWrapper.TYPE_CONFIGURE});
    return mc;
}
项目:Matisse-Image-and-Video-Selector    文件: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});
}
项目:Farmacias    文件:DbProvider.java   
private MatrixCursor createMatrixCursor(Cursor cursor, int cursorOrigin) {
    MatrixCursor matrixCursor = new MatrixCursor(suggestionsColumnNames, cursor.getCount());
    MatrixCursor.RowBuilder builder;
    if (cursor.moveToFirst()) {
        do {
            builder = matrixCursor.newRow();
            if (cursorOrigin == RECENT_SEARCH_ORIGIN) {

                builder.add(FindQuickSearchAdapter.HISTORY_ROW);
                builder.add(cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_QUERY)));

            } else {

                builder.add(FindQuickSearchAdapter.DATABASE_ROW);
                builder.add(cursor.getString(cursor.getColumnIndex(DbContract.FarmaciasEntity.NAME)));
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return matrixCursor;
}
项目:Farmacias    文件:FindFragment.java   
public MatrixCursor transformListInToCursor(List<Pharmacy> pharmacyList) {
    if (pharmacyList == null) return null;
    String[] columnNames = {DbContract.FarmaciasEntity._ID,
            DbContract.FarmaciasEntity.NAME,
            DbContract.FarmaciasEntity.ADDRESS,
            DbContract.FarmaciasEntity.LOCALITY,
            DbContract.FarmaciasEntity.PROVINCE
    };
    MatrixCursor cursor = new MatrixCursor(columnNames, pharmacyList.size());
    MatrixCursor.RowBuilder builder;
    for (Pharmacy ph : pharmacyList) {
        builder = cursor.newRow();
        builder.add(ph.get_id());
        builder.add(ph.getName());
        builder.add(ph.getAddress());
        builder.add(ph.getLocality());
        builder.add(ph.getProvince());
    }
    return cursor;
}
项目:Hello-Music-droid    文件:MusicService.java   
private void updateCursorForDownloadedFile(Context context, Uri uri) {
    synchronized (this) {
        closeCursor();
        MatrixCursor cursor = new MatrixCursor(PROJECTION_MATRIX);
        String title = getValueForDownloadedFile(this, uri, "title");
        cursor.addRow(new Object[]{
                null,
                null,
                null,
                title,
                null,
                null,
                null,
                null
        });
        mCursor = cursor;
        mCursor.moveToFirst();
    }
}
项目:KomaMusic    文件:MusicService.java   
/**
 * Creates a pseudo cursor for downloaded audio files with minimal info
 *
 * @param context needed to query the download uri
 * @param uri     the uri of the downloaded file
 */
private void updateCursorForDownloadedFile(Context context, Uri uri) {
    synchronized (this) {
        closeCursor();  // clear mCursor
        MatrixCursor cursor = new MatrixCursor(PROJECTION_MATRIX);
        // get title of the downloaded file ; Downloads.Impl.COLUMN_TITLE
        String title = getValueForDownloadedFile(this, uri, "title");
        // populating the cursor with bare minimum info
        cursor.addRow(new Object[]{
                null,
                null,
                null,
                title,
                null,
                null,
                null,
                null
        });
        mCursor = cursor;
        mCursor.moveToFirst();
    }
}
项目:orgzly-android    文件:AgendaFragment.java   
private MergeCursor mergeDates(long nextId, Map<Long, MatrixCursor> agenda) {
    List<Cursor> allCursors = new ArrayList<>();

    for (long dateMilli: agenda.keySet()) {
        DateTime date = new DateTime(dateMilli);
        MatrixCursor dateCursor = new MatrixCursor(Columns.AGENDA_SEPARATOR_COLS);
        MatrixCursor.RowBuilder dateRow = dateCursor.newRow();
        dateRow.add(nextId++);
        dateRow.add(userTimeFormatter.formatDate(AgendaUtils.buildOrgDateTimeFromDate(date, null)));
        dateRow.add(1); // Separator
        allCursors.add(dateCursor);
        allCursors.add(agenda.get(dateMilli));
    }

    return new MergeCursor(allCursors.toArray(new Cursor[allCursors.size()]));
}
项目:xlight_android_native    文件:LocalStorageProvider.java   
@Override
public Cursor queryRoots(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_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.internal_storage));
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
项目:xlight_android_native    文件: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;
}
项目:xlight_android_native    文件:LocalStorageProvider.java   
private void includeFile(final MatrixCursor result, final File file)
        throws FileNotFoundException {
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath());
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    String mimeType = getDocumentType(file.getAbsolutePath());
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE
            : 0;
    // We only show thumbnails for image files - expect a call to
    // openDocumentThumbnail for each file that has
    // this flag set
    if (mimeType.startsWith("image/"))
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    row.add(Document.COLUMN_FLAGS, flags);
    // COLUMN_SIZE is required, but can be null
    row.add(Document.COLUMN_SIZE, file.length());
    // These columns are optional
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
    // Document.COLUMN_ICON can be a resource id identifying a custom icon.
    // The system provides default icons
    // based on mime type
    // Document.COLUMN_SUMMARY is optional additional information about the
    // file
}
项目:aos-Video    文件:AutoScraperActivity.java   
private MatrixCursor buildAdapterCursor(Cursor cursor) {
    // Create a clone of the provided cursor but keep only the needed columns
    MatrixCursor newCursor = new MatrixCursor(SCRAPER_ADAPTER_COLS);

    if (mFileCount > 0) {
        int columns = newCursor.getColumnCount();
        cursor.moveToFirst();
        do {
            // Build an array with the data corresponding to the current row
            ArrayList<String> rowData = new ArrayList<String>(columns);
            rowData.add(cursor.getString(mIdIndex));
            rowData.add(cursor.getString(mDataIndex));
            rowData.add(cursor.getString(mTitleIndex));

            // Add the row to the cloned cursor
            newCursor.addRow(rowData);
        } while (cursor.moveToNext());
    }

    return newCursor;
}
项目:buildAPKsSamples    文件:WeatherDataProvider.java   
@Override
public synchronized int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
    assert(uri.getPathSegments().size() == 1);

    // In this sample, we only update the content provider individually for each row with new
    // temperature values.
    final int index = Integer.parseInt(uri.getPathSegments().get(0));
    final MatrixCursor c = new MatrixCursor(
            new String[]{ Columns.ID, Columns.DAY, Columns.TEMPERATURE });
    assert(0 <= index && index < sData.size());
    final WeatherDataPoint data = sData.get(index);
    data.degrees = values.getAsInteger(Columns.TEMPERATURE);

    // Notify any listeners that the data backing the content provider has changed, and return
    // the number of rows affected.
    getContext().getContentResolver().notifyChange(uri, null);
    return 1;
}
项目: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});
}
项目:Cable-Android    文件: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.RECEIPT_COUNT,
        ThreadDatabase.EXPIRES_IN, ThreadDatabase.LAST_SEEN}, 1);

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

    cursorList.add(switchToArchiveCursor);
  }

  return new MergeCursor(cursorList.toArray(new Cursor[0]));
}
项目:VanGogh    文件:AlbumLoader.java   
@Override
public Cursor loadInBackground() {
    Cursor albums = super.loadInBackground();
    MatrixCursor allAlbum = new MatrixCursor(COLUMNS);
    int totalCount = 0;
    while (albums.moveToNext()) {
        totalCount += albums.getInt(albums.getColumnIndex(COLUMN_COUNT));
    }
    String allAlbumCoverPath;
    if (albums.moveToFirst()) {
        allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA));
    } else {
        allAlbumCoverPath = "";
    }
    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});
}
项目:ContentPal    文件:BaseView.java   
@NonNull
@Override
public Cursor rows(@NonNull UriParams uriParams, @NonNull Projection<T> projection, @NonNull final Predicate predicate, @NonNull final Optional<String> sorting) throws RemoteException
{
    List<String> args = new LinkedList<>();
    for (Predicate.Argument arg : predicate.arguments(EmptyTransactionContext.INSTANCE))
    {
        args.add(arg.value());
    }
    String[] projectionArray = projection.toArray();
    Cursor cursor = mClient.query(uriParams.withParam(mTableUri.buildUpon()).build(),
            projectionArray,
            predicate.selection(EmptyTransactionContext.INSTANCE).toString(),
            args.toArray(new String[args.size()]),
            sorting.value(null /* fallback: null */));
    return cursor == null ? new MatrixCursor(projectionArray) : cursor;
}
项目:KeePass2Android    文件:Kp2aFileProvider.java   
private MatrixCursor getCheckConnectionCursor(Uri uri) {
    try
    {
        checkConnection(uri);
        Log.d("KP2A_FC_P", "checking connection for " + uri + " ok.");
        return null;
    }
    catch (Exception e)
    {
        Log.d("KP2A_FC_P","Check connection failed with: " + e.toString());

        MatrixCursor matrixCursor = new MatrixCursor(BaseFileProviderUtils.CONNECTION_CHECK_CURSOR_COLUMNS);
        RowBuilder newRow = matrixCursor.newRow();
        String message = e.getLocalizedMessage();
        if (message == null)
            message = e.getMessage();
        if (message == null)
            message = e.toString();
        newRow.add(message);
        return matrixCursor;
    }
}
项目:KeePass2Android    文件:Kp2aFileProvider.java   
private RowBuilder addFileInfo(MatrixCursor matrixCursor, int id,
        FileEntry f) {
    int type = !f.isDirectory ? BaseFile.FILE_TYPE_FILE : BaseFile.FILE_TYPE_DIRECTORY;
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(id);// _ID
    newRow.add(BaseFile
            .genContentIdUriBase(
                    getAuthority())
            .buildUpon().appendPath(f.path)
            .build().toString());
    newRow.add(f.path);
    if (f.displayName == null)
        Log.w("KP2AJ", "displayName is null for " + f.path);
    newRow.add(f.displayName);
    newRow.add(f.canRead ? 1 : 0);
    newRow.add(f.canWrite ? 1 : 0);
    newRow.add(f.sizeInBytes);
    newRow.add(type);
    if (f.lastModifiedTime > 0)
        newRow.add(f.lastModifiedTime);
    else 
        newRow.add(null);
    newRow.add(FileUtils.getResIcon(type, f.displayName));
    return newRow;
}
项目:KeePass2Android    文件:Kp2aFileProvider.java   
private void addDeletedFileInfo(MatrixCursor matrixCursor, String filename) {
    int type = BaseFile.FILE_TYPE_NOT_EXISTED;
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(0);// _ID
    newRow.add(BaseFile
            .genContentIdUriBase(
                    getAuthority())
            .buildUpon().appendPath(filename)
            .build().toString());
    newRow.add(filename);
    newRow.add(filename);
    newRow.add(0);
    newRow.add(0);
    newRow.add(0);
    newRow.add(type);
    newRow.add(null);
    newRow.add(FileUtils.getResIcon(type, filename));
}
项目:Applozic-Android-Chat-Sample    文件:LocalStorageProvider.java   
@Override
public Cursor queryRoots(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_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, "internal storage");
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    //row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
项目:Applozic-Android-Chat-Sample    文件: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;
}
项目:Applozic-Android-Chat-Sample    文件:LocalStorageProvider.java   
private void includeFile(final MatrixCursor result, final File file)
        throws FileNotFoundException {
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath());
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    String mimeType = getDocumentType(file.getAbsolutePath());
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE
            : 0;
    // We only show thumbnails for image files - expect a call to
    // openDocumentThumbnail for each file that has
    // this flag set
    if (mimeType.startsWith("image/"))
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    row.add(Document.COLUMN_FLAGS, flags);
    // COLUMN_SIZE is required, but can be null
    row.add(Document.COLUMN_SIZE, file.length());
    // These columns are optional
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
    // Document.COLUMN_ICON can be a resource id identifying a custom icon.
    // The system provides default icons
    // based on mime type
    // Document.COLUMN_SUMMARY is optional additional information about the
    // file
}
项目:Applozic-Android-Chat-Sample    文件:LocalStorageProvider.java   
@Override
public Cursor queryRoots(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_ROOT_PROJECTION);
    // Add Home directory
    File homeDir = Environment.getExternalStorageDirectory();
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath());
    row.add(Root.COLUMN_TITLE, "internal storage");
    row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE);
    //row.add(Root.COLUMN_ICON, R.drawable.ic_provider);
    // These columns are optional
    row.add(Root.COLUMN_AVAILABLE_BYTES, homeDir.getFreeSpace());
    // Root.COLUMN_MIME_TYPE is another optional column and useful if you
    // have multiple roots with different
    // types of mime types (roots that don't match the requested mime type
    // are automatically hidden)
    return result;
}
项目:Applozic-Android-Chat-Sample    文件: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;
}
项目:Applozic-Android-Chat-Sample    文件:LocalStorageProvider.java   
private void includeFile(final MatrixCursor result, final File file)
        throws FileNotFoundException {
    final MatrixCursor.RowBuilder row = result.newRow();
    // These columns are required
    row.add(Document.COLUMN_DOCUMENT_ID, file.getAbsolutePath());
    row.add(Document.COLUMN_DISPLAY_NAME, file.getName());
    String mimeType = getDocumentType(file.getAbsolutePath());
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    int flags = file.canWrite() ? Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE
            : 0;
    // We only show thumbnails for image files - expect a call to
    // openDocumentThumbnail for each file that has
    // this flag set
    if (mimeType.startsWith("image/"))
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    row.add(Document.COLUMN_FLAGS, flags);
    // COLUMN_SIZE is required, but can be null
    row.add(Document.COLUMN_SIZE, file.length());
    // These columns are optional
    row.add(Document.COLUMN_LAST_MODIFIED, file.lastModified());
    // Document.COLUMN_ICON can be a resource id identifying a custom icon.
    // The system provides default icons
    // based on mime type
    // Document.COLUMN_SUMMARY is optional additional information about the
    // file
}
项目:TVPlatformContentProvider    文件:AbsPlaylistProvider.java   
private Cursor queryPublishedPlaylist() {
    List<ProviderPlaylistItem> playlist = getPublishedPlaylist();
    MatrixCursor cursor = new MatrixCursor(new String[] {
            COL_VIDEO_ID,
            COL_VIDEO_TITLE,
            COL_VIDEO_URL,
            COL_STREAM_TYPE
    });

    if (playlist != null) {
        for (ProviderPlaylistItem item : playlist) {
            cursor.addRow(new String[] {
                    item.getVideoId(),
                    item.getTitle(),
                    item.getUrl(),
                    Integer.toString(item.getStreamType())
            });
        }    
    }

    return cursor;
}
项目:TVPlatformContentProvider    文件:AbsPlaylistProvider.java   
private Cursor queryLastPlayedItem() {
    ProviderPlaylistItem item = getLastPlayedItem();
    MatrixCursor cursor = new MatrixCursor(new String[] {
            COL_VIDEO_ID,
            COL_VIDEO_TITLE,
            COL_VIDEO_URL,
            COL_STREAM_TYPE
    });

    if (item != null) {
        cursor.addRow(new String[] {
                item.getVideoId(),
                item.getTitle(),
                item.getUrl(),
                Integer.toString(item.getStreamType())
        });
        return cursor;
    }

    return null;
}
项目:TVPlatformContentProvider    文件:AbsPlaylistProvider.java   
private Cursor queryPrevItemInPlaylist(String videoId) {
    ProviderPlaylistItem prevItem = getPrevItemInPlaylist(videoId);
    MatrixCursor cursor = new MatrixCursor(new String[] {
            COL_VIDEO_ID,
            COL_VIDEO_TITLE,
            COL_VIDEO_URL,
            COL_STREAM_TYPE
    });

    if (prevItem != null) {
        cursor.addRow(new String[] {
                prevItem.getVideoId(),
                prevItem.getTitle(),
                prevItem.getUrl(),
                Integer.toString(prevItem.getStreamType())
        });
        return cursor;
    }

    return null;
}
项目:AlchemistAndroidUtil    文件: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;
}
项目:zonebeacon    文件:DataSourceTest.java   
@Test
public void test_findGateways() {
    MatrixCursor cursor = new MatrixCursor(new String[] {
            "_id", "name", "ip_address", "port_number", "system_type_id"
    });

    cursor.addRow(new String[] {"1", "gateway 1", "192.168.1.100", "11000", "1"});
    cursor.addRow(new String[] {"2", "gateway 2", "192.168.1.150", "11000", "1"});
    cursor.addRow(new String[] {"3", "gateway 3", "192.168.1.200", "11000", "1"});

    when(database.rawQuery(anyString(), any(String[].class))).thenReturn(cursor);
    List<Gateway> gateways = source.findGateways();

    assertEquals(3, gateways.size());
    assertEquals("gateway 1", gateways.get(0).getName());
    assertEquals("gateway 2", gateways.get(1).getName());
    assertEquals("gateway 3", gateways.get(2).getName());
}
项目:zonebeacon    文件:DataSourceTest.java   
@Test
public void test_findCommandTypes() {
    Gateway gateway = new Gateway();
    gateway.setSystemTypeId(1L);

    MatrixCursor cursor = new MatrixCursor(new String[] {
            "_id", "name", "base_serial_on_code", "base_serial_off_code", "system_type_id",
            "activate_controller_selection"
    });

    cursor.addRow(new String[] {"1", "command type 1", "1", "1", "1", "0"});
    cursor.addRow(new String[] {"2", "command type 2", "1", "1", "1", "0"});
    cursor.addRow(new String[] {"3", "command type 3", "1", "1", "1", "0"});

    when(database.rawQuery(anyString(), any(String[].class))).thenReturn(cursor);
    List<CommandType> types = source.findCommandTypes(gateway);

    assertEquals(3, types.size());
    assertEquals("command type 1", types.get(0).getName());
    assertEquals("command type 2", types.get(1).getName());
    assertEquals("command type 3", types.get(2).getName());
    assertTrue(cursor.isClosed());
}
项目:zonebeacon    文件:DataSourceTest.java   
@Test
public void test_findCommandTypes_noRows() {
    Gateway gateway = new Gateway();
    gateway.setSystemTypeId(1L);

    MatrixCursor cursor = new MatrixCursor(new String[] {
            "_id", "name", "base_serial_on_code", "base_serial_off_code", "system_type_id",
            "activate_controller_selection"
    });

    when(database.rawQuery(anyString(), any(String[].class))).thenReturn(cursor);
    List<CommandType> types = source.findCommandTypes(gateway);

    assertEquals(0, types.size());
    assertTrue(cursor.isClosed());
}
项目:zonebeacon    文件:DataSourceTest.java   
@Test
public void test_findSystemTypes() {
    MatrixCursor cursor = new MatrixCursor(new String[] {
            "_id", "name", "version"
    });

    cursor.addRow(new String[] {"1", "system type 1", "1"});
    cursor.addRow(new String[] {"2", "system type 2", "1"});
    cursor.addRow(new String[] {"3", "system type 3", "2"});

    when(database.rawQuery(anyString(), any(String[].class))).thenReturn(cursor);
    List<SystemType> types = source.findSystemTypes();

    assertEquals(3, types.size());
    assertEquals("system type 1", types.get(0).getName());
    assertEquals("system type 2", types.get(1).getName());
    assertEquals("system type 3", types.get(2).getName());
    assertTrue(cursor.isClosed());
}
项目:zonebeacon    文件:DataSourceTest.java   
@Test
public void test_findCommands() {
    MatrixCursor cursor = new MatrixCursor(new String[] {
            "_id", "name", "gateway_id", "number", "command_type_id", "controller_number"
    });

    cursor.addRow(new String[] {"1", "command 1", "1", "1", "1", "1"});
    cursor.addRow(new String[] {"2", "command 2", "1", "1", "1", "1"});
    cursor.addRow(new String[] {"3", "command 3", "1", "1", "1", "1"});

    when(database.rawQuery(anyString(), any(String[].class))).thenReturn(cursor);

    Gateway gateway = new Gateway();
    gateway.setId(1);
    List<Command> commands = source.findCommands(gateway);

    assertEquals(3, commands.size());
    assertEquals("command 1", commands.get(0).getName());
    assertEquals("command 2", commands.get(1).getName());
    assertEquals("command 3", commands.get(2).getName());
}