From 656143240c1e003cd39141c98548e7f0c625cc14 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Thu, 18 Feb 2016 15:56:25 -0500 Subject: [PATCH] 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 --- src/com/android/settings/display/DisplayDensityUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/display/DisplayDensityUtils.java b/src/com/android/settings/display/DisplayDensityUtils.java index cef5418c36f..891b7fb88a6 100644 --- a/src/com/android/settings/display/DisplayDensityUtils.java +++ b/src/com/android/settings/display/DisplayDensityUtils.java @@ -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; }