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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations