/** * Returns a copy of this resource configuration with a different {@link #sdkVersion}, or this * configuration if the {@code sdkVersion} is the same. * * @param sdkVersion The SDK version of the returned configuration. * @return A copy of this configuration with the only difference being #sdkVersion. */ public final ResTable_config withSdkVersion(int sdkVersion) { if (sdkVersion == this.sdkVersion) { return this; } return new ResTable_config(size, mcc, mnc, language, country, orientation, touchscreen, density, keyboard, navigation, inputFlags, screenWidth, screenHeight, sdkVersion, minorVersion, screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp, screenHeightDp, localeScript, localeVariant, screenLayout2, colorMode, screenConfigPad2, unknown); }
result.put(Type.MCC, mcc != 0 ? "mcc" + mcc : ""); result.put(Type.MNC, mnc != 0 ? "mnc" + mnc : ""); result.put(Type.LANGUAGE_STRING, languageString()); result.put(Type.LOCALE_SCRIPT_STRING, localeScriptString()); result.put(Type.REGION_STRING, !regionString().isEmpty() ? "r" + regionString() : ""); result.put(Type.LOCALE_VARIANT_STRING, localeVariantString()); result.put(Type.SCREEN_LAYOUT_DIRECTION, getOrDefault(SCREENLAYOUT_LAYOUTDIR_VALUES, screenLayoutDirection(), "")); result.put(Type.SMALLEST_SCREEN_WIDTH_DP, smallestScreenWidthDp != 0 ? "sw" + smallestScreenWidthDp + "dp" : ""); result.put(Type.SCREEN_HEIGHT_DP, screenHeightDp != 0 ? "h" + screenHeightDp + "dp" : ""); result.put(Type.SCREEN_LAYOUT_SIZE, getOrDefault(SCREENLAYOUT_SIZE_VALUES, screenLayoutSize(), "")); result.put(Type.SCREEN_LAYOUT_LONG, getOrDefault(SCREENLAYOUT_LONG_VALUES, screenLayoutLong(), "")); result.put(Type.SCREEN_LAYOUT_ROUND, getOrDefault(SCREENLAYOUT_ROUND_VALUES, screenLayoutRound(), "")); result.put(Type.COLOR_MODE_HDR, getOrDefault(COLOR_MODE_HDR_VALUES, colorModeHdr(), "")); result.put( Type.COLOR_MODE_WIDE_COLOR_GAMUT, getOrDefault(COLOR_MODE_WIDE_COLOR_GAMUT_VALUES, colorModeWideColorGamut(), "")); result.put(Type.ORIENTATION, getOrDefault(ORIENTATION_VALUES, orientation, "")); result.put(Type.UI_MODE_TYPE, getOrDefault(UI_MODE_TYPE_VALUES, uiModeType(), "")); result.put(Type.UI_MODE_NIGHT, getOrDefault(UI_MODE_NIGHT_VALUES, uiModeNight(), "")); result.put(Type.DENSITY_DPI, getOrDefault(DENSITY_DPI_VALUES, density, density + "dpi")); result.put(Type.TOUCHSCREEN, getOrDefault(TOUCHSCREEN_VALUES, touchscreen, "")); result.put(Type.KEYBOARD_HIDDEN, getOrDefault(KEYBOARDHIDDEN_VALUES, keyboardHidden(), "")); result.put(Type.KEYBOARD, getOrDefault(KEYBOARD_VALUES, keyboard, ""));
ResTable_config config = new ResTable_config(); config.setBcp47Locale(locale);
int resTabSize = resTab.screenLayoutSize(); if (resTabSize != ResTable_config.SCREENSIZE_ANY) { screenLayoutSize = resTabSize; int resTabLong = resTab.screenLayoutLong(); if (resTabLong != ResTable_config.SCREENLONG_ANY) { screenLayoutLong = resTabLong; int resTabLayoutDir = resTab.screenLayoutDirection(); if (resTabLayoutDir != ResTable_config.LAYOUTDIR_ANY) { screenLayoutLayoutDir = resTabLayoutDir; int resTabRound = resTab.screenLayoutRound(); if (resTabRound != ResTable_config.SCREENROUND_ANY) { screenLayoutRound = resTabRound << 8; String lang = resTab.languageString(); String region = resTab.regionString(); String script = resTab.scriptString(); int resTabType = resTab.uiModeType(); if (resTabType != ResTable_config.UI_MODE_TYPE_ANY) { uiModeType = resTabType; int resTabNight = resTab.uiModeNight(); if (resTabNight != ResTable_config.UI_MODE_NIGHT_ANY) { uiModeNight = resTabNight; if (resTab.keyboardHidden() != ResTable_config.KEYSHIDDEN_ANY) {
@Test public void parse_languageAndRegion() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("fr-rFR", config); assertThat(config.languageString()).isEqualTo("fr"); assertThat(config.regionString()).isEqualTo("FR"); }
@Test public void parse_language() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("en", config); assertThat(config.languageString()).isEqualTo("en"); assertThat(config.minorVersion).isEqualTo(0); }
@Test public void getBcp47Locale_shouldReturnCanonicalizedTag() { ResTable_config resTable_config = new ResTable_config(); resTable_config.language[0] = 'j'; resTable_config.language[1] = 'a'; resTable_config.country[0] = 'j'; resTable_config.country[1] = 'p'; assertThat(resTable_config.getBcp47Locale(/* canonicalize= */ true)).isEqualTo("ja-jp"); }
@Test public void testLocale() throws Exception { ResTable_config resTable_config = new ResTable_config(); resTable_config.language[0] = 'e'; resTable_config.language[1] = 'n'; resTable_config.country[0] = 'u'; resTable_config.country[1] = 'k'; assertThat(resTable_config.locale()) .isEqualTo(('e' << 24) | ('n' << 16) | ('u' << 8) | 'k'); }
int resTabSize = resTab.screenLayoutSize(); if (resTabSize != ResTable_config.SCREENSIZE_ANY) { screenLayoutSize = resTabSize; int resTabLong = resTab.screenLayoutLong(); if (resTabLong != ResTable_config.SCREENLONG_ANY) { screenLayoutLong = resTabLong; int resTabLayoutDir = resTab.screenLayoutDirection(); if (resTabLayoutDir != ResTable_config.LAYOUTDIR_ANY) { screenLayoutLayoutDir = resTabLayoutDir; int resTabRound = resTab.screenLayoutRound(); if (resTabRound != ResTable_config.SCREENROUND_ANY) { screenLayoutRound = resTabRound << 8; String lang = resTab.languageString(); String region = resTab.regionString(); String script = resTab.scriptString(); int resTabType = resTab.uiModeType(); if (resTabType != ResTable_config.UI_MODE_TYPE_ANY) { uiModeType = resTabType; int resTabNight = resTab.uiModeNight(); if (resTabNight != ResTable_config.UI_MODE_NIGHT_ANY) { uiModeNight = resTabNight; if (resTab.keyboardHidden() != ResTable_config.KEYSHIDDEN_ANY) {
@Test public void parse_multipleQualifiers() { ResTable_config config = new ResTable_config(); assertThat(ConfigDescription.parse("en-rUS-sw320dp-v7", config)).isTrue(); assertThat(config.languageString()).isEqualTo("en"); assertThat(config.regionString()).isEqualTo("US"); assertThat(config.smallestScreenWidthDp).isEqualTo(320); assertThat(config.sdkVersion).isEqualTo(ConfigDescription.SDK_HONEYCOMB_MR2); }
ATRACE_NAME("AssetManager::SetConfiguration"); ResTable_config configuration = new ResTable_config(); String locale_utf8 = locale; CHECK(locale_utf8 != null); configuration.setBcp47Locale(locale_utf8);
@Test public void getBcp47Locale_philippines_shouldReturnFil() { ResTable_config resTable_config = new ResTable_config(); resTable_config.language[0] = 't'; resTable_config.language[1] = 'l'; resTable_config.country[0] = 'p'; resTable_config.country[1] = 'h'; assertThat(resTable_config.getBcp47Locale(/* canonicalize= */ true)).isEqualTo("fil-ph"); } }
result.put(Type.MCC, mcc != 0 ? "mcc" + mcc : ""); result.put(Type.MNC, mnc != 0 ? "mnc" + mnc : ""); result.put(Type.LANGUAGE_STRING, languageString()); result.put(Type.LOCALE_SCRIPT_STRING, localeScriptString()); result.put(Type.REGION_STRING, !regionString().isEmpty() ? "r" + regionString() : ""); result.put(Type.LOCALE_VARIANT_STRING, localeVariantString()); result.put(Type.SCREEN_LAYOUT_DIRECTION, getOrDefault(SCREENLAYOUT_LAYOUTDIR_VALUES, screenLayoutDirection(), "")); result.put(Type.SMALLEST_SCREEN_WIDTH_DP, smallestScreenWidthDp != 0 ? "sw" + smallestScreenWidthDp + "dp" : ""); result.put(Type.SCREEN_HEIGHT_DP, screenHeightDp != 0 ? "h" + screenHeightDp + "dp" : ""); result.put(Type.SCREEN_LAYOUT_SIZE, getOrDefault(SCREENLAYOUT_SIZE_VALUES, screenLayoutSize(), "")); result.put(Type.SCREEN_LAYOUT_LONG, getOrDefault(SCREENLAYOUT_LONG_VALUES, screenLayoutLong(), "")); result.put(Type.SCREEN_LAYOUT_ROUND, getOrDefault(SCREENLAYOUT_ROUND_VALUES, screenLayoutRound(), "")); result.put(Type.COLOR_MODE_HDR, getOrDefault(COLOR_MODE_HDR_VALUES, colorModeHdr(), "")); result.put( Type.COLOR_MODE_WIDE_COLOR_GAMUT, getOrDefault(COLOR_MODE_WIDE_COLOR_GAMUT_VALUES, colorModeWideColorGamut(), "")); result.put(Type.ORIENTATION, getOrDefault(ORIENTATION_VALUES, orientation, "")); result.put(Type.UI_MODE_TYPE, getOrDefault(UI_MODE_TYPE_VALUES, uiModeType(), "")); result.put(Type.UI_MODE_NIGHT, getOrDefault(UI_MODE_NIGHT_VALUES, uiModeNight(), "")); result.put(Type.DENSITY_DPI, getOrDefault(DENSITY_DPI_VALUES, density, density + "dpi")); result.put(Type.TOUCHSCREEN, getOrDefault(TOUCHSCREEN_VALUES, touchscreen, "")); result.put(Type.KEYBOARD_HIDDEN, getOrDefault(KEYBOARDHIDDEN_VALUES, keyboardHidden(), "")); result.put(Type.KEYBOARD, getOrDefault(KEYBOARD_VALUES, keyboard, ""));
ResTable_config build() { return new ResTable_config(0, mcc, mnc, language, region, orientation, touchscreen, density, keyboard, navigation, inputFlags, screenWidth, screenHeight, sdkVersion, minorVersion, screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp, screenHeightDp, localeScript, localeVariant, screenLayout2, screenConfigPad1, screenConfigPad2, null ); }
ResTable_config config = new ResTable_config(); config.setBcp47Locale(locale);
public static Qualifiers parse(String qualifiers, boolean applyVersionForCompat) { final ResTable_config config = new ResTable_config(); if (!qualifiers.isEmpty() && !ConfigDescription.parse(qualifiers, config, applyVersionForCompat)) { throw new IllegalArgumentException("failed to parse qualifiers '" + qualifiers + "'." + " See https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules for expected format."); } return new Qualifiers(qualifiers, config); }
ATRACE_NAME("AssetManager::SetConfiguration"); ResTable_config configuration = new ResTable_config(); String locale_utf8 = locale; CHECK(locale_utf8 != null); configuration.setBcp47Locale(locale_utf8);
@VisibleForTesting ResTable_config getConfiguration() { final Ref<ResTable_config> config = new Ref<>(new ResTable_config()); assetManagerForJavaObject().getConfiguration(config); return config.get(); }
private static ResTable_config from(String qualifiers) { ResTable_config config = new ResTable_config(); if (!Strings.isNullOrEmpty(qualifiers) && !ConfigDescription.parse(qualifiers, config, false)) { throw new IllegalArgumentException("Invalid qualifiers \"" + qualifiers + "\""); } return config; } }
buffer.get(unknown); return new ResTable_config(size, mcc, mnc, language, region, orientation, touchscreen, density, keyboard, navigation, inputFlags, screenWidth, screenHeight, sdkVersion, minorVersion, screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp,