X-Git-Url: http://nitlanguage.org diff --git a/lib/android/assets_and_resources.nit b/lib/android/assets_and_resources.nit index 897938a..40dace2 100644 --- a/lib/android/assets_and_resources.nit +++ b/lib/android/assets_and_resources.nit @@ -121,7 +121,7 @@ end class AssetManager # Native asset manager - private var native_assets_manager: NativeAssetManager = app.native_activity.assets.new_global_ref is lazy + private var native_assets_manager: NativeAssetManager = app.native_context.assets.new_global_ref is lazy # Close this asset manager fun close do native_assets_manager.close @@ -138,7 +138,7 @@ class AssetManager # Return a string array of all the assets at the given path fun list(path: String): Array[String] do - sys.jni_env.push_local_frame(1) + sys.jni_env.push_local_frame(8) var java_array = native_assets_manager.list(path.to_java_string) var nit_array = new Array[String] for s in java_array do @@ -150,16 +150,15 @@ class AssetManager # Open an asset using ACCESS_STREAMING mode, returning a NativeInputStream private fun open(file_name: String): NativeInputStream do - sys.jni_env.push_local_frame(1) + sys.jni_env.push_local_frame(2) var return_value = native_assets_manager.open(file_name.to_java_string) - sys.jni_env.pop_local_frame - return return_value + return return_value.pop_from_local_frame end # Open an asset using it's name and returning a NativeAssetFileDescriptor # `file_name` is private fun open_fd(file_name: String): NativeAssetFileDescriptor do - sys.jni_env.push_local_frame(1) + sys.jni_env.push_local_frame(2) var return_value = native_assets_manager.open_fd(file_name.to_java_string).new_global_ref sys.jni_env.pop_local_frame return return_value @@ -218,8 +217,7 @@ class ResourcesManager private init native(res: NativeResources, app_package: String) do - self.android_resources = res.new_global_ref - self.app_package = app_package + init(res.new_global_ref, app_package) end # Get a color from resources @@ -304,9 +302,31 @@ private extern class NativeBitmap in "Java" `{ android.graphics.Bitmap `} # Create a NativeBitmap using a resource ID and the NativeResources # Called by the ResourceManager new from_resources(res: NativeResources, id: Int) in "Java" `{ return BitmapFactory.decodeResource(res, (int)id); `} + + # Width in pixels + # + # Wraps Java: `int android.graphics.Bitmap.getWidth()` fun width: Int in "Java" `{ return self.getWidth(); `} + + # Height in pixels + # + # Wraps Java: `int android.graphics.Bitmap.getHeight()` fun height: Int in "Java" `{ return self.getHeight(); `} + # Number of bytes per row + # + # Wraps Java: `int android.graphics.Bitmap.getRowBytes()` + fun row_bytes: Int in "Java" `{ + return self.getRowBytes(); + `} + + # Does this bitmap has an alpha channel? + # + # Wraps Java: `boolean android.graphics.Bitmap.hasAlpha()` + fun has_alpha: Bool in "Java" `{ + return self.hasAlpha(); + `} + # HACK for bug #845 redef fun new_global_ref import sys, Sys.jni_env `{ Sys sys = NativeBitmap_sys(self); @@ -314,6 +334,9 @@ private extern class NativeBitmap in "Java" `{ android.graphics.Bitmap `} return (*env)->NewGlobalRef(env, self); `} + redef fun pop_from_local_frame_with_env(jni_env) `{ + return (*jni_env)->PopLocalFrame(jni_env, self); + `} end # Android AssetFileDescriptor, can be retrieve by AssetManager and used to load a sound in a SoundPool @@ -349,7 +372,7 @@ extern class NativeAssetFileDescriptor in "Java" `{ android.content.res.AssetFil fun declared_length: Int in "Java" `{ return (int)self.getDeclaredLength(); `} # fun extras: Bundle in "Java" `{ return self.getExtras(); `} - fun file_descriptor: NativeFileDescriptor in "Java" `{ + fun file_descriptor: NativeFileDescriptor in "Java" `{ FileDescriptor fd = self.getFileDescriptor(); if (fd == null) { Log.e("AssetFileDesciptorError", "Can't retrieve the FileDescriptor of this AssetFileDescriptor"); @@ -377,8 +400,8 @@ end redef class App # Resource Manager used to manage resources placed in the `res` folder of the app var resource_manager: ResourcesManager is lazy do - var res = native_activity.resources - var pkg = native_activity.package_name + var res = native_context.resources + var pkg = native_context.package_name return new ResourcesManager.native(res, pkg.to_s) end @@ -386,7 +409,7 @@ redef class App var asset_manager: AssetManager is lazy do return new AssetManager end -redef extern class NativeActivity +redef extern class NativeContext # Get the native AssetsManager of the application, used to initialize the nit's AssetManager private fun assets: NativeAssetManager in "Java" `{