List of usage examples for android.database Cursor getBlob
byte[] getBlob(int columnIndex);
From source file:com.technoxist.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. jav a2 s. c om*/ byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getActionBar().setIcon(R.drawable.icon); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { hideSwipeProgress(); // Start services here if not already started 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(); } } }
From source file:com.app.uafeed.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 ww.jav a2 s. c o m byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getActionBar().setIcon(R.drawable.icon); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task boolean isRefreshing = FetcherService.hasTasks(mEntriesIds[mCurrentPagerPos]); activity.getProgressBar().setVisibility(isRefreshing ? View.VISIBLE : View.GONE); // 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:com.ericsender.android_nanodegree.popmovie.com.ericsender.android_nanodegree.popmovie.data.TestProvider.java
public void testGettingMovieAndMaybeFavorite() { mContext.getContentResolver().delete(MovieContract.FavoriteEntry.CONTENT_URI, null, null); Map<Long, ContentValues> listContentValues = TestUtilities.createSortedMovieValues(getContext(), "popular"); ContentValues[] arr = (ContentValues[]) listContentValues.values().toArray(new ContentValues[0]); mContext.getContentResolver().bulkInsert(MovieContract.MovieEntry.CONTENT_URI, arr); ContentValues[] movie_ids = new ContentValues[arr.length]; for (int i = 0; i < arr.length; i++) (movie_ids[i] = new ContentValues()).put(MovieContract.RatingEntry.COLUMN_MOVIE_ID, arr[i].getAsLong(MovieContract.MovieEntry.COLUMN_MOVIE_ID)); mContext.getContentResolver().bulkInsert(MovieContract.FavoriteEntry.CONTENT_URI, movie_ids); TestUtilities.verifyFavoriteValuesInDatabase(listContentValues, mContext); Long expected = movie_ids[0].getAsLong(MovieContract.MovieEntry.COLUMN_MOVIE_ID); Cursor c = mContext.getContentResolver().query(MovieContract.MovieEntry.buildUriUnionFavorite(expected), null, null, null, null);//w w w . ja v a 2 s. c o m assertTrue(c.moveToFirst()); assertEquals(2, c.getCount()); assertEquals(expected.longValue(), c.getLong(0)); assertTrue(c.moveToNext()); assertTrue(c.getBlob(1).length > 0); c.close(); mContext.getContentResolver().delete(MovieContract.FavoriteEntry.buildUri(), MovieContract.FavoriteEntry.COLUMN_MOVIE_ID + "=?", new String[] { expected.toString() }); c = mContext.getContentResolver().query(MovieContract.MovieEntry.buildUriUnionFavorite(expected), null, null, null, null); assertTrue(c.moveToFirst()); assertEquals(1, c.getCount()); assertTrue(c.getBlob(1).length > 0); }
From source file:net.fred.feedex.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 ww w. ja v a 2 s. co m*/ byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getActionBar().setIcon(R.drawable.icon); } mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { showSwipeProgress(); } 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(); } } }
From source file:org.sufficientlysecure.keychain.ui.keyview.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()) { // Or just ignore, this is probably some intermediate state during certify break; }// w ww. j a v a2 s. c om try { int certStatus = cursor.getInt(UserIdsAdapter.INDEX_VERIFIED); byte[] data = cursor.getBlob(UserIdsAdapter.INDEX_ATTRIBUTE_DATA); UriAttribute linkedId = LinkedAttribute.fromAttributeData(data); loadIdentity(linkedId, certStatus); } 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.nextgis.ngm_clink_monitoring.fragments.CreateObjectFragment.java
public static Float getMinDistanceFromPrevPoints(FragmentActivity activity, String objectLayerName, Location location) {// www . j a v a2 s .c o m Float minDist = null; Uri uri = Uri.parse("content://" + FoclSettingsConstantsUI.AUTHORITY + "/" + objectLayerName); String[] columns = new String[] { FIELD_GEOM }; Cursor cursor; try { cursor = activity.getContentResolver().query(uri, columns, null, null, null); } catch (Exception e) { Log.d(TAG, e.getLocalizedMessage()); cursor = null; } if (null != cursor) { try { if (cursor.moveToFirst()) { int columnGeom = cursor.getColumnIndex(FIELD_GEOM); do { try { GeoGeometry geometry = GeoGeometryFactory.fromBlob(cursor.getBlob(columnGeom)); if (null != geometry && geometry instanceof GeoMultiPoint) { GeoMultiPoint mpt = (GeoMultiPoint) geometry; if (0 < mpt.size()) { int kk = 0; do { GeoPoint pt = new GeoPoint(mpt.get(kk)); pt.setCRS(GeoConstants.CRS_WEB_MERCATOR); pt.project(GeoConstants.CRS_WGS84); Location dstLocation = new Location(""); dstLocation.setLatitude(pt.getY()); dstLocation.setLongitude(pt.getX()); float dist = location.distanceTo(dstLocation); minDist = null == minDist ? dist : Math.min(minDist, dist); ++kk; } while (kk < mpt.size()); } } } catch (IOException | ClassNotFoundException e) { // e.printStackTrace(); } } while (cursor.moveToNext()); } } catch (Exception e) { //Log.d(TAG, e.getLocalizedMessage()); } finally { cursor.close(); } } return minDist; }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
private void editBookmark(BrowserBookmarksAdapter adapter, int position) { Intent intent = new Intent(this, AddBookmarkPage.class); Cursor cursor = adapter.getItem(position); Bundle item = new Bundle(); item.putString(BrowserContract.Bookmarks.TITLE, cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE)); item.putString(BrowserContract.Bookmarks.URL, cursor.getString(BookmarksLoader.COLUMN_INDEX_URL)); byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_FAVICON); if (data != null) { item.putParcelable(BrowserContract.Bookmarks.FAVICON, BitmapFactory.decodeByteArray(data, 0, data.length)); }/*from ww w .j av a2 s . c o m*/ item.putLong(BrowserContract.Bookmarks._ID, cursor.getLong(BookmarksLoader.COLUMN_INDEX_ID)); item.putLong(BrowserContract.Bookmarks.PARENT, cursor.getLong(BookmarksLoader.COLUMN_INDEX_PARENT)); intent.putExtra(AddBookmarkPage.EXTRA_EDIT_BOOKMARK, item); intent.putExtra(AddBookmarkPage.EXTRA_IS_FOLDER, cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) == 1); startActivity(intent); }
From source file:org.sufficientlysecure.keychain.provider.ProviderHelper.java
/** * Must be an uri pointing to an account * * @param uri/*ww w .ja v a 2 s . c o m*/ * @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(KeychainContract.ApiApps.PACKAGE_NAME))); settings.setPackageSignature( cursor.getBlob(cursor.getColumnIndex(KeychainContract.ApiApps.PACKAGE_SIGNATURE))); } } finally { if (cursor != null) { cursor.close(); } } return settings; }
From source file:org.thialfihar.android.apg.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! long keyId = data.getLong(INDEX_MASTER_KEY_ID); String keyIdStr = PgpKeyHelper.convertKeyIdToHexShort(keyId); ((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); if (fingerprintBlob == null) { // FALLBACK for old database entries fingerprintBlob = ProviderHelper.getFingerprint(this, mDataUri); }/*from w w w . j ava 2 s. c o m*/ String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob); ((TextView) findViewById(R.id.fingerprint)).setText(PgpKeyHelper.colorizeFingerprint(fingerprint)); } break; case LOADER_ID_USER_IDS: mUserIdsAdapter.swapCursor(data); break; } }
From source file:com.flym.dennikn.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 . c om*/ 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(); } } }