Example usage for android.database Cursor getBlob

List of usage examples for android.database Cursor getBlob

Introduction

In this page you can find the example usage for android.database Cursor getBlob.

Prototype

byte[] getBlob(int columnIndex);

Source Link

Document

Returns the value of the requested column as a byte array.

Usage

From source file:org.sufficientlysecure.keychain.ui.ViewKeyFragment.java

@Override
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  w w.j  a  v a 2s.  co m
    if (data == null) {
        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.getCount() == 1 && data.moveToFirst()) {

            mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
            mFingerprint = data.getBlob(INDEX_FINGERPRINT);
            long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);

            // init other things after we know if it's a secret key
            initUserIds(mIsSecret);
            initLinkedIds(mIsSecret);
            initLinkedContactLoader(masterKeyId, mIsSecret);
            initCardButtonsVisibility(mIsSecret);
        }
        break;
    }

    case LOADER_ID_USER_IDS: {
        setContentShown(true, false);
        mUserIdsAdapter.swapCursor(data);

        break;
    }

    case LOADER_ID_LINKED_IDS: {
        mLinkedIdsAdapter.swapCursor(data);

        if (mIsSecret) {
            mLinkedIdsCard.setVisibility(View.VISIBLE);
            mLinkedIdsEmpty.setVisibility(mLinkedIdsAdapter.getCount() > 0 ? View.GONE : View.VISIBLE);
        } else {
            mLinkedIdsCard.setVisibility(mLinkedIdsAdapter.getCount() > 0 ? View.VISIBLE : View.GONE);
            mLinkedIdsEmpty.setVisibility(View.GONE);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mPostponeType == PostponeType.LINKED) {
            mLinkedIdsCard.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                @TargetApi(VERSION_CODES.LOLLIPOP)
                @Override
                public boolean onPreDraw() {
                    mLinkedIdsCard.getViewTreeObserver().removeOnPreDrawListener(this);
                    getActivity().startPostponedEnterTransition();
                    return true;
                }
            });
        }
        break;
    }

    case LOADER_ID_LINKED_CONTACT: {
        if (data.moveToFirst()) { // if we have a linked contact
            long contactId = data.getLong(INDEX_CONTACT_ID);
            loadLinkedSystemContact(contactId);
        }
        break;
    }
    }
}

From source file:net.news.inrss.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        Log.d(TAG, "refreshUI() called with: " + "entryCursor = [" + entryCursor + "]");
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);/*from  ww  w.  j a v  a 2s.co m*/

        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])) {
            // 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));
            }
        }

        // 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();
        }
    }
}

From source file:org.thialfihar.android.apg.provider.ProviderHelper.java

public LongSparseArray<PGPKeyRing> getPGPKeyRings(Uri queryUri) {
    Cursor cursor = mContentResolver.query(queryUri,
            new String[] { KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA }, null, null, null);

    LongSparseArray<PGPKeyRing> result = new LongSparseArray<PGPKeyRing>(cursor.getCount());
    try {//  w  ww  . ja  v a2s  .c  o  m
        if (cursor != null && cursor.moveToFirst())
            do {
                long masterKeyId = cursor.getLong(0);
                byte[] data = cursor.getBlob(1);
                if (data != null) {
                    result.put(masterKeyId, PgpConversionHelper.BytesToPGPKeyRing(data));
                }
            } while (cursor.moveToNext());
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return result;
}

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

private void fetchPhotoAsync(final RecipientEntry entry, final Uri photoThumbnailUri) {
    final AsyncTask<Void, Void, Void> photoLoadTask = new AsyncTask<Void, Void, Void>() {
        @Override//from   ww w . j a v  a  2s.  co  m
        protected Void doInBackground(Void... params) {
            final Cursor photoCursor = mContentResolver.query(photoThumbnailUri, PhotoQuery.PROJECTION, null,
                    null, null);
            if (photoCursor != null) {
                try {
                    if (photoCursor.moveToFirst()) {
                        final byte[] photoBytes = photoCursor.getBlob(PhotoQuery.PHOTO);
                        entry.setPhotoBytes(photoBytes);

                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                mPhotoCacheMap.put(photoThumbnailUri, photoBytes);
                                notifyDataSetChanged();
                            }
                        });
                    }
                } finally {
                    photoCursor.close();
                }
            }
            return null;
        }
    };
    photoLoadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}

From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java

