app::assets
This module is a client of assets_and_resources
as the latter
covers the services of Android.
core :: union_find
union–find algorithm using an efficient disjoint-set data structuregamnit :: camera_control_android
Two fingers camera manipulation, pinch to zoom and slide to scroll
# Implementation of `app::assets`
#
# This module is a client of `assets_and_resources` as the latter
# covers the services of Android.
module assets
intrude import assets_and_resources
redef class TextAsset
redef fun load
do
jni_env.push_local_frame 8
var manager = app.asset_manager
var stream = manager.open(path)
if stream.is_java_null then
self.error = new Error("Failed to open asset at '{path}'")
jni_env.pop_local_frame
self.to_s = ""
return ""
end
var text = stream.read_all
stream.close
if text.is_java_null then
self.error = new Error("Failed to read content of asset file at '{path}'")
jni_env.pop_local_frame
self.to_s = ""
return ""
end
var content = text.to_s
jni_env.pop_local_frame
self.to_s = content
return content
end
end
redef class NativeInputStream
# Read and return all the content of this stream
private fun read_all: JavaString in "Java" `{
// `available` returns the n of bytes currently available, not the total.
// This may cause problems in the future with large asset files.
try {
int size = self.available();
byte[] bytes = new byte[size];
self.read(bytes, 0, size);
return new String(bytes);
} catch (java.lang.Exception exception) {
exception.printStackTrace();
return null;
}
`}
end
lib/android/assets.nit:15,1--70,3