List of usage examples for android.database Cursor getBlob
byte[] getBlob(int columnIndex);
From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java
public void onLoadFinished(Loader<Cursor> loader, Cursor data) { /* TODO better error handling? May cause problems when a key is deleted, * because the notification triggers faster than the activity closes. */// w w w . jav a 2s . co m // Avoid NullPointerExceptions... if (data.getCount() == 0) { return; } boolean nothingSpecial = true; // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) if (data.moveToFirst()) { final byte[] fp = data.getBlob(INDEX_TRUST_FINGERPRINT); final String fingerprint = KeyFormattingUtils.convertFingerprintToHex(fp); startSearch(fingerprint); } setContentShown(true); }
From source file:com.tune.news.fragment.EntryFragment.java
private void refreshUI(Cursor entryCursor) { if (entryCursor != null) { String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos) : entryCursor.getString(mFeedNamePos); BaseActivity activity = (BaseActivity) getActivity(); activity.setTitle(feedTitle);//from w w w. j av a 2s. com byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getSupportActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getSupportActionBar().setIcon(null); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { showSwipeProgress(); // If the service is not started, start it here to avoid an infinite loading if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) { MainApplication.getContext() .startService(new Intent(MainApplication.getContext(), FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); } } else { hideSwipeProgress(); } // Mark the article as read if (entryCursor.getInt(mIsReadPos) != 1) { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread(new Runnable() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getReadContentValues(), null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }).start(); } // Finally hide the progress bar hideSwipeProgress(); } }
From source file:com.carlrice.reader.fragment.EntryFragment.java
private void refreshUI(Cursor entryCursor) { if (entryCursor != null) { String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos) : entryCursor.getString(mFeedNamePos); BaseActivity activity = (BaseActivity) getActivity(); activity.setTitle(feedTitle);//w ww .j a va 2s . co m byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); UiUtils.getFaviconPalette(bitmap, mToolbarPaletteListener); mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { showSwipeProgress(); // If the service is not started, start it here to avoid an infinite loading if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) { Application.context().startService(new Intent(Application.context(), FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); } } else { hideSwipeProgress(); } // Mark the article as read if (entryCursor.getInt(mIsReadPos) != 1) { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread(new Runnable() { @Override public void run() { ContentResolver cr = Application.context().getContentResolver(); cr.update(uri, FeedData.getReadContentValues(), null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }).start(); } } }
From source file:com.facebook.stetho.inspector.protocol.module.Database.java
/** * Flatten all columns and all rows of a cursor to a single array. The array cannot be * interpreted meaningfully without the number of columns. * * @param cursor/*from w ww . j av a2s .c om*/ * @param limit Maximum number of rows to process. * @return List of Java primitives matching the value type of each column. */ private List<Object> flattenRows(Cursor cursor, int limit) { Util.throwIfNot(limit >= 0); List<Object> flatList = new ArrayList<Object>(); final int numColumns = cursor.getColumnCount(); for (int row = 0; row < limit && cursor.moveToNext(); row++) { for (int column = 0; column < numColumns; column++) { switch (cursor.getType(column)) { case Cursor.FIELD_TYPE_NULL: flatList.add(null); break; case Cursor.FIELD_TYPE_INTEGER: flatList.add(cursor.getLong(column)); break; case Cursor.FIELD_TYPE_FLOAT: flatList.add(cursor.getDouble(column)); break; case Cursor.FIELD_TYPE_BLOB: flatList.add(cursor.getBlob(column)); break; case Cursor.FIELD_TYPE_STRING: default: flatList.add(cursor.getString(column)); break; } } } if (!cursor.isAfterLast()) { for (int column = 0; column < numColumns; column++) { flatList.add("{truncated}"); } } return flatList; }
From source file:com.mk4droid.IMC_Services.DatabaseHandler.java
/** * Getting all categories/*from www.j a va 2 s. c o m*/ * @return */ public ArrayList<Category> getAllCategories() { ArrayList<Category> mCategL = new ArrayList<Category>(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_Categories; if (!db.isOpen()) db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Category mCategory = new Category(cursor.getInt(0), cursor.getString(1), cursor.getBlob(2), cursor.getInt(3), cursor.getInt(4), cursor.getInt(5)); mCategL.add(mCategory); } while (cursor.moveToNext()); } cursor.close(); return mCategL; }
From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java
private LongSparseArray<UncachedPublicKey> getUncachedMasterKeys(Uri queryUri) { Cursor cursor = mContentResolver.query(queryUri, new String[] { KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA }, null, null, null); LongSparseArray<UncachedPublicKey> result = new LongSparseArray<UncachedPublicKey>(cursor.getCount()); try {//from w w w . j a v a2 s. c om if (cursor != null && cursor.moveToFirst()) do { long masterKeyId = cursor.getLong(0); byte[] data = cursor.getBlob(1); if (data != null) { try { result.put(masterKeyId, UncachedKeyRing.decodePublicFromData(data).getPublicKey()); } catch (PgpGeneralException e) { Log.e(Constants.TAG, "Error parsing keyring, skipping."); } catch (IOException e) { Log.e(Constants.TAG, "IO error, skipping keyring"); } } } while (cursor.moveToNext()); } finally { if (cursor != null) { cursor.close(); } } return result; }
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);/*from w w w .j a v a 2s. 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:org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Avoid NullPointerExceptions... if (data == null || data.getCount() == 0) { return;/*from w w w.j a va 2s . c o m*/ } // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) switch (loader.getId()) { case LOADER_ID_UNIFIED: { if (data.moveToFirst()) { // get name, email, and comment from USER_ID OpenPgpUtils.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID)); if (mainUserId.name != null) { setTitle(mainUserId.name); } else { setTitle(R.string.user_id_no_name); } byte[] fingerprint = data.getBlob(INDEX_FINGERPRINT); // get key id from MASTER_KEY_ID long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); String formattedKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(masterKeyId); getSupportActionBar().setSubtitle(formattedKeyId); mHasSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0; boolean isRevoked = data.getInt(INDEX_IS_REVOKED) > 0; boolean isExpired = data.getInt(INDEX_IS_EXPIRED) != 0; boolean isVerified = data.getInt(INDEX_VERIFIED) > 0; // Note: order is important int color; if (isRevoked || isExpired) { color = getResources().getColor(R.color.key_flag_red); } else if (mHasSecret) { color = getResources().getColor(R.color.android_green_light); } else { if (isVerified) { color = getResources().getColor(R.color.android_green_light); } else { color = getResources().getColor(R.color.key_flag_orange); } } mToolbar.setBackgroundColor(color); mStatusBar.setBackgroundColor(ViewKeyActivity.getStatusBarBackgroundColor(color)); mSlidingTabLayout.setBackgroundColor(color); break; } } } }
From source file:org.thialfihar.android.apg.provider.ProviderHelper.java
/** * Must be an uri pointing to an account * * @param uri/*from www. j a va 2 s. c om*/ * @return */ public AppSettings getApiAppSettings(Uri uri) { AppSettings settings = null; Cursor cursor = mContentResolver.query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { settings = new AppSettings(); settings.setPackageName(cursor.getString(cursor.getColumnIndex(ApgContract.ApiApps.PACKAGE_NAME))); settings.setPackageSignature( cursor.getBlob(cursor.getColumnIndex(ApgContract.ApiApps.PACKAGE_SIGNATURE))); } } finally { if (cursor != null) { cursor.close(); } } return settings; }
From source file:org.kontalk.ui.MessagingNotification.java
/** * Updates system notification for unread messages. * @param context/*from w w w . j a va 2 s. c o m*/ * @param isNew if true a new message has come (starts notification alerts) */ public static void updateMessagesNotification(Context context, boolean isNew) { // no default account. WTF?!? Account account = Authenticator.getDefaultAccount(context); if (account == null) return; // if notifying new messages, wait a little bit // to let all incoming messages come through /* FIXME this is useless because message are slow to arrive anyway (time to receive packs, store messages in db, etc. wastes too much time if (isNew) { try { Thread.sleep(500); } catch (InterruptedException e) { // ignored } } */ ContentResolver res = context.getContentResolver(); NotificationManagerCompat nm = NotificationManagerCompat.from(context); String query = MESSAGES_UNREAD_SELECTION; String[] args = null; String[] proj; String order; Uri uri; if (supportsBigNotifications()) { uri = Messages.CONTENT_URI; proj = MESSAGES_UNREAD_PROJECTION; order = Messages.DEFAULT_SORT_ORDER; } else { uri = Threads.CONTENT_URI; proj = THREADS_UNREAD_PROJECTION; order = Threads.INVERTED_SORT_ORDER; } // is there a peer to not notify for? final String paused = sPaused; if (paused != null) { query += " AND " + CommonColumns.PEER + " <> ? AND " + "(" + Groups.GROUP_JID + " IS NULL OR " + Groups.GROUP_JID + " <> ?)"; args = new String[] { paused, paused }; } Cursor c = res.query(uri, proj, query, args, order); // this shouldn't happen, but who knows... if (c == null) { nm.cancel(NOTIFICATION_ID_MESSAGES); return; } // no unread messages - delete notification int unread = c.getCount(); if (unread == 0) { c.close(); nm.cancel(NOTIFICATION_ID_MESSAGES); return; } // notifications are disabled if (!Preferences.getNotificationsEnabled(context) || sDisabled) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(context.getApplicationContext()); Set<Uri> conversationIds = new HashSet<>(unread); if (supportsBigNotifications()) { NotificationGenerator ngen = new NotificationGenerator(context, builder); long id = 0; while (c.moveToNext()) { // thread_id for PendingIntent id = c.getLong(0); String peer = c.getString(1); String mime = c.getString(2); byte[] content = c.getBlob(3); String attMime = c.getString(4); boolean encrypted = c.getInt(5) != 0; String groupJid = c.getString(6); String groupSubject = c.getString(7); // store conversation id for intents conversationIds.add(ContentUris.withAppendedId(Threads.CONTENT_URI, id)); ngen.addMessage(peer, mime, content, attMime, encrypted, groupJid, groupSubject); } c.close(); int convCount = ngen.build(account, unread, conversationIds.iterator().next()); builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE); Intent ni; // more than one unread conversation - open conversations list if (convCount > 1) { ni = new Intent(context, ConversationsActivity.class); ni.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); } // one unread conversation - open compose message on that thread else { ni = ComposeMessage.fromConversation(context, id); } PendingIntent pi = createPendingIntent(context, ni); builder.setContentIntent(pi); } else { // loop all threads and accumulate them MessageAccumulator accumulator = new MessageAccumulator(context); while (c.moveToNext()) { long threadId = c.getLong(0); String peer = c.getString(1); String mime = c.getString(2); String content = c.getString(3); boolean encrypted = c.getInt(4) != 0; if (encrypted) { content = context.getString(R.string.text_encrypted); } else if (content == null) { content = CompositeMessage.getSampleTextContent(mime); } else if (GroupCommandComponent.supportsMimeType(mime)) { // content is in a special format GroupThreadContent parsed = GroupThreadContent.parseIncoming(content); try { peer = parsed.sender; content = GroupCommandComponent.getTextContent(context, parsed.command, true); } catch (UnsupportedOperationException e) { // TODO using another string content = context.getString(R.string.peer_unknown); } } accumulator.accumulate(threadId, peer, content, c.getInt(5), // group data c.getString(6), c.getString(7)); conversationIds.add(ContentUris.withAppendedId(Threads.CONTENT_URI, threadId)); } c.close(); builder.setTicker(accumulator.getTicker()); Contact contact = accumulator.getContact(); if (contact != null) { Bitmap avatar = contact.getAvatarBitmap(context); if (avatar != null) builder.setLargeIcon(avatar); } builder.setNumber(accumulator.unreadCount); builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setContentTitle(accumulator.getTitle()); builder.setContentText(accumulator.getText()); builder.setContentIntent(accumulator.getPendingIntent()); } // build on delete intent for conversations Intent notificationDeleteIntent = new Intent(context, NotificationActionReceiver.class); notificationDeleteIntent.setAction(ACTION_NOTIFICATION_DELETED); notificationDeleteIntent.putExtra("org.kontalk.datalist", conversationIds.toArray(new Uri[conversationIds.size()])); builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, notificationDeleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)); if (isNew) { setDefaults(context, builder); } // features (priority, category) setFeatures(context, builder); nm.notify(NOTIFICATION_ID_MESSAGES, builder.build()); /* TODO take this from configuration boolean quickReply = false; if (isNew && quickReply) { Intent i = new Intent(context.getApplicationContext(), QuickReplyActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); i.putExtra("org.kontalk.quickreply.FROM", accumulator.getLastMessagePeer()); i.putExtra("org.kontalk.quickreply.MESSAGE", accumulator.getLastMessageText()); i.putExtra("org.kontalk.quickreply.OPEN_INTENT", accumulator.getLastMessagePendingIntent()); context.startActivity(i); } */ }