Code example for DisplayMetrics

0
        shadow.setWidth(1024);
        shadow.setHeight(600);
        shadow.setXdpi(183.0f);
        shadow.setYdpi(184.0f);
 
        DisplayMetrics metrics = new DisplayMetrics();
 
        display.getMetrics(metrics);
 
        assertEquals(1.5f, metrics.density, 0.05);
        assertEquals(DisplayMetrics.DENSITY_MEDIUM, metrics.densityDpi);
        assertEquals(1.6f, metrics.scaledDensity, 0.05);
        assertEquals(1024, metrics.widthPixels);
        assertEquals(600, metrics.heightPixels);
        assertEquals(183.0f, metrics.xdpi, 0.05);
        assertEquals(184.0f, metrics.ydpi, 0.05);
    } 
 
    /** 
     * The {@link android.view.Display#getOrientation()} method is deprecated, but for 
     * testing purposes, return the value gotten from {@link android.view.Display#getRotation()}