List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:com.netthreads.traffic.view.TrafficDataMapFragment.java
/** * Process data using defined visitor./*from w ww. ja va 2 s . c o m*/ * * @param region * @param visitor */ private void visitData(String region, CursorVisitor visitor) { Cursor cursor = null; int itemCount = 0; Context context = getActivity(); try { SELECT_REGIONS[0] = region; cursor = getActivity().getContentResolver().query(TrafficDataRecordProvider.CONTENT_URI, TrafficDataListFragment.PROJECTION, WHERE_REGION, SELECT_REGIONS, null); itemCount = cursor.getCount(); if (itemCount > 0) { cursor.moveToFirst(); while (!cursor.isAfterLast()) { visitor.visit(context, cursor); cursor.moveToNext(); } } } catch (Throwable t) { Log.e("visitData", t.getLocalizedMessage()); } finally { if (cursor != null && (itemCount > 0)) { cursor.close(); } } }
From source file:com.im4j.picturebeautify.picchooser.ImagesFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.gallery, null); Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE }, MediaStore.Images.Media.BUCKET_ID + " = ?", new String[] { String.valueOf(getArguments().getInt("bucket")) }, MediaStore.Images.Media.DATE_MODIFIED + " ASC"); final List<GridItem> images = new ArrayList<GridItem>(cur.getCount()); if (cur != null) { if (cur.moveToFirst()) { while (!cur.isAfterLast()) { images.add(new GridItem(cur.getString(1), cur.getString(0), cur.getString(2), cur.getLong(3))); cur.moveToNext();// w w w . j av a 2 s . c o m } } cur.close(); } GridView grid = (GridView) v.findViewById(R.id.grid); grid.setAdapter(new GalleryAdapter(getActivity(), images)); grid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((SelectPictureActivity) getActivity()).imageSelected(images.get(position).path, images.get(position).imageTaken, images.get(position).imageSize); } }); return v; }
From source file:org.fossasia.phimpme.editor.picchooser.ImagesFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View v = inflater.inflate(R.layout.gallery, null); Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE }, MediaStore.Images.Media.BUCKET_ID + " = ?", new String[] { String.valueOf(getArguments().getInt("bucket")) }, MediaStore.Images.Media.DATE_MODIFIED + " DESC"); final List<GridItem> images = new ArrayList<GridItem>(cur.getCount()); if (cur != null) { if (cur.moveToFirst()) { while (!cur.isAfterLast()) { images.add(new GridItem(cur.getString(1), cur.getString(0), cur.getString(2), cur.getLong(3))); cur.moveToNext();/*from ww w .ja v a2 s. c om*/ } } cur.close(); } GridView grid = (GridView) v.findViewById(R.id.grid); grid.setAdapter(new GalleryAdapter(getActivity(), images)); grid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((SelectPictureActivity) getActivity()).imageSelected(images.get(position).path, images.get(position).imageTaken, images.get(position).imageSize); } }); return v; }
From source file:fr.eoit.activity.fragment.blueprint.RequiredDecryptorFragment.java
@Override public void onLoadFinished(Cursor cursor) { if (DbUtil.hasAtLeastOneRow(cursor)) { String[] from = new String[] { Item.COLUMN_NAME_NAME, "decryptorDesc" }; int[] to = new int[] { android.R.id.text1, android.R.id.text2 }; MatrixCursor decryptorCursor = new MatrixCursor( new String[] { Item._ID, Item.COLUMN_NAME_NAME, "decryptorDesc" }); DbUtil.addRowToMatrixCursor(decryptorCursor, 0L, "None", ""); cursor.moveToFirst();/*from w w w . ja v a 2s . c om*/ int selectedItem = 0; while (!cursor.isAfterLast()) { long itemId = cursor.getLong(cursor.getColumnIndexOrThrow(Item._ID)); DbUtil.addRowToMatrixCursor(decryptorCursor, itemId, cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)), getDecryptorDescription(DecryptorUtil.getDecryptorBonuses(itemId), getActivity().getResources())); if (itemId == decryptorId) { selectedItem = cursor.getPosition() + 1; } cursor.moveToNext(); } SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, decryptorCursor, from, to, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); Spinner spinner = (Spinner) getActivity().findViewById(R.id.DECRYPTOR_SPINNER); adapter.setDropDownViewResource(R.layout.decryptor_drop_down_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new SpinnerDecryptorOnItemSelectedListener()); spinner.setSelection(selectedItem); } }
From source file:edu.mit.mobile.android.livingpostcards.CardEditActivity.java
/** * Queries the card media to determine if the card media have any contributors other than the * owner of the card.// w w w . j av a 2 s . com * * @param card * @return */ private boolean hasNonOwnerContributors(Uri card) { boolean hasNonOwnerContributors = false; final String myAuthorUri = Authenticator.getUserUri(this); final String[] proj = new String[] { CardMedia.COL_AUTHOR_URI }; final Cursor media = Card.MEDIA.query(getContentResolver(), card, proj); final int cardMediaAuthorCol = media.getColumnIndexOrThrow(CardMedia.COL_AUTHOR_URI); try { for (media.moveToFirst(); !hasNonOwnerContributors && !media.isAfterLast(); media.moveToNext()) { final String cardAuthor = media.getString(cardMediaAuthorCol); hasNonOwnerContributors |= !myAuthorUri.equals(cardAuthor); } } finally { media.close(); } return hasNonOwnerContributors; }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Gets modified rows of a table./*w w w . jav a 2 s .c om*/ * @param table Table * @return List of rows as JSONObject * @throws JSONException */ public List<JSONObject> getDirtyRows(String table) throws JSONException { String query = null; switch (table) { case "patient": query = "SELECT pa.tribe, pa.creator, pa.date_created, pa.changed_by, pa.date_changed," + " pa.voided, pa.voided_by, pa.date_voided, pa.void_reason, pe.uuid FROM patient" + " pa INNER JOIN person pe ON pe.person_id = pa.patient_id " + " WHERE pa.dirty = 1"; break; case "person": query = "SELECT pe.gender, pe.birthdate, pe.birthdate_estimated, pe.dead, pe.death_date," + " pe.cause_of_death, pe.creator, pe.date_created, pe.changed_by, pe.date_changed," + " pe.voided, pe.voided_by, pe.date_voided, pe.void_reason, pe.uuid FROM person pe" + " WHERE pe.dirty = 1"; break; case "patient_identifier": query = "SELECT pe.uuid AS patient_id, pi.identifier, pi.identifier_type, pi.preferred," + " pi.location_id, pi.creator, pi.date_created, pi.date_changed, pi.changed_by, pi.voided," + " pi.voided_by, pi.date_voided, pi.void_reason, pi.uuid FROM patient_identifier pi" + " INNER JOIN person pe ON pi.patient_id = pe.person_id" + " WHERE pi.dirty = 1"; break; case "person_address": query = "SELECT pe.uuid AS person_id, pa.preferred, pa.address1, pa.address2, pa.city_village," + " pa.state_province, pa.postal_code, pa.country, pa.latitude, pa.longitude, pa.start_date," + " pa.end_date, pa.creator, pa.date_created, pa.voided, pa.voided_by, pa.date_voided," + " pa.void_reason, pa.county_district, pa.address3, pa.address4, pa.address5, pa.address6," + " pa.date_changed, pa.changed_by, pa.uuid FROM person_address pa" + " INNER JOIN person pe ON pa.person_id = pe.person_id" + " WHERE pa.dirty = 1"; break; case "person_name": query = "SELECT pn.preferred, pe.uuid AS person_id, pn.prefix, pn.given_name, pn.middle_name," + " pn.family_name_prefix, pn.family_name, pn.family_name2, pn.family_name_suffix, pn.degree," + " pn.creator, pn.date_created, pn.voided, pn.voided_by, pn.date_voided, pn.void_reason," + " pn.changed_by, pn.date_changed, pn.uuid FROM person_name pn" + " INNER JOIN person pe ON pn.person_id = pe.person_id" + " WHERE pn.dirty = 1"; break; case "encounter": query = "SELECT en.encounter_type, pe.uuid AS patient_id, en.location_id, en.form_id," + " en.encounter_datetime, en.creator, en.date_created, en.voided, en.voided_by," + " en.date_voided, en.void_reason, en.changed_by, en.date_changed, en.visit_id," + " en.uuid FROM encounter en INNER JOIN person pe ON en.patient_id = pe.person_id" + " WHERE en.dirty = 1"; break; case "obs": query = "SELECT pe.uuid AS person_id, o.concept_id, en.uuid AS encounter_id, o.order_id," + " o.obs_datetime, o.location_id, o2.uuid AS obs_group_id, o.accession_number," + " o.value_group_id, o.value_boolean, o.value_coded, o.value_coded_name_id, o.value_drug," + " o.value_datetime, o.value_numeric, o.value_modifier, o.value_text, o.value_complex," + " o.comments, o.creator, o.date_created, o.voided, o.voided_by, o.date_voided, o.void_reason," + " o.uuid, o.previous_version FROM obs o INNER JOIN person pe ON o.person_id = pe.person_id" + " INNER JOIN encounter en ON en.encounter_id = o.encounter_id" + " LEFT JOIN obs o2 ON o2.obs_id = o.obs_group_id" + " WHERE o.dirty = 1 ORDER BY o.obs_group_id"; break; } Cursor cursor = mDatabase.rawQuery(query, new String[] {}); cursor.moveToFirst(); List<JSONObject> items = new ArrayList<>(); JSONObject root; JSONObject obj; // For every row while (!cursor.isAfterLast()) { root = new JSONObject(); obj = new JSONObject(); // For every column for (int i = 0; i < cursor.getColumnCount(); i++) { String key = cursor.getColumnName(i); // Convert value to JSON type if (cursor.isNull(i)) { obj.put(key, JSONObject.NULL); } else { obj.put(key, cursor.getString(i)); } } root.put("table", table); root.put("values", obj); items.add(root); cursor.moveToNext(); } cursor.close(); return items; }
From source file:org.sufficientlysecure.keychain.ui.MultiUserIdsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrix = new MatrixCursor(new String[] { "_id", "user_data", "grouped" }) { @Override/*w w w . ja va 2 s . c o m*/ public byte[] getBlob(int column) { return super.getBlob(column); } }; data.moveToFirst(); long lastMasterKeyId = 0; String lastName = ""; ArrayList<String> uids = new ArrayList<>(); boolean header = true; // Iterate over all rows while (!data.isAfterLast()) { long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); String userId = data.getString(INDEX_USER_ID); OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId); // Two cases: boolean grouped = masterKeyId == lastMasterKeyId; boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name); // Remember for next loop lastName = pieces.name; Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped")); if (!subGrouped) { // 1. This name should NOT be grouped with the previous, so we flush the buffer Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); // indicate that we have a header for this masterKeyId header = false; // Now clear the buffer, and add the new user id, for the next round uids.clear(); } // 2. This name should be grouped with the previous, just add to buffer uids.add(userId); lastMasterKeyId = masterKeyId; // If this one wasn't grouped, the next one's gotta be a header if (!grouped) { header = true; } // Regardless of the outcome, move to next entry data.moveToNext(); } // If there is anything left in the buffer, flush it one last time if (!uids.isEmpty()) { Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); } mUserIdsAdapter.swapCursor(matrix); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Utility method to load the list of browser history. *//*w w w . j a va2 s. c o m*/ private static ArrayList<BookmarkInfo> loadBrowserHistory(Launcher context) { ArrayList<BookmarkInfo> bookmarks = new ArrayList<BookmarkInfo>(); Cursor cursor = context.managedQuery(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, Browser.BookmarkColumns.DATE + " DESC"); if (cursor != null) { int count = 0; cursor.moveToFirst(); if (cursor.moveToFirst() && cursor.getCount() > 0) { while (cursor.isAfterLast() == false) { String title = cursor.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX); String url = cursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX); String bookmarkIndex = cursor.getString(Browser.HISTORY_PROJECTION_BOOKMARK_INDEX); Log.d(LOG_TAG, "bookmarkIndex=" + bookmarkIndex); if (url != null && title != null && !bookmarkIndex.equals("1")) { // check for duplicates boolean found = false; for (BookmarkInfo bookmarkInfo : bookmarks) { if (bookmarkInfo.getUrl() != null && bookmarkInfo.getUrl().equals(url)) { found = true; break; } } if (!found) { BookmarkInfo bookmark = new BookmarkInfo(); bookmark.setTitle(title); bookmark.setUrl(url); bookmarks.add(bookmark); } } cursor.moveToNext(); if (++count >= BROWSER_HISTORY_LIMIT) { break; } } } } return bookmarks; }
From source file:info.guardianproject.otr.app.im.app.AccountListActivity.java
public void signIn(long accountId) { if (accountId <= 0) { Log.w(TAG, "signIn: account id is 0, bail"); return;//w ww .ja v a 2s. c om } Cursor cursor = mAdapter.getCursor(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { long cAccountId = cursor.getLong(ACTIVE_ACCOUNT_ID_COLUMN); if (cAccountId == accountId) break; cursor.moveToNext(); } // Remember that the user signed in. setKeepSignedIn(accountId, true); long providerId = cursor.getLong(PROVIDER_ID_COLUMN); String password = cursor.getString(ACTIVE_ACCOUNT_PW_COLUMN); boolean isActive = false; // TODO(miron) mSignInHelper.signIn(password, providerId, accountId, isActive); cursor.moveToPosition(-1); }
From source file:com.ksharkapps.musicnow.ui.activities.SearchActivity.java
/** * {@inheritDoc}//www . j a v a2s . c o m */ @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { Cursor cursor = mAdapter.getCursor(); cursor.moveToPosition(position); if (cursor.isBeforeFirst() || cursor.isAfterLast()) { return; } // Get the MIME type final String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE)); // If it's an artist, open the artist profile if ("artist".equals(mimeType)) { NavUtils.openArtistProfile(this, cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST))); } else if ("album".equals(mimeType)) { // If it's an album, open the album profile NavUtils.openAlbumProfile(this, cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)), cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST)), cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID))); } else if (position >= 0 && id >= 0) { // If it's a song, play it and leave final long[] list = new long[] { id }; MusicUtils.playAll(this, list, 0, false); } // Close it up cursor.close(); cursor = null; // All done finish(); }