(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder)
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Cursor query(Uri uri, String[] projection, String selection, |
| 55 | String[] selectionArgs, String sortOrder) { |
| 56 | final File file = getFileForUri(uri); |
| 57 | if (file == null) |
| 58 | throw new IllegalArgumentException("File not found"); |
| 59 | |
| 60 | String displayName = uri.getQueryParameter(DISPLAYNAME_FIELD); |
| 61 | |
| 62 | if (projection == null) { |
| 63 | projection = COLUMNS; |
| 64 | } |
| 65 | |
| 66 | String[] cols = new String[projection.length]; |
| 67 | Object[] values = new Object[projection.length]; |
| 68 | int i = 0; |
| 69 | for (String col : projection) { |
| 70 | if (OpenableColumns.DISPLAY_NAME.equals(col)) { |
| 71 | cols[i] = OpenableColumns.DISPLAY_NAME; |
| 72 | values[i++] = (displayName == null) ? file.getName() : displayName; |
| 73 | } else if (OpenableColumns.SIZE.equals(col)) { |
| 74 | cols[i] = OpenableColumns.SIZE; |
| 75 | values[i++] = file.length(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | cols = copyOf(cols, i); |
| 80 | values = copyOf(values, i); |
| 81 | |
| 82 | final MatrixCursor cursor = new MatrixCursor(cols, 1); |
| 83 | cursor.addRow(values); |
| 84 | return cursor; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public String getType(Uri uri) { |
no test coverage detected