List of usage examples for android.database Cursor getBlob
byte[] getBlob(int columnIndex);
From source file:android.database.DatabaseUtils.java
/** * Read the entire contents of a cursor row and store them in a ContentValues. * * @param cursor the cursor to read from. * @param values the {@link ContentValues} to put the row into. *//*from ww w . j a va 2 s . c o m*/ public static void cursorRowToContentValues(Cursor cursor, ContentValues values) { AbstractWindowedCursor awc = (cursor instanceof AbstractWindowedCursor) ? (AbstractWindowedCursor) cursor : null; String[] columns = cursor.getColumnNames(); int length = columns.length; for (int i = 0; i < length; i++) { if (awc != null && awc.isBlob(i)) { values.put(columns[i], cursor.getBlob(i)); } else { values.put(columns[i], cursor.getString(i)); } } }
From source file:at.flack.receiver.SmsReceiver.java
public final Bitmap fetchThumbnail(Context context, String address) { Integer id = fetchThumbnailId(context, address); if (id == null) return null; final Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, id); final Cursor cursor = context.getContentResolver().query(uri, PHOTO_BITMAP_PROJECTION, null, null, null); try {//www . j av a2s. c o m Bitmap thumbnail = null; if (cursor.moveToFirst()) { final byte[] thumbnailBytes = cursor.getBlob(0); if (thumbnailBytes != null) { thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length); } } return thumbnail; } finally { cursor.close(); } }
From source file:org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView vHeaderId = (TextView) view.findViewById(R.id.user_id_header); TextView vName = (TextView) view.findViewById(R.id.user_id_item_name); TextView vAddresses = (TextView) view.findViewById(R.id.user_id_item_addresses); byte[] data = cursor.getBlob(1); int isHeader = cursor.getInt(2); Parcel p = Parcel.obtain();/* w w w . ja v a 2 s . c om*/ p.unmarshall(data, 0, data.length); p.setDataPosition(0); ArrayList<String> uids = p.createStringArrayList(); p.recycle(); { // first one String userId = uids.get(0); OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId); if (splitUserId.name != null) { vName.setText(splitUserId.name); } else { vName.setText(R.string.user_id_no_name); } if (isHeader == 1) { vHeaderId.setVisibility(View.VISIBLE); String message; if (splitUserId.name != null) { message = mContext.getString(R.string.section_uids_to_certify) + splitUserId.name; } else { message = mContext.getString(R.string.section_uids_to_certify) + context.getString(R.string.user_id_no_name); } vHeaderId.setText(message); } else { vHeaderId.setVisibility(View.GONE); } } StringBuilder lines = new StringBuilder(); for (String uid : uids) { OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(uid); if (splitUserId.email == null) { continue; } lines.append(splitUserId.email); if (splitUserId.comment != null) { lines.append(" (").append(splitUserId.comment).append(")"); } lines.append('\n'); } // If we have any data here, show it if (lines.length() > 0) { // delete last newline lines.setLength(lines.length() - 1); vAddresses.setVisibility(View.VISIBLE); vAddresses.setText(lines); } else { vAddresses.setVisibility(View.GONE); } final CheckBox vCheckBox = (CheckBox) view.findViewById(R.id.user_id_item_check_box); final int position = cursor.getPosition(); vCheckBox.setOnCheckedChangeListener(null); vCheckBox.setChecked(mCheckStates.get(position)); vCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mCheckStates.set(position, b); } }); vCheckBox.setClickable(false); vCheckBox.setVisibility(checkboxVisibility ? View.VISIBLE : View.GONE); View vUidBody = view.findViewById(R.id.user_id_body); vUidBody.setClickable(true); vUidBody.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { vCheckBox.toggle(); } }); }
From source file:cn.edu.wyu.documentviewer.RecentsProvider.java
/** * Purge all internal data whose authority matches the given * {@link Predicate}./*from w w w . java 2s.co m*/ */ private void purgeByAuthority(Predicate<String> predicate) { final SQLiteDatabase db = mHelper.getWritableDatabase(); final DocumentStack stack = new DocumentStack(); Cursor cursor = db.query(TABLE_RECENT, null, null, null, null, null, null); try { while (cursor.moveToNext()) { try { final byte[] rawStack = cursor.getBlob(cursor.getColumnIndex(RecentColumns.STACK)); DurableUtils.readFromArray(rawStack, stack); if (stack.root != null && predicate.apply(stack.root.authority)) { final String key = getCursorString(cursor, RecentColumns.KEY); db.delete(TABLE_RECENT, RecentColumns.KEY + "=?", new String[] { key }); } } catch (IOException ignored) { } } } finally { //IoUtils.closeQuietly(cursor); IOUtils.closeQuietly(cursor); } cursor = db.query(TABLE_STATE, new String[] { StateColumns.AUTHORITY }, null, null, StateColumns.AUTHORITY, null, null); try { while (cursor.moveToNext()) { final String authority = getCursorString(cursor, StateColumns.AUTHORITY); if (predicate.apply(authority)) { db.delete(TABLE_STATE, StateColumns.AUTHORITY + "=?", new String[] { authority }); Log.d(TAG, "Purged state for " + authority); } } } finally { //IoUtils.closeQuietly(cursor); IOUtils.closeQuietly(cursor); } cursor = db.query(TABLE_RESUME, null, null, null, null, null, null); try { while (cursor.moveToNext()) { try { final byte[] rawStack = cursor.getBlob(cursor.getColumnIndex(ResumeColumns.STACK)); DurableUtils.readFromArray(rawStack, stack); if (stack.root != null && predicate.apply(stack.root.authority)) { final String packageName = getCursorString(cursor, ResumeColumns.PACKAGE_NAME); db.delete(TABLE_RESUME, ResumeColumns.PACKAGE_NAME + "=?", new String[] { packageName }); } } catch (IOException ignored) { } } } finally { //IoUtils.closeQuietly(cursor); IOUtils.closeQuietly(cursor); } }
From source file:info.guardianproject.notepadbot.NoteCipher.java
private void viewEntry(final long id) { if (mCacheWord.isLocked()) return;/*from ww w. j a v a2 s . c o m*/ getSupportLoaderManager().restartLoader(VIEW_ID, null, new LoaderManager.LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new NoteEdit.NoteContentLoader(NoteCipher.this, mDbHelper, id); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor note) { byte[] blob = note.getBlob(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_DATA)); String mimeType = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TYPE)); if (mimeType == null) mimeType = "text/plain"; if (blob != null) { String title = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)); NoteUtils.savePublicFile(NoteCipher.this, title, mimeType, blob); } note.close(); } @Override public void onLoaderReset(Loader<Cursor> loader) { } }); }
From source file:info.guardianproject.notepadbot.NoteCipher.java
private void shareEntry(final long id) { if (mCacheWord.isLocked()) { return;/*w w w. j ava2s . c om*/ } getSupportLoaderManager().restartLoader(SHARE_ID, null, new LoaderManager.LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new NoteEdit.NoteContentLoader(NoteCipher.this, mDbHelper, id); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor note) { byte[] blob = note.getBlob(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_DATA)); String title = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)); String mimeType = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TYPE)); if (mimeType == null) mimeType = "text/plain"; if (blob != null) { try { NoteUtils.shareData(NoteCipher.this, title, mimeType, blob); } catch (IOException e) { Toast.makeText(NoteCipher.this, getString(R.string.err_export, e.getMessage()), Toast.LENGTH_LONG).show(); } } else { String body = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)); NoteUtils.shareText(NoteCipher.this, body); } note.close(); } @Override public void onLoaderReset(Loader<Cursor> loader) { } }); }
From source file:com.luorrak.ouroboros.thread.ThreadFragment.java
public void startDownload() { Cursor imageCursor = infiniteDbHelper.getGalleryCursor(resto); do {/*from ww w . ja va 2 s. c o m*/ ArrayList<Media> mediaArrayList = (ArrayList<Media>) Util.deserializeObject(imageCursor .getBlob(imageCursor.getColumnIndex(DbContract.ThreadEntry.COLUMN_THREAD_MEDIA_FILES))); for (Media mediaItem : mediaArrayList) { networkHelper.downloadFile(boardName, mediaItem.fileName, mediaItem.ext, getActivity()); } } while (imageCursor.moveToNext()); imageCursor.close(); }
From source file:org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter.java
public UriAttribute getItemAtPosition(Cursor cursor) { int rank = cursor.getInt(INDEX_RANK); Log.d(Constants.TAG, "requested rank: " + rank); UriAttribute ret = mLinkedIdentityCache.get(rank); if (ret != null) { Log.d(Constants.TAG, "cached!"); return ret; }// w ww . j av a 2 s . c o m Log.d(Constants.TAG, "not cached!"); try { byte[] data = cursor.getBlob(INDEX_ATTRIBUTE_DATA); ret = LinkedAttribute.fromAttributeData(data); mLinkedIdentityCache.put(rank, ret); return ret; } catch (IOException e) { Log.e(Constants.TAG, "could not read linked identity subpacket data", e); return null; } }
From source file:com.ravi.apps.android.newsbytes.HeadlinesAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { // Extract the view holder. ViewHolder viewHolder = (ViewHolder) view.getTag(); // Get the mark as favorite flag. int isFavorite = cursor.getInt(HeadlinesFragment.COL_IS_FAVORITE); // If it's marked as favorite load image from byte stream, else use Picasso for loading. if (isFavorite == 1) { // Get the thumbnail blob from cursor. byte[] thumbnailByteStream = cursor.getBlob(HeadlinesFragment.COL_THUMBNAIL); // Check if blob for thumbnail is non null. if (thumbnailByteStream != null) { // Get the thumbnail bitmap from byte array. Bitmap thumbnailBitmap = BitmapFactory.decodeByteArray(thumbnailByteStream, 0, thumbnailByteStream.length); // Set the thumbnail bitmap into the image view. viewHolder.thumbnailView.setImageBitmap(thumbnailBitmap); viewHolder.thumbnailView.setScaleType(ImageView.ScaleType.FIT_XY); } else {//from w w w. j a va 2 s .c om // Show thumbnail placeholder icon and log error message. viewHolder.thumbnailView.setImageResource(R.drawable.thumbnail_placeholder); Log.e(LOG_TAG, context.getString(R.string.msg_err_no_thumbnail)); } } else { // Get the thumbnail uri. String urlThumbnail = cursor.getString(HeadlinesFragment.COL_URI_THUMBNAIL); // Check if url for thumbnail is non null. if (urlThumbnail != null) { // Remove escape characters from the string. String url = Utility.removeCharsFromString(urlThumbnail, "\\"); // Load the thumbnail into image view using Picasso. Picasso.with(context).load(url).placeholder(R.drawable.thumbnail_placeholder).fit() .into(viewHolder.thumbnailView); } else { // Show thumbnail placeholder icon and log error message. viewHolder.thumbnailView.setImageResource(R.drawable.thumbnail_placeholder); Log.e(LOG_TAG, context.getString(R.string.msg_err_no_thumbnail)); } } // Get the headline and set it onto the text view. String headline = cursor.getString(HeadlinesFragment.COL_HEADLINE); // Check if headline is non null and non empty. if (headline != null && !headline.isEmpty()) { viewHolder.headlineView.setText(headline); viewHolder.headlineView.setContentDescription(headline); } else { // Display headline not available message and log error message. viewHolder.headlineView.setText(context.getString(R.string.msg_err_no_headline)); viewHolder.headlineView.setContentDescription(context.getString(R.string.msg_err_no_headline)); Log.e(LOG_TAG, context.getString(R.string.msg_err_no_headline)); } // Generate transition names for shared elements for devices running lollipop or above. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { viewHolder.thumbnailView.setTransitionName(THUMBNAIL_TRANSITION_NAME + cursor.getPosition()); viewHolder.headlineView.setTransitionName(HEADLINE_TRANSITION_NAME + cursor.getPosition()); } }
From source file:edu.stanford.mobisocial.dungbeetle.DBIdentityProvider.java
public String userProfile() { Cursor c = mHelper.getReadableDatabase().rawQuery("SELECT * FROM " + MyInfo.TABLE, new String[] {}); try {/*from w ww .j a v a2 s . c o m*/ c.moveToFirst(); JSONObject obj = new JSONObject(); try { obj.put("name", c.getString(c.getColumnIndexOrThrow(MyInfo.NAME))); } catch (JSONException e) { } return JSON.fastAddBase64(obj.toString(), "picture", c.getBlob(c.getColumnIndexOrThrow(MyInfo.PICTURE))); } finally { c.close(); } }