Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use on Java. Could you give some sample #19

Closed
ioviov opened this issue May 5, 2021 · 21 comments
Closed

How to use on Java. Could you give some sample #19

ioviov opened this issue May 5, 2021 · 21 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ioviov
Copy link

ioviov commented May 5, 2021

Hi! A lot of thanks for your job!

I used before https://github.com/Dhaval2404/ImagePicker , but Google send a letter "We've detected that your app contains the requestLegacyExternalStorage flag in the manifest file of 1 or more of your app bundles or APKs."

And I found your comments and your library, so...

My old code was:

private void avatarTouch() {
        ImagePicker.Companion.with(this)
                .crop(1f, 1f)
                .compress(1024)
                .maxResultSize(1080, 1080)
                .start();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK) {

            Uri uri = data.getData();
            //File file = ImagePicker.Companion.getFile(data);
            //String filePath = ImagePicker.Companion.getFilePath(data);

            if (uri != null) {
                Picasso.get().load(uri).into(viewManager.avatarImageView);
            }

        } else if (resultCode == ImagePicker.RESULT_ERROR) {
            // Error
            Map<String, String> map = new HashMap<>();
            map.put("error", ImagePicker.Companion.getError(data));
            FirebaseModel.shared().sendAnalytics(MyApplication.context, "image_picker_error", map);

            Toast.makeText(MyApplication.context, ImagePicker.Companion.getError(data), Toast.LENGTH_LONG).show();
        } else {
            // Cancel
        }
    }

Could you please help me to change my code. I can't find an example on java how to use your library :(
Thanks!

@Drjacky Drjacky self-assigned this May 5, 2021
@Drjacky Drjacky added the help wanted Extra attention is needed label May 5, 2021
@Drjacky Drjacky closed this as completed May 5, 2021
@ioviov
Copy link
Author

ioviov commented May 5, 2021

I'm sorry
I see errors in builder, as I understand in your library there are no thees methods, see attached files.

Screenshot at May 05 16-21-45

Screenshot at May 05 16-22-01

In Readme I see:

ImagePicker.Companion.with(this)
.crop() //Crop image(Optional), Check Customization for more option
.cropOval() //Allow dimmed layer to have a circle inside
.compress(1024) //Final image size will be less than 1 MB(Optional)
.maxResultSize(1080, 1080) //Final image resolution will be less than 1080 x 1080(Optional)
.start()

@Drjacky
Copy link
Owner

Drjacky commented May 5, 2021

You're right. I need to edit the Readme.
There is no need for compress method; It has been removed since it was comparing the size of the file and not the image, and the resize operation is enough to reduce the size of the final file.

Thanks for addressing this.

@Drjacky
Copy link
Owner

Drjacky commented May 5, 2021

@ioviov Instead of start(), use createIntent() or createIntentFromDialog().

@ioviov
Copy link
Author

ioviov commented May 6, 2021

@Drjacky I tried using createIntent() on simulator and real phone, but it's not working, nothing appears.
Possibly in version 2.1.6 this fixed, I will try

Also in Readme you wrote maxResultSize(1080, 1080) but for java you should use maxResultSize(1080, 1080, false)

@ioviov
Copy link
Author

ioviov commented May 6, 2021

I tried use 2.1.6 but during Sync task I see error

My class public class MyApplication extends MultiDexApplication {

Screenshot at May 06 11-57-07

I fixed this by added in my Manifest xmlns:tools="http://schemas.android.com/tools" and tools:replace="name"

So I use createIntent() and it's not working, nothing appears.

@Drjacky Drjacky reopened this May 6, 2021
@Drjacky Drjacky added the bug Something isn't working label May 6, 2021
@Drjacky
Copy link
Owner

Drjacky commented May 7, 2021

@ioviov Please test v2.1.7 and let me know if the issue solved or not.

@ioviov
Copy link
Author

ioviov commented May 7, 2021

@Drjacky I can't do Sync task : (

Screenshot at May 07 20-09-28

@Drjacky
Copy link
Owner

Drjacky commented May 7, 2021

@ioviov Sorry, maven has an issue right now. It doesn't accept new uploads.
Right now, it's on JitPack: https://jitpack.io/#Drjacky/ImagePicker/2.1.7

@ioviov
Copy link
Author

ioviov commented May 7, 2021

It's ok
Sorry, I'm not guru on Java, so I need to wait? Or what I should to do right now?
Thanks!

@Drjacky
Copy link
Owner

Drjacky commented May 7, 2021

Click on the link and check the HOW TO section:

To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.Drjacky:ImagePicker:2.1.7'
}

