LukasLechnerDev / ClickableAreasImages

An android library which lets you define clickable areas in your images.
Other
97 stars 26 forks source link

Not working with android Pie #12

Open leonam13 opened 5 years ago

leonam13 commented 5 years ago

im trying to use it with API 28 - Android Pie and it's not working

mhoseini967 commented 4 years ago

this problem because you cant get real size drawable . so you should change below code :

private void getImageDimensions(ImageView imageView){
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    imageWidthInPx = (int) (drawable.getBitmap().getWidth() / Resources.getSystem().getDisplayMetrics().density);
    imageHeightInPx = (int) (drawable.getBitmap().getHeight() / Resources.getSystem().getDisplayMetrics().density);
}

to :

private void getImageDimensions(){
    imageWidthInPx = your_image_width;
    imageHeightInPx = your_image_height;
}

}
jpereztenerife commented 4 years ago

this problem because you cant get real size drawable . so you should change below code :

private void getImageDimensions(ImageView imageView){
    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
    imageWidthInPx = (int) (drawable.getBitmap().getWidth() / Resources.getSystem().getDisplayMetrics().density);
    imageHeightInPx = (int) (drawable.getBitmap().getHeight() / Resources.getSystem().getDisplayMetrics().density);
}

to :

private void getImageDimensions(){
    imageWidthInPx = your_image_width;
    imageHeightInPx = your_image_height;
}

}

@mhoseini967 I've also tried to use this on Android 9, but the clickable areas are way off. I noticed they are still there but like 1000px to the right and about 200px down? This is just an estimation.

I made them show a dialogue, and they work fine in other devices with an older version of Android. I tried forking and changing that code, but it keeps failing.

I also tried setting directly the width and height of my picture:

    private int imageWidthInPx = 2688;
    private int imageHeightInPx = 1376;

but nothing.

Other things I've tried: Using imageWidthInPx = (int) (2688 / Resources.getSystem().getDisplayMetrics().density); (plus the equivalent for height) and imageWidthInPx = (int) (2688 / getResources().getDisplayMetrics().density); neither worked either.

