List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:free.yhc.netmbuddy.share.Json.java
static JSONObject videoToJson(long vid) { final int COLI_VIDEOID = 0; final int COLI_TITLE = 1; final int COLI_AUTHOR = 2; final int COLI_VOLUME = 3; final int COLI_PLAYTIME = 4; final int COLI_BOOKMARKS = 5; Cursor c = DB.get().queryVideo(vid, new ColVideo[] { ColVideo.VIDEOID, ColVideo.TITLE, ColVideo.AUTHOR, ColVideo.VOLUME, ColVideo.PLAYTIME, ColVideo.BOOKMARKS }); if (!c.moveToFirst()) { c.close();/*from w w w . j a v a2 s .com*/ return null; } JSONObject jo = new JSONObject(); try { jo.put(FYTID, c.getString(COLI_VIDEOID)); jo.put(FTITLE, c.getString(COLI_TITLE)); // NOTE // Below field - author - is newly added at Database version 2 // So, we cannot sure that DB includes valid field value for them. if (Utils.isValidValue(c.getString(COLI_AUTHOR))) jo.put(FAUTHOR, c.getString(COLI_AUTHOR)); jo.put(FPLAYTIME, c.getInt(COLI_PLAYTIME)); jo.put(FBOOKMARKS, c.getString(COLI_BOOKMARKS)); int vol = c.getInt(COLI_VOLUME); if (Policy.DEFAULT_VIDEO_VOLUME != vol) jo.put(FVOLUME, vol); } catch (JSONException e) { jo = null; } c.close(); return jo; }
From source file:org.fdroid.enigtext.mms.MmsCommunication.java
protected static MmsConnectionParameters getMmsConnectionParameters(Context context, String apn, boolean proxyIfPossible) throws ApnUnavailableException { Cursor cursor = null; try {/*from w w w . ja v a2 s .c o m*/ cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(apn); if (cursor == null || !cursor.moveToFirst()) return getLocalMmsConnectionParameters(context); do { String mmsc = cursor.getString(cursor.getColumnIndexOrThrow("mmsc")); String proxy = null; String port = null; if (proxyIfPossible) { proxy = cursor.getString(cursor.getColumnIndexOrThrow("mmsproxy")); port = cursor.getString(cursor.getColumnIndexOrThrow("mmsport")); } if (!Util.isEmpty(mmsc)) return new MmsConnectionParameters(mmsc, proxy, port); } while (cursor.moveToNext()); return getLocalMmsConnectionParameters(context); } catch (SQLiteException sqe) { Log.w("MmsCommunication", sqe); return getLocalMmsConnectionParameters(context); } catch (SecurityException se) { Log.w("MmsCommunication", se); return getLocalMmsConnectionParameters(context); } catch (IllegalArgumentException iae) { Log.w("MmsCommunication", iae); return getLocalMmsConnectionParameters(context); } finally { if (cursor != null) cursor.close(); } }
From source file:com.example.facebook_photo.Utility.java
public static int getOrientation(Context context, Uri photoUri) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor.getCount() != 1) { return -1; }//from w ww . ja v a 2s.com cursor.moveToFirst(); int orientation = cursor.getInt(0); cursor.close(); return orientation; }
From source file:Main.java
public static String getPathFromUri(Context context, Uri uri) { if (uri == null) { return null; }/*from w w w . java2 s.com*/ Cursor cursor = null; try { String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(uri, proj, null, null, null); if (cursor == null) { return null; } int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public static long uriFileSize(Context context, String contentUri) { long result = 0; Uri uri = Uri.parse(contentUri);/* ww w . ja v a 2 s. c o m*/ if (!uri.getScheme().equals("content")) { return (fileUriFileSize(context, contentUri)); } String[] p = { MediaStore.MediaColumns.SIZE }; Cursor cursor = context.getContentResolver().query(uri, p, // which columns null, // which rows (all rows) null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int iColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE); if (cursor.moveToFirst()) { result = cursor.getLong(iColumn); } } return (result); }
From source file:Main.java
public static String uriTitle(Context context, String contentUri) { String result = null;// w w w .j av a 2 s .c o m String[] p = { MediaStore.MediaColumns.TITLE }; Uri uri = Uri.parse(contentUri); if (!uri.getScheme().equals("content")) { return (fileUriTitle(context, contentUri)); } Cursor cursor = context.getContentResolver().query(uri, p, // which columns null, // which rows (all rows) null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int iColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE); if (cursor.moveToFirst()) { result = cursor.getString(iColumn); } } return (result); }
From source file:org.jared.synodroid.ds.utils.Utils.java
public static String getContentName(ContentResolver resolver, Uri uri) { Cursor cursor = resolver.query(uri, null, null, null, null); cursor.moveToFirst(); int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); if (nameIndex >= 0) { return cursor.getString(nameIndex); } else {//w ww . j av a2 s . c o m return null; } }
From source file:m2.android.archetype.example.FacebookSdk.Settings.java
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; }/*from w w w .j a v a 2 s .c o m*/ String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME)); c.close(); return attributionId; }
From source file:Main.java
/** * Return text content of clipboard as individual lines * @param ctx//from ww w. ja v a 2 s. c o m * @return */ @SuppressLint("NewApi") private static ArrayList<String> getTextLines(Context ctx) { String EOL = "\\r?\\n|\\r"; if (checkForText(ctx)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); // Gets the clipboard as text. CharSequence cs = item.getText(); if (cs == null) { // item might be an URI Uri pasteUri = item.getUri(); if (pasteUri != null) { // FIXME untested try { Log.d("ClipboardUtils", "Clipboard contains an uri"); ContentResolver cr = ctx.getContentResolver(); String uriMimeType = cr.getType(pasteUri); // pasteData = resolveUri(pasteUri); // If the return value is not null, the Uri is a content Uri if (uriMimeType != null) { // Does the content provider offer a MIME type that the current application can use? if (uriMimeType.equals(ClipDescription.MIMETYPE_TEXT_PLAIN)) { // Get the data from the content provider. Cursor pasteCursor = cr.query(pasteUri, null, null, null, null); // If the Cursor contains data, move to the first record if (pasteCursor != null) { if (pasteCursor.moveToFirst()) { String pasteData = pasteCursor.getString(0); return new ArrayList<String>(Arrays.asList(pasteData.split(EOL))); } // close the Cursor pasteCursor.close(); } } } } catch (Exception e) { // FIXME given that the above is unteted, cath all here Log.e("ClipboardUtils", "Resolving URI failed " + e); e.printStackTrace(); return null; } } } else { Log.d("ClipboardUtils", "Clipboard contains text"); String pasteData = cs.toString(); return new ArrayList<String>(Arrays.asList(pasteData.split(EOL))); } } else { // Gets the clipboard as text. @SuppressWarnings("deprecation") CharSequence cs = oldClipboard.getText(); if (cs != null) { String pasteData = cs.toString(); if (pasteData != null) { // should always be the case return new ArrayList<String>(Arrays.asList(pasteData.split(EOL))); } } } Log.e("ClipboardUtils", "Clipboard contains an invalid data type"); } return null; }
From source file:za.co.neilson.alarm.database.Database.java
public static List<Alarm> getAll() { List<Alarm> alarms = new ArrayList<Alarm>(); Cursor cursor = Database.getCursor(); if (cursor.moveToFirst()) { do {/* w w w. j av a 2 s . c o m*/ // COLUMN_ALARM_ID, // COLUMN_ALARM_ACTIVE, // COLUMN_ALARM_TIME, // COLUMN_ALARM_DAYS, // COLUMN_ALARM_DIFFICULTY, // COLUMN_ALARM_TONE, // COLUMN_ALARM_VIBRATE, // COLUMN_ALARM_NAME Alarm alarm = new Alarm(); alarm.setId(cursor.getInt(0)); alarm.setAlarmActive(cursor.getInt(1) == 1); alarm.setAlarmTime(cursor.getString(2)); byte[] repeatDaysBytes = cursor.getBlob(3); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(repeatDaysBytes); try { ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Alarm.Day[] repeatDays; Object object = objectInputStream.readObject(); if (object instanceof Alarm.Day[]) { repeatDays = (Alarm.Day[]) object; alarm.setDays(repeatDays); } } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } alarm.setDifficulty(Difficulty.values()[cursor.getInt(4)]); alarm.setAlarmTonePath(cursor.getString(5)); alarm.setVibrate(cursor.getInt(6) == 1); alarm.setAlarmName(cursor.getString(7)); alarms.add(alarm); } while (cursor.moveToNext()); } cursor.close(); return alarms; }