use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 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;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeThemeCopy.
// static void NativeThemeCopy(JNIEnv* env, jclass /*clazz*/, jlong dst_asset_manager_ptr,
// jlong dst_theme_ptr, jlong src_asset_manager_ptr, jlong src_theme_ptr) {
@Implementation(minSdk = Q)
protected static void nativeThemeCopy(long dst_asset_manager_ptr, long dst_theme_ptr, long src_asset_manager_ptr, long src_theme_ptr) {
Theme dst_theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(dst_theme_ptr);
Theme src_theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(src_theme_ptr);
if (dst_asset_manager_ptr != src_asset_manager_ptr) {
CppAssetManager2 dst_assetmanager = AssetManagerFromLong(dst_asset_manager_ptr);
CHECK(dst_theme.GetAssetManager() == dst_assetmanager);
// (void) dst_assetmanager;
CppAssetManager2 src_assetmanager = AssetManagerFromLong(src_asset_manager_ptr);
CHECK(src_theme.GetAssetManager() == src_assetmanager);
// (void) src_assetmanager;
dst_theme.SetTo(src_theme);
} else {
dst_theme.SetTo(src_theme);
}
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeThemeGetAttributeValue.
// static jint NativeThemeGetAttributeValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong
// theme_ptr,
// jint resid, jobject typed_value,
// jboolean resolve_references) {
@Implementation(minSdk = P)
protected static int nativeThemeGetAttributeValue(long ptr, long theme_ptr, @AttrRes int resid, @NonNull TypedValue typed_value, boolean resolve_references) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
CHECK(theme.GetAssetManager() == assetmanager);
// (void) assetmanager; // huh?
final Ref<Res_value> value = new Ref<>(null);
final Ref<Integer> flags = new Ref<>(null);
ApkAssetsCookie cookie = theme.GetAttribute(resid, value, flags);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
final Ref<Integer> ref = new Ref<>(0);
if (resolve_references) {
final Ref<ResTable_config> selected_config = new Ref<>(null);
cookie = theme.GetAssetManager().ResolveReference(cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
}
}
return CopyValue(cookie, value.get(), ref.get(), flags.get(), null, typed_value);
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeResolveAttrs.
// static jboolean NativeResolveAttrs(JNIEnv* env, jclass /*clazz*/, jlong ptr, jlong theme_ptr,
// jint def_style_attr, jint def_style_resid, jintArray
// java_values,
// jintArray java_attrs, jintArray out_java_values,
// jintArray out_java_indices) {
@Implementation(minSdk = P)
protected static boolean nativeResolveAttrs(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, @Nullable int[] java_values, @NonNull int[] java_attrs, @NonNull int[] out_java_values, @NonNull int[] out_java_indices) {
int attrs_len = java_attrs.length;
int out_values_len = out_java_values.length;
if (out_values_len < (attrs_len * STYLE_NUM_ENTRIES)) {
throw new IndexOutOfBoundsException("outValues too small");
}
int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
java_attrs;
if (attrs == null) {
return JNI_FALSE;
}
int[] values = null;
int values_len = 0;
if (java_values != null) {
values_len = java_values.length;
values = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_values, null));
java_values;
if (values == null) {
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
return JNI_FALSE;
}
}
int[] out_values = out_java_values;
// reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_values, null));
if (out_values == null) {
// }
return JNI_FALSE;
}
int[] out_indices = null;
if (out_java_indices != null) {
int out_indices_len = out_java_indices.length;
if (out_indices_len > attrs_len) {
out_indices = out_java_indices;
// reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_java_indices, null));
if (out_indices == null) {
// env.ReleasePrimitiveArrayCritical(out_java_values, out_values, JNI_ABORT);
return JNI_FALSE;
}
}
}
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
CHECK(theme.GetAssetManager() == assetmanager);
// (void) assetmanager;
boolean result = ResolveAttrs(theme, (int) (def_style_attr), (int) (def_style_resid), values, values_len, attrs, attrs_len, out_values, out_indices);
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
return result ? JNI_TRUE : JNI_FALSE;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetResourceName.
// static jstring NativeGetResourceName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid) {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourceName(long ptr, @AnyRes int resid) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
CppAssetManager2.ResourceName name = new ResourceName();
if (!assetmanager.GetResourceName(resid, name)) {
return null;
}
StringBuilder result = new StringBuilder();
if (name.package_ != null) {
result.append(name.package_);
}
if (name.type != null) /*|| name.type16 != null*/
{
if (!(result.length() == 0)) {
result.append(":");
}
// if (name.type != null) {
result.append(name.type);
// } else {
// result.append( /*util.Utf16ToUtf8(StringPiece16(*/ name.type16 /*, name.type_len))*/);
// }
}
if (name.entry != null) /*|| name.entry16 != null*/
{
if (!(result.length() == 0)) {
result.append("/");
}
// if (name.entry != null) {
result.append(name.entry);
// } else {
// result.append( /*util.Utf16ToUtf8(StringPiece16(*/ name.entry16 /*, name.entry_len)*/);
// }
}
return result.toString();
}
Aggregations