List of usage examples for android.database MatrixCursor addRow
public void addRow(Iterable<?> columnValues)
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private Cursor getDNSCursor(final String host) { final MatrixCursor c = new MatrixCursor(TwidereDataStore.DNS.MATRIX_COLUMNS); try {//from ww w . j av a 2 s .com final String address = mHostAddressResolver.resolve(host); if (host != null && address != null) { c.addRow(new String[] { host, address }); } } catch (final IOException e) { } return c; }
From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java
@Override public Cursor swapCursor(Cursor cursor) { clearCaches();/* w w w .j ava 2s . 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:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private Cursor getCachedImageCursor(final String url) { if (Utils.isDebugBuild()) { Log.d(LOGTAG, String.format("getCachedImageCursor(%s)", url)); }// w w w.j a va2s. com final MatrixCursor c = new MatrixCursor(FiretweetDataStore.CachedImages.MATRIX_COLUMNS); final File file = mImagePreloader.getCachedImageFile(url); if (url != null && file != null) { c.addRow(new String[] { url, file.getPath() }); } return c; }
From source file:net.sf.fdshare.BaseProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final String filePath = uri.getPath(); if (TextUtils.isEmpty(filePath)) throw new IllegalArgumentException("Empty path!"); if (projection == null) { projection = new String[] { MediaStore.MediaColumns.MIME_TYPE, OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };/* w w w . ja v a 2 s .co m*/ } final MatrixCursor result = new MatrixCursor(projection); final TimestampedMime info = guessTypeInternal(filePath); final Object[] row = new Object[projection.length]; for (int i = 0; i < projection.length; i++) { String projColumn = projection[i]; if (TextUtils.isEmpty(projColumn)) continue; switch (projColumn.toLowerCase()) { case OpenableColumns.DISPLAY_NAME: row[i] = uri.getLastPathSegment(); break; case OpenableColumns.SIZE: row[i] = info.size >= 0 ? info.size : null; break; case MediaStore.MediaColumns.MIME_TYPE: final String forcedType = uri.getQueryParameter("type"); if (!TextUtils.isEmpty(forcedType)) row[i] = "null".equals(forcedType) ? null : forcedType; else row[i] = info.mime[0]; break; case MediaStore.MediaColumns.DATA: Log.w("BaseProvider", "Relying on MediaColumns.DATA is unreliable and must be avoided!"); row[i] = uri.getPath(); break; } } result.addRow(row); return result; }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private Cursor getDNSCursor(final String host) { final MatrixCursor c = new MatrixCursor(FiretweetDataStore.DNS.MATRIX_COLUMNS); try {/* w w w . ja va2s . co m*/ final InetAddress[] addresses = mHostAddressResolver.resolve(host); for (InetAddress address : addresses) { c.addRow(new String[] { host, address.getHostAddress() }); } } catch (final IOException ignore) { Crashlytics.logException(ignore); if (Utils.isDebugBuild()) { Log.w(LOGTAG, ignore); } } return c; }
From source file:org.sufficientlysecure.keychain.ui.MultiUserIdsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrix = new MatrixCursor(new String[] { "_id", "user_data", "grouped" }) { @Override/* w ww . j ava 2s . c om*/ public byte[] getBlob(int column) { return super.getBlob(column); } }; data.moveToFirst(); long lastMasterKeyId = 0; String lastName = ""; ArrayList<String> uids = new ArrayList<>(); boolean header = true; // Iterate over all rows while (!data.isAfterLast()) { long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); String userId = data.getString(INDEX_USER_ID); OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId); // Two cases: boolean grouped = masterKeyId == lastMasterKeyId; boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name); // Remember for next loop lastName = pieces.name; Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped")); if (!subGrouped) { // 1. This name should NOT be grouped with the previous, so we flush the buffer Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); // indicate that we have a header for this masterKeyId header = false; // Now clear the buffer, and add the new user id, for the next round uids.clear(); } // 2. This name should be grouped with the previous, just add to buffer uids.add(userId); lastMasterKeyId = masterKeyId; // If this one wasn't grouped, the next one's gotta be a header if (!grouped) { header = true; } // Regardless of the outcome, move to next entry data.moveToNext(); } // If there is anything left in the buffer, flush it one last time if (!uids.isEmpty()) { Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); } mUserIdsAdapter.swapCursor(matrix); }
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
private Cursor getUnreadCountsCursorByType(final String type) { final MatrixCursor c = new MatrixCursor(TwidereDataStore.UnreadCounts.MATRIX_COLUMNS); final int count; if (TAB_TYPE_HOME_TIMELINE.equals(type) || TAB_TYPE_STAGGERED_HOME_TIMELINE.equals(type)) { count = mUnreadStatuses.size();/*w ww. j av a 2 s. co m*/ } else if (TAB_TYPE_MENTIONS_TIMELINE.equals(type)) { count = mUnreadMentions.size(); } else if (TAB_TYPE_DIRECT_MESSAGES.equals(type)) { count = mUnreadMessages.size(); } else { count = 0; } if (type != null) { c.addRow(new Object[] { -1, type, count }); } return c; }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { try {//w w w . jav a2s .c om final int tableId = getTableId(uri); final String table = getTableNameById(tableId); checkReadPermission(tableId, table, projection); switch (tableId) { case VIRTUAL_TABLE_ID_DATABASE_READY: { if (mDatabaseWrapper.isReady()) return new MatrixCursor(projection != null ? projection : new String[0]); return null; } case VIRTUAL_TABLE_ID_PERMISSIONS: { final MatrixCursor c = new MatrixCursor(FiretweetDataStore.Permissions.MATRIX_COLUMNS); final Map<String, String> map = mPermissionsManager.getAll(); for (final Map.Entry<String, String> item : map.entrySet()) { c.addRow(new Object[] { item.getKey(), item.getValue() }); } return c; } case VIRTUAL_TABLE_ID_ALL_PREFERENCES: { return getPreferencesCursor(mPreferences, null); } case VIRTUAL_TABLE_ID_PREFERENCES: { return getPreferencesCursor(mPreferences, uri.getLastPathSegment()); } case VIRTUAL_TABLE_ID_DNS: { return getDNSCursor(uri.getLastPathSegment()); } case VIRTUAL_TABLE_ID_CACHED_IMAGES: { return getCachedImageCursor(uri.getQueryParameter(QUERY_PARAM_URL)); } case VIRTUAL_TABLE_ID_NOTIFICATIONS: { final List<String> segments = uri.getPathSegments(); if (segments.size() == 2) return getNotificationsCursor(ParseUtils.parseInt(segments.get(1), -1)); else return getNotificationsCursor(); } case VIRTUAL_TABLE_ID_UNREAD_COUNTS: { final List<String> segments = uri.getPathSegments(); if (segments.size() == 2) return getUnreadCountsCursor(ParseUtils.parseInt(segments.get(1), -1)); else return getUnreadCountsCursor(); } case VIRTUAL_TABLE_ID_UNREAD_COUNTS_BY_TYPE: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 3) return null; return getUnreadCountsCursorByType(segments.get(2)); } case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 4) return null; final long accountId = ParseUtils.parseLong(segments.get(2)); final long conversationId = ParseUtils.parseLong(segments.get(3)); final SQLSelectQuery query = ConversationQueryBuilder.buildByConversationId(projection, accountId, conversationId, selection, sortOrder); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, DirectMessages.CONTENT_URI); return c; } case TABLE_ID_DIRECT_MESSAGES_CONVERSATION_SCREEN_NAME: { final List<String> segments = uri.getPathSegments(); if (segments.size() != 4) return null; final long accountId = ParseUtils.parseLong(segments.get(2)); final String screenName = segments.get(3); final SQLSelectQuery query = ConversationQueryBuilder.buildByScreenName(projection, accountId, screenName, selection, sortOrder); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, DirectMessages.CONTENT_URI); return c; } case VIRTUAL_TABLE_ID_CACHED_USERS_WITH_RELATIONSHIP: { final long accountId = ParseUtils.parseLong(uri.getLastPathSegment(), -1); final SQLSelectQuery query = CachedUsersQueryBuilder.withRelationship(projection, selection, sortOrder, accountId); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, CachedUsers.CONTENT_URI); return c; } case VIRTUAL_TABLE_ID_CACHED_USERS_WITH_SCORE: { final long accountId = ParseUtils.parseLong(uri.getLastPathSegment(), -1); final SQLSelectQuery query = CachedUsersQueryBuilder.withScore(projection, selection, sortOrder, accountId); final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs); setNotificationUri(c, CachedUsers.CONTENT_URI); return c; } case VIRTUAL_TABLE_ID_DRAFTS_UNSENT: { final FiretweetApplication app = FiretweetApplication.getInstance(getContext()); final AsyncTwitterWrapper twitter = app.getTwitterWrapper(); final RawItemArray sendingIds = new RawItemArray(twitter.getSendingDraftIds()); final Expression where; if (selection != null) { where = Expression.and(new Expression(selection), Expression.notIn(new Column(Drafts._ID), sendingIds)); } else { where = Expression.and(Expression.notIn(new Column(Drafts._ID), sendingIds)); } final Cursor c = mDatabaseWrapper.query(Drafts.TABLE_NAME, projection, where.getSQL(), selectionArgs, null, null, sortOrder); setNotificationUri(c, getNotificationUri(tableId, uri)); return c; } } if (table == null) return null; final Cursor c = mDatabaseWrapper.query(table, projection, selection, selectionArgs, null, null, sortOrder); setNotificationUri(c, getNotificationUri(tableId, uri)); return c; } catch (final SQLException e) { Crashlytics.logException(e); throw new IllegalStateException(e); } }
From source file:net.sf.xfd.provider.PublicProvider.java
@Nullable @Override// w w w.j a v a 2 s.c o m public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String path = uri.getPath(); if (TextUtils.isEmpty(uri.getPath())) { path = "/"; } try { assertAbsolute(path); } catch (FileNotFoundException e) { return null; } path = canonString(path); if (!path.equals(uri.getPath())) { uri = uri.buildUpon().path(path).build(); } if (!checkAccess(uri, "r")) { return null; } if (projection == null) { projection = COMMON_PROJECTION; } final OS os = base.getOS(); if (os == null) { return null; } try { final MatrixCursor cursor = new MatrixCursor(projection, 1); final Object[] row = new Object[projection.length]; final Stat stat = new Stat(); final String name = extractName(path); final String mime = base.getTypeFast(path, name, stat); for (int i = 0; i < projection.length; ++i) { String col = projection[i]; switch (col) { case BaseColumns._ID: row[i] = stat.st_ino; break; case COLUMN_DISPLAY_NAME: row[i] = name; break; case COLUMN_SIZE: row[i] = stat.st_size; break; case COLUMN_MIME_TYPE: row[i] = mime; break; default: row[i] = null; } } cursor.addRow(row); final Context context = getContext(); assert context != null; final String packageName = context.getPackageName(); cursor.setNotificationUri(context.getContentResolver(), DocumentsContract.buildDocumentUri(packageName + FileProvider.AUTHORITY_SUFFIX, path)); return cursor; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:org.dvbviewer.controller.ui.fragments.ChannelEpg.java
@Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { Loader<Cursor> loader = null; if (Config.SYNC_EPG && mCHannel != null) { String where = EpgTbl.EPG_ID + SqlSynatx.EQUALS + mCHannel.getEpgID() + SqlSynatx.AND + EpgTbl.END + SqlSynatx.BETWEEN + mDateInfo.getEpgDate().getTime() + SqlSynatx.AND + DateUtils.addDay(mDateInfo.getEpgDate()).getTime(); loader = new CursorLoader(getActivity(), EpgTbl.CONTENT_URI, null, where, null, EpgTbl.END); } else {//from ww w . j a v a 2s .c o m loader = new EpgLoader<Cursor>(getActivity(), mDateInfo) { @Override protected void onForceLoad() { super.onForceLoad(); setListShown(false); } @Override public Cursor loadInBackground() { MatrixCursor cursor = null; Date now = mDateInfo.getEpgDate(); String nowFloat = DateUtils.getFloatDate(now); Date tommorrow = DateUtils.addDay(now); String tommorrowFloat = DateUtils.getFloatDate(tommorrow); String url = ServerConsts.URL_CHANNEL_EPG + mCHannel.getEpgID() + "&start=" + nowFloat + "&end=" + tommorrowFloat; try { List<EpgEntry> result = null; EpgEntryHandler handler = new EpgEntryHandler(); String xml = ServerRequest.getRSString(url); result = handler.parse(xml); if (result != null && !result.isEmpty()) { String[] columnNames = new String[] { EpgTbl._ID, EpgTbl.EPG_ID, EpgTbl.TITLE, EpgTbl.SUBTITLE, EpgTbl.DESC, EpgTbl.START, EpgTbl.END }; cursor = new MatrixCursor(columnNames); for (EpgEntry entry : result) { cursor.addRow(new Object[] { entry.getId(), entry.getEpgID(), entry.getTitle(), entry.getSubTitle(), entry.getDescription(), entry.getStart().getTime(), entry.getEnd().getTime() }); } } } catch (AuthenticationException e) { Log.e(ChannelEpg.class.getSimpleName(), "AuthenticationException"); e.printStackTrace(); showToast(getString(R.string.error_invalid_credentials)); } catch (ParseException e) { Log.e(ChannelEpg.class.getSimpleName(), "ParseException"); e.printStackTrace(); } catch (ClientProtocolException e) { Log.e(ChannelEpg.class.getSimpleName(), "ClientProtocolException"); e.printStackTrace(); } catch (IOException e) { Log.e(ChannelEpg.class.getSimpleName(), "IOException"); e.printStackTrace(); } catch (URISyntaxException e) { Log.e(ChannelEpg.class.getSimpleName(), "URISyntaxException"); e.printStackTrace(); showToast(getString(R.string.error_invalid_url) + "\n\n" + ServerConsts.REC_SERVICE_URL); } catch (IllegalStateException e) { Log.e(ChannelEpg.class.getSimpleName(), "IllegalStateException"); e.printStackTrace(); showToast(getString(R.string.error_invalid_url) + "\n\n" + ServerConsts.REC_SERVICE_URL); } catch (IllegalArgumentException e) { Log.e(ChannelEpg.class.getSimpleName(), "IllegalArgumentException"); showToast(getString(R.string.error_invalid_url) + "\n\n" + ServerConsts.REC_SERVICE_URL); } catch (Exception e) { Log.e(ChannelEpg.class.getSimpleName(), "Exception"); e.printStackTrace(); } return cursor; } }; } return loader; }