Loading core/java/android/content/res/Configuration.java +18 −1 Original line number Diff line number Diff line Loading @@ -532,6 +532,18 @@ public final class Configuration implements Parcelable, Comparable<Configuration */ public static final int DENSITY_DPI_UNDEFINED = 0; /** * Value for {@link #densityDpi} for resources that scale to any density (vector drawables). * {@hide} */ public static final int DENSITY_DPI_ANY = 0xfffe; /** * Value for {@link #densityDpi} for resources that are not meant to be scaled. * {@hide} */ public static final int DENSITY_DPI_NONE = 0xffff; /** * The target screen density being rendered to, * corresponding to Loading Loading @@ -1453,7 +1465,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration } switch (config.densityDpi) { case 0: case DENSITY_DPI_UNDEFINED: break; case 120: parts.add("ldpi"); Loading @@ -1476,6 +1488,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration case 640: parts.add("xxxhdpi"); break; case DENSITY_DPI_ANY: parts.add("anydpi"); break; case DENSITY_DPI_NONE: parts.add("nodpi"); default: parts.add(config.densityDpi + "dpi"); break; Loading include/androidfw/ResourceTypes.h +1 −0 Original line number Diff line number Diff line Loading @@ -954,6 +954,7 @@ struct ResTable_config DENSITY_XHIGH = ACONFIGURATION_DENSITY_XHIGH, DENSITY_XXHIGH = ACONFIGURATION_DENSITY_XXHIGH, DENSITY_XXXHIGH = ACONFIGURATION_DENSITY_XXXHIGH, DENSITY_ANY = ACONFIGURATION_DENSITY_ANY, DENSITY_NONE = ACONFIGURATION_DENSITY_NONE }; Loading libs/androidfw/ResourceTypes.cpp +28 −9 Original line number Diff line number Diff line Loading @@ -2206,13 +2206,30 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, if (screenType || o.screenType) { if (density != o.density) { // density is tough. Any density is potentially useful // Use the system default density (DENSITY_MEDIUM, 160dpi) if none specified. const int thisDensity = density ? density : int(ResTable_config::DENSITY_MEDIUM); const int otherDensity = o.density ? o.density : int(ResTable_config::DENSITY_MEDIUM); // We always prefer DENSITY_ANY over scaling a density bucket. if (thisDensity == ResTable_config::DENSITY_ANY) { return true; } else if (otherDensity == ResTable_config::DENSITY_ANY) { return false; } int requestedDensity = requested->density; if (requested->density == 0 || requested->density == ResTable_config::DENSITY_ANY) { requestedDensity = ResTable_config::DENSITY_MEDIUM; } // DENSITY_ANY is now dealt with. We should look to // pick a density bucket and potentially scale it. // Any density is potentially useful // because the system will scale it. Scaling down // is generally better than scaling up. // Default density counts as 160dpi (the system default) // TODO - remove 160 constants int h = (density?density:160); int l = (o.density?o.density:160); int h = thisDensity; int l = otherDensity; bool bImBigger = true; if (l > h) { int t = h; Loading @@ -2221,17 +2238,16 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, bImBigger = false; } int reqValue = (requested->density?requested->density:160); if (reqValue >= h) { if (requestedDensity >= h) { // requested value higher than both l and h, give h return bImBigger; } if (l >= reqValue) { if (l >= requestedDensity) { // requested value lower than both l and h, give l return !bImBigger; } // saying that scaling down is 2x better than up if (((2 * l) - reqValue) * h > reqValue * reqValue) { if (((2 * l) - requestedDensity) * h > requestedDensity * requestedDensity) { return !bImBigger; } else { return bImBigger; Loading Loading @@ -2702,6 +2718,9 @@ String8 ResTable_config::toString() const { case ResTable_config::DENSITY_NONE: res.append("nodpi"); break; case ResTable_config::DENSITY_ANY: res.append("anydpi"); break; default: res.appendFormat("%ddpi", dtohs(density)); break; Loading libs/androidfw/tests/Android.mk +2 −1 Original line number Diff line number Diff line Loading @@ -21,8 +21,9 @@ LOCAL_PATH:= $(call my-dir) testFiles := \ ByteBucketArray_test.cpp \ Config_test.cpp \ ConfigLocale_test.cpp \ Idmap_test.cpp \ ResourceTypes_test.cpp \ ResTable_test.cpp \ Split_test.cpp \ TypeWrappers_test.cpp \ Loading libs/androidfw/tests/ResourceTypes_test.cpp→libs/androidfw/tests/ConfigLocale_test.cpp +9 −9 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ #include <gtest/gtest.h> namespace android { TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterLanguage) { TEST(ConfigLocaleTest, packAndUnpack2LetterLanguage) { ResTable_config config; config.packLanguage("en"); Loading @@ -44,7 +44,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterLanguage) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterRegion) { TEST(ConfigLocaleTest, packAndUnpack2LetterRegion) { ResTable_config config; config.packRegion("US"); Loading @@ -59,7 +59,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterRegion) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguage) { TEST(ConfigLocaleTest, packAndUnpack3LetterLanguage) { ResTable_config config; config.packLanguage("eng"); Loading @@ -75,7 +75,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguage) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) { TEST(ConfigLocaleTest, packAndUnpack3LetterLanguageAtOffset16) { ResTable_config config; config.packLanguage("tgp"); Loading @@ -88,8 +88,8 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) { // which is equivalent to: // 1 [0] [1] [2] // 1-01111-00110-10011 EXPECT_EQ(0xbc, config.language[0]); EXPECT_EQ(0xd3, config.language[1]); EXPECT_EQ(char(0xbc), config.language[0]); EXPECT_EQ(char(0xd3), config.language[1]); char out[4] = { 1, 1, 1, 1}; config.unpackLanguage(out); Loading @@ -99,7 +99,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterRegion) { TEST(ConfigLocaleTest, packAndUnpack3LetterRegion) { ResTable_config config; config.packRegion("419"); Loading Loading @@ -131,7 +131,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterRegion) { } } TEST(ResourceTypesTest, IsMoreSpecificThan) { TEST(ConfigLocaleTest, IsMoreSpecificThan) { ResTable_config l; ResTable_config r; Loading Loading @@ -170,7 +170,7 @@ TEST(ResourceTypesTest, IsMoreSpecificThan) { EXPECT_TRUE(r.isMoreSpecificThan(l)); } TEST(ResourceTypesTest, setLocale) { TEST(ConfigLocaleTest, setLocale) { ResTable_config test; test.setBcp47Locale("en-US"); EXPECT_EQ('e', test.language[0]); Loading Loading
core/java/android/content/res/Configuration.java +18 −1 Original line number Diff line number Diff line Loading @@ -532,6 +532,18 @@ public final class Configuration implements Parcelable, Comparable<Configuration */ public static final int DENSITY_DPI_UNDEFINED = 0; /** * Value for {@link #densityDpi} for resources that scale to any density (vector drawables). * {@hide} */ public static final int DENSITY_DPI_ANY = 0xfffe; /** * Value for {@link #densityDpi} for resources that are not meant to be scaled. * {@hide} */ public static final int DENSITY_DPI_NONE = 0xffff; /** * The target screen density being rendered to, * corresponding to Loading Loading @@ -1453,7 +1465,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration } switch (config.densityDpi) { case 0: case DENSITY_DPI_UNDEFINED: break; case 120: parts.add("ldpi"); Loading @@ -1476,6 +1488,11 @@ public final class Configuration implements Parcelable, Comparable<Configuration case 640: parts.add("xxxhdpi"); break; case DENSITY_DPI_ANY: parts.add("anydpi"); break; case DENSITY_DPI_NONE: parts.add("nodpi"); default: parts.add(config.densityDpi + "dpi"); break; Loading
include/androidfw/ResourceTypes.h +1 −0 Original line number Diff line number Diff line Loading @@ -954,6 +954,7 @@ struct ResTable_config DENSITY_XHIGH = ACONFIGURATION_DENSITY_XHIGH, DENSITY_XXHIGH = ACONFIGURATION_DENSITY_XXHIGH, DENSITY_XXXHIGH = ACONFIGURATION_DENSITY_XXXHIGH, DENSITY_ANY = ACONFIGURATION_DENSITY_ANY, DENSITY_NONE = ACONFIGURATION_DENSITY_NONE }; Loading
libs/androidfw/ResourceTypes.cpp +28 −9 Original line number Diff line number Diff line Loading @@ -2206,13 +2206,30 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, if (screenType || o.screenType) { if (density != o.density) { // density is tough. Any density is potentially useful // Use the system default density (DENSITY_MEDIUM, 160dpi) if none specified. const int thisDensity = density ? density : int(ResTable_config::DENSITY_MEDIUM); const int otherDensity = o.density ? o.density : int(ResTable_config::DENSITY_MEDIUM); // We always prefer DENSITY_ANY over scaling a density bucket. if (thisDensity == ResTable_config::DENSITY_ANY) { return true; } else if (otherDensity == ResTable_config::DENSITY_ANY) { return false; } int requestedDensity = requested->density; if (requested->density == 0 || requested->density == ResTable_config::DENSITY_ANY) { requestedDensity = ResTable_config::DENSITY_MEDIUM; } // DENSITY_ANY is now dealt with. We should look to // pick a density bucket and potentially scale it. // Any density is potentially useful // because the system will scale it. Scaling down // is generally better than scaling up. // Default density counts as 160dpi (the system default) // TODO - remove 160 constants int h = (density?density:160); int l = (o.density?o.density:160); int h = thisDensity; int l = otherDensity; bool bImBigger = true; if (l > h) { int t = h; Loading @@ -2221,17 +2238,16 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, bImBigger = false; } int reqValue = (requested->density?requested->density:160); if (reqValue >= h) { if (requestedDensity >= h) { // requested value higher than both l and h, give h return bImBigger; } if (l >= reqValue) { if (l >= requestedDensity) { // requested value lower than both l and h, give l return !bImBigger; } // saying that scaling down is 2x better than up if (((2 * l) - reqValue) * h > reqValue * reqValue) { if (((2 * l) - requestedDensity) * h > requestedDensity * requestedDensity) { return !bImBigger; } else { return bImBigger; Loading Loading @@ -2702,6 +2718,9 @@ String8 ResTable_config::toString() const { case ResTable_config::DENSITY_NONE: res.append("nodpi"); break; case ResTable_config::DENSITY_ANY: res.append("anydpi"); break; default: res.appendFormat("%ddpi", dtohs(density)); break; Loading
libs/androidfw/tests/Android.mk +2 −1 Original line number Diff line number Diff line Loading @@ -21,8 +21,9 @@ LOCAL_PATH:= $(call my-dir) testFiles := \ ByteBucketArray_test.cpp \ Config_test.cpp \ ConfigLocale_test.cpp \ Idmap_test.cpp \ ResourceTypes_test.cpp \ ResTable_test.cpp \ Split_test.cpp \ TypeWrappers_test.cpp \ Loading
libs/androidfw/tests/ResourceTypes_test.cpp→libs/androidfw/tests/ConfigLocale_test.cpp +9 −9 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ #include <gtest/gtest.h> namespace android { TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterLanguage) { TEST(ConfigLocaleTest, packAndUnpack2LetterLanguage) { ResTable_config config; config.packLanguage("en"); Loading @@ -44,7 +44,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterLanguage) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterRegion) { TEST(ConfigLocaleTest, packAndUnpack2LetterRegion) { ResTable_config config; config.packRegion("US"); Loading @@ -59,7 +59,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack2LetterRegion) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguage) { TEST(ConfigLocaleTest, packAndUnpack3LetterLanguage) { ResTable_config config; config.packLanguage("eng"); Loading @@ -75,7 +75,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguage) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) { TEST(ConfigLocaleTest, packAndUnpack3LetterLanguageAtOffset16) { ResTable_config config; config.packLanguage("tgp"); Loading @@ -88,8 +88,8 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) { // which is equivalent to: // 1 [0] [1] [2] // 1-01111-00110-10011 EXPECT_EQ(0xbc, config.language[0]); EXPECT_EQ(0xd3, config.language[1]); EXPECT_EQ(char(0xbc), config.language[0]); EXPECT_EQ(char(0xd3), config.language[1]); char out[4] = { 1, 1, 1, 1}; config.unpackLanguage(out); Loading @@ -99,7 +99,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterLanguageAtOffset16) { EXPECT_EQ(0, out[3]); } TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterRegion) { TEST(ConfigLocaleTest, packAndUnpack3LetterRegion) { ResTable_config config; config.packRegion("419"); Loading Loading @@ -131,7 +131,7 @@ TEST(ResourceTypesTest, ResourceConfig_packAndUnpack3LetterRegion) { } } TEST(ResourceTypesTest, IsMoreSpecificThan) { TEST(ConfigLocaleTest, IsMoreSpecificThan) { ResTable_config l; ResTable_config r; Loading Loading @@ -170,7 +170,7 @@ TEST(ResourceTypesTest, IsMoreSpecificThan) { EXPECT_TRUE(r.isMoreSpecificThan(l)); } TEST(ResourceTypesTest, setLocale) { TEST(ConfigLocaleTest, setLocale) { ResTable_config test; test.setBcp47Locale("en-US"); EXPECT_EQ('e', test.language[0]); Loading