Your pixel handling seems wrong

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
znakeeye
Newbie
Newbie
Posts: 44
Joined: Mon Jan 07, 2013 12:00 am

Your pixel handling seems wrong

Post by znakeeye » Sun Mar 17, 2013 11:22 pm

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

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Your pixel handling seems wrong

Post by Yeray » Tue Mar 19, 2013 2:35 pm

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"
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

znakeeye
Newbie
Newbie
Posts: 44
Joined: Mon Jan 07, 2013 12:00 am

Re: Your pixel handling seems wrong

Post by znakeeye » Tue Mar 19, 2013 8:13 pm

That's the code I was looking for. Thanks!

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Your pixel handling seems wrong

Post by Yeray » Wed Mar 20, 2013 8:33 am

Great! :-)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply