Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- Button galleryBtn = new Button(getActivity());
- galleryBtn.setText("Import Photo...");
- galleryBtn.setOnClickListener(v -> {
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_GET_CONTENT);
- intent.setType("image/*");
- this.startActivityForResult(intent, 0);
- });
- //... some more code here
- }
- //... some more code here
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == 0)
- try {
- if (data != null) {
- InputStream stream = getActivity().getContentResolver().openInputStream(
- data.getData());
- imageBitmap = BitmapFactory.decodeStream(stream);
- stream.close();
- imageView.setImageBitmap(imageBitmap);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- imageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image);
- public class ImageBox {
- public static Queue<Bitmap> mQ = new LinkedBlockingQueue<Bitmap>();
- }
- private void downloadFile(final String url){
- mExecutorService.submit(new Runnable() {
- @Override
- public void run() {
- Bitmap b = BitmapFromURL.getBitmapFromURL(url);
- synchronized (this){
- TaskCount--;
- }
- Intent i = new Intent(ACTION_ON_GET_IMAGE);
- ImageBox.mQ.offer(b);
- sendBroadcast(i);
- if(TaskCount<=0)stopSelf();
- }
- });
- }
- private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- LOG.d(TAG, "BroadcastReceiver get broadcast");
- String action = intent.getAction();
- if (DownLoadImageService.ACTION_ON_GET_IMAGE.equals(action)) {
- Bitmap b = ImageBox.mQ.poll();
- if(b==null)return;
- if(mListener!=null)mListener.OnGetImage(b);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement