List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param c/*from w ww . ja v a 2s.c o m*/ * @return true if the authenticated user can change the item's privacy level. */ public static boolean canChangePrivacyLevel(Context context, Cursor c) { final String useruri = Authenticator.getUserUri(context); return useruri == null || useruri.equals(c.getString(c.getColumnIndex(_AUTHOR_URI))); }
From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java
private static List<NameValuePair> getStarredReadNameValuePairs(DatabaseConnection dbConn, Cursor cursor) { String subscription_id = cursor .getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID)); String rss_item_id = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_RSSITEM_ID)); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("async", "true")); nameValuePairs.add(new BasicNameValuePair("s", dbConn.getRowIdBySubscriptionID(subscription_id))); nameValuePairs.add(new BasicNameValuePair("i", rss_item_id)); return nameValuePairs; }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * TODO make this pick the set of tags for a set of content. * * @param cr a content resolver/*from w w w . j a v a2s .c o m*/ * @return the top MAX_POPULAR_TAGS most popular tags in the set, with the most popular first. */ public static List<String> getPopularTags(ContentResolver cr) { final Map<String, Integer> tagPop = new HashMap<String, Integer>(); final List<String> popTags; final Cursor c = cr.query(Tag.CONTENT_URI, Tag.DEFAULT_PROJECTION, null, null, null); final int tagColumn = c.getColumnIndex(Tag._NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { final String tag = c.getString(tagColumn); final Integer count = tagPop.get(tag); if (count == null) { tagPop.put(tag, 1); } else { tagPop.put(tag, count + 1); } } c.close(); popTags = new ArrayList<String>(tagPop.keySet()); Collections.sort(popTags, new Comparator<String>() { public int compare(String object1, String object2) { return tagPop.get(object2).compareTo(tagPop.get(object1)); } }); int limit; if (popTags.size() < MAX_POPULAR_TAGS) { limit = popTags.size(); } else { limit = MAX_POPULAR_TAGS; } return popTags.subList(0, limit); }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> readAll() { Cursor cursor = null; try {// ww w.j a v a 2 s . c o m List<Pergunta> all = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id <> " + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nomeIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nomeIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); all.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> getPerguntasUsuario() { Cursor cursor = null; try {/*from w w w. ja va 2 s.c o m*/ List<Pergunta> questions = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id =" + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nameIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nameIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); questions.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.whiuk.philip.opensmime.PathConverter.java
private static FileInformation handleContentScheme(Context context, Uri uri) { try {// www. ja va 2 s . com ContentResolver contentResolver = context.getContentResolver(); // all fields for one document Cursor cursor = contentResolver.query(uri, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { // Note it's called "Display Name". This is // provider-specific, and might not necessarily be the file name. String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); String mimeType = cursor .getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)); InputStream stream = contentResolver.openInputStream(uri); File tmpFile = copyToTempFile(context, stream); return new FileInformation(tmpFile, displayName, mimeType); } } catch (IOException e) { Log.e(OpenSMIME.LOG_TAG, "error in PathConverter.handleContentScheme", e); } return null; }
From source file:de.fau.cs.mad.smile.android.encryption.PathConverter.java
private static FileInformation handleContentScheme(Context context, Uri uri) { try {// w ww .ja va 2 s . c o m ContentResolver contentResolver = context.getContentResolver(); // all fields for one document Cursor cursor = contentResolver.query(uri, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { // Note it's called "Display Name". This is // provider-specific, and might not necessarily be the file name. String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); String mimeType = cursor .getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)); InputStream stream = contentResolver.openInputStream(uri); File tmpFile = copyToTempFile(context, stream); return new FileInformation(tmpFile, displayName, mimeType); } } catch (IOException e) { Log.e(SMileCrypto.LOG_TAG, "error in PathConverter.handleContentScheme", e); } return null; }
From source file:com.trk.aboutme.facebook.Settings.java
/** * Acquire the current attribution id from the facebook app. * @return returns null if the facebook app is not present on the phone. *//*from w w w .java 2 s .c om*/ public static String getAttributionId(ContentResolver contentResolver) { String[] projection = { ATTRIBUTION_ID_COLUMN_NAME }; Cursor c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null); if (c == null || !c.moveToFirst()) { return null; } String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME)); c.close(); return attributionId; }
From source file:com.energysystem.videoexplorerTV.video.VideoProvider.java
public static HashMap<String, List<Video>> buildMedia(String url, Cursor data) throws JSONException { mMovieList = new HashMap<String, List<Video>>(); mMovieList.clear();// ww w.ja v a 2 s . c o m Log.e("Abrimos", "Videos"); List<Video> categoryList = new ArrayList<Video>(); List<Video> categoryList2 = new ArrayList<Video>(); while (data.moveToNext()) { int videoID = data.getInt(data.getColumnIndex(MediaStore.Video.Media._ID)); int title = data.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE); int category = data.getColumnIndexOrThrow(MediaStore.Video.Media.CATEGORY); int durationID = data.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION); int data_string = data.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); //int videoUrl = data.getColumnIndexOrThrow(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString()); // int bgImageUrl = data.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI.toString()); int duration = Integer.parseInt(data.getString(durationID)); String categoria = new File(data.getString(data_string)).getParent(); Log.e("Ruta:", categoria); if (categoria.equals("/storage/emulated/0/Movies")) { categoryList.add(buildMovieInfo(categoria, data.getString(title), "Descripcion", String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID) .toString())); mMovieList.put("Almacenamiento Interno", categoryList); } else { categoryList2.add(buildMovieInfo(categoria, data.getString(title), "Descripcion", String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID) .toString())); mMovieList.put("USB", categoryList2); } } /*JSONObject jsonObj = new VideoProvider().parseUrl(url); JSONArray categories = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS); if (null != categories) { Log.d(TAG, "category #: " + categories.length()); String title; String videoUrl; String bgImageUrl; String cardImageUrl; String studio; for (int i = 0; i < categories.length(); i++) { JSONObject category = categories.getJSONObject(i); String category_name = category.getString(TAG_CATEGORY); JSONArray videos = category.getJSONArray(TAG_MEDIA); Log.d(TAG, "category: " + i + " Name:" + category_name + " video length: " + videos.length()); List<Video> categoryList = new ArrayList<Video>(); if (null != videos) { for (int j = 0; j < videos.length(); j++) { JSONObject video = videos.getJSONObject(j); String description = video.getString(TAG_DESCRIPTION); JSONArray videoUrls = video.getJSONArray(TAG_SOURCES); if (null == videoUrls || videoUrls.length() == 0) { continue; } title = video.getString(TAG_TITLE); videoUrl = getVideoPrefix(category_name, videoUrls.getString(0)); bgImageUrl = getThumbPrefix(category_name, title, video.getString(TAG_BACKGROUND)); cardImageUrl = getThumbPrefix(category_name, title, video.getString(TAG_CARD_THUMB)); studio = video.getString(TAG_STUDIO); categoryList.add(buildMovieInfo(category_name, title, description, studio, videoUrl, cardImageUrl, bgImageUrl)); } mMovieList.put(category_name, categoryList); } } }*/ Log.e("VideoProvider", "Tamano mMovie: " + mMovieList.size()); return mMovieList; }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Gets the name of a contact from the Android contacts provider, given a phone number. * * @param applicationContext The application context. * @param phoneNumber The phone number of the contact. * @return the name of the contact./* ww w. jav a 2 s.c o m*/ */ public static String getContactName(Context applicationContext, String phoneNumber) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = applicationContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor.moveToFirst()) { String name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); cursor.close(); return name; } else { cursor.close(); return null; } }