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

Not working with android Pie #12

Open
leonam13 opened this issue Nov 27, 2018 · 13 comments
Open

Not working with android Pie #12

leonam13 opened this issue Nov 27, 2018 · 13 comments

Comments

@leonam13
Copy link

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

@mhoseini967
Copy link

mhoseini967 commented Nov 17, 2019

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
Copy link

jpereztenerife commented Jun 4, 2020

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
Copy link
Contributor

jorgequirozh commented Jul 21, 2020

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
Copy link

nilodp commented Sep 1, 2020

Hello!
could someone fix these errors!

@jorgequirozh
Copy link
Contributor

Hello!
could someone fix these errors!

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

@nilodp
Copy link

nilodp commented Sep 1, 2020

Hi!
Sorry!

I wrote there

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

I am use this!

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

Is correct?

@nilodp
Copy link

nilodp commented Sep 4, 2020

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
Copy link

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
Copy link
Contributor

jorgequirozh commented Sep 29, 2020

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
Copy link

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
Copy link
Contributor

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)

@nilodp
Copy link

nilodp commented Sep 30, 2020

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
Copy link

tommybomb commented Jan 3, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants