List of usage examples for android.content CursorLoader CursorLoader
public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder)
From source file:com.ogunwale.android.app.yaps.ui.PhotosActivity.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. We // only has one Loader, so we don't care about the ID. //@formatter:off String[] projection = new String[] { PhotosProvider.AlbumTable._ID, PhotosProvider.AlbumTable.COLUMN_NAME_COVER_BITMAP, PhotosProvider.AlbumTable.COLUMN_NAME_TITLE, PhotosProvider.AlbumTable.COLUMN_NAME_PHOTOS_COUNT, PhotosProvider.AlbumTable.COLUMN_NAME_LOCATION }; String selection = String.format(Locale.getDefault(), "%s=?", PhotosProvider.AlbumTable.COLUMN_NAME_SOURCE); String[] selectionArgs = new String[] { String.valueOf(mSourceSelection.getValue()) }; //@formatter:on // Create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. return new CursorLoader(this, PhotosProvider.AlbumTable.CONTENT_URI, projection, selection, selectionArgs, null);/* w w w . ja va 2 s . co m*/ }
From source file:de.msal.shoutemo.fragments.ChatFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { switch (id) { case LOADER_ID_MESSAGES: String where = null;/*from www . j a v a 2 s.co m*/ if (args != null) { where = args.getString("WHERE"); } return new CursorLoader(getActivity(), ChatDb.Posts.CONTENT_URI, null, where, null, null); default: return null; } }
From source file:com.example.android.cupboard.EditorActivity.java
@Override public Loader<Cursor> onCreateLoader(int i, Bundle bundle) { // Since the editor shows all food attributes, define a projection that contains // all columns from the pantry table String[] projection = { FoodEntry._ID, PantryContract.FoodEntry.COLUMN_FOOD_NAME, PantryContract.FoodEntry.COLUMN_USE_BY_DATE, PantryContract.FoodEntry.COLUMN_FOOD_AMOUNT, PantryContract.FoodEntry.COLUMN_FOOD_AMOUNT_UNIT }; // This loader will execute the ContentProvider's query method on a background thread return new CursorLoader(this, // Parent activity context mCurrentFoodUri, // Query the content URI for the current food item projection, // Columns to include in the resulting Cursor null, // No selection clause null, // No selection arguments null); // Default sort order }
From source file:com.ncode.android.apps.schedo.ui.EventsFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle data) { LOGD(TAG, "onCreateLoader, id=" + id + ", data=" + data); final Intent intent = BaseActivity.fragmentArgumentsToIntent(data); Uri eventsUri = intent.getData();//from ww w .j a v a 2 s . com if ((id == EventsQuery.NORMAL_TOKEN || id == EventsQuery.SEARCH_TOKEN) && eventsUri == null) { LOGD(TAG, "intent.getData() is null, setting to default events search"); eventsUri = ScheduleContract.Events.CONTENT_URI; } Loader<Cursor> loader = null; String liveStreamedOnlySelection = UIUtils.shouldShowLiveEventsOnly(getActivity()) ? "IFNULL(" + ScheduleContract.Events.EVENT_LIVESTREAM_URL + ",'')!=''" : null; if (id == EventsQuery.NORMAL_TOKEN) { LOGD(TAG, "Creating events loader for " + eventsUri + ", selection " + liveStreamedOnlySelection); loader = new CursorLoader(getActivity(), eventsUri, EventsQuery.NORMAL_PROJECTION, liveStreamedOnlySelection, null, ScheduleContract.Events.SORT_BY_TYPE_THEN_TIME); } else if (id == EventsQuery.SEARCH_TOKEN) { LOGD(TAG, "Creating search loader for " + eventsUri + ", selection " + liveStreamedOnlySelection); loader = new CursorLoader(getActivity(), eventsUri, EventsQuery.SEARCH_PROJECTION, liveStreamedOnlySelection, null, ScheduleContract.Events.SORT_BY_TYPE_THEN_TIME); } else if (id == TAG_METADATA_TOKEN) { LOGD(TAG, "Creating metadata loader"); loader = TagMetadata.createCursorLoader(getActivity()); } return loader; }
From source file:com.google.samples.apps.iosched.ui.SessionsFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle data) { LOGD(TAG, "onCreateLoader, id=" + id + ", data=" + data); final Intent intent = BaseActivity.fragmentArgumentsToIntent(data); Uri sessionsUri = intent.getData();// ww w .j a va2 s .com if ((id == SessionsQuery.NORMAL_TOKEN || id == SessionsQuery.SEARCH_TOKEN) && sessionsUri == null) { LOGD(TAG, "intent.getData() is null, setting to default sessions search"); sessionsUri = ScheduleContract.Sessions.CONTENT_URI; } Loader<Cursor> loader = null; String liveStreamedOnlySelection = UIUtils.shouldShowLiveSessionsOnly(getActivity()) ? "IFNULL(" + ScheduleContract.Sessions.SESSION_LIVESTREAM_URL + ",'')!=''" : null; if (id == SessionsQuery.NORMAL_TOKEN) { LOGD(TAG, "Creating sessions loader for " + sessionsUri + ", selection " + liveStreamedOnlySelection); loader = new CursorLoader(getActivity(), sessionsUri, SessionsQuery.NORMAL_PROJECTION, liveStreamedOnlySelection, null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); } else if (id == SessionsQuery.SEARCH_TOKEN) { LOGD(TAG, "Creating search loader for " + sessionsUri + ", selection " + liveStreamedOnlySelection); loader = new CursorLoader(getActivity(), sessionsUri, SessionsQuery.SEARCH_PROJECTION, liveStreamedOnlySelection, null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); } else if (id == TAG_METADATA_TOKEN) { LOGD(TAG, "Creating metadata loader"); loader = TagMetadata.createCursorLoader(getActivity()); } return loader; }
From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle paramBundle) { switch (id) { case Constants.Loader.LOADER_LOGIN: return new CursorLoader(this, RedditContract.Login.CONTENT_URI, null, null, null, RedditContract.Login.DEFAULT_SORT); default:/* w w w . j a v a2 s . co m*/ return super.onCreateLoader(id, paramBundle); } }
From source file:com.hackensack.umc.activity.ProfileActivity.java
private String getPath(Uri uri) { String[] data = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(ProfileActivity.this, uri, data, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();// w w w .j a v a 2 s.c om return cursor.getString(column_index); }
From source file:com.buddi.client.dfu.DfuActivity.java
@Override public Loader<Cursor> onCreateLoader(final int id, final Bundle args) { final Uri uri = args.getParcelable(EXTRA_URI); /*/*from w w w .j av a 2 s. com*/ * Some apps, f.e. Google Drive allow to select file that is not on the device. There is no "_data" column handled by that provider. Let's try to obtain all columns and than check * which columns are present. */ //final String[] projection = new String[] { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.DATA }; return new CursorLoader(this, uri, null /* all columns, instead of projection */, null, null, null); }
From source file:spring16.cs442.com.obtchat_10.BluetoothChatFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true);//from w ww . j a v a2 s . co m } break; case REQUEST_CONNECT_DEVICE_INSECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, false); } break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session setupChat(); } else { // User did not enable Bluetooth or an error occurred //Log.d(TAG, "BT not enabled"); Toast.makeText(self, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); //getActivity().finish(); } break; case 44: if (resultCode == Activity.RESULT_OK && data != null) { String realPath; // SDK < API11 if (Build.VERSION.SDK_INT < 11) realPath = RealPathUtil.getRealPathFromURI_BelowAPI11(this, data.getData()); // SDK >= 11 && SDK < 19 else if (Build.VERSION.SDK_INT < 19) realPath = RealPathUtil.getRealPathFromURI_API11to18(this, data.getData()); // SDK > 19 (Android 4.4) else realPath = RealPathUtil.getRealPathFromURI_API19(this, data.getData()); //setTextViews(Build.VERSION.SDK_INT, data.getData().getPath(),realPath); //Toast.makeText(MainActivity.this, file.toString(), Toast.LENGTH_LONG).show(); Uri uritoSend = Uri.fromFile(new File(realPath)); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/*"); //String uri = uritoSend; intent.putExtra(Intent.EXTRA_STREAM, uritoSend); startActivity(intent); } } LinearLayout layout = (LinearLayout) findViewById(R.id.chatFragment); if (resultCode == RESULT_OK) { if (requestCode == 1888) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); File destination = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg"); FileOutputStream fo; try { destination.createNewFile(); fo = new FileOutputStream(destination); fo.write(bytes.toByteArray()); fo.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Drawable d = Drawable.createFromPath(destination.getPath()); layout.setBackgroundDrawable(d); //ivImage.setImageBitmap(thumbnail); } else if (requestCode == 79) { Uri selectedImageUri = data.getData(); String[] projection = { MediaStore.MediaColumns.DATA }; CursorLoader cursorLoader = new CursorLoader(this, selectedImageUri, projection, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); String selectedImagePath = cursor.getString(column_index); Bitmap bm; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(selectedImagePath, options); final int REQUIRED_SIZE = 200; int scale = 1; while (options.outWidth / scale / 2 >= REQUIRED_SIZE && options.outHeight / scale / 2 >= REQUIRED_SIZE) scale *= 2; options.inSampleSize = scale; options.inJustDecodeBounds = false; bm = BitmapFactory.decodeFile(selectedImagePath, options); Drawable d = Drawable.createFromPath(selectedImagePath); layout.setBackgroundDrawable(d); } } }
From source file:com.antew.redditinpictures.library.ui.base.BaseFragmentActivityWithMenu.java
/** * Instantiate and return a new Loader for the given ID. * * @param id/*from ww w. j a va 2 s.co m*/ * The ID whose loader is to be created. * @param args * Any arguments supplied by the caller. * * @return Return a new Loader instance that is ready to start loading. */ @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { switch (id) { case Constants.Loader.LOADER_SUBREDDITS: String selection = null; String[] selectionArgs = null; if (args != null && args.containsKey(Constants.Extra.EXTRA_QUERY)) { String query = args.getString(Constants.Extra.EXTRA_QUERY); if (Strings.notEmpty(query)) { selection = RedditContract.SubredditColumns.DISPLAY_NAME + " LIKE ?"; selectionArgs = new String[] { "%" + query + "%" }; } } return new CursorLoader(this, RedditContract.Subreddits.CONTENT_URI, RedditContract.Subreddits.SUBREDDITS_PROJECTION, selection, selectionArgs, mSubredditSort); } return null; }