Access res files from Qt for Android - android

How can I set for example ToolButton's icon to be "ic_not_interested_black_48dp.png"
I have android/res directory in my Qt project, there are some directories for different screen sizes, drawable-hdpi, drawable-ldpi etc.
What is the best approach to set the correct icon for a given screen.
Does Qt/Android resolve this on its own or do I have to create function that returns me correct prefix 'drawable-hdpi/' or 'drawable-ldpi/' based on my screen size?

While the high DPI support has been substantially improved in Qt 5.6, the support for varying icon density is not yet there.
What you might be able to do though, is use QFileSelector. Upon startup, check the DPI of the device's display with QScreen (e.g. devicePixelRatio), and then map that value to drawable-ldpi, drawable-hdpi, etc. Once you have the correct string, add it to the list of selectors by calling setExtraSelectors(). That way, assuming you have a directory structure like the one below, the correct icon file will be chosen:
drawable-ldpi/
ic_not_interested_black.png
drawable-hdpi/
ic_not_interested_black.png
You'll then need to define a Q_INVOKABLE function in a QObject-derived class and then expose it to QML (e.g. via a context property) that takes a path to an icon file and calls QFileSelector::select(iconPath). When you're done, your usage of it in QML will look something like this:
ToolButton {
iconSource: iconSelector.select("ic_not_interested_black.png")
}

yes you have to create different size and resolution icons drawable-hdpi means high density drawable-ldpi means its low density
There are A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
for details it will help you to load your app in high level to low level devices without performance loss.

Related

