Search in sources :

Example 41 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeGetResourceTypeName.

// static jstring NativeGetResourceTypeName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid)
// {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourceTypeName(long ptr, @AnyRes int resid) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    final ResourceName name = new ResourceName();
    if (!assetmanager.GetResourceName(resid, name)) {
        return null;
    }
    if (name.type != null) {
        return name.type;
    // } else if (name.get().type16 != null) {
    // return name.get().type16; // env.NewString(reinterpret_cast<jchar*>(name.type16),
    // name.type_len);
    }
    return null;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResourceName(org.robolectric.res.android.CppAssetManager2.ResourceName) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 42 with CppAssetManager2

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

the class ShadowArscAssetManager9 method NdkAssetManagerForJavaObject.

// ----------------------------------------------------------------------------
// interface AAssetManager {}
// 
// // Let the opaque type AAssetManager refer to a guarded AssetManager2 instance.
// static class GuardedAssetManager implements AAssetManager {
// CppAssetManager2 guarded_assetmanager = new CppAssetManager2();
// }
static CppAssetManager2 NdkAssetManagerForJavaObject(/* JNIEnv* env,*/
AssetManager jassetmanager) {
    // long assetmanager_handle = env.GetLongField(jassetmanager, gAssetManagerOffsets.mObject);
    long assetmanager_handle = ReflectionHelpers.getField(jassetmanager, "mObject");
    CppAssetManager2 am = Registries.NATIVE_ASSET_MANAGER_REGISTRY.getNativeObject(assetmanager_handle);
    if (am == null) {
        throw new IllegalStateException("AssetManager has been finalized!");
    }
    return am;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2)

Example 43 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeGetAssignedPackageIdentifiers.

// static jobject NativeGetAssignedPackageIdentifiers(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
@Implementation(minSdk = P, maxSdk = Q)
@NonNull
protected static SparseArray<String> nativeGetAssignedPackageIdentifiers(long ptr) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    SparseArray<String> sparse_array = new SparseArray<>();
    if (sparse_array == null) {
        // An exception is pending.
        return null;
    }
    assetmanager.ForEachPackage((String package_name, byte package_id) -> {
        // env.NewStringUTF(package_name);
        String jpackage_name = package_name;
        if (jpackage_name == null) {
            // An exception is pending.
            return;
        }
        // env.CallVoidMethod(sparse_array, gSparseArrayOffsets.put, (int) (package_id),
        // jpackage_name);
        sparse_array.put(package_id, jpackage_name);
    });
    return sparse_array;
}
Also used : SparseArray(android.util.SparseArray) CppAssetManager2(org.robolectric.res.android.CppAssetManager2) NonNull(android.annotation.NonNull) Implementation(org.robolectric.annotation.Implementation)

Example 44 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeGetLocales.

// static jobjectArray NativeGetLocales(JNIEnv* env, jclass /*class*/, jlong ptr,
// jboolean exclude_system) {
@Implementation(minSdk = P)
@Nullable
protected static String[] nativeGetLocales(long ptr, boolean exclude_system) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Set<String> locales = assetmanager.GetResourceLocales(exclude_system, true);
    String[] array = // env.NewObjectArray(locales.size(), g_stringClass, null);
    new String[locales.size()];
    // if (array == null) {
    // return null;
    // }
    int idx = 0;
    for (String locale : locales) {
        String java_string = locale;
        if (java_string == null) {
            return null;
        }
        // env.SetObjectArrayElement(array, idx++, java_string);
        array[idx++] = java_string;
    // env.DeleteLocalRef(java_string);
    }
    return array;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 45 with CppAssetManager2

use of org.robolectric.res.android.CppAssetManager2 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)

Aggregations

CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)66 Implementation (org.robolectric.annotation.Implementation)62 Nullable (android.annotation.Nullable)24 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)20 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)18 ResTable_config (org.robolectric.res.android.ResTable_config)18 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)18 Ref (org.robolectric.res.android.Ref)16 FileNotFoundException (java.io.FileNotFoundException)12 Asset (org.robolectric.res.android.Asset)11 Theme (org.robolectric.res.android.CppAssetManager2.Theme)11 ResourceName (org.robolectric.res.android.CppAssetManager2.ResourceName)8 CppApkAssets (org.robolectric.res.android.CppApkAssets)4 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)4 ResXMLParser (org.robolectric.res.android.ResXMLParser)4 AnyRes (android.annotation.AnyRes)2 AttrRes (android.annotation.AttrRes)2 NonNull (android.annotation.NonNull)2 ApkAssets (android.content.res.ApkAssets)2 Configuration (android.content.res.Configuration)2