private KeyRing getWrappedKeyRing(Uri queryUri, boolean secret) throws NotFoundException {
    Cursor cursor = mContentResolver.query(queryUri, new String[] {
            // we pick from cache only information that is not easily available from keyrings
            KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED,
            // and of course, ring data
            secret ? KeyRings.PRIVKEY_DATA : KeyRings.PUBKEY_DATA }, null, null, null);
    try {//from www .j a  v a2 s.co  m
        if (cursor != null && cursor.moveToFirst()) {

            boolean hasAnySecret = cursor.getInt(0) > 0;
            int verified = cursor.getInt(1);
            byte[] blob = cursor.getBlob(2);
            if (secret & !hasAnySecret) {
                throw new NotFoundException("Secret key not available!");
            }
            return secret ? new WrappedSecretKeyRing(blob, hasAnySecret, verified)
                    : new WrappedPublicKeyRing(blob, hasAnySecret, verified);
        } else {
            throw new NotFoundException("Key not found!");
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:org.sufficientlysecure.keychain.ui.CertifyKeyActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case LOADER_ID_KEYRING:
        // the first key here is our master key
        if (data.moveToFirst()) {
            // TODO: put findViewById in onCreate!
            mPubKeyId = data.getLong(INDEX_MASTER_KEY_ID);
            String keyIdStr = PgpKeyHelper.convertKeyIdToHex(mPubKeyId);
            ((TextView) findViewById(R.id.key_id)).setText(keyIdStr);

            String mainUserId = data.getString(INDEX_USER_ID);
            ((TextView) findViewById(R.id.main_user_id)).setText(mainUserId);

            byte[] fingerprintBlob = data.getBlob(INDEX_FINGERPRINT);
            String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
            ((TextView) findViewById(R.id.view_key_fingerprint))
                    .setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
        }/*from w  w w . j a  va 2s .c o  m*/
        break;
    case LOADER_ID_USER_IDS:
        mUserIdsAdapter.swapCursor(data);
        break;
    }
}

From source file:com.android.leanlauncher.WidgetPreviewLoader.java

private Bitmap readFromDb(String name, Bitmap b) {
    if (mCachedSelectQuery == null) {
        mCachedSelectQuery = CacheDb.COLUMN_NAME + " = ? AND " + CacheDb.COLUMN_SIZE + " = ?";
    }/*from   w w w  .  j  ava 2 s .  c o  m*/
    SQLiteDatabase db = mDb.getReadableDatabase();
    Cursor result;
    try {
        result = db.query(CacheDb.TABLE_NAME, new String[] { CacheDb.COLUMN_PREVIEW_BITMAP }, // cols to return
                mCachedSelectQuery, // select query
                new String[] { name, mSize }, // args to select query
                null, null, null, null);
    } catch (SQLiteDiskIOException e) {
        recreateDb();
        return null;
    } catch (SQLiteCantOpenDatabaseException e) {
        throw e;
    }
    if (result.getCount() > 0) {
        result.moveToFirst();
        byte[] blob = result.getBlob(0);
        result.close();
        final BitmapFactory.Options opts = mCachedBitmapFactoryOptions.get();
        opts.inBitmap = b;
        opts.inSampleSize = 1;
        try {
            return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
        } catch (IllegalArgumentException e) {
            removeItemFromDb(mDb, name);
            return null;
        }
    } else {
        result.close();
        return null;
    }
}

From source file:org.chromium.chrome.browser.util.ChromeFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Uri fileUri = getFileUriWhenReady(uri);
    if (fileUri == null)
        return null;

    // Workaround for a bad assumption that particular MediaStore columns exist by certain third
    // party applications.
    // http://crbug.com/467423.
    Cursor source = super.query(fileUri, 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  www  .ja  v  a  2  s. com
    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.linked.LinkedIdViewFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case LOADER_ID_LINKED_ID:

        // Nothing to load means break if we are *expected* to load
        if (!cursor.moveToFirst()) {
            if (mIdLoadedListener != null) {
                Notify.create(getActivity(), "Error loading identity!", Notify.LENGTH_LONG, Style.ERROR).show();
                finishFragment();//from   w  w w  . j av  a2  s .  c o  m
            }
            // Or just ignore, this is probably some intermediate state during certify
            break;
        }

        try {
            int certStatus = cursor.getInt(UserIdsAdapter.INDEX_VERIFIED);

            byte[] data = cursor.getBlob(UserIdsAdapter.INDEX_ATTRIBUTE_DATA);
            UriAttribute linkedId = LinkedAttribute.fromAttributeData(data);

            loadIdentity(linkedId, certStatus);

            if (mIdLoadedListener != null) {
                mIdLoadedListener.onIdentityLoaded();
                mIdLoadedListener = null;
            }

        } catch (IOException e) {
            Log.e(Constants.TAG, "error parsing identity", e);
            Notify.create(getActivity(), "Error parsing identity!", Notify.LENGTH_LONG, Style.ERROR).show();
            finishFragment();
        }

        break;
    }
}

From source file:com.android.ex.chips.BaseRecipientAdapter.java

protected void fetchPhoto(final RecipientEntry entry, final Uri photoThumbnailUri) {
    byte[] photoBytes = mPhotoCacheMap.get(photoThumbnailUri);
    if (photoBytes != null) {
        entry.setPhotoBytes(photoBytes);
        return;/*from  w w  w.  j av a 2 s .c o  m*/
    }
    final Cursor photoCursor = mContentResolver.query(photoThumbnailUri, PhotoQuery.PROJECTION, null, null,
            null);
    if (photoCursor != null) {
        try {
            if (photoCursor.moveToFirst()) {
                photoBytes = photoCursor.getBlob(PhotoQuery.PHOTO);
                entry.setPhotoBytes(photoBytes);
                mPhotoCacheMap.put(photoThumbnailUri, photoBytes);
            }
        } finally {
            photoCursor.close();
        }
    }
}