Round display scaling densities down to the nearest 2 DPI

This will prevent scaling artifacts due to odd densities. We will not
make any adjustments to the "normal" density, which will preserve
tvdpi or whatever the device manufacturer needed to use.

Rounding the density down is always safe, since it will not push us
below our 320dp lower bound on minimum effective screen dimension.

Bug: 27225670
Change-Id: Ib084bb3d4fc70a59106ac74df5394c21e9f8c7bd
This commit is contained in:
Alan Viverette
2016-02-18 15:56:25 -05:00
parent adcec744b2
commit 656143240c

View File

@@ -116,7 +116,8 @@ class DisplayDensityUtils {
if (numSmaller > 0) {
final float interval = (1 - minScale) / numSmaller;
for (int i = numSmaller - 1; i >= 0; i--) {
final int density = (int) (normalDensity * (1 - (i + 1) * interval));
// Round down to a multiple of 2 by truncating the low bit.
final int density = ((int) (normalDensity * (1 - (i + 1) * interval))) & ~1;
if (currentDensity == density) {
currentDensityIndex = curIndex;
}
@@ -136,7 +137,8 @@ class DisplayDensityUtils {
if (numLarger > 0) {
final float interval = (maxScale - 1) / numLarger;
for (int i = 0; i < numLarger; i++) {
final int density = (int) (normalDensity * (1 + (i + 1) * interval));
// Round down to a multiple of 2 by truncating the low bit.
final int density = ((int) (normalDensity * (1 + (i + 1) * interval))) & ~1;
if (currentDensity == density) {
currentDensityIndex = curIndex;
}