-1

I have created a recycle view, which consists of no of images that can be selected from the camera as well as the gallery, we have added two options to recycleview images that are deleted and crop option. On Delete option click the recycleview item gets remove and recycleview gets update, Now I wish to implement crop functionality on recycleview images and add update them again to the recycleview.

following is working UI design on link https://ibb.co/kxXcnq

Following is crop option click event where i am getting the uri of the image: I have created this in seperate class of image adapter:

 holder.cropImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Show the removed item label`enter code here`

            File file = imagesFiles.get(position);
            Uri uri = Uri.parse(file.getAbsolutePath());

            Log.d("file name :", file.getAbsolutePath());
        }
    });

2 Answers2

0

You can crop the image and save to the same Array List position in adapter and notify position of the apdater by using adapter.notifyItemChanged(position);

Vivek Faldu
  • 336
  • 3
  • 19
  • how I can perform crop operation on the image in an adapter which I have created separately, and update the receycleview. – Receipt Bag Nov 13 '18 at 10:21
  • @ReceiptBag Is your cropping code static(Means you crop the bitmap area with same height and width for example cropping image in 1:1 ratio) – Vivek Faldu Nov 13 '18 at 10:25
0
  1. Pass the selected Image from Adapter to this libraries activities https://github.com/ArthurHub/Android-Image-Cropper after cropping you will get result
  2. Then i think you will get the position of image so u update with new image in the list
Jins Lukose
  • 699
  • 6
  • 19
  • I tried applying the library already, it giving me nothing, it does not start the crop actvity `File file = imagesFiles.get(position); Uri uri = Uri.parse(file.getAbsolutePath()); AppCompatActivity activity = (AppCompatActivity) view.getContext(); CropImage.activity(uri).start(activity);` – Receipt Bag Nov 13 '18 at 10:45
  • @ReceiptBag What's this? – Jins Lukose Nov 13 '18 at 10:46
  • i am getting uri of the selected image from recycleview, that image i have to open with the crop library, i have already pass the uri to CropImage Class which opens the crop activity in order to crop the image with the uri – Receipt Bag Nov 13 '18 at 10:50
  • @ReceiptBag ok what's the problem? – Jins Lukose Nov 13 '18 at 10:54
  • 1
    as per your instruction i have implemented Image-Cropper library, // this two lines gives me image file in form of uri `File file = imagesFiles.get(position); Uri uri = Uri.parse(file.getAbsolutePath());` // gets activity from adapter class in order to use in next line code `AppCompatActivity activity = (AppCompatActivity) view.getContext();` // this is used to crop the image with uri, it opens the crop activity `CropImage.activity(uri).start(activity);` but this line of code does not start any crop activity, it just does not do anything. – Receipt Bag Nov 13 '18 at 11:01
  • @ReceiptBag try this https://stackoverflow.com/questions/15228812/crop-image-in-android OR https://github.com/jdamcd/android-crop – Jins Lukose Nov 13 '18 at 11:14