Screen densities and sizes on android (Diff between large/x-large.. // hdpi, xhdpi...)

I've read so much about these things already, so many threads, but there still some things that I don't understand about how to, as a both developer and a designer, avoid problems with different sized screens.
So my question is mainly: What is the difference between putting drawables into mdpi,hdpi,xhdpi,xxhdpi folders as opposed to normal,large,xlarge folders? Should I do both?
I want drawables to act like this: If it takes 50% of the width of the screen on a smartphone, it should take 50% of the screen on a tablet. That's where I'm also confused - Both my phone and tablet are 1920x1080 and both fall into the xhdpi bucket (I believe), but their physical screen sizes are very much different.
Now I save drawables according to the mdpi, hdpi... ratios. Therefore I get results like this on the phone:
When I just out of curiosity created folders for drawables large and xlarge (I didn't know the ratios), I get this, which is closer to what I'm aiming for (but is obviously too big):
But what's the point of using the xhdpi (etc) buckets? Am I understanding this completely wrong? Someone please enlighten me. I hope this question makes sense. My point is - I want the scales of text and pictures to fill about as much of the screen on a tablet as on a smartphone.
Thanks
We developers just create drawbles for mdpi, hdpi, xhdpi, xxhdpi because screen resolution of devices maybe different. While in the case of the normal, large, xlarge folders it is used for the case of screen sizes.We Use This configuration qualifiers (mdpi, hdpi, xhdpi, xxhdpi) because for example for low budget phone, resolution maybe less and will show 48px drawable bigger while high end devices will show it smaller. That's why we create drawables for different resolutions of phones varying from 42(maybe) to 192 px.Similarly normal,large,xlarge folders are used in respect with screen size.
If you want to compress app size, you may use vector drawables. They are just created for one time and look consistent on every time.For Custom icons, export it to .svg or .psd format and create it as vector drawable through android studio.
Edit : I usually create my logo on Photoshop and android studio efficiently exports it to vector drawable.
xlarge screens are at least 960dp x 720dp.
large screens are at least 640dp x 480dp.
normal screens are at least 470dp x 320dp.
small screens are at least 426dp x 320dp.
Vector drawables are put in drawables folder. There is one more advantage of using vector drawables that is one May animate it.
Note : Beginning with Android 3.2 (API level 13), these size groups small, normal, large,xlarge folders are deprecated in favor of a new technique for managing screen sizes based on the available screen width. If you're developing for Android 3.2 and greater use mdpi,hdpi,xhdpi,xxhdpi folders.
The configuration qualifiers (described in detail below) that you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi (high), xhdpi extra-high), xxhdpi (extra-extra-high), and xxxhdpi (extra-extra-extra-high).
Screen Density of devices
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Images Sizes as per folders.
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
144x144 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density. Hope this will help.You ask me more about this in detail in comments.

What dp should I use for Android icons?

I found this LINK that outlines what dimensions of images/icons/notifications/etc in Android should be. I then looked for some solid standard icons and stumbled upon Google's REPOSITORY. Each icon exists in 18, 24, 36, and 48dp. I can then download each image for mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi.
Why do they offer the 4 different dp's if for each of the dp's I get the icon for all 6 folders (mdpi, hdpi, etc)? Also, which dp is the best? Should I use 48 simply because it's the most crisp?
Size which you pick from this is image size. Each folder inside, is that image, with that size, scaled to proper resolution for each device type screen size (mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi).
Which size you will use, it's your choice (or Material Design, if you decide to follow these rules).
The key here is to support multiple screens and different densities.
Almost every application should have alternative drawable resources for different screen densities, because almost every application has a launcher icon and that icon should look good on all screen densities. Likewise, if you include other bitmap drawables in your application (such as for menu icons or other graphics in your application), you should provide alternative versions or each one, for different densities.
To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities.
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
For more information, please refer to the developer site.
18dp is for small contextual icons
24dp is for notification icons
36dp is for action bar, dialog & tab icons
48dp is for launcher icons

How to provide different resolutions for header image?

This is a follow up question to this post. I have a header image on one of my screens and want to scale it to the full width but keeping the aspect ratio. So it should do something like this:
I can do that, but now I have the problem that the image scales relatively bad. (Imagine some text on the picture above, this is not the best example). How can I provide several pictures in different resolutions to android so that android take the pictures which is best for the current screen size/density situation?
Android support different screen densities through the use of configuration qualifier as follow:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
The best practice is to create a directory under the res/drawables/ directory with those qualifier. Eg.: /res/drawable/hpdi and store an image of the appropriate resolution in that folder. Do the same for the other qualifier; the proper image resolution will be chosen automatically based on the screen density of the device. Image filename must be the same in each of the configuration qualifier directory.
More info: Android Developers documentation.

Mobile Design: Should I be using double resolution images?

The Galaxy S5 has a display resolution of 1920 x 1080, an iphone is 1334 x 750, and many others are similar. Do these resolutions work the same way that Apple's retina screens work, where images will look blurry unless they have an #2x size version?
Basically, if I am creating a mobile landing page for an add, and I use an image that is 300px wide in the browser, will that image look sharp like it does in the browser or do I need to do something else to make sure it looks good on mobile devices?
If you're talking about photos or photo-like images, Android resizes those fairly well and does a fair job of avoiding unpleasant image artifacts because it uses very accurate rescaling methods.
Anything you expect to be "pixel-perfect" like a 2px-wide line in the image is simply always to be somewhat blurry in a resized result. For those types of images, you'd want to generate different resolution versions of the images in the drawables-* (or mipmap-*) folders and keep in mind the relationship between screen density and pixels.
MDPI is 1:1
HDPI is 1.5:1
XHDPI is 2:1
XXHDPI is 3:1
XXXHDPI is 4:1 (and something you're unlikely to find right now)
...so if you wanted a 1px border in an image that's to be displayed on an XXHDPI screen, in the drawable file that line would need to be 3px wide. The good news is that since these downscale and upscale quite accurately, under most circumstances, an image from drawables-xxhdpi will retain a perfectly clean edge when downsized to all the others (except HDPI, because 1.5) and an image from drawables-mdpi will upscale decently as well. Android will do the best it can at picking an appropriate image to upscale/downscale from the drawables/mipmaps folders when some are missing (i.e., you might not need to populate all of them).
Android's support for higher resolution screens is based on screen density.
A set of six generalized densities:
- ldpi (low) ~120dpi
- mdpi (medium) ~160dpi
- hdpi (high) ~240dpi
- xhdpi (extra-high) ~320dpi
- xxhdpi (extra-extra-high) ~480dpi
- xxxhdpi (extra-extra-extra-high) ~640dpi
http://developer.android.com/guide/practices/screens_support.html
You need to create additional drawable folders and place your higher resolution images there. drawables-hdpi, drawables-xhdpi, drawables-xxhdpi, etc...
There are some tools that will help you resize images to the various densities too. Like this one: https://github.com/redwarp/9-Patch-Resizer

Android drawable mdpi

I am working on a Android Project.
I put the images (320*480) into the mdpi -folder. There are some information in Android developer site that 480*800 tablets(7") also takes images from the mdpi- folder. When the 7" tablet takes images form that mdpi- folder it become smaller. There is only one mdpi- folder so how do i exactly manage it .
You should read the Android developer documentation on Providing Alternative Resources.
From my answer to this similar question:
The ImageView will render the image inside of it at the correct resolution for the device. As per the documentation on providing resources, you must make sure that you provide resources at the correct DPI for each of the resolution types. Android will pick the best resource resolution for you, but if only one resource exists then it will pick that one and try to render at the device resolution.
So, find out the correct DPI for your device, and add the image (at the correct DPI) into that folder and it should appear at the correct size. If the image is placed in the wrong folder then it will appear a different size. Another useful link is the Density Independence documentation.
Note: let's assume your device is an HDPI device. The res/drawables/drawable-hdpi folder might not exit in your project but you can just add it in manually.
Don't mix up screen size with screen density. There are qualifiers related to screen size (e.g. small, normal, large, ...) and qualifiers related to density (e.g. ldpi, mdpi, ...).
You can even combine these qualifiers, for example in drawable-normal-mdpi you can put resources that will be used on devices with normal screen (phones) with a mdpi density.
you should create ldpi, hdpi, xhpi folder too. And you need to copy your image with same name by calculating its ratio.
ldpi - mdpi - hdpi - xhdpi
3 4 6 8
There is a 3:4:6:8 scaling ratio between the four primary densities
(ignoring the tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in
mdpi, 18x18 in hdpi and 24x24 in xhdpi.
If you decide that your image resources don't look good enough on a
television or other certain devices and want to try tvdpi resources,
the scaling factor is 1.33*mdpi. For example, a 100px x 100px image
for mdpi screens should be 133px x 133px for tvdpi.

Categories

Resources