List of usage examples for android.database Cursor getBlob
byte[] getBlob(int columnIndex);
From source file:com.adampash.contactSearch.ContactsSearchModule.java
@Kroll.method private TiBlob fetchThumbnail(int thumbnailId) { ContentResolver contentResolver = appContext.getContentResolver(); String[] PHOTO_BITMAP_PROJECTION = new String[] { ContactsContract.CommonDataKinds.Photo.PHOTO }; Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, thumbnailId); Cursor cursor = contentResolver.query(uri, PHOTO_BITMAP_PROJECTION, null, null, null); try {/*from w w w. ja va 2s . c o m*/ Bitmap thumbnail = null; if (cursor.moveToFirst()) { byte[] thumbnailBytes = cursor.getBlob(0); if (thumbnailBytes != null) { thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length); } } /* return thumbnail; */ return TiBlob.blobFromImage(thumbnail); } finally { cursor.close(); } }
From source file:com.germainz.identiconizer.services.IdenticonRemovalService.java
private void processPhotos(ArrayList<ContactInfo> contactInfos) { for (int i = 0, j = contactInfos.size(); i < j; i++) { updateNotification(getString(R.string.identicons_remove_service_running_title), String.format(getString(R.string.identicons_remove_service_contact_summary), i, j)); // ContactsListActivity gives us name_raw_contact_id, which is not unique. // For example, if the user has 3 accounts (e.g. Google, WhatsApp and Viber) then three // photo rows will exist, one for each. // We want to get those that have a photo set (any photo, not identicons.) // We can't assume name_raw_contact_id == raw_contact_id because it might only match // one photo row (which might be empty) when multiple accounts are present. Cursor cursor = getIdenticonPhotos(contactInfos.get(i).nameRawContactId); while (cursor.moveToNext()) { int contactId = cursor.getInt(0); byte[] data = cursor.getBlob(1); if (data != null) removeIdenticon(contactId); }/*w w w . java 2s. c o m*/ } if (!mOps.isEmpty()) { updateNotification(getString(R.string.identicons_remove_service_running_title), getString(R.string.identicons_remove_service_contact_summary_finishing)); try { // Perform operations in batches of 100, to avoid TransactionTooLargeExceptions for (int i = 0, j = mOps.size(); i < j; i += 100) getContentResolver().applyBatch(ContactsContract.AUTHORITY, new ArrayList<ContentProviderOperation>(mOps.subList(i, i + Math.min(100, j - i)))); } catch (RemoteException | OperationApplicationException e) { Log.e(TAG, "Unable to apply batch", e); } } }
From source file:com.germainz.identiconizer.services.IdenticonCreationService.java
private byte[] getContactPhotoBlob(long photoId) { String[] projection = new String[] { ContactsContract.Data.DATA15 }; String where = ContactsContract.Data._ID + " == " + String.valueOf(photoId) + " AND " + ContactsContract.Data.MIMETYPE + "=='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, where, null, null);// w ww . j a v a 2 s .c om byte[] blob = null; if (cursor.moveToFirst()) { blob = cursor.getBlob(0); } cursor.close(); return blob; }
From source file:co.nerdart.ourss.activity.EntriesListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = getIntent();/*from ww w. j av a 2s . c o m*/ long feedId = intent.getLongExtra(FeedColumns._ID, 0); String title = null; if (feedId > 0) { Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI(feedId), FEED_PROJECTION, null, null, null); if (cursor.moveToFirst()) { title = cursor.isNull(0) ? cursor.getString(1) : cursor.getString(0); iconBytes = cursor.getBlob(2); } cursor.close(); } if (title != null) { setTitle(title); } if (savedInstanceState == null) { EntriesListFragment fragment = new EntriesListFragment(); Bundle args = new Bundle(); args.putParcelable(EntriesListFragment.ARG_URI, intent.getData()); fragment.setArguments(args); fragment.setHasOptionsMenu(true); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, "fragment").commit(); } if (iconBytes != null && iconBytes.length > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(24); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null) { if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } } if (MainActivity.mNotificationManager == null) { MainActivity.mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); } }
From source file:org.droidparts.inner.converter.ArrayCollectionConverter.java
@Override public <G1, G2> Object readFromCursor(Class<Object> valType, Class<G1> genericArg1, Class<G2> genericArg2, Cursor cursor, int columnIndex) throws Exception { Converter<G1> converter = ConverterRegistry.getConverter(genericArg1); if (converter.getDBColumnType() == BLOB) { byte[] arr = cursor.getBlob(columnIndex); return (arr != null) ? PersistUtils.fromBytes(arr) : null; } else {/*from w w w . j ava 2 s . c o m*/ String str = cursor.getString(columnIndex); String[] parts = (str.length() > 0) ? str.split("\\" + SEP) : new String[0]; if (isArray(valType)) { return parseTypeArr(converter, genericArg1, parts); } else { return parseTypeColl(converter, valType, genericArg1, parts); } } }
From source file:com.tct.fw.ex.chips.DefaultPhotoManager.java
private void fetchPhotoAsync(final RecipientEntry entry, final Uri photoThumbnailUri, final PhotoManagerCallback callback) { final AsyncTask<Void, Void, byte[]> photoLoadTask = new AsyncTask<Void, Void, byte[]>() { @Override// w w w. j av a2 s . c om protected byte[] doInBackground(Void... params) { // First try running a query. Images for local contacts are // loaded by sending a query to the ContactsProvider. final Cursor photoCursor = mContentResolver.query(photoThumbnailUri, PhotoQuery.PROJECTION, null, null, null); if (photoCursor != null) { try { if (photoCursor.moveToFirst()) { return photoCursor.getBlob(PhotoQuery.PHOTO); } } finally { photoCursor.close(); } } else { // If the query fails, try streaming the URI directly. // For remote directory images, this URI resolves to the // directory provider and the images are loaded by sending // an openFile call to the provider. try { InputStream is = mContentResolver.openInputStream(photoThumbnailUri); if (is != null) { byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { int size; while ((size = is.read(buffer)) != -1) { baos.write(buffer, 0, size); } } finally { is.close(); } return baos.toByteArray(); } } catch (IOException ex) { // ignore } } return null; } @Override protected void onPostExecute(final byte[] photoBytes) { entry.setPhotoBytes(photoBytes); if (photoBytes != null) { mPhotoCacheMap.put(photoThumbnailUri, photoBytes); if (callback != null) { callback.onPhotoBytesAsynchronouslyPopulated(); } } else if (callback != null) { callback.onPhotoBytesAsyncLoadFailed(); } } }; photoLoadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }
From source file:com.pursuer.reader.easyrss.network.SubscriptionDataSyncer.java
private void syncSubscriptionIcons() throws DataSyncerException { final Context context = dataMgr.getContext(); if (!NetworkUtils.checkSyncingNetworkStatus(context, networkConfig)) { return;//from w ww . j av a 2 s . com } final ContentResolver resolver = context.getContentResolver(); final Cursor cur = resolver.query(Subscription.CONTENT_URI, new String[] { Subscription._UID, Subscription._ICON, Subscription._URL }, null, null, null); for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { final String uid = cur.getString(0); final byte[] data = cur.getBlob(1); final String subUrl = cur.getString(2); if (subUrl != null && data == null) { final SubscriptionIconUrl fetchUrl = new SubscriptionIconUrl(isHttpsConnection, subUrl); try { final byte[] iconData = httpGetQueryByte(fetchUrl); final Bitmap icon = BitmapFactory.decodeByteArray(iconData, 0, iconData.length); final int size = icon.getWidth() * icon.getHeight() * 2; final ByteArrayOutputStream output = new ByteArrayOutputStream(size); icon.compress(Bitmap.CompressFormat.PNG, 100, output); output.flush(); output.close(); dataMgr.updateSubscriptionIconByUid(uid, output.toByteArray()); } catch (final IOException exception) { cur.close(); throw new DataSyncerException(exception); } } } cur.close(); }
From source file:info.guardianproject.notepadbot.NoteEdit.java
private void populateFields(Cursor note) { try {//from ww w.ja va 2s. c o m if (note == null) return; mBlob = note.getBlob(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_DATA)); mMimeType = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TYPE)); if (mMimeType == null) mMimeType = "text/plain"; boolean isImage = mMimeType.startsWith("image"); if (isImage) { // Load up the image's dimensions not the image itself BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); if (mBlob.length > 100000) bmpFactoryOptions.inSampleSize = 4; else bmpFactoryOptions.inSampleSize = 2; Bitmap blobb = BitmapFactory.decodeByteArray(mBlob, 0, mBlob.length, bmpFactoryOptions); mImageView.setImageBitmap(blobb); mImageView.setVisibility(View.VISIBLE); } else { mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY))); // Focus by default on the body of the note mBodyText.requestFocus(); mBodyText.setSelection(mBodyText.length()); if (mTextSize != 0) mBodyText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); mImageView.setVisibility(View.GONE); } mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE))); note.close(); } catch (Exception e) { Log.e("notepadbot", "error populating", e); Toast.makeText(this, getString(R.string.err_loading_note, e.getMessage()), Toast.LENGTH_LONG).show(); } }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyYubiKeyFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (!data.moveToFirst()) { // wut?/*from ww w .j a v a 2 s .c o m*/ return; } boolean allBound = true; boolean noneBound = true; do { SecretKeyType keyType = SecretKeyType.fromNum(data.getInt(INDEX_HAS_SECRET)); byte[] fingerprint = data.getBlob(INDEX_FINGERPRINT); Integer index = naiveIndexOf(mFingerprints, fingerprint); if (index == null) { continue; } if (keyType == SecretKeyType.DIVERT_TO_CARD) { noneBound = false; } else { allBound = false; } } while (data.moveToNext()); if (allBound) { vButton.setVisibility(View.GONE); vStatus.setText(R.string.yubikey_status_bound); } else { vButton.setVisibility(View.VISIBLE); vStatus.setText(noneBound ? R.string.yubikey_status_unbound : R.string.yubikey_status_partly); } }
From source file:org.sufficientlysecure.keychain.ui.ViewKeySecurityTokenFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (!data.moveToFirst()) { // wut?//from w w w. j a v a 2 s . c o m return; } boolean allBound = true; boolean noneBound = true; do { SecretKeyType keyType = SecretKeyType.fromNum(data.getInt(INDEX_HAS_SECRET)); byte[] fingerprint = data.getBlob(INDEX_FINGERPRINT); Integer index = naiveIndexOf(mFingerprints, fingerprint); if (index == null) { continue; } if (keyType == SecretKeyType.DIVERT_TO_CARD) { noneBound = false; } else { allBound = false; } } while (data.moveToNext()); if (allBound) { vButton.setVisibility(View.GONE); vStatus.setText(R.string.security_token_status_bound); } else { vButton.setVisibility(View.VISIBLE); vStatus.setText( noneBound ? R.string.security_token_status_unbound : R.string.security_token_status_partly); } }