Any way to make this work on Android Pie? :-(

jorgequirozh commented 4 years ago

So I just spent an entire afternoon going through this code and found the problem, Starting with Android Pie, .getBitmap().getWidth() reports the actual size of the drawable on the screen, thus the operation made with Resources.getSystem().getDisplayMetrics().density is not needed. just set imageWidthInPx to .getBitmap().getWidth() (plus the equivalent for height) and it'll work. In order to maintain backwards compatibility some sort of if statement must be implemented. Hope this helps someone!

nilodp commented 4 years ago

Hello! could someone fix these errors!

jorgequirozh commented 4 years ago

Hello! could someone fix these errors!

Hi, the latest version is fully compatible with Android 9+, what issue are you experiencing?

nilodp commented 4 years ago

Hi! Sorry!

I wrote there

[(https://github.com/LukasLechnerDev/ClickableAreasImages/issues/11)}

I am use this!

implementation 'com.github.Lukle:ClickableAreasImages:v0.1'

Is correct?

nilodp commented 4 years ago

Hello! could someone fix these errors!

Hi, the latest version is fully compatible with Android 9+, what issue are you experiencing?

Hello!

I do a new test today and dont work!

WORK targetSdkVersion 26

compileSdkVersion 28 buildToolsVersion '29.0.2' defaultConfig { applicationId "br.com.xxxxxxxx" minSdkVersion 21 targetSdkVersion 26 versionCode 8 versionName "1.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' }

DONT WORK targetSdkVersion 28 compileSdkVersion 28 buildToolsVersion '29.0.2' defaultConfig { applicationId "br.com.xxxxxxxx" minSdkVersion 21 targetSdkVersion 28 versionCode 8 versionName "1.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' }

tommybomb commented 4 years ago

Hi, I have tried to implement these new changes and it still fails. Before changes, the clickable areas were not in the correct coordinates when I use WQHD+ display but work on all other resolutions on newest android. After changes, clickable images don't work at all on any resolution. Please help me work through this someone! Thank you in advance.

jorgequirozh commented 4 years ago

Hi, I have tried to implement these new changes and it still fails. Before changes, the clickable areas were not in the correct coordinates when I use WQHD+ display but work on all other resolutions on newest android. After changes, clickable images don't work at all on any resolution. Please help me work through this someone! Thank you in advance.

What device/Android version are you running? The changes I proposed are now merged so it should work without any modifications. I tried this code with several Samsung and Huawei devices on Android 9 and 10 and found no issues. If you want to troubleshoot this yourself, print/toast the values of imageWidthInPx and imageHeightInPx when getImageDimensions() is called and make sure the values match the actual dimensions of the drawable, which was the cause of this particular issue I encountered, as the code originally calculated dimensions dividing them by the display density however I found that after Android 9, .getBitmap().getWidth() as used in the code returns the actual size of the drawable so it was not necessary to divide by the display density (and doing so resulted in wrong coordinates being calculated). I added an if statement to check for API level/Android version so it still divides by the density when needed (Android 8 and earlier). If you make any changes or have more questions please do post them here, I used this library extensively for my college graduation project (Computer engineering) over the last few months so I became quite familiar with it. The original author is also around and promptly accepted my merge requests.

tommybomb commented 4 years ago

ok. big problem solved. I had my drawables in mdpi - xxxhdpi folders. that was the problem all along. so i put my original drawables in a nodpi folder. Problem solved.

jorgequirozh commented 4 years ago

ok. big problem solved. I had my drawables in mdpi - xxxhdpi folders. that was the problem all along. so i put my original drawables in a nodpi folder. Problem solved.

That's great to know! Hopefully it'll help other users in the future. Just for reference -can you post which devices/versions you successfully tested the library? I can confirm it worked with:

nilodp commented 4 years ago

ok. big problem solved. I had my drawables in mdpi - xxxhdpi folders. that was the problem all along. so i put my original drawables in a nodpi folder. Problem solved.

That's great to know! Hopefully it'll help other users in the future. Just for reference -can you post which devices/versions you successfully tested the library? I can confirm it worked with:

  • Motorola G8 Power (Android 10)
  • Huawei P10 (Android 9)
  • BlackBerry KeyOne (Android 8)
  • Motorola G4 (Android 7)
  • 7-inch Fire Tablet (Lineage/Android 7)
  • Samsung J7 (Android 6)
  • LG G3 (Android 5)

Hi!

Hi! It didn't work with the emulator on android 10! I created a simple project and made it available in the link below: Please download to see the problem! Thank you!

https://drive.google.com/file/d/15Qx34ZiG8vrESZC87f2wtaHj2kmifGGN/view?usp=sharing

`defaultConfig { applicationId "br.com.pd.testclickimage" minSdkVersion 16 targetSdkVersion 28//For work change here to 26 versionCode 1 versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}`
tommybomb commented 3 years ago

Hi Jorge or Lukas,

I hope you are doing well. I’ve been working on my app with the clickable areas image library and I have a question that maybe you can answer…. Is there a way to implement long clicks on the clickable areas image? I saw some references to long clicks in the code but wasn’t sure how to implement. Any thoughts?

Thanks in advance!

Tommy

On Sep 28, 2020, at 7:55 PM, Jorge Quiroz notifications@github.com wrote:

Hi, I have tried to implement these new changes and it still fails. Before changes, the clickable areas were not in the correct coordinates when I use WQHD+ display but work on all other resolutions on newest android. After changes, clickable images don't work at all on any resolution. Please help me work through this someone! Thank you in advance.

What device/Android version are you running? The changes I proposed are now merged so it should work without any modifications. I tried this code with several Samsung and Huawei devices on Android 9 and 10 and found no issues. If you want to troubleshoot this yourself, show through terminal the values of imageWidthInPx and imageHeightInPx when getImageDimensions() is called and make sure the values match the actual dimensions of the drawable (which was the cause of this particular issue I encountered, as the code originally calculated dimensions dividing them by the display density however I found that after Android 9, .getBitmap().getWidth() as used in the code returns the actual size of the drawable so it was not necessary to divide by the display density. I added an if statement to check for API level/Android version so it still divides by the density when needed (Android 8 and earlier). If you make any changes or have more questions please do post them here, I used this library extensively for my college graduation project (Computer engineering) over the last few months so I became quite familiar with it. The original author is also around and promptly accepted my merge requests.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/LukasLechnerDev/ClickableAreasImages/issues/12#issuecomment-700395127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGCZY6SIZHR4FH2VWTN4NPTSIFEBFANCNFSM4GGVXUEQ.