Java 类android.database.MatrixCursor.RowBuilder 实例源码

项目: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));
}
项目: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));
}
项目:ombuds-android    文件:FileAttachmentProvider.java   
@Override
public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder)
{
    final File file = new File(uri.getPath());

    if (!file.getAbsolutePath().startsWith(getContext().getCacheDir().getAbsolutePath()))
        throw new IllegalArgumentException("not in cache dir: " + uri);

    final MatrixCursor cursor = new MatrixCursor(projection);
    final RowBuilder row = cursor.newRow();
    for (int i = 0; i < projection.length; i++)
    {
        final String columnName = projection[i];
        if (columnName.equals(MediaStore.MediaColumns.DATA))
            row.add(file.getAbsolutePath());
        else if (columnName.equals(MediaStore.MediaColumns.SIZE))
            row.add(file.length());
        else if (columnName.equals(MediaStore.MediaColumns.DISPLAY_NAME))
            row.add(uri.getLastPathSegment());
        else
            throw new IllegalArgumentException("cannot handle: " + columnName);
    }

    return cursor;
}
项目:mc_backup    文件:TestTopSitesCursorWrapper.java   
private Cursor createPinnedSitesCursor(Integer[] positions) {
    MatrixCursor c = new MatrixCursor(PINNED_SITES_COLUMNS);

    if (positions == null) {
        return c;
    }

    for (int i = 0; i < positions.length; i++) {
        int position = positions[i];

        RowBuilder row = c.newRow();
        row.add(-1);
        row.add(PINNED_PREFIX + "url" + i);
        row.add(PINNED_PREFIX + "title" + i);
        row.add(position);
    }

    return c;
}
项目:android-filechooser    文件:LocalFileProvider.java   
/**
 * Retrieves file information of a single file.
 * 
 * @param uri
 *            the URI pointing to a file.
 * @return the file information. Can be {@code null}, based on the input
 *         parameters.
 */
private MatrixCursor doRetrieveFileInfo(Uri uri) {
    MatrixCursor matrixCursor = BaseFileProviderUtils.newBaseFileCursor();

    File file = extractFile(uri);
    int type = file.isFile() ? BaseFile._FileTypeFile
            : (file.isDirectory() ? BaseFile._FileTypeDirectory : (file
                    .exists() ? BaseFile._FileTypeUnknown
                    : BaseFile._FileTypeNotExisted));
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(0);// _ID
    newRow.add(BaseFile.genContentIdUriBase(LocalFileContract._Authority)
            .buildUpon().appendPath(Uri.fromFile(file).toString()).build()
            .toString());
    newRow.add(file.getAbsolutePath());
    newRow.add(file.getName());
    newRow.add(file.canRead() ? 1 : 0);
    newRow.add(file.canWrite() ? 1 : 0);
    newRow.add(file.length());
    newRow.add(type);
    newRow.add(file.lastModified());
    newRow.add(FileUtils.getResIcon(type, file.getName()));

    return matrixCursor;
}
项目:keepass2android    文件:LocalFileProvider.java   
/**
 * Retrieves file information of a single file.
 * 
 * @param uri
 *            the URI pointing to a file.
 * @return the file information. Can be {@code null}, based on the input
 *         parameters.
 */
private MatrixCursor doRetrieveFileInfo(Uri uri) {
    MatrixCursor matrixCursor = BaseFileProviderUtils.newBaseFileCursor();

    File file = extractFile(uri);
    int type = file.isFile() ? BaseFile.FILE_TYPE_FILE : (file
            .isDirectory() ? BaseFile.FILE_TYPE_DIRECTORY
            : (file.exists() ? BaseFile.FILE_TYPE_UNKNOWN
                    : BaseFile.FILE_TYPE_NOT_EXISTED));
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(0);// _ID
    newRow.add(BaseFile
            .genContentIdUriBase(
                    LocalFileContract.getAuthority(getContext()))
            .buildUpon().appendPath(Uri.fromFile(file).toString()).build()
            .toString());
    newRow.add(Uri.fromFile(file).toString());
    newRow.add(file.getName());
    newRow.add(file.canRead() ? 1 : 0);
    newRow.add(file.canWrite() ? 1 : 0);
    newRow.add(file.length());
    newRow.add(type);
    newRow.add(file.lastModified());
    newRow.add(FileUtils.getResIcon(type, file.getName()));

    return matrixCursor;
}
项目:KeePass2Android    文件:LocalFileProvider.java   
/**
 * Retrieves file information of a single file.
 * 
 * @param uri
 *            the URI pointing to a file.
 * @return the file information. Can be {@code null}, based on the input
 *         parameters.
 */
