List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.dwdesign.tweetings.util.Utils.java
public static String[] getAccountScreenNames(final Context context) { String[] accounts = new String[0]; if (context == null) return accounts; final String[] cols = new String[] { Accounts.USERNAME }; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, null, null, null); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USERNAME); cur.moveToFirst();/*from w ww . jav a 2 s . c om*/ accounts = new String[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getString(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static String[] getActivatedAccountScreenNames(final Context context) { String[] accounts = new String[0]; if (context == null) return accounts; final String[] cols = new String[] { Accounts.USERNAME }; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, Accounts.IS_ACTIVATED + "=1", null, null); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USERNAME); cur.moveToFirst();/*from www . j a v a2s . c om*/ accounts = new String[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getString(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getAccountIds(final Context context) { long[] accounts = new long[0]; if (context == null) return accounts; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, new String[] { Accounts.USER_ID }, null, null, null); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USER_ID); cur.moveToFirst();//from w ww . java2 s .c om accounts = new long[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getLong(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getActivatedAccountIds(final Context context) { long[] accounts = new long[0]; if (context == null) return accounts; final String[] cols = new String[] { Accounts.USER_ID }; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, Accounts.IS_ACTIVATED + "=1", null, Accounts.USER_ID); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Accounts.USER_ID); cur.moveToFirst();/* w w w . j a va 2 s.c om*/ accounts = new long[cur.getCount()]; int i = 0; while (!cur.isAfterLast()) { accounts[i] = cur.getLong(idx); i++; cur.moveToNext(); } cur.close(); } return accounts; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static String getImagePathFromUri(final Context context, final Uri uri) { if (context == null || uri == null) return null; final String media_uri_start = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString(); if (uri.toString().startsWith(media_uri_start)) { final String[] proj = { MediaStore.Images.Media.DATA }; final Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); if (cursor == null || cursor.getCount() <= 0) return null; final int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from www .j a va2s .c o m*/ final String path = cursor.getString(column_index); cursor.close(); return path; } else { final String path = uri.getPath(); if (path != null) { if (new File(path).exists()) return path; } } return null; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getLastStatusIdsFromDatabase(final Context context, final Uri uri) { if (context == null || uri == null) return null; final long[] account_ids = getActivatedAccountIds(context); final String[] cols = new String[] { Statuses.STATUS_ID }; final ContentResolver resolver = context.getContentResolver(); final long[] status_ids = new long[account_ids.length]; int idx = 0;//from w ww . j av a 2 s .c o m for (final long account_id : account_ids) { final String where = Statuses.ACCOUNT_ID + " = " + account_id; final Cursor cur = resolver.query(uri, cols, where, null, Statuses.STATUS_ID); if (cur == null) { continue; } if (cur.getCount() > 0) { cur.moveToFirst(); status_ids[idx] = cur.getLong(cur.getColumnIndexOrThrow(Statuses.STATUS_ID)); } cur.close(); idx++; } return status_ids; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getLastMessageIdsFromDatabase(final Context context, final Uri uri) { if (context == null || uri == null) return null; final long[] account_ids = getActivatedAccountIds(context); final String[] cols = new String[] { DirectMessages.MESSAGE_ID }; final ContentResolver resolver = context.getContentResolver(); final long[] status_ids = new long[account_ids.length]; int idx = 0;//from w w w . j a v a 2 s . c o m for (final long account_id : account_ids) { final String where = Statuses.ACCOUNT_ID + " = " + account_id; final Cursor cur = resolver.query(uri, cols, where, null, DirectMessages.MESSAGE_ID); if (cur == null) { continue; } if (cur.getCount() > 0) { cur.moveToFirst(); status_ids[idx] = cur.getLong(cur.getColumnIndexOrThrow(DirectMessages.MESSAGE_ID)); } cur.close(); idx++; } return status_ids; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getNewestStatusIdsFromDatabase(final Context context, final Uri uri) { if (context == null || uri == null) return null; final long[] account_ids = getActivatedAccountIds(context); final String[] cols = new String[] { Statuses.STATUS_ID }; final ContentResolver resolver = context.getContentResolver(); final long[] status_ids = new long[account_ids.length]; int idx = 0;/*from w w w . j a v a2 s .co m*/ for (final long account_id : account_ids) { final String where = Statuses.ACCOUNT_ID + " = " + account_id; final Cursor cur = resolver.query(uri, cols, where, null, Statuses.DEFAULT_SORT_ORDER); if (cur == null) { continue; } if (cur.getCount() > 0) { cur.moveToFirst(); status_ids[idx] = cur.getLong(cur.getColumnIndexOrThrow(Statuses.STATUS_ID)); } cur.close(); idx++; } return status_ids; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long[] getNewestMessageIdsFromDatabase(final Context context, final Uri uri) { if (context == null || uri == null) return null; final long[] account_ids = getActivatedAccountIds(context); final String[] cols = new String[] { DirectMessages.MESSAGE_ID }; final ContentResolver resolver = context.getContentResolver(); final long[] status_ids = new long[account_ids.length]; int idx = 0;// ww w . java 2 s .c o m for (final long account_id : account_ids) { final String where = Statuses.ACCOUNT_ID + " = " + account_id; final Cursor cur = resolver.query(uri, cols, where, null, DirectMessages.DEFAULT_SORT_ORDER); if (cur == null) { continue; } if (cur.getCount() > 0) { cur.moveToFirst(); status_ids[idx] = cur.getLong(cur.getColumnIndexOrThrow(DirectMessages.MESSAGE_ID)); } cur.close(); idx++; } return status_ids; }
From source file:com.dwdesign.tweetings.util.Utils.java
public static AccessToken getTwitterAccessToken(final Context context, final long account_id) { if (context == null) return null; AccessToken accessToken = null;//from ww w. j a v a2 s.co m final StringBuilder where = new StringBuilder(); where.append(Accounts.USER_ID + "=" + account_id); final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, where.toString(), null, null); if (cur != null) { if (cur.getCount() == 1) { cur.moveToFirst(); accessToken = new AccessToken(cur.getString(cur.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN)), cur.getString(cur.getColumnIndexOrThrow(Accounts.TOKEN_SECRET))); } cur.close(); } return accessToken; }