List of usage examples for android.database MatrixCursor MatrixCursor
public MatrixCursor(String[] columnNames, int initialCapacity)
From source file:org.chromium.chrome.browser.util.CompatibilityFileProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder); String[] columnNames = source.getColumnNames(); String[] newColumnNames = columnNamesWithData(columnNames); if (columnNames == newColumnNames) return source; MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount()); source.moveToPosition(-1);// w ww .j a va 2 s. co m while (source.moveToNext()) { MatrixCursor.RowBuilder row = cursor.newRow(); for (int i = 0; i < columnNames.length; i++) { switch (source.getType(i)) { case Cursor.FIELD_TYPE_INTEGER: row.add(source.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.add(source.getFloat(i)); break; case Cursor.FIELD_TYPE_STRING: row.add(source.getString(i)); break; case Cursor.FIELD_TYPE_BLOB: row.add(source.getBlob(i)); break; case Cursor.FIELD_TYPE_NULL: default: row.add(null); break; } } } source.close(); return cursor; }
From source file:org.sufficientlysecure.keychain.ui.widget.CacheTTLSpinner.java
private void initView(Context context) { CacheTTLPrefs prefs = Preferences.getPreferences(context).getPassphraseCacheTtl(); MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "TTL", "description" }, 5); int i = 0;/* w ww . j a va 2 s .c o m*/ for (int ttl : CacheTTLPrefs.CACHE_TTLS) { if (!prefs.ttlTimes.contains(ttl)) { continue; } cursor.addRow( new Object[] { i++, ttl, getContext().getString(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl)) }); } setAdapter(new SimpleCursorAdapter(getContext(), R.layout.simple_item, cursor, new String[] { "description" }, new int[] { R.id.simple_item_text }, 0)); }
From source file:android.support.content.TestQueryCallback.java
@Override public @Nullable Cursor runQueryInBackground(Query query) { mQueryLatch.accept(query);//from ww w. j a v a 2 s . c om Bundle extras = new Bundle(); extras.putParcelable(URI_KEY, query.getUri()); extras.putInt(URI_PAGE_ID, query.getId()); MatrixCursor cursor = new MatrixCursor(new String[] { "id" }, 0); cursor.setExtras(extras); return cursor; }
From source file:org.schabi.newpipe.fragments.search.SuggestionListAdapter.java
/** * Update the suggestion list//from w w w .j a v a 2 s.c o m * @param suggestions the list of suggestions */ public void updateAdapter(List<String> suggestions) { MatrixCursor cursor = new MatrixCursor(columns, suggestions.size()); int i = 0; for (String suggestion : suggestions) { String[] columnValues = new String[columns.length]; columnValues[INDEX_TITLE] = suggestion; columnValues[INDEX_ID] = Integer.toString(i); cursor.addRow(columnValues); i++; } changeCursor(cursor); }
From source file:io.nuclei.cyto.share.CytoFileProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder); if (source == null) return null; try {//from ww w. j ava 2 s . co m final String[] columnNames = source.getColumnNames(); String[] names = columnNames; List<String> missingNames = getMissingColumns(columnNames); int mimeTypeIndex = -1; if (missingNames.size() > 0) { String[] newColumnNames = Arrays.copyOf(columnNames, columnNames.length + missingNames.size()); int ix = columnNames.length; for (String missingName : missingNames) { newColumnNames[ix] = missingName; if (MediaStore.MediaColumns.MIME_TYPE.equals(missingName)) mimeTypeIndex = ix; ix++; } names = newColumnNames; } MatrixCursor cursor = new MatrixCursor(names, source.getCount()); source.moveToPosition(-1); int columnLength = columnNames.length; while (source.moveToNext()) { MatrixCursor.RowBuilder row = cursor.newRow(); for (int i = 0; i < names.length; i++) { if (i < columnLength) row.add(source.getString(i)); else if (i == mimeTypeIndex) { // populate the MIME_TYPE column with a guess as to the mime type of the file final int lastDot = uri.getPath().lastIndexOf('.'); if (lastDot >= 0) { String extension = uri.getPath().substring(lastDot + 1); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mimeType != null) row.add(mimeType); else row.add("application/octet"); } else row.add("application/octet"); } else row.add(null); } } return cursor; } finally { source.close(); } }
From source file:com.btmura.android.reddit.content.RelatedSubredditLoader.java
private MatrixCursor buildCursor(TreeSet<String> subreddits) { int i = 0;/*from w ww .j a v a 2s . c o m*/ MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES, subreddits.size()); for (String subreddit : subreddits) { cursor.addRow(Array.of(i++, subreddit)); } return cursor; }
From source file:com.vishwa.pinit.LocationSuggestionProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { switch (uriMatcher.match(uri)) { case SEARCH_SUGGEST: String query = uri.getLastPathSegment(); MatrixCursor cursor = new MatrixCursor(SEARCH_SUGGEST_COLUMNS, 1); if (Geocoder.isPresent()) { try { mGeocoder = new Geocoder(getContext(), Locale.ENGLISH); List<Address> addressList = mGeocoder.getFromLocationName(query, 5); for (int i = 0; i < addressList.size(); i++) { Address address = addressList.get(i); StringBuilder fullAddress = new StringBuilder(); for (int j = 1; j < address.getMaxAddressLineIndex(); j++) { fullAddress.append(address.getAddressLine(j)); }/*from w ww. j av a 2 s. c o m*/ cursor.addRow(new String[] { Integer.toString(i), address.getAddressLine(0).toString(), fullAddress.toString(), address.getLatitude() + "," + address.getLongitude() }); } return cursor; } catch (IllegalArgumentException e) { return getLocationSuggestionsUsingAPI(query, cursor); } catch (IOException e) { return getLocationSuggestionsUsingAPI(query, cursor); } } default: throw new IllegalArgumentException("Unknown Uri: " + uri); } }
From source file:org.chromium.chrome.browser.util.ChromeFileProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Uri fileUri = getFileUriWhenReady(uri); if (fileUri == null) return null; // Workaround for a bad assumption that particular MediaStore columns exist by certain third // party applications. // http://crbug.com/467423. Cursor source = super.query(fileUri, projection, selection, selectionArgs, sortOrder); String[] columnNames = source.getColumnNames(); String[] newColumnNames = columnNamesWithData(columnNames); if (columnNames == newColumnNames) return source; MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount()); source.moveToPosition(-1);/*from w w w. jav a2 s . c o m*/ while (source.moveToNext()) { MatrixCursor.RowBuilder row = cursor.newRow(); for (int i = 0; i < columnNames.length; i++) { switch (source.getType(i)) { case Cursor.FIELD_TYPE_INTEGER: row.add(source.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: row.add(source.getFloat(i)); break; case Cursor.FIELD_TYPE_STRING: row.add(source.getString(i)); break; case Cursor.FIELD_TYPE_BLOB: row.add(source.getBlob(i)); break; case Cursor.FIELD_TYPE_NULL: default: row.add(null); break; } } } source.close(); return cursor; }
From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java
@Override public Cursor swapCursor(Cursor cursor) { clearCaches();/* w w w . ja va 2 s. c o m*/ if (cursor == null) return super.swapCursor(null); MatrixCursor mc = new MatrixCursor(DbTable.SHIFTS.getFieldNames(), cursor.getCount() + 7); int jd = mStartingJulianDay; final int colCount = cursor.getColumnCount(); SparseArray<List<Object[]>> jdToRowArray = new SparseArray<List<Object[]>>(); if (cursor.moveToFirst()) { final int jdIndex = cursor.getColumnIndex(DbField.JULIAN_DAY.name); do { Object[] row = new Object[colCount]; for (int i = 0; i < colCount; i++) row[i] = cursor.getString(i); final int shiftDay = cursor.getInt(jdIndex); List<Object[]> rowsOnSameJd = jdToRowArray.get(shiftDay, null); if (rowsOnSameJd == null) rowsOnSameJd = new ArrayList<Object[]>(); rowsOnSameJd.add(row); jdToRowArray.put(shiftDay, rowsOnSameJd); } while (cursor.moveToNext()); } for (int i = jd; i < jd + 7; i++) { List<Object[]> rows = jdToRowArray.get(i); if (rows != null) for (Object[] row : rows) mc.addRow(row); //Add a 'Add Shift' row Object[] row = new Object[colCount]; row[0] = mRand.nextInt(Integer.MAX_VALUE); // DbField.ID row[1] = i; // DbField.JULIAN_DAY row[2] = i; // DbField.END_JULIAN_DAY row[3] = -1; // DbField.START_TIME row[4] = -1; // DbField.END_TIME row[5] = -1; // DbField.PAY_RATE row[6] = NEW_ROW_KEY; // DbField.NAME row[7] = null; // DbField.NOTE row[8] = -1; // DbField.BREAK_DURATION row[9] = 0; // DbField.IS_TEMPLATE row[10] = -1; // DbField.REMINDER mc.addRow(row); } return super.swapCursor(mc); }
From source file:com.android.ex.chips.RecipientAlternatesAdapter.java
/** * @return a new cursor based on the given cursor with all duplicate destinations removed. * It's only intended to use for the alternate list, so... * - This method ignores all other fields and dedupe solely on the destination. Normally, * if a cursor contains multiple contacts and they have the same destination, we'd still want * to show both./*from w ww . j ava 2s. co m*/ * - This method creates a MatrixCursor, so all data will be kept in memory. We wouldn't want * to do this if the original cursor is large, but it's okay here because the alternate list * won't be that big. */ // Visible for testing /* package */static Cursor removeDuplicateDestinations(Cursor original) { final MatrixCursor result = new MatrixCursor(original.getColumnNames(), original.getCount()); final HashSet<String> destinationsSeen = new HashSet<String>(); original.moveToPosition(-1); while (original.moveToNext()) { final String destination = original.getString(Query.DESTINATION); if (destinationsSeen.contains(destination)) { continue; } destinationsSeen.add(destination); Object[] cursorObjects; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { cursorObjects = new Object[] { original.getString(Query.NAME), original.getString(Query.DESTINATION), original.getInt(Query.DESTINATION_TYPE), original.getString(Query.DESTINATION_LABEL), original.getLong(Query.CONTACT_ID), original.getLong(Query.DATA_ID), original.getString(Query.PHOTO_THUMBNAIL_URI), original.getInt(Query.DISPLAY_NAME_SOURCE) }; } else { cursorObjects = new Object[] { original.getString(Query.NAME), original.getString(Query.DESTINATION), original.getInt(Query.DESTINATION_TYPE), original.getString(Query.DESTINATION_LABEL), original.getLong(Query.CONTACT_ID), original.getLong(Query.DATA_ID), original.getString(Query.PHOTO_ID) }; } result.addRow(cursorObjects); } return result; }