private MatrixCursor doRetrieveFileInfo(Uri uri) {
    MatrixCursor matrixCursor = BaseFileProviderUtils.newBaseFileCursor();

    File file = extractFile(uri);
    int type = file.isFile() ? BaseFile.FILE_TYPE_FILE : (file
            .isDirectory() ? BaseFile.FILE_TYPE_DIRECTORY
            : (file.exists() ? BaseFile.FILE_TYPE_UNKNOWN
                    : BaseFile.FILE_TYPE_NOT_EXISTED));
    RowBuilder newRow = matrixCursor.newRow();
    newRow.add(0);// _ID
    newRow.add(BaseFile
            .genContentIdUriBase(
                    LocalFileContract.getAuthority(getContext()))
            .buildUpon().appendPath(Uri.fromFile(file).toString()).build()
            .toString());
    newRow.add(Uri.fromFile(file).toString());
    newRow.add(file.getName());
    newRow.add(file.canRead() ? 1 : 0);
    newRow.add(file.canWrite() ? 1 : 0);
    newRow.add(file.length());
    newRow.add(type);
    newRow.add(file.lastModified());
    newRow.add(FileUtils.getResIcon(type, file.getName()));

    return matrixCursor;
}
项目:mc_backup    文件:RecentTabsPanel.java   
private void addRow(MatrixCursor c, String url, String title, int type, String data) {
    final RowBuilder row = c.newRow();
    row.add(-1);
    row.add(url);
    row.add(title);
    row.add(type);
    row.add(data);
}
项目:mc_backup    文件:TestTopSitesCursorWrapper.java   
private Cursor createTopSitesCursor(int count) {
    MatrixCursor c = new MatrixCursor(TOP_SITES_COLUMNS);

    for (int i = 0; i < count; i++) {
        RowBuilder row = c.newRow();
        row.add(-1);
        row.add(TOP_PREFIX + "url" + i);
        row.add(TOP_PREFIX + "title" + i);
        row.add(i);
        row.add(i);
    }

    return c;
}
项目:mc_backup    文件:TestTopSitesCursorWrapper.java   
private Cursor createSuggestedSitesCursor(int count) {
    MatrixCursor c = new MatrixCursor(SUGGESTED_SITES_COLUMNS);

    for (int i = 0; i < count; i++) {
        RowBuilder row = c.newRow();
        row.add(-1);
        row.add(SUGGESTED_PREFIX + "url" + i);
        row.add(SUGGESTED_PREFIX + "title" + i);
    }

    return c;
}
项目:AlarmOn    文件:MediaSongsView.java   
public void includeDefault() {
  final ArrayList<String> defaultColumns =
    new ArrayList<>(songsColumns.length + 1);
  defaultColumns.addAll(Arrays.asList(songsColumns));
  defaultColumns.add(BaseColumns._ID);
  final MatrixCursor defaultsCursor = new MatrixCursor(defaultColumns.toArray(
          new String[defaultColumns.size()]));
  RowBuilder row = defaultsCursor.newRow();
  row.add("Default");
  row.add(DEFAULT_TONE_INDEX);
  includeStaticCursor(defaultsCursor);
}
项目:silent-text-android    文件:StatusProvider.java   
public static Cursor query( Context context ) {
    MatrixCursor cursor = new MatrixCursor( new String [] {
        KEY
    }, 1 );
    Status status = Status.from( context );
    RowBuilder row = cursor.newRow();
    row.add( Integer.valueOf( status.value() ) );
    return cursor;
}
项目:SecureShareLib    文件:TransferStorageProvider.java   
@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
    final RowBuilder row = result.newRow();
    row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT);
    row.add(Root.COLUMN_FLAGS,
            Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_RECENTS | Root.FLAG_SUPPORTS_CREATE);
    row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher_download);
    row.add(Root.COLUMN_TITLE, getContext().getString(R.string.root_downloads));
    row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);
    return result;
}
项目:SecureShareLib    文件:TransferStorageProvider.java   
private void includeDefaultDocument(MatrixCursor result) {
    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);
    row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    row.add(Document.COLUMN_FLAGS,
            Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_DIR_SUPPORTS_CREATE);
}
项目:keepass2android    文件:HistoryProvider.java   
/**
 * Appends file name and real URI into {@code cursor}.
 * 
 * @param cursor
 *            the original cursor. It will be closed when done.
 * @return the new cursor.
 */
