List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.chatwing.whitelabel.fragments.CommunicationDrawerFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { TextView unreadCountView = getUnreadCountView(loader); if (unreadCountView == null) return;/*from w ww . j av a 2s . c om*/ if (data == null || !data.moveToFirst() || data.getCount() == 0) { unreadCountView.setVisibility(View.GONE); return; } int columnIndex = data.getColumnIndexOrThrow(COLUMN_NAME_SUM_UNREAD_COUNT); int unreadCount = data.getInt(columnIndex); if (unreadCount == 0) { unreadCountView.setVisibility(View.GONE); } else { unreadCountView.setText(Integer.toString(unreadCount)); unreadCountView.setVisibility(View.VISIBLE); } }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * @param cursor The {@link Cursor} used to perform our query. * @return The song list for a MIME type. *///from w ww .ja va 2 s . c om public static long[] getSongListForCursor(Cursor cursor) { if (cursor == null) { return sEmptyList; } final int len = cursor.getCount(); final long[] list = new long[len]; cursor.moveToFirst(); int columnIndex; try { columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID); } catch (final IllegalArgumentException notaplaylist) { columnIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID); } for (int i = 0; i < len; i++) { list[i] = cursor.getLong(columnIndex); cursor.moveToNext(); } cursor.close(); return list; }
From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java
/** * pick file name from content provider with Gallery-flavor format *///from w w w. j a v a 2 s .co m public String getGalleryImagePath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); if (cursor == null) { return null; // uri could be not suitable for ContentProviders, i.e. points to file } int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
From source file:com.wikitude.virtualhome.AugmentedActivity.java
public String getPath(Uri uri) { // 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 = getContentResolver().query(uri, projection, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/* w w w . ja v a 2 s .com*/ return cursor.getString(column_index); } // this is our fallback here return uri.getPath(); }
From source file:mobisocial.musubi.util.UriImage.java
private void initFromContentUri(Context context, Uri uri) { Cursor c = context.getContentResolver().query(uri, null, null, null, null); if (c == null) { throw new IllegalArgumentException("Query on " + uri + " returns null result."); }/*from www .j a va 2 s . c om*/ try { if ((c.getCount() != 1) || !c.moveToFirst()) { throw new IllegalArgumentException("Query on " + uri + " returns 0 or multiple rows."); } String filePath = c.getString(c.getColumnIndexOrThrow(Images.Media.DATA)); mContentType = c.getString(c.getColumnIndexOrThrow(Images.Media.MIME_TYPE)); mPath = filePath; } finally { c.close(); } }
From source file:com.android.mms.ui.SelectRecipientsList.java
private String getCheckedNumbersAsText() { StringBuilder result = new StringBuilder(); for (PhoneNumber number : mCheckedPhoneNumbers) { result.append(CONTACT_SEP_LEFT); result.append(getString(R.string.contact_info_text_as_name)); result.append(number.getName()); Cursor cursor = getContactsDetailCursor(number.getContactId()); try {//from w w w . j av a 2 s . co m if (cursor != null) { int mimeIndex = cursor.getColumnIndexOrThrow(ContactsContract.Data.MIMETYPE); int phoneIndex = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER); int emailIndex = cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.ADDRESS); while (cursor.moveToNext()) { result.append(ITEM_SEP); String mimeType = cursor.getString(mimeIndex); if (mimeType.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) { result.append(getString(R.string.contact_info_text_as_phone)); result.append(cursor.getString(phoneIndex)); } else if (mimeType.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) { result.append(getString(R.string.contact_info_text_as_email)); result.append(cursor.getString(emailIndex)); } } } } finally { if (cursor != null) { cursor.close(); } } result.append(CONTACT_SEP_RIGHT); } return result.toString(); }
From source file:com.cloverstudio.spika.CameraCropActivity.java
private String getImagePath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();// ww w.j av a 2s .c om return cursor.getString(column_index); }
From source file:com.andrew.apollo.ui.activities.SearchActivity.java
/** * {@inheritDoc}/*from ww w . j ava2 s .c om*/ */ @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))); } 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(); }
From source file:com.ezac.gliderlogs.FlightPassengerActivity.java
private void fillData(Uri uri, String date) { String selection;//from w w w .j av a2s .c o m Cursor cursor; stringArrayList.clear(); String[] projection = { GliderLogTables.E_ID, GliderLogTables.E_DATE, GliderLogTables.E_TIME, GliderLogTables.E_NAME, GliderLogTables.E_PHONE }; selection = GliderLogTables.E_DATE + " LIKE '" + date + "'"; String sort = "" + GliderLogTables.E_TIME + " ASC"; cursor = getContentResolver().query(uri, projection, selection, null, sort); //Log.d(TAG,"select " + selection + " cnt: " + cursor.getCount()); if ((cursor != null) && (cursor.getCount() > 0)) { cursor.moveToFirst(); do { stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.E_ID))); String mydate = cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.E_DATE)); String[] d = mydate.split("-"); stringArrayList.add(d[2] + "-" + d[1] + "-" + d[0]); String mytime = cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.E_TIME)); String[] t = mytime.split(":"); stringArrayList.add(t[0] + ":" + t[1]); stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.E_NAME))); stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.E_PHONE))); stringArrayList.add(""); } while (cursor.moveToNext()); } cursor.close(); }