diff options
author | Christian Williams <christianw@google.com> | 2017-11-08 17:10:38 -0800 |
---|---|---|
committer | Christian Williams <christianw@google.com> | 2017-11-08 17:10:38 -0800 |
commit | 70813a3ee209ad0043a461a64c8ac495c372b83b (patch) | |
tree | 9329aa48fd8f63df15ee20f9cd1f454e59a39f17 | |
parent | 4a11caf182f86aa6f6363715e4f6071b5c352369 (diff) | |
download | robolectric-shadows-70813a3ee209ad0043a461a64c8ac495c372b83b.tar.gz |
Provide defaults for more device configuration.
Size normal, notlong, notround, port, notnight, finge.
4 files changed, 64 insertions, 11 deletions
diff --git a/resources/src/main/java/org/robolectric/res/android/ResTable_config.java b/resources/src/main/java/org/robolectric/res/android/ResTable_config.java index f0915ff5e..f5cbbe9ce 100644 --- a/resources/src/main/java/org/robolectric/res/android/ResTable_config.java +++ b/resources/src/main/java/org/robolectric/res/android/ResTable_config.java @@ -218,7 +218,7 @@ public class ResTable_config { // public static final int MASK_SCREENSIZE = 0x0f; public static final int SCREENSIZE_ANY = ACONFIGURATION_SCREENSIZE_ANY; public static final int SCREENSIZE_SMALL = ACONFIGURATION_SCREENSIZE_SMALL; -// public static final int SCREENSIZE_NORMAL = ACONFIGURATION_SCREENSIZE_NORMAL; + public static final int SCREENSIZE_NORMAL = ACONFIGURATION_SCREENSIZE_NORMAL; public static final int SCREENSIZE_LARGE = ACONFIGURATION_SCREENSIZE_LARGE; public static final int SCREENSIZE_XLARGE = ACONFIGURATION_SCREENSIZE_XLARGE; @@ -517,16 +517,32 @@ public class ResTable_config { return screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK; } + public final void screenLayoutDirection(int value) { + screenLayout = (byte) ((screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | value); + } + public final int screenLayoutSize() { return screenLayout & SCREENLAYOUT_SIZE_MASK; } + public final void screenLayoutSize(int value) { + screenLayout = (byte) ((screenLayout & ~SCREENLAYOUT_SIZE_MASK) | value); + } + public final int screenLayoutLong() { return screenLayout & SCREENLAYOUT_LONG_MASK; } + public final void screenLayoutLong(int value) { + screenLayout = (byte) ((screenLayout & ~SCREENLAYOUT_LONG_MASK) | value); + } + public final int screenLayoutRound() { - return screenLayout & SCREENLAYOUT_ROUND_MASK; + return screenLayout2 & MASK_SCREENROUND; + } + + public final void screenLayoutRound(int value) { + screenLayout2 = (byte) ((screenLayout2 & ~MASK_SCREENROUND) | value); } public int colorMode; @@ -537,10 +553,18 @@ public class ResTable_config { return uiMode & UI_MODE_TYPE_MASK; } + public final void uiModeType(int value) { + uiMode = (uiMode & ~UI_MODE_TYPE_MASK) | value; + } + public final int uiModeNight() { return uiMode & UI_MODE_NIGHT_MASK; } + public final void uiModeNight(int value) { + uiMode = (uiMode & ~UI_MODE_NIGHT_MASK) | value; + } + public int smallestScreenWidthDp; public int screenWidthDp; public int screenHeightDp; @@ -865,7 +889,6 @@ public class ResTable_config { // constants for isBetterThan... public static final int MASK_LAYOUTDIR = SCREENLAYOUT_LAYOUTDIR_MASK; static final int MASK_SCREENSIZE = SCREENLAYOUT_SIZE_MASK; - static final int SCREENSIZE_NORMAL = ACONFIGURATION_SCREENSIZE_NORMAL; diff --git a/robolectric/src/test/java/org/robolectric/android/BootstrapTest.java b/robolectric/src/test/java/org/robolectric/android/BootstrapTest.java index ea729bc12..329c55b81 100644 --- a/robolectric/src/test/java/org/robolectric/android/BootstrapTest.java +++ b/robolectric/src/test/java/org/robolectric/android/BootstrapTest.java @@ -9,22 +9,28 @@ import static android.content.res.Configuration.NAVIGATIONHIDDEN_YES; import static android.content.res.Configuration.NAVIGATION_DPAD; import static android.content.res.Configuration.NAVIGATION_UNDEFINED; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; +import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_UNDEFINED; import static android.content.res.Configuration.SCREENLAYOUT_LAYOUTDIR_LTR; import static android.content.res.Configuration.SCREENLAYOUT_LAYOUTDIR_MASK; import static android.content.res.Configuration.SCREENLAYOUT_LAYOUTDIR_RTL; import static android.content.res.Configuration.SCREENLAYOUT_LONG_MASK; +import static android.content.res.Configuration.SCREENLAYOUT_LONG_NO; import static android.content.res.Configuration.SCREENLAYOUT_LONG_UNDEFINED; import static android.content.res.Configuration.SCREENLAYOUT_LONG_YES; import static android.content.res.Configuration.SCREENLAYOUT_ROUND_MASK; +import static android.content.res.Configuration.SCREENLAYOUT_ROUND_NO; import static android.content.res.Configuration.SCREENLAYOUT_ROUND_UNDEFINED; import static android.content.res.Configuration.SCREENLAYOUT_ROUND_YES; import static android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK; +import static android.content.res.Configuration.SCREENLAYOUT_SIZE_NORMAL; import static android.content.res.Configuration.SCREENLAYOUT_SIZE_UNDEFINED; import static android.content.res.Configuration.SCREENLAYOUT_SIZE_XLARGE; +import static android.content.res.Configuration.TOUCHSCREEN_FINGER; import static android.content.res.Configuration.TOUCHSCREEN_NOTOUCH; import static android.content.res.Configuration.TOUCHSCREEN_UNDEFINED; import static android.content.res.Configuration.UI_MODE_NIGHT_MASK; +import static android.content.res.Configuration.UI_MODE_NIGHT_NO; import static android.content.res.Configuration.UI_MODE_NIGHT_UNDEFINED; import static android.content.res.Configuration.UI_MODE_NIGHT_YES; import static android.content.res.Configuration.UI_MODE_TYPE_APPLIANCE; @@ -63,7 +69,7 @@ public class BootstrapTest { String outQualifiers = Bootstrap.applyQualifiers("", RuntimeEnvironment.getApiLevel(), configuration, displayMetrics); - assertThat(outQualifiers).isEqualTo("sw320dp-w320dp-mdpi-v" + RuntimeEnvironment.getApiLevel()); + assertThat(outQualifiers).isEqualTo("sw320dp-w320dp-normal-notlong-notround-port-notnight-mdpi-finger-v" + RuntimeEnvironment.getApiLevel()); assertThat(configuration.mcc).isEqualTo(0); assertThat(configuration.mnc).isEqualTo(0); @@ -71,12 +77,12 @@ public class BootstrapTest { assertThat(configuration.smallestScreenWidthDp).isEqualTo(320); assertThat(configuration.screenWidthDp).isEqualTo(320); assertThat(configuration.screenHeightDp).isEqualTo(0); - assertThat(configuration.screenLayout & SCREENLAYOUT_SIZE_MASK).isEqualTo(SCREENLAYOUT_SIZE_UNDEFINED); - assertThat(configuration.screenLayout & SCREENLAYOUT_LONG_MASK).isEqualTo(SCREENLAYOUT_LONG_UNDEFINED); - assertThat(configuration.screenLayout & SCREENLAYOUT_ROUND_MASK).isEqualTo(SCREENLAYOUT_ROUND_UNDEFINED); - assertThat(configuration.orientation).isEqualTo(ORIENTATION_UNDEFINED); + assertThat(configuration.screenLayout & SCREENLAYOUT_SIZE_MASK).isEqualTo(SCREENLAYOUT_SIZE_NORMAL); + assertThat(configuration.screenLayout & SCREENLAYOUT_LONG_MASK).isEqualTo(SCREENLAYOUT_LONG_NO); + assertThat(configuration.screenLayout & SCREENLAYOUT_ROUND_MASK).isEqualTo(SCREENLAYOUT_ROUND_NO); + assertThat(configuration.orientation).isEqualTo(ORIENTATION_PORTRAIT); assertThat(configuration.uiMode & UI_MODE_TYPE_MASK).isEqualTo(UI_MODE_TYPE_UNDEFINED); - assertThat(configuration.uiMode & UI_MODE_NIGHT_MASK).isEqualTo(UI_MODE_NIGHT_UNDEFINED); + assertThat(configuration.uiMode & UI_MODE_NIGHT_MASK).isEqualTo(UI_MODE_NIGHT_NO); if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.JELLY_BEAN) { assertThat(configuration.densityDpi).isEqualTo(DisplayMetrics.DENSITY_DEFAULT); @@ -85,7 +91,7 @@ public class BootstrapTest { assertThat(displayMetrics.density).isEqualTo(1.0f); } - assertThat(configuration.touchscreen).isEqualTo(TOUCHSCREEN_UNDEFINED); + assertThat(configuration.touchscreen).isEqualTo(TOUCHSCREEN_FINGER); assertThat(configuration.keyboardHidden).isEqualTo(KEYBOARDHIDDEN_UNDEFINED); assertThat(configuration.keyboard).isEqualTo(KEYBOARD_UNDEFINED); assertThat(configuration.navigationHidden).isEqualTo(NAVIGATIONHIDDEN_UNDEFINED); diff --git a/robolectric/src/test/java/org/robolectric/android/DrawableResourceLoaderTest.java b/robolectric/src/test/java/org/robolectric/android/DrawableResourceLoaderTest.java index 76914d11b..ffd3ceec1 100644 --- a/robolectric/src/test/java/org/robolectric/android/DrawableResourceLoaderTest.java +++ b/robolectric/src/test/java/org/robolectric/android/DrawableResourceLoaderTest.java @@ -38,7 +38,7 @@ public class DrawableResourceLoaderTest { } @Test - public void testGetDrawable_shouldWorkWithSystem() throws Exception { + public void testGetDrawablBundlee_shouldWorkWithSystem() throws Exception { assertNotNull(resources.getDrawable(android.R.drawable.ic_popup_sync)); } diff --git a/shadows/framework/src/main/java/org/robolectric/android/Bootstrap.java b/shadows/framework/src/main/java/org/robolectric/android/Bootstrap.java index f498b29a3..a9740d3a5 100644 --- a/shadows/framework/src/main/java/org/robolectric/android/Bootstrap.java +++ b/shadows/framework/src/main/java/org/robolectric/android/Bootstrap.java @@ -38,6 +38,26 @@ public class Bootstrap { resTab.screenWidthDp = 320; } + if (resTab.screenLayoutSize() == ResTable_config.SCREENSIZE_ANY) { + resTab.screenLayoutSize(ResTable_config.SCREENSIZE_NORMAL); + } + + if (resTab.screenLayoutLong() == ResTable_config.SCREENLONG_ANY) { + resTab.screenLayoutLong(ResTable_config.SCREENLONG_NO); + } + + if (resTab.screenLayoutRound() == ResTable_config.SCREENROUND_ANY) { + resTab.screenLayoutRound(ResTable_config.SCREENROUND_NO); + } + + if (resTab.orientation == ResTable_config.ORIENTATION_ANY) { + resTab.orientation = ResTable_config.ORIENTATION_PORT; + } + + if (resTab.uiModeNight() == ResTable_config.UI_MODE_NIGHT_ANY) { + resTab.uiModeNight(ResTable_config.UI_MODE_NIGHT_NO); + } + switch (resTab.density) { case Configuration.DENSITY_DPI_ANY: throw new IllegalArgumentException("'anydpi' isn't actually a dpi"); @@ -47,6 +67,10 @@ public class Bootstrap { resTab.density = DisplayMetrics.DENSITY_DEFAULT; } + if (resTab.touchscreen == ResTable_config.TOUCHSCREEN_ANY) { + resTab.touchscreen = ResTable_config.TOUCHSCREEN_FINGER; + } + configuration.smallestScreenWidthDp = resTab.smallestScreenWidthDp; configuration.screenWidthDp = resTab.screenWidthDp; configuration.orientation = resTab.orientation; |