The reason we work with millimeters is mostly for uniformity across 
platforms as a universal standard. Changing to the Android DIP standard 
would be problematic as all the tooling/theming etc is based around 
millimeters so we can expose that in an API but not leverage this. It 
wouldn't help. 

Are you talking about this method? :

    @Override
    public int getDeviceDensity() {
        DisplayMetrics metrics = new DisplayMetrics();
        if (getActivity() != null) {
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(
metrics);
        } else {
            metrics = getContext().getResources().getDisplayMetrics();
        }

        if(metrics.densityDpi < DisplayMetrics.DENSITY_MEDIUM) {
            return Display.DENSITY_LOW;
        }

        if(metrics.densityDpi < 213) {
            return Display.DENSITY_MEDIUM;
        }

        // 213 == TV
        if(metrics.densityDpi >= 213 &&  metrics.densityDpi <= 
DisplayMetrics.DENSITY_HIGH) {
            return Display.DENSITY_HIGH;
        }

        if(metrics.densityDpi > DisplayMetrics.DENSITY_HIGH && 
metrics.densityDpi 
< 400) {
            return Display.DENSITY_VERY_HIGH;
        }

        if(metrics.densityDpi >= 400 && metrics.densityDpi < 560) {
            return Display.DENSITY_HD;
        }

        if(metrics.densityDpi >= 560 && metrics.densityDpi <= 640) {
            return Display.DENSITY_2HD;
        }
        if(metrics.densityDpi > 640) {
            return Display.DENSITY_4K;
        }

        return Display.DENSITY_MEDIUM;
    }


In this case using the densityDpi field makes a lot of sense as it's the 
officially sanctioned Android API that does exactly this. 

I'm talking about this method only:

    public int convertToPixels(int dipCount, boolean horizontal) {
        DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
        float ppi = dm.density * 160f;
        return (int) (((float) dipCount) / 25.4f * ppi);
    }

Right now this is defensive code designed against the bugs in dm.xdpi/ydpi 
which I'm assuming you want to use instead. To work correctly you would 
need to guard against misconfigured xdpi by checking that the range 
difference isn't too big.

Notice that this method is usually invoked with *1000 of the value asked 
and then converted to a floating point value for higher accuracy.

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/f6ce8e6b-8eea-462d-a2c0-c85651f5fdf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to