List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:cn.code.notes.gtask.data.SqlData.java
private void loadFromCursor(Cursor c) { mDataId = c.getLong(DATA_ID_COLUMN); mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN); mDataContent = c.getString(DATA_CONTENT_COLUMN); mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN); mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN); }
From source file:com.pdftron.pdf.utils.Utils.java
public static String getUriDisplayName(Context context, Uri contentUri) { String displayName = null;//from w ww . j a va 2 s . com String[] projection = { OpenableColumns.DISPLAY_NAME }; Cursor cursor = null; if (contentUri.getScheme().equalsIgnoreCase("file")) { return contentUri.getLastPathSegment(); } try { cursor = context.getContentResolver().query(contentUri, projection, null, null, null); if (cursor != null && cursor.moveToFirst()) { int nameIndex = cursor.getColumnIndexOrThrow(projection[0]); if (nameIndex >= 0) { displayName = cursor.getString(nameIndex); } } } catch (Exception e) { displayName = null; } if (cursor != null) { cursor.close(); } return displayName; }
From source file:com.bourke.kitchentimer.utils.Utils.java
public static boolean exportCSV(Context context, Cursor cursor) { if (cursor.getCount() == 0) return true; // An array to hold the rows that will be written to the CSV file. final int rowLenght = FoodMetaData.COLUMNS.length - 1; String[] row = new String[rowLenght]; System.arraycopy(FoodMetaData.COLUMNS, 1, row, 0, rowLenght); CSVWriter writer = null;//ww w. j a va 2 s . c o m boolean success = false; try { writer = new CSVWriter(new FileWriter(Constants.CSV_FILE)); // Write descriptive headers. writer.writeNext(row); int nameIndex = cursor.getColumnIndex(FoodMetaData.NAME); int hoursIndex = cursor.getColumnIndex(FoodMetaData.HOURS); int minutesIndex = cursor.getColumnIndex(FoodMetaData.MINUTES); int secondsIndex = cursor.getColumnIndex(FoodMetaData.SECONDS); if (cursor.requery()) { while (cursor.moveToNext()) { row[0] = cursor.getString(nameIndex); row[1] = cursor.getInt(hoursIndex) + ""; row[2] = cursor.getInt(minutesIndex) + ""; row[3] = cursor.getInt(secondsIndex) + ""; // NOTE: writeNext() handles nulls in row[] gracefully. writer.writeNext(row); } } success = true; } catch (Exception ex) { Log.e("Utils", "exportCSV", ex); } finally { try { if (null != writer) writer.close(); } catch (IOException ex) { } } return success; }
From source file:Main.java
/** * Try to get the exif orientation of the passed image uri * * @param context//from w w w. j av a 2 s. co m * @param uri * @return */ public static int getExifOrientation(Context context, Uri uri) { final String scheme = uri.getScheme(); ContentProviderClient provider = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { return getExifOrientation(uri.getPath()); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { provider = context.getContentResolver().acquireContentProviderClient(uri); } catch (SecurityException e) { return 0; } if (provider != null) { Cursor result; try { result = provider.query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.Images.ImageColumns.DATA }, null, null, null); } catch (Exception e) { e.printStackTrace(); return 0; } if (result == null) { return 0; } int orientationColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION); int dataColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.DATA); try { if (result.getCount() > 0) { result.moveToFirst(); int rotation = 0; if (orientationColumnIndex > -1) { rotation = result.getInt(orientationColumnIndex); } if (dataColumnIndex > -1) { String path = result.getString(dataColumnIndex); rotation |= getExifOrientation(path); } return rotation; } } finally { result.close(); } } } return 0; }
From source file:com.ruuhkis.cookies.CookieSQLSource.java
/** * Creates SQLCookie from cursor that is assumed * to be located at SQLCookie entry/*ww w . j a v a 2s. c o m*/ * @param cursor * @return */ private SQLCookie cursorToCookie(Cursor cursor) { SQLCookie cookie = new SQLCookie(); cookie.setComment(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT))); cookie.setCommentURL(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COMMENT_URL))); cookie.setDomain(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_DOMAIN))); long expiryDate = cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_EXPIRY_DATE)); cookie.setExpiryDate(expiryDate != -1 ? new Date(expiryDate) : null); cookie.setName(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_NAME))); cookie.setPath(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PATH))); cookie.setPersistent(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PERSISTENT)) == 1); cookie.setPorts(getPorts(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID)))); cookie.setSecure(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_SECURE)) == 1); cookie.setValue(cursor.getString(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VALUE))); cookie.setVersion(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_VERSION))); cookie.setId(cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_ID))); return cookie; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static HashSet<String> getBannedTrolls(Context context) { HashSet<String> bannedTrolls = null; DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); String q = "SELECT name FROM banned_users WHERE bandisabled=0"; Cursor c = dbwrite.rawQuery(q, null); int count = c.getCount(); if (count > 0) { bannedTrolls = new HashSet<String>(c.getColumnCount()); c.moveToFirst();//from w w w.j a v a 2 s . c o m for (int i = 0; i < count; i++) { bannedTrolls.add(c.getString(0)); c.moveToNext(); } } c.close(); dbwrite.close(); db.close(); if (bannedTrolls == null) bannedTrolls = new HashSet<String>(0); return bannedTrolls; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static void updateContactPhotoHd(Context context, ContentResolver resolver, long rawContactId, ContactPhoto photo, BatchOperation batchOperation) { final Cursor c = resolver.query(DataQuery.CONTENT_URI, DataQuery.PROJECTION, Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", new String[] { String.valueOf(rawContactId), Photo.CONTENT_ITEM_TYPE }, null); final ContactOperations contactOp = ContactOperations.updateExistingContact(context, rawContactId, true, batchOperation);//from w w w . ja v a2 s. c o m if ((c != null) && c.moveToFirst()) { final long id = c.getLong(DataQuery.COLUMN_ID); final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id); contactOp.updateAvatar(c.getString(DataQuery.COLUMN_DATA1), photo.getPhotoUrl(), uri); c.close(); } else { Log.i(TAG, "creating row, count: " + c.getCount()); contactOp.addAvatar(photo.getPhotoUrl()); } Log.d(TAG, "updating check timestamp"); final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); contactOp.updateSyncTimestamp1(System.currentTimeMillis(), uri); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static HashSet<String> getBannedThreads(String group, Context context) { HashSet<String> bannedThreads = null; int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); String q = "SELECT clean_subject FROM banned_threads WHERE subscribed_group_id=" + groupid + " AND bandisabled=0"; Cursor c = dbread.rawQuery(q, null); if (c.getCount() > 0) { bannedThreads = new HashSet<String>(c.getCount()); c.moveToFirst();/*from w w w . j a va 2s. co m*/ int count = c.getCount(); for (int i = 0; i < count; i++) { bannedThreads.add(c.getString(0)); c.moveToNext(); } } c.close(); dbread.close(); db.close(); if (bannedThreads == null) bannedThreads = new HashSet<String>(0); return bannedThreads; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static HashSet<String> getStarredSubjectsSet(Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Cursor c; String query = "SELECT clean_subject FROM starred_threads"; c = dbread.rawQuery(query, null);//from www. j a va 2 s . c o m HashSet<String> set = new HashSet<String>(c.getCount()); c.moveToFirst(); int count = c.getCount(); for (int i = 0; i < count; i++) { set.add(c.getString(0)); c.moveToNext(); } c.close(); dbread.close(); db.close(); return set; }
From source file:foam.zizim.android.BoskoiService.java
public static BlogData getBlogData(int id) { Cursor cursor; cursor = BoskoiApplication.mDb.fetchBlogById(id); BlogData blogData = null;//from ww w. j ava 2 s. com if (cursor.moveToFirst()) { int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_ID); int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_TITLE); int dateIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_DATE); int descIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_DESCRIPTION); int linkIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_LINK); do { blogData = new BlogData(); blogData.setId(Util.toInt(cursor.getString(idIndex))); blogData.setTitle(cursor.getString(titleIndex)); blogData.setDescription(cursor.getString(descIndex)); blogData.setLink(cursor.getString(linkIndex)); blogData.setDate(cursor.getString(dateIndex)); } while (cursor.moveToNext()); } cursor.close(); return blogData; }