Let me know if it works.

@ioviov
Copy link
Author

ioviov commented May 7, 2021

Well I have the same

Screenshot at May 07 20-57-58

And

Screenshot at May 07 20-59-27

@ioviov
Copy link
Author

ioviov commented May 7, 2021

And

Screenshot at May 07 21-00-53

@Drjacky
Copy link
Owner

Drjacky commented May 7, 2021

Okay, forget the Jitpack. It's on maven now: https://repo1.maven.org/maven2/com/github/Drjacky/ImagePicker/2.1.7/

@ioviov
Copy link
Author

ioviov commented May 7, 2021

@Drjacky Well, it's ok
Manifest merge failed is fixed now, thanks!

But createIntent() still not working
When I tap on View nothing happens

@Drjacky
Copy link
Owner

Drjacky commented May 7, 2021

Could you create a sample project and attach it here?

@ioviov
Copy link
Author

ioviov commented May 7, 2021

Ok, I will do it on next week (I'll try on Monday), thanks

@ioviov
Copy link
Author

ioviov commented May 11, 2021

Hi!
I created the sample

I tested with implementation 'com.github.dhaval2404:imagepicker:1.8' and it works fine. I can chose image or take a photo

With you library when I tap on ImageView nothing to happen

SampleImagePicker.zip

Thank you

@Drjacky
Copy link
Owner

Drjacky commented May 11, 2021

@ioviov
SampleImagePicker-Solution.zip

You would need to define which one you want: galleryOnly, cameraOnly;
And if you want both, the createIntent changes to createIntentFromDialog:

ImagePicker.Companion.with(requireActivity())
                .crop()
                .cropOval()
                .maxResultSize(512, 512, true)
                .createIntentFromDialog((Function1) (new Function1() {
                    public Object invoke(Object var1) {
                        this.invoke((Intent) var1);
                        return Unit.INSTANCE;
                    }

                    public final void invoke(@NotNull Intent it) {
                        Intrinsics.checkNotNullParameter(it, "it");
                        galleryLauncher.launch(it);
                    }
                }));

P.S I've improved some other parts too. Good to check.

@ioviov
Copy link
Author

ioviov commented May 11, 2021

@Drjacky A lot of thanks!!!
It works good!

It will be good that you write this full example, how to use library on Java in README, for another users

ActivityResultLauncher<Intent> galleryLauncher =
            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), (ActivityResult result) -> {
                if (result.getResultCode() == RESULT_OK) {
                    Uri uri = result.getData().getData();
                    // For example 
                    Picasso.get().load(uri).into(avatarImageView);
                } else if (result.getResultCode() == ImagePicker.RESULT_ERROR) {
                    // Use ImagePicker.Companion.getError(result.getData()) to show an error
                }
            });

ImagePicker.Companion.with(requireActivity())
                .cropSquare()
                .maxResultSize(1080, 1080, true)
                .createIntentFromDialog((Function1) (new Function1() {
                    public Object invoke(Object var1) {
                        this.invoke((Intent) var1);
                        return Unit.INSTANCE;
                    }

                    public final void invoke(@NotNull Intent it) {
                        Intrinsics.checkNotNullParameter(it, "it");
                        galleryLauncher.launch(it);
                    }
                }));

@Drjacky
Copy link
Owner

Drjacky commented May 11, 2021

v2.1.8 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants