List of usage examples for android.support.v4.content CursorLoader CursorLoader
public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder)
From source file:Main.java
public static File parseFileByIntentData(Context context, Intent data) { File file = null;//w w w . j a v a2 s . com if (data != null && data.getData() != null) { String[] proj = { MediaStore.Images.Media.DATA }; CursorLoader cursorLoader = new CursorLoader(context, data.getData(), proj, null, null, null); Cursor cursor = null; try { cursor = cursorLoader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); file = new File(cursor.getString(column_index)); } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } } return file; }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store */// w ww . ja v a 2s . c o m public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:com.google.android.demos.atom.widget.FeedAdapter.java
public static Loader<Cursor> createLoader(Context context, Uri uri) { return new CursorLoader(context, uri, PROJECTION, null, null, null); }
From source file:com.deliciousdroid.platform.TagManager.java
public static CursorLoader GetTags(String account, String sortorder, Context context) { final String[] projection = new String[] { Tag._ID, Tag.Name, Tag.Count }; final String selection = Tag.Account + "=?"; final String[] selectionargs = new String[] { account }; return new CursorLoader(context, Tag.CONTENT_URI, projection, selection, selectionargs, sortorder); }
From source file:com.deliciousdroid.platform.BundleManager.java
public static CursorLoader GetBundles(String account, String sortorder, Context context) { String[] projection = new String[] { Bundle._ID, Bundle.Name, Bundle.Tags }; String selection = Bundle.Account + "=?"; String[] selectionargs = new String[] { account }; return new CursorLoader(context, Bundle.CONTENT_URI, projection, selection, selectionargs, sortorder); }
From source file:com.pindroid.platform.NoteManager.java
public static CursorLoader GetNotes(String account, String sortorder, Context context) { final String[] projection = new String[] { Note._ID, Note.Title, Note.Text, Note.Hash, Note.Pid, Note.Account, Note.Added, Note.Updated }; final String selection = Note.Account + "=?"; final String[] selectionargs = new String[] { account }; return new CursorLoader(context, Note.CONTENT_URI, projection, selection, selectionargs, sortorder); }
From source file:com.marvin.rocklock.PlaylistUtils.java
/** * Gets the playlist ID given it's name//from w w w . j a v a 2s. c om * * @param context The activity calling this method * @param name The playlist name * @return The playlist ID */ public static int getPlaylistId(RockLockActivity context, String name) { String[] proj = { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME }; String formattedName = name.replace("'", "''"); String filter = MediaStore.Audio.Playlists.NAME + "= '" + formattedName + "'"; CursorLoader loader = new CursorLoader(context, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, proj, filter, null, null); Cursor testCursor = loader.loadInBackground(); int idx = -1; boolean hasFirst = testCursor.moveToFirst(); if (hasFirst) { idx = testCursor.getInt(0); } testCursor.close(); return idx; }
From source file:can.yrt.onebusaway.QueryUtils.java
static protected CursorLoader newRecentQuery(final Context context, final Uri uri, final String[] projection, final String accessTime, final String useCount) { // "Recently" means seven days in the past final long last = System.currentTimeMillis() - 7 * DateUtils.DAY_IN_MILLIS; Uri limit = uri.buildUpon().appendQueryParameter("limit", "20").build(); String regionWhere = ""; if (Application.get().getCurrentRegion() != null) { if (projection.equals(QueryUtils.StopList.Columns.PROJECTION)) { regionWhere = " AND " + StopList.getRegionWhere(); } else if (projection.equals(QueryUtils.RouteList.Columns.PROJECTION)) { regionWhere = " AND " + RouteList.getRegionWhere(); }//from w w w . ja v a 2 s . c om } return new CursorLoader( context, limit, projection, "((" + accessTime + " IS NOT NULL AND " + accessTime + " > " + last + ") OR (" + useCount + " > 0))" + regionWhere, null, accessTime + " desc, " + useCount + " desc"); }
From source file:com.dogmalabs.wonderadapter.demo.util.CursorUtil.java
public Loader<Cursor> getWondersLoader() { Uri uri = Contract.getContentUri(context, Contract.Cursor.Wonders.PATH_DIR); return new CursorLoader(context, uri, projection, selection, selectionArgs, orderBy); }
From source file:can.yrt.onebusaway.MyStarredStopsFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(getActivity(), ObaContract.Stops.CONTENT_URI, QueryUtils.StopList.Columns.PROJECTION, ObaContract.Stops.FAVORITE + "=1" + (Application.get().getCurrentRegion() == null ? "" : " AND " + QueryUtils.getRegionWhere(ObaContract.Stops.REGION_ID, Application.get().getCurrentRegion().getId())), null, ObaContract.Stops.USE_COUNT + " desc"); }