Page 1 of 1

Your pixel handling seems wrong

Posted: Sun Mar 17, 2013 11:22 pm
by 17064597
I've noticed that if I set a font size of 18, it looks ok on my Nexus 4, but on my Galaxy Mini (with horrible resolution) the font is LARGE. I believe your APIs expect "pixel count", which doesn't reflect what you see on a real device. Instead, DPs (device independent pixels) should be used.

Is it up to the API consumer (me) to make the conversion? E.g. when setting the font size of 18 pixels, I would instead calculate the physical pixel size and convert from "12 dip". On my Nexus 4 this would become 18 pixels. On my Galaxy Mini it would probably be some 12 pixels.

I see this in your code:

Code: Select all

transient public static final int DEFAULTSIZE = 10;
That explains why my chart looks like an anabola freak on my Galaxy Mini :P

Re: Your pixel handling seems wrong

Posted: Tue Mar 19, 2013 2:35 pm
by yeray
Hi,

Have you tried setting a font size relative to the screen density?

Code: Select all

		DisplayMetrics metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		float myDensity = metrics.density;

		tChart1.getAspect().setView3D(false);
		tChart1.getLegend().setVisible(false);
		tChart1.getHeader().getFont().setSize((int)(tChart1.getHeader().getFont().getSize() * myDensity));
		tChart1.getHeader().setText("Text size = " + String.valueOf(tChart1.getHeader().getFont().getSize()));
The above gives me:
- Android 4.2.2 emulator, 3.2" screen (320x480 mdpi): "Text Size = 10"
- Android 4.2.2 emulator, 4" screen (480x800 hdpi): "Text Size = 15"
- Galaxy Mini with CM 10.1 (Android 4.2.2), 3.14" screen (240x320 ldpi I think): "Text Size = 7"

Re: Your pixel handling seems wrong

Posted: Tue Mar 19, 2013 8:13 pm
by 17064597
That's the code I was looking for. Thanks!

Re: Your pixel handling seems wrong

Posted: Wed Mar 20, 2013 8:33 am
by yeray
Great! :-)