Refactor DeviceProfile tests based on dump() and use real device dimensions for tests.

- Added roundPxValueFromFloat when converting dp/sp to px to deterministically round up values around .5

Fix: 240133465
Bug: 237542518
Test: DeviceProfileTest.kt
Change-Id: If4239f714487fe5bf2ef44274e2ce415bd75c86d
This commit is contained in:
Pat Manning
2022-08-01 17:54:43 +00:00
committed by Alex Chau
parent 8157be497d
commit 5f74bfd76d
23 changed files with 1802 additions and 5914 deletions
+4 -2
View File
@@ -88,6 +88,7 @@ import com.android.launcher3.model.data.SearchActionItemInfo;
import com.android.launcher3.pm.ShortcutConfigActivityInfo;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.testing.shared.ResourceUtils;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
@@ -525,10 +526,11 @@ public final class Utilities {
}
public static int pxFromSp(float size, DisplayMetrics metrics, float scale) {
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
size, metrics) * scale);
float value = scale * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size, metrics);
return ResourceUtils.roundPxValueFromFloat(value);
}
public static String createDbSelectionQuery(String columnName, IntArray values) {
return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, values.toConcatString());
}