List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
static private void addContactMethodsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(ContactMethods.CONTENT_URI, null, "person=" + personId, null, null); int kindIndex = c.getColumnIndexOrThrow(ContactMethods.KIND); int dataIndex = c.getColumnIndexOrThrow(ContactMethods.DATA); int auxDataIndex = c.getColumnIndexOrThrow(ContactMethods.AUX_DATA); try {/*from w ww. j a va 2s . c o m*/ while (c.moveToNext()) { int kind = c.getInt(kindIndex); switch (kind) { case Contacts.KIND_IM: { ImAddress address = new ImAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_IM); address.setAddress(c.getString(dataIndex)); Object object = ContactMethods.decodeImProtocol(c.getString(auxDataIndex)); if (object == null) { address.setProtocolPredefined(ImAddress.PROTOCOL_NONE); } else if (object instanceof Integer) { address.setProtocolPredefined(PROVIDER_IM_PROTOCOL_TO_ENTRY_PROTOCOL.get((Integer) object)); } else { if (!(object instanceof String)) { throw new IllegalArgumentException("expected an String, " + object); } address.setProtocolPredefined(ImAddress.PROTOCOL_CUSTOM); address.setProtocolCustom((String) object); } entry.addImAddress(address); break; } case Contacts.KIND_POSTAL: { PostalAddress address = new PostalAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_POSTAL); address.setValue(c.getString(dataIndex)); entry.addPostalAddress(address); break; } case Contacts.KIND_EMAIL: { EmailAddress address = new EmailAddress(); cursorToContactsElement(address, c, PROVIDER_TYPE_TO_ENTRY_EMAIL); address.setAddress(c.getString(dataIndex)); entry.addEmailAddress(address); break; } } } } finally { if (c != null) c.close(); } }
From source file:com.cloudmine.api.db.RequestDBOpenHelper.java
/** * Convert Cursor contents to a map from the request id to the request. The Map will have the same iteration order * as the Cursor// w w w .ja v a2 s.com * @param cursor * @return */ private LinkedHashMap<Integer, RequestDBObject> createRequestMapping(Cursor cursor) { int idIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_ID); int jsonIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_JSON_BODY); int urlIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_TARGET_URL); int verbIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_VERB); int syncedIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_SYNCHRONIZED); int headerNameIndex = cursor.getColumnIndexOrThrow(KEY_HEADER_NAME); int headerValueIndex = cursor.getColumnIndexOrThrow(KEY_HEADER_VALUE); int objectIdIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_OBJECT_ID); int fileIdIndex = cursor.getColumnIndexOrThrow(KEY_REQUEST_FILE_ID); LinkedHashMap<Integer, RequestDBObject> requestMapping = new LinkedHashMap<Integer, RequestDBObject>(); while (cursor.moveToNext()) { Integer id = cursor.getInt(idIndex); RequestDBObject request = requestMapping.get(id); if (request == null) { String json = cursor.getString(jsonIndex); String url = cursor.getString(urlIndex); String verb = cursor.getString(verbIndex); String objectId = cursor.getString(objectIdIndex); String fileId = cursor.getString(fileIdIndex); int syncOrdinal = cursor.getInt(syncedIndex); RequestDBObject.SyncStatus status = RequestDBObject.SyncStatus.getSyncStatus(syncOrdinal); request = new RequestDBObject(url, RequestDBObject.Verb.getVerb(verb), json, objectId, fileId, id, status, new ArrayList<Header>()); requestMapping.put(id, request); } String headerName = cursor.getString(headerNameIndex); String headerValue = cursor.getString(headerValueIndex); request.addHeader(new BasicHeader(headerName, headerValue)); } return requestMapping; }
From source file:au.com.cybersearch2.classyfy.ClassyfyLogic.java
/** * Perform content provider query for fast text search, Must be executed on background thread. * @param searchQuery Query string/*from ww w. j av a 2s. c o m*/ * @return */ public List<ListItem> doSearchQuery(String searchQuery) { // Perform the search, passing in the search query as an argument to the Cursor Loader SuggestionCursorParameters params = new SuggestionCursorParameters(searchQuery, ClassyFySearchEngine.LEX_CONTENT_URI, ClassyFyProvider.SEARCH_RESULTS_LIMIT); ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(params.getUri(), params.getProjection(), params.getSelection(), params.getSelectionArgs(), params.getSortOrder()); List<ListItem> fieldList = new ArrayList<ListItem>(); int nameColumnId = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1); int valueColumnId = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_2); // Id column name set in android.support.v4.widget.CursorAdaptor int idColumnId = cursor.getColumnIndexOrThrow("_id"); if (cursor.getCount() > 0) { cursor.moveToPosition(-1); while (cursor.moveToNext()) { String name = cursor.getString(nameColumnId); String value = cursor.getString(valueColumnId); long id = cursor.getLong(idColumnId); fieldList.add(new ListItem(name, value, id)); } } cursor.close(); return fieldList; }
From source file:ca.mudar.mtlaucasou.BaseListFragment.java
/** * When item is selected, send geocoordinates to the listener which is * implemented by the Activity. The Activity deals with the MapFragment. *///from ww w. j a va 2 s . c o m @Override public void onListItemClick(ListView l, View v, int position, long id) { Cursor cursor = (Cursor) getListAdapter().getItem(position); double geoLat = cursor.getDouble(cursor.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LAT)); double geoLng = cursor.getDouble(cursor.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LNG)); GeoPoint geoPoint = new GeoPoint((int) (geoLat * 1E6), (int) (geoLng * 1E6)); if (mListener != null) { mListener.onPlacemarkSelected(geoPoint); } }
From source file:com.dongbang.yutian.activity.CommonScanActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); String photo_path;/*from ww w .j a v a 2 s . com*/ if (resultCode == RESULT_OK) { switch (requestCode) { case PHOTOREQUESTCODE: String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = this.getContentResolver().query(data.getData(), proj, null, null, null); if (cursor.moveToFirst()) { int colum_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); photo_path = cursor.getString(colum_index); if (photo_path == null) { photo_path = Utils.getPath(getApplicationContext(), data.getData()); } scanManager.scanningImage(photo_path); } } } }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void addGroupMembershipToContactEntry(String account, ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(GroupMembership.RAW_CONTENT_URI, null, "person=" + personId, null, null); try {/* w ww . j a v a2 s .co m*/ int serverIdIndex = c.getColumnIndexOrThrow(GroupMembership.GROUP_SYNC_ID); int localIdIndex = c.getColumnIndexOrThrow(GroupMembership.GROUP_ID); while (c.moveToNext()) { String serverId = c.getString(serverIdIndex); if (serverId == null) { final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, c.getLong(localIdIndex)); Cursor groupCursor = cr.query(groupUri, new String[] { Groups._SYNC_ID }, null, null, null); try { if (groupCursor.moveToNext()) { serverId = groupCursor.getString(0); } } finally { groupCursor.close(); } } if (serverId == null) { // the group hasn't been synced yet, we can't complete this operation since // we don't know what server id to use for the group throw new ParseException("unable to construct GroupMembershipInfo since the " + "group _sync_id isn't known yet, will retry later"); } GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(); String groupId = getCanonicalGroupsFeedForAccount(account) + "/" + serverId; groupMembershipInfo.setGroup(groupId); groupMembershipInfo.setDeleted(false); entry.addGroup(groupMembershipInfo); } } finally { if (c != null) c.close(); } }
From source file:com.android.nsboc.ComposeFragment.java
public String getPath(Uri uri) { // just some safety built in if (uri == null) { return null; }/* w w w. java 2 s . c o m*/ // try to retrieve the image from the media store first // this will only work for images selected from gallery String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().managedQuery(uri, projection, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } // this is our fallback here return uri.getPath(); }
From source file:com.android.gallery3d.data.UriImage.java
private String getPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(mApplication.getAndroidContext(), contentUri, proj, null, null, null);/*from w w w. j ava 2 s. c om*/ Cursor cursor = loader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
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 w w .java 2s . com*/ 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(); } }
From source file:net.mutina.uclimb.ForegroundCameraLauncher.java
/** * Queries the media store to find out what the file path is for the Uri we supply * * @param contentUri the Uri of the audio/image/video * @param ctx the current applicaiton context * @return the full path to the file/*from w w w . j ava 2 s .com*/ */ private String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) { String[] proj = { _DATA }; Cursor cursor = ctx.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(_DATA); cursor.moveToFirst(); return cursor.getString(column_index); }