Search in sources :

Example 31 with ResTable_config

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

the class ShadowArscAssetManager10 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)

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