List of usage examples for android.database Cursor getBlob
byte[] getBlob(int columnIndex);
From source file:com.luorrak.ouroboros.catalog.WatchListAdapter.java
@Override public void onBindViewHolderCursor(RecyclerView.ViewHolder holder, Cursor cursor) { WatchListViewHolder watchlistViewHolder = (WatchListViewHolder) holder; watchlistViewHolder.watchlistObject.title = cursor .getString(cursor.getColumnIndex(DbContract.WatchlistEntry.COLUMN_TITLE)); watchlistViewHolder.watchlistObject.board = cursor .getString(cursor.getColumnIndex(DbContract.WatchlistEntry.COLUMN_BOARD)); watchlistViewHolder.watchlistObject.no = cursor .getString(cursor.getColumnIndex(DbContract.WatchlistEntry.COLUMN_NO)); watchlistViewHolder.watchlistObject.serializedMediaList = cursor .getBlob(cursor.getColumnIndex(DbContract.WatchlistEntry.COLUMN_MEDIA_FILES)); watchlistViewHolder.watchlistTitle.setText(watchlistViewHolder.watchlistObject.title); if (watchlistViewHolder.watchlistObject.serializedMediaList != null) { ArrayList<Media> deserializedMediaList = (ArrayList<Media>) Util .deserializeObject(watchlistViewHolder.watchlistObject.serializedMediaList); Ion.with(watchlistViewHolder.watchlistThumbnail) .load(ChanUrls.getThumbnailUrl(watchlistViewHolder.watchlistObject.board, deserializedMediaList.get(0).fileName)) .withBitmapInfo();/*from ww w .j ava2 s. c om*/ } }
From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java
private Object getValueFromCursor(Cursor cursor, int index, int columnType) { switch (columnType) { case Cursor.FIELD_TYPE_FLOAT: return cursor.getFloat(index); case Cursor.FIELD_TYPE_INTEGER: return cursor.getInt(index); case Cursor.FIELD_TYPE_BLOB: // convert byte[] to binary string; it's good enough, because // WebSQL doesn't support blobs anyway return new String(cursor.getBlob(index)); case Cursor.FIELD_TYPE_STRING: return cursor.getString(index); }//from ww w . j a v a 2s .c om return null; }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
/** * Processes all groups with non-null {@link #COLUMN_PENDING_MEMBERS}: the pending memberships * are (if possible) applied, keeping cached memberships in sync. * @param addressBook address book to take groups from * @throws ContactsStorageException on contact provider errors */// w w w . j av a 2 s . c o m public static void applyPendingMemberships(LocalAddressBook addressBook) throws ContactsStorageException { try { @Cleanup Cursor cursor = addressBook.provider.query(addressBook.syncAdapterURI(Groups.CONTENT_URI), new String[] { Groups._ID, COLUMN_PENDING_MEMBERS }, COLUMN_PENDING_MEMBERS + " IS NOT NULL", new String[] {}, null); BatchOperation batch = new BatchOperation(addressBook.provider); while (cursor != null && cursor.moveToNext()) { long id = cursor.getLong(0); Constants.log.fine("Assigning members to group " + id); // delete all memberships and cached memberships for this group batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newDelete(addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI)) .withSelection( "(" + GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?) OR (" + CachedGroupMembership.MIMETYPE + "=? AND " + CachedGroupMembership.GROUP_ID + "=?)", new String[] { GroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id), CachedGroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id) }) .withYieldAllowed(true))); // extract list of member UIDs List<String> members = new LinkedList<>(); byte[] raw = cursor.getBlob(1); @Cleanup("recycle") Parcel parcel = Parcel.obtain(); parcel.unmarshall(raw, 0, raw.length); parcel.setDataPosition(0); parcel.readStringList(members); // insert memberships for (String uid : members) { Constants.log.fine("Assigning member: " + uid); try { LocalContact member = addressBook.findContactByUID(uid); member.addToGroup(batch, id); } catch (FileNotFoundException e) { Constants.log.log(Level.WARNING, "Group member not found: " + uid, e); } } // remove pending memberships batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newUpdate(addressBook.syncAdapterURI(ContentUris.withAppendedId(Groups.CONTENT_URI, id))) .withValue(COLUMN_PENDING_MEMBERS, null).withYieldAllowed(true))); batch.commit(); } } catch (RemoteException e) { throw new ContactsStorageException("Couldn't get pending memberships", e); } }
From source file:org.droidparts.persist.sql.EntityManager.java
protected Object readFromCursor(Cursor cursor, int columnIndex, Class<?> valType, Class<?> arrCollItemType) throws IllegalArgumentException { if (cursor.isNull(columnIndex)) { return null; } else if (isBoolean(valType)) { return cursor.getInt(columnIndex) == 1; } else if (isByte(valType)) { return Byte.valueOf(cursor.getString(columnIndex)); } else if (isByteArray(valType)) { return cursor.getBlob(columnIndex); } else if (isDouble(valType)) { return cursor.getDouble(columnIndex); } else if (isFloat(valType)) { return cursor.getFloat(columnIndex); } else if (isInteger(valType)) { return cursor.getInt(columnIndex); } else if (isLong(valType)) { return cursor.getLong(columnIndex); } else if (isShort(valType)) { return cursor.getShort(columnIndex); } else if (isString(valType)) { return cursor.getString(columnIndex); } else if (isUUID(valType)) { return UUID.fromString(cursor.getString(columnIndex)); } else if (isDate(valType)) { return new Date(cursor.getLong(columnIndex)); } else if (isBitmap(valType)) { byte[] arr = cursor.getBlob(columnIndex); return BitmapFactory.decodeByteArray(arr, 0, arr.length); } else if (isJsonObject(valType) || isJsonArray(valType)) { String str = cursor.getString(columnIndex); try {// w w w .j ava 2s.com return isJsonObject(valType) ? new JSONObject(str) : new JSONArray(str); } catch (JSONException e) { throw new IllegalArgumentException(e); } } else if (isEnum(valType)) { return instantiateEnum(valType, cursor.getString(columnIndex)); } else if (isEntity(valType)) { long id = cursor.getLong(columnIndex); @SuppressWarnings("unchecked") Entity entity = instantiate((Class<Entity>) valType); entity.id = id; return entity; } else if (isArray(valType) || isCollection(valType)) { String str = cursor.getString(columnIndex); String[] parts = (str.length() > 0) ? str.split("\\" + SEP) : new String[0]; if (isArray(valType)) { return toTypeArr(arrCollItemType, parts); } else { @SuppressWarnings("unchecked") Collection<Object> coll = (Collection<Object>) instantiate(valType); coll.addAll(toTypeColl(arrCollItemType, parts)); return coll; } } else { throw new IllegalArgumentException("Need to manually read " + valType.getName() + " from cursor."); } }
From source file:org.sufficientlysecure.keychain.ui.CertifyFingerprintFragment.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. *//*from w ww .j a v a 2 s. co m*/ // Avoid NullPointerExceptions... if (data.getCount() == 0) { return; } // 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()) { byte[] fingerprintBlob = data.getBlob(INDEX_UNIFIED_FINGERPRINT); if (mEnablePhrasesConfirm) { displayWordConfirm(fingerprintBlob); } else { displayHexConfirm(fingerprintBlob); } break; } } } setContentShown(true); }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvUserIdsFragment.java
public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Avoid NullPointerExceptions, if we get an empty result set. if (data.getCount() == 0) { return;//from w w w .j a v a2 s . com } switch (loader.getId()) { case LOADER_ID_UNIFIED: { data.moveToFirst(); mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID); mHasSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0; mFingerprint = data.getBlob(INDEX_FINGERPRINT); break; } case LOADER_ID_USER_IDS: { // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) mUserIdsAdapter.swapCursor(data); setContentShown(true); break; } } }
From source file:com.indeema.mail.utils.NotificationUtils.java
private static Bitmap getContactIcon(final Context context, final String displayName, final String senderAddress, final Folder folder) { if (senderAddress == null) { return null; }//from www .j av a 2 s .c o m Bitmap icon = null; final List<Long> contactIds = findContacts(context, Arrays.asList(new String[] { senderAddress })); // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); if (contactIds != null) { for (final long id : contactIds) { final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); final Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); final Cursor cursor = context.getContentResolver().query(photoUri, new String[] { Photo.PHOTO }, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { final byte[] data = cursor.getBlob(0); if (data != null) { icon = BitmapFactory.decodeStream(new ByteArrayInputStream(data)); if (icon != null && icon.getHeight() < idealIconHeight) { // We should scale this image to fit the intended size icon = Bitmap.createScaledBitmap(icon, idealIconWidth, idealIconHeight, true); } if (icon != null) { break; } } } } finally { cursor.close(); } } } } if (icon == null) { // Make a colorful tile! final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE); icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress); } if (icon == null) { // Icon should be the default mail icon. icon = getDefaultNotificationIcon(context, folder, false /* single new message */); } return icon; }
From source file:com.chen.mail.utils.NotificationUtils.java
private static Bitmap getContactIcon(final Context context, final String displayName, final String senderAddress, final Folder folder) { if (senderAddress == null) { return null; }/* w ww . j av a2 s . c om*/ Bitmap icon = null; final List<Long> contactIds = findContacts(context, Arrays.asList(new String[] { senderAddress })); // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); if (contactIds != null) { for (final long id : contactIds) { final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); final Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); final Cursor cursor = context.getContentResolver().query(photoUri, new String[] { Photo.PHOTO }, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { final byte[] data = cursor.getBlob(0); if (data != null) { icon = BitmapFactory.decodeStream(new ByteArrayInputStream(data)); if (icon != null && icon.getHeight() < idealIconHeight) { // We should scale this image to fit the intended size icon = Bitmap.createScaledBitmap(icon, idealIconWidth, idealIconHeight, true); } if (icon != null) { break; } } } } finally { cursor.close(); } } } } if (icon == null) { // Make a colorful tile! final ImageCanvas.Dimensions dimensions = new ImageCanvas.Dimensions(idealIconWidth, idealIconHeight, ImageCanvas.Dimensions.SCALE_ONE); icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress); } if (icon == null) { // Icon should be the default mail icon. icon = getDefaultNotificationIcon(context, folder, false /* single new message */); } return icon; }
From source file:org.mozilla.gecko.AwesomeBar.java
@Override public boolean onContextItemSelected(MenuItem item) { if (mContextMenuSubject == null) return false; final int id; final String url; byte[] b = null; String title = ""; if (mContextMenuSubject instanceof Cursor) { Cursor cursor = (Cursor) mContextMenuSubject; id = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID)); url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)); b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON)); title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE)); } else if (mContextMenuSubject instanceof Map) { @SuppressWarnings("rawtypes") Map map = (Map) mContextMenuSubject; id = -1;/*from w ww . ja va 2 s .co m*/ url = (String) map.get(URLColumns.URL); b = (byte[]) map.get(URLColumns.FAVICON); title = (String) map.get(URLColumns.TITLE); } else { return false; } mContextMenuSubject = null; switch (item.getItemId()) { case R.id.open_new_tab: { GeckoApp.mAppContext.loadUrl(url, Type.ADD); Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show(); break; } case R.id.remove_bookmark: { (new GeckoAsyncTask<Void, Void, Void>() { @Override public Void doInBackground(Void... params) { BrowserDB.removeBookmark(mResolver, id); return null; } @Override public void onPostExecute(Void result) { Toast.makeText(AwesomeBar.this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show(); } }).execute(); break; } case R.id.add_to_launcher: { Bitmap bitmap = null; if (b != null) bitmap = BitmapFactory.decodeByteArray(b, 0, b.length); GeckoAppShell.createShortcut(title, url, bitmap, ""); break; } case R.id.share: { GeckoAppShell.openUriExternal(url, "text/plain", "", "", Intent.ACTION_SEND, title); break; } default: { return super.onContextItemSelected(item); } } return true; }
From source file:edu.stanford.mobisocial.dungbeetle.DBIdentityProvider.java
public Contact contactForUser() { Cursor c = mHelper.getReadableDatabase().rawQuery("SELECT * FROM " + MyInfo.TABLE, new String[] {}); try {//from w ww. j a v a 2s . c o m c.moveToFirst(); long id = Contact.MY_ID; String name = c.getString(c.getColumnIndexOrThrow(MyInfo.NAME)); String email = c.getString(c.getColumnIndexOrThrow(MyInfo.EMAIL)); String about = c.getString(c.getColumnIndexOrThrow(MyInfo.ABOUT)); //hack, make about info the status field of the contact class Contact contact = new Contact(id, mPubKeyTag, name, email, 0, 0, false, null, about, null, null, 0); byte[] picdata = c.getBlob(c.getColumnIndexOrThrow(MyInfo.PICTURE)); if (picdata != null) { contact.picture = BitmapFactory.decodeByteArray(picdata, 0, picdata.length); } return contact; } finally { c.close(); } }