private Cursor appendNameAndRealUri(Cursor cursor) {
    if (cursor == null || cursor.getCount() == 0)
        return cursor;

    final int colUri = cursor.getColumnIndex(HistoryContract.COLUMN_URI);
    if (colUri < 0)
        return cursor;

    String[] columns = new String[cursor.getColumnCount()
            + ADDITIONAL_COLUMNS.length];
    System.arraycopy(cursor.getColumnNames(), 0, columns, 0,
            cursor.getColumnCount());
    System.arraycopy(ADDITIONAL_COLUMNS, 0, columns,
            cursor.getColumnCount(), ADDITIONAL_COLUMNS.length);

    MatrixCursor result = new MatrixCursor(columns);
    if (cursor.moveToFirst()) {
        do {
            RowBuilder builder = result.newRow();

            Cursor fileInfo = null;
            for (int i = 0; i < cursor.getColumnCount(); i++) {
                String data = cursor.getString(i);
                builder.add(data);

                if (i == colUri)
                    fileInfo = getContext().getContentResolver().query(
                            Uri.parse(data), null, null, null, null);
            }

            if (fileInfo != null) {
                if (fileInfo.moveToFirst()) {
                    builder.add(BaseFileProviderUtils.getFileName(fileInfo));
                    builder.add(BaseFileProviderUtils.getRealUri(fileInfo)
                            .toString());
                }
                fileInfo.close();
            }
        } while (cursor.moveToNext());
    }// if

    cursor.close();

    return result;
}
项目:KeePass2Android    文件:HistoryProvider.java   
/**
 * Appends file name and real URI into {@code cursor}.
 * 
 * @param cursor
 *            the original cursor. It will be closed when done.
 * @return the new cursor.
 */
private Cursor appendNameAndRealUri(Cursor cursor) {
    if (cursor == null || cursor.getCount() == 0)
        return cursor;

    final int colUri = cursor.getColumnIndex(HistoryContract.COLUMN_URI);
    if (colUri < 0)
        return cursor;

    String[] columns = new String[cursor.getColumnCount()
            + ADDITIONAL_COLUMNS.length];
    System.arraycopy(cursor.getColumnNames(), 0, columns, 0,
            cursor.getColumnCount());
    System.arraycopy(ADDITIONAL_COLUMNS, 0, columns,
            cursor.getColumnCount(), ADDITIONAL_COLUMNS.length);

    MatrixCursor result = new MatrixCursor(columns);
    if (cursor.moveToFirst()) {
        do {
            RowBuilder builder = result.newRow();

            Cursor fileInfo = null;
            for (int i = 0; i < cursor.getColumnCount(); i++) {
                String data = cursor.getString(i);
                builder.add(data);

                if (i == colUri)
                    fileInfo = getContext().getContentResolver().query(
                            Uri.parse(data), null, null, null, null);
            }

            if (fileInfo != null) {
                if (fileInfo.moveToFirst()) {
                    builder.add(BaseFileProviderUtils.getFileName(fileInfo));
                    builder.add(BaseFileProviderUtils.getRealUri(fileInfo)
                            .toString());
                }
                fileInfo.close();
            }
        } while (cursor.moveToNext());
    }// if

    cursor.close();

    return result;
}
项目:mc_backup    文件:SuggestedSites.java   
/**
 * Returns a {@code Cursor} with the list of suggested websites.
 *
 * @param limit maximum number of suggested sites.
 * @param locale the target locale.
 * @param excludeUrls list of URLs to be excluded from the list.
 */
