Search in sources :

Example 21 with ResTable_config

use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.

the class QualifiersTest method configFrom.

private String configFrom(String path) {
    Path xmlFile = Paths.get(path, "whatever.xml");
    Qualifiers qualifiers = Qualifiers.fromParentDir(xmlFile.getParent());
    ResTable_config config = new XmlContext("package", xmlFile, qualifiers).getConfig();
    return config.toString();
}
Also used : Path(java.nio.file.Path) ResTable_config(org.robolectric.res.android.ResTable_config)

Example 22 with ResTable_config

use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.

the class ShadowArscAssetManager method setConfiguration.

@HiddenApi
@Implementation(minSdk = O)
public void setConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int colorMode, int sdkVersion) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return;
    }
    ResTable_config config = new ResTable_config();
    // memset(&config, 0, sizeof(config));
    // const char* locale8 = locale != NULL ? env->GetStringUTFChars(locale, NULL) : NULL;
    // Constants duplicated from Java class android.content.res.Configuration.
    int kScreenLayoutRoundMask = 0x300;
    int kScreenLayoutRoundShift = 8;
    config.mcc = mcc;
    config.mnc = mnc;
    config.orientation = orientation;
    config.touchscreen = touchscreen;
    config.density = density;
    config.keyboard = keyboard;
    config.inputFlags = keyboardHidden;
    config.navigation = navigation;
    config.screenWidth = screenWidth;
    config.screenHeight = screenHeight;
    config.smallestScreenWidthDp = smallestScreenWidthDp;
    config.screenWidthDp = screenWidthDp;
    config.screenHeightDp = screenHeightDp;
    config.screenLayout = screenLayout;
    config.uiMode = uiMode;
    config.colorMode = (byte) colorMode;
    config.sdkVersion = sdkVersion;
    config.minorVersion = 0;
    // In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer
    // in C++. We must extract the round qualifier out of the Java screenLayout and put it
    // into screenLayout2.
    config.screenLayout2 = (byte) ((screenLayout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift);
    am.setConfiguration(config, locale);
// if (locale != null) env->ReleaseStringUTFChars(locale, locale8);
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 23 with ResTable_config

use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.

the class ShadowArscAssetManager method getConfiguration.

@VisibleForTesting
ResTable_config getConfiguration() {
    final Ref<ResTable_config> config = new Ref<>(new ResTable_config());
    assetManagerForJavaObject().getConfiguration(config);
    return config.get();
}
Also used : Ref(org.robolectric.res.android.Ref) ResTable_config(org.robolectric.res.android.ResTable_config) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 with ResTable_config

use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeSetConfiguration.

// static void NativeSetConfiguration(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint mcc, jint
// mnc,
// jstring locale, jint orientation, jint touchscreen, jint
// density,
// jint keyboard, jint keyboard_hidden, jint navigation,
// jint screen_width, jint screen_height,
// jint smallest_screen_width_dp, jint screen_width_dp,
// jint screen_height_dp, jint screen_layout, jint ui_mode,
// jint color_mode, jint major_version) {
@Implementation(minSdk = P)
protected static void nativeSetConfiguration(long ptr, int mcc, int mnc, @Nullable String locale, int orientation, int touchscreen, int density, int keyboard, int keyboard_hidden, int navigation, int screen_width, int screen_height, int smallest_screen_width_dp, int screen_width_dp, int screen_height_dp, int screen_layout, int ui_mode, int color_mode, int major_version) {
    ATRACE_NAME("AssetManager::SetConfiguration");
    ResTable_config configuration = new ResTable_config();
    // memset(&configuration, 0, sizeof(configuration));
    configuration.mcc = (short) (mcc);
    configuration.mnc = (short) (mnc);
    configuration.orientation = (byte) (orientation);
    configuration.touchscreen = (byte) (touchscreen);
    configuration.density = (short) (density);
    configuration.keyboard = (byte) (keyboard);
    configuration.inputFlags = (byte) (keyboard_hidden);
    configuration.navigation = (byte) (navigation);
    configuration.screenWidth = (short) (screen_width);
    configuration.screenHeight = (short) (screen_height);
    configuration.smallestScreenWidthDp = (short) (smallest_screen_width_dp);
    configuration.screenWidthDp = (short) (screen_width_dp);
    configuration.screenHeightDp = (short) (screen_height_dp);
    configuration.screenLayout = (byte) (screen_layout);
    configuration.uiMode = (byte) (ui_mode);
    configuration.colorMode = (byte) (color_mode);
    configuration.sdkVersion = (short) (major_version);
    if (locale != null) {
        String locale_utf8 = locale;
        CHECK(locale_utf8 != null);
        configuration.setBcp47Locale(locale_utf8);
    }
    // Constants duplicated from Java class android.content.res.Configuration.
    int kScreenLayoutRoundMask = 0x300;
    int kScreenLayoutRoundShift = 8;
    // In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer
    // in C++. We must extract the round qualifier out of the Java screenLayout and put it
    // into screenLayout2.
    configuration.screenLayout2 = (byte) ((screen_layout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift);
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    assetmanager.SetConfiguration(configuration);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResTable_config(org.robolectric.res.android.ResTable_config) Implementation(org.robolectric.annotation.Implementation)

Example 25 with ResTable_config

use of org.robolectric.res.android.ResTable_config in project robolectric by robolectric.

the class ShadowLegacyAssetManager method setConfiguration.

@HiddenApi
@Implementation(minSdk = VERSION_CODES.O)
public void setConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int colorMode, int majorVersion) {
    // AssetManager* am = assetManagerForJavaObject(env, clazz);
    ResTable_config config = new ResTable_config();
    // Constants duplicated from Java class android.content.res.Configuration.
    final int kScreenLayoutRoundMask = 0x300;
    final int kScreenLayoutRoundShift = 8;
    config.mcc = mcc;
    config.mnc = mnc;
    config.orientation = orientation;
    config.touchscreen = touchscreen;
    config.density = density;
    config.keyboard = keyboard;
    config.inputFlags = keyboardHidden;
    config.navigation = navigation;
    config.screenWidth = screenWidth;
    config.screenHeight = screenHeight;
    config.smallestScreenWidthDp = smallestScreenWidthDp;
    config.screenWidthDp = screenWidthDp;
    config.screenHeightDp = screenHeightDp;
    config.screenLayout = screenLayout;
    config.uiMode = uiMode;
    // config.colorMode = colorMode; // todo
    config.sdkVersion = majorVersion;
    config.minorVersion = 0;
    // In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer
    // in C++. We must extract the round qualifier out of the Java screenLayout and put it
    // into screenLayout2.
    config.screenLayout2 = (byte) ((screenLayout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift);
    if (locale != null) {
        config.setBcp47Locale(locale);
    }
    // am->setConfiguration(config, locale8);
    this.config = config;
}
Also used : ResTable_config(org.robolectric.res.android.ResTable_config) SuppressLint(android.annotation.SuppressLint) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

ResTable_config (org.robolectric.res.android.ResTable_config)31 Implementation (org.robolectric.annotation.Implementation)22 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)18 Ref (org.robolectric.res.android.Ref)17 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)16 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)14 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)10 Nullable (android.annotation.Nullable)8 Test (org.junit.Test)5 HiddenApi (org.robolectric.annotation.HiddenApi)4 CppAssetManager (org.robolectric.res.android.CppAssetManager)3 Configuration (android.content.res.Configuration)2 Path (java.nio.file.Path)2 CppApkAssets (org.robolectric.res.android.CppApkAssets)2 Theme (org.robolectric.res.android.CppAssetManager2.Theme)2 ResStringPool (org.robolectric.res.android.ResStringPool)2 ResTable (org.robolectric.res.android.ResTable)2 SuppressLint (android.annotation.SuppressLint)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Locale (java.util.Locale)1