List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferRecord.java
/** * Updates all the fields from database using the given Cursor. * * @param c A Cursor pointing to a transfer record. *///from w w w . j a va2 s . c o m public void updateFromDB(Cursor c) { this.id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID)); this.mainUploadId = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_MAIN_UPLOAD_ID)); this.type = TransferType.getType(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_TYPE))); this.state = TransferState.getState(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE))); this.bucketName = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_BUCKET_NAME)); this.key = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_KEY)); this.versionId = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_VERSION_ID)); this.bytesTotal = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_TOTAL)); this.bytesCurrent = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_CURRENT)); this.speed = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_SPEED)); this.isRequesterPays = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_REQUESTER_PAYS)); this.isMultipart = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_MULTIPART)); this.isLastPart = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_LAST_PART)); this.isEncrypted = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_ENCRYPTED)); this.partNumber = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_PART_NUM)); this.eTag = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_ETAG)); this.file = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE)); this.multipartId = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_MULTIPART_ID)); this.rangeStart = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_DATA_RANGE_START)); this.rangeLast = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_DATA_RANGE_LAST)); this.fileOffset = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE_OFFSET)); this.headerContentType = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_TYPE)); this.headerContentLanguage = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_LANGUAGE)); this.headerContentDisposition = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_DISPOSITION)); this.headerContentEncoding = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_ENCODING)); this.headerCacheControl = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CACHE_CONTROL)); this.headerExpire = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_EXPIRE)); this.userMetadata = JsonUtils .jsonToMap(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_USER_METADATA))); this.expirationTimeRuleId = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_EXPIRATION_TIME_RULE_ID)); this.httpExpires = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HTTP_EXPIRES_DATE)); this.sseAlgorithm = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_SSE_ALGORITHM)); this.sseKMSKey = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_SSE_KMS_KEY)); this.md5 = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_CONTENT_MD5)); this.cannedAcl = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_CANNED_ACL)); }
From source file:com.pdftron.pdf.utils.Utils.java
public static String getRealPathFromImageURI(Context context, Uri contentUri) { if (null == context || null == contentUri) { return ""; }/* w ww .j av a2s . c o m*/ Cursor cursor = null; try { // can post image String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) if (null != cursor) { cursor.moveToFirst(); int column_index = cursor.getColumnIndexOrThrow(proj[0]); return cursor.getString(column_index); } return ""; } catch (Exception e) { AnalyticsHandlerAdapter.getInstance().sendException(e); } finally { if (cursor != null) { cursor.close(); } } return ""; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void cursorToGroupEntry(Cursor c, GroupEntry entry) throws ParseException { if (!TextUtils.isEmpty(c.getString(c.getColumnIndexOrThrow(Groups.SYSTEM_ID)))) { throw new ParseException("unable to modify system groups"); }//from ww w. j a v a 2 s .co m entry.setTitle(c.getString(c.getColumnIndexOrThrow(Groups.NAME))); entry.setContent(c.getString(c.getColumnIndexOrThrow(Groups.NOTES))); entry.setSystemGroup(null); }
From source file:com.tct.mail.providers.Attachment.java
/** * Get the value of the data column for this Uri. This is useful for * MediaStore Uris, and other file-based ContentProviders. * * @param context The context.//from w ww . j ava2 s. c o m * @param uri The Uri to query. * @param selection (Optional) Filter used in the query. * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S if (uri == null) { return null; } //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } catch (IllegalArgumentException e) { LogUtils.e(LOG_TAG, e, "ArgumentException in projection"); } // TS: Gantao 2016-02-19 EMAIL BUGFIX_1650866 ADD_S catch (NullPointerException e) { LogUtils.e(LOG_TAG, e, "NullPointerException while query"); } // TS: Gantao 2016-02-19 EMAIL BUGFIX_1650866 ADD_E finally { if (cursor != null) cursor.close(); } return null; }
From source file:cn.newgxu.android.notty.adapter.UsersAdapter.java
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View v = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, null); ViewHolder holder = new ViewHolder(); holder.authedName = (TextView) v.findViewById(android.R.id.text1); holder.authedNameIndex = cursor.getColumnIndexOrThrow(C.user.AUTHED_NAME); v.setTag(holder);/*from w ww .j a v a 2s .co m*/ return v; }
From source file:com.bydavy.card.receipts.ReceiptPagerAdapter.java
public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; }/*w w w. ja va 2 s . com*/ final Cursor oldCursor = mCursor; mCursor = newCursor; if (newCursor != null) { mRowIDColumn = newCursor.getColumnIndexOrThrow(BaseColumns._ID); mRowShopColumn = newCursor.getColumnIndexOrThrow(Receipts.COLUMN_NAME_SHOP); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetChanged(); } return oldCursor; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void cursorToContactEntry(String account, ContentResolver cr, Cursor c, ContactEntry entry) throws ParseException { entry.setTitle(c.getString(c.getColumnIndexOrThrow(People.NAME))); entry.setContent(c.getString(c.getColumnIndexOrThrow(People.NOTES))); entry.setYomiName(c.getString(c.getColumnIndexOrThrow(People.PHONETIC_NAME))); long syncLocalId = c.getLong(c.getColumnIndexOrThrow(SyncConstValue._SYNC_LOCAL_ID)); addContactMethodsToContactEntry(cr, syncLocalId, entry); addPhonesToContactEntry(cr, syncLocalId, entry); addOrganizationsToContactEntry(cr, syncLocalId, entry); addGroupMembershipToContactEntry(account, cr, syncLocalId, entry); addExtensionsToContactEntry(cr, syncLocalId, entry); }
From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditItem2.java
/** * <b>This part of code if copied from:</b><br> * {@link http://geekonjava.blogspot.ca/2014/03/upload-image-on-server-in-android-using.html} * // w w w.java 2 s . c om * @param uri * @return the value of one column as a String. */ // "http://geekonjava.blogspot.ca/2014/03/upload-image-on-server-in-android-using.html" // March 24 2015 public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().managedQuery(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
From source file:com.germainz.identiconizer.services.IdenticonCreationService.java
private void setContactPhoto(ContentResolver resolver, byte[] bytes, int personId, String name) { ContentValues values = new ContentValues(); int photoRow = -1; String where = ContactsContract.Data.RAW_CONTACT_ID + " == " + String.valueOf(personId) + " AND " + ContactsContract.Data.MIMETYPE + "=='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; Cursor cursor = resolver.query(ContactsContract.Data.CONTENT_URI, null, where, null, null); int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID); if (cursor.moveToFirst()) { photoRow = cursor.getInt(idIdx); }/* w w w . j ava2s .co m*/ cursor.close(); if (photoRow >= 0) { final String selection = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; final String[] selectionArgs = new String[] { String.valueOf(personId), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE }; values.put(ContactsContract.Data.RAW_CONTACT_ID, personId); values.put(ContactsContract.Data.IS_PRIMARY, 1); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bytes); values.put("skip_processing", "skip_processing"); // We're not using applyBatch because of the 1024K limit of the transaction buffer, // which isn't enough when we're using a large identicon size and certain styles (e.g. // the Spirograph style, which occupies roughly that much on its own when the size is // set to 720x720.) if (getContentResolver().update(ContactsContract.Data.CONTENT_URI, values, selection, selectionArgs) != 1) mUpdateErrors.add(new ContactInfo(personId, name, bytes.length)); } else { values.put(ContactsContract.Data.RAW_CONTACT_ID, personId); values.put(ContactsContract.Data.IS_PRIMARY, 1); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bytes); values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); values.put("skip_processing", "skip_processing"); if (getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values) == null) mInsertErrors.add(new ContactInfo(personId, name, bytes.length)); } }
From source file:com.android.calendar.event.CreateEventDialogFragment.java
private void setCalendarFields(Cursor cursor) { int calendarIdIndex = cursor.getColumnIndexOrThrow(Calendars._ID); int colorIndex = cursor.getColumnIndexOrThrow(Calendars.CALENDAR_COLOR); int calendarNameIndex = cursor.getColumnIndexOrThrow(Calendars.CALENDAR_DISPLAY_NAME); int accountNameIndex = cursor.getColumnIndexOrThrow(Calendars.ACCOUNT_NAME); int calendarOwnerIndex = cursor.getColumnIndexOrThrow(Calendars.OWNER_ACCOUNT); mCalendarId = cursor.getLong(calendarIdIndex); mCalendarOwner = cursor.getString(calendarOwnerIndex); mColor.setBackgroundColor(Utils.getDisplayColorFromColor(cursor.getInt(colorIndex))); String accountName = cursor.getString(accountNameIndex); String calendarName = cursor.getString(calendarNameIndex); mCalendarName.setText(calendarName); if (calendarName.equals(accountName)) { mAccountName.setVisibility(View.GONE); } else {/* w w w .jav a2 s. co m*/ mAccountName.setVisibility(View.VISIBLE); mAccountName.setText(accountName); } }