public synchronized Cursor get(int limit, Locale locale, List<String> excludeUrls) {
    final MatrixCursor cursor = new MatrixCursor(COLUMNS);

    // Return an empty cursor if suggested sites have been
    // disabled by the user.
    if (!isEnabled()) {
        return cursor;
    }

    final boolean isNewLocale = isNewLocale(context, locale);

    // Force the suggested sites file in profile dir to be re-generated
    // if the locale has changed.
    if (isNewLocale) {
        getFile().delete();
    }

    if (cachedSites == null || isNewLocale) {
        Log.d(LOGTAG, "No cached sites, refreshing.");
        refresh();
    }

    // Return empty cursor if there was an error when
    // loading the suggested sites or the list is empty.
    if (cachedSites == null || cachedSites.isEmpty()) {
        return cursor;
    }

    excludeUrls = includeBlacklist(excludeUrls);

    final int sitesCount = cachedSites.size();
    Log.d(LOGTAG, "Number of suggested sites: " + sitesCount);

    final int maxCount = Math.min(limit, sitesCount);
    for (Site site : cachedSites.values()) {
        if (cursor.getCount() == maxCount) {
            break;
        }

        if (excludeUrls != null && excludeUrls.contains(site.url)) {
            continue;
        }

        final boolean restrictedProfile =  RestrictedProfiles.isRestrictedProfile(context);

        if (restrictedProfile == site.restricted) {
            final RowBuilder row = cursor.newRow();
            row.add(-1);
            row.add(site.url);
            row.add(site.title);
        }
    }

    cursor.setNotificationUri(context.getContentResolver(),
                              BrowserContract.SuggestedSites.CONTENT_URI);

    return cursor;
}
项目:SecureShareLib    文件:TransferStorageProvider.java   
private void includeTransferFromCursor(MatrixCursor result, Cursor cursor) {
    final long id = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
    final String docId = String.valueOf(id);

    final String displayName = cursor.getString(
            cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE));
    String summary = cursor.getString(
            cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION));
    String mimeType = cursor.getString(
            cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_MEDIA_TYPE));
    if (mimeType == null) {
        // Provide fake MIME type so it's openable
        mimeType = "vnd.android.document/file";
    }
    Long size = cursor.getLong(
            cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
    if (size == -1) {
        size = null;
    }

    final int status = cursor.getInt(
            cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS));
    switch (status) {
        case DownloadManager.STATUS_SUCCESSFUL:
            break;
        case DownloadManager.STATUS_PAUSED:
            summary = getContext().getString(R.string.download_queued);
            break;
        case DownloadManager.STATUS_PENDING:
            summary = getContext().getString(R.string.download_queued);
            break;
        case DownloadManager.STATUS_RUNNING:
            final long progress = cursor.getLong(cursor.getColumnIndexOrThrow(
                    DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
            if (size != null) {
                final long percent = progress * 100 / size;
                summary = getContext().getString(R.string.download_running_percent, percent);
            } else {
                summary = getContext().getString(R.string.download_running);
            }
            break;
        case DownloadManager.STATUS_FAILED:
        default:
            summary = getContext().getString(R.string.download_error);
            break;
    }

    int flags = Document.FLAG_SUPPORTS_DELETE | Document.FLAG_SUPPORTS_WRITE;
    if (mimeType != null && mimeType.startsWith("image/")) {
        flags |= Document.FLAG_SUPPORTS_THUMBNAIL;
    }

    final long lastModified = cursor.getLong(
            cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP));

    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME, displayName);
    row.add(Document.COLUMN_SUMMARY, summary);
    row.add(Document.COLUMN_SIZE, size);
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_LAST_MODIFIED, lastModified);
    row.add(Document.COLUMN_FLAGS, flags);
}
项目:silent-text-android    文件:RemoteContactRepository.java   
private static MatrixCursor add( MatrixCursor cursor, UserSearchResult userSearchResult ) {

        RowBuilder row = cursor.newRow();

        row.add( userSearchResult.getUserID() );
        row.add( userSearchResult.getDisplayName() );
        row.add( null );

        return cursor;

    }