String
keys to various value typesandroid :: Bundle :: array_of_bool
Retrieves theArray[Bool]
value corresponding to the given key
android :: Bundle :: array_of_char
Retrieves theArray[Char]
value corresponding to the given key
android :: Bundle :: array_of_float
Retrieves theArray[Float]
value corresponding to the given key
android :: Bundle :: array_of_int
Retrieves theArray[Int]
value corresponding to the given key
android :: Bundle :: array_of_string
Retrieves theArray[String]
value corresponding to the given key
android :: Bundle :: defaultinit
android :: Bundle :: deserialize
Retrieve anObject
serialized via []=
function
android :: Bundle :: deserialize_array
Retrieve anArray
of Object
serialized via []=
function
Bundle
wrapping native_bundle
android :: Bundle :: array_of_bool
Retrieves theArray[Bool]
value corresponding to the given key
android :: Bundle :: array_of_char
Retrieves theArray[Char]
value corresponding to the given key
android :: Bundle :: array_of_float
Retrieves theArray[Float]
value corresponding to the given key
android :: Bundle :: array_of_int
Retrieves theArray[Int]
value corresponding to the given key
android :: Bundle :: array_of_string
Retrieves theArray[String]
value corresponding to the given key
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
android :: Bundle :: defaultinit
android :: Bundle :: deserialize
Retrieve anObject
serialized via []=
function
android :: Bundle :: deserialize_array
Retrieve anArray
of Object
serialized via []=
function
Bundle
wrapping native_bundle
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# A class mapping `String` keys to various value types
class Bundle
private var native_bundle: NativeBundle = (new NativeBundle).new_global_ref is lazy
# Get a new `Bundle` wrapping `native_bundle`
init from(native_bundle: NativeBundle) do self.native_bundle = native_bundle
# Returns `true` if the Bundle contains this key
fun has(key: String): Bool
do
sys.jni_env.push_local_frame(1)
var return_value = native_bundle.contains_key(key.to_java_string)
sys.jni_env.pop_local_frame
return return_value
end
# Returns the number of entries in the current `Bundle`
fun size: Int do return native_bundle.size
# Returns true if the current `Bundle` is empty
fun is_empty: Bool do return native_bundle.is_empty
# Clears all entries
fun clear do native_bundle.clear
# Removes the entry associated with the given key
fun remove(key: String)
do
sys.jni_env.push_local_frame(1)
native_bundle.remove(key.to_java_string)
sys.jni_env.pop_local_frame
end
# Returns a `HashSet[String]` containing every mapping keys in the current
# `Bundle`
fun keys: HashSet[String]
do
var javastring_set = native_bundle.key_set
var string_set = new HashSet[String]
for element in javastring_set do
string_set.add(element.to_s)
end
return string_set
end
# Add key-value information by dynamically choosing the appropriate
# java method according to value type
# If there's already a value associated with this key, the new value
# overwrites it
#
# To retrieve entries, you'll have to call the type corresponding method
# conforming to these rules:
#
# | Nit type | corresponding getter |
# |:----------------------|:--------------------------------|
# | `Int` | `long` |
# | `Float` | `double` |
# | `Bool` | `bool` |
# | `Char` | `char` |
# | `String` | `string` |
# | `Serializable` | `deserialize` |
# | `Array[Int]` | `array_of_long` |
# | `Array[Float]` | `array_of_double` |
# | `Array[Bool]` | `array_of_bool` |
# | `Array[Char]` | `array_of_char` |
# | `Array[String]` | `array_of_string` |
# | `Array[Serializable]` | `deserialize_array` |
fun []=(key: String, value: Serializable): Bundle
do
sys.jni_env.push_local_frame(1)
value.add_to_bundle(self.native_bundle, key.to_java_string)
sys.jni_env.pop_local_frame
return self
end
# Retrieve an `Object` serialized via `[]=` function
# Returns `null` if there's no serialized object corresponding to the given key
# or if it's the wrong value type
# Make sure that the serialized object is `serialize` or that it
# redefines the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize(key: String): nullable Object
do
var serialized_string = self.string(key)
if serialized_string == null then return null
var deserializer = new JsonDeserializer(serialized_string)
return deserializer.deserialize
end
# Retrieve an `Array` of `Object` serialized via `[]=` function
# Returns `null` if there's no serialized `Array` corresponding to the given key
# or if it's the wrong value type
# Make sure that the serialized objects are `serialize` or that they
# redefine the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize_array(key: String): nullable Array[nullable Object]
do
var serialized_array = self.array_of_string(key)
if serialized_array == null then return null
var deserialized_array = new Array[nullable Object]
for serialized_element in serialized_array do
var deserializer = new JsonDeserializer(serialized_element)
deserialized_array.add(deserializer.deserialize)
end
return deserialized_array
end
# Retrieves the `String` value corresponding to the given key
# Returns `null` if none or if it's the wrong value type
fun string(key: String): nullable String
do
sys.jni_env.push_local_frame(2)
var jstr = native_bundle.get_string(key.to_java_string)
var str = null
if not jstr.is_java_null then str = jstr.to_s
sys.jni_env.pop_local_frame
return str
end
# Retrieves the `Bool` value corresponding to the given key
# Returns the `def_value` if none or if it's the wrong value type
fun bool(key: String, def_value: Bool): Bool
do
sys.jni_env.push_local_frame(1)
var return_value =
native_bundle.get_boolean_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
end
# Retrieves the `Char` value corresponding to the given key
# Returns the `def_value` if none or if it's the wrong value type
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun char(key: String, def_value: Char): Char
do
sys.jni_env.push_local_frame(1)
var return_value =
native_bundle.get_char_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
end
# Retrieves the `Int` value corresponding to the given key
# Returns the `def_value` if none or if it's the wrong value type
fun int(key: String, def_value: Int): Int
do
sys.jni_env.push_local_frame(1)
var return_value =
native_bundle.get_long_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
end
# Retrieves the `Float` value corresponding to the given key
# Returns the `def_value` if none or if it's the wrong value type
fun float(key: String, def_value: Float): Float
do
sys.jni_env.push_local_frame(1)
var return_value =
native_bundle.get_double_with_def_value(key.to_java_string, def_value)
sys.jni_env.pop_local_frame
return return_value
end
# Retrieves the `Array[Float]` value corresponding to the given key
# Returns the `null` if none or if it's the wrong value type
fun array_of_float(key: String): nullable Array[Float]
do
sys.jni_env.push_local_frame(1)
var return_value = native_bundle.get_double_array(key.to_java_string)
sys.jni_env.pop_local_frame
if return_value.is_empty then return null
return return_value
end
# Retrieves the `Array[Char]` value corresponding to the given key
# Returns the `null` if none or if it's the wrong value type
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun array_of_char(key: String): nullable Array[Char]
do
sys.jni_env.push_local_frame(1)
var return_value = native_bundle.get_char_array(key.to_java_string)
sys.jni_env.pop_local_frame
if return_value.is_empty then return null
return return_value
end
# Retrieves the `Array[Int]` value corresponding to the given key
# Returns the `null` if none or if it's the wrong value type
fun array_of_int(key: String): nullable Array[Int]
do
sys.jni_env.push_local_frame(1)
var return_value = native_bundle.get_long_array(key.to_java_string)
sys.jni_env.pop_local_frame
if return_value.is_empty then return null
return return_value
end
# Retrieves the `Array[Bool]` value corresponding to the given key
# Returns the `null` if none or if it's the wrong value type
fun array_of_bool(key: String): nullable Array[Bool]
do
sys.jni_env.push_local_frame(1)
var return_value = native_bundle.get_boolean_array(key.to_java_string)
sys.jni_env.pop_local_frame
if return_value.is_empty then return null
return return_value
end
# Retrieves the `Array[String]` value corresponding to the given key
# Returns the `null` if none or if it's the wrong value type
fun array_of_string(key: String): nullable Array[String]
do
sys.jni_env.push_local_frame(1)
var return_value = native_bundle.get_string_array(key.to_java_string)
sys.jni_env.pop_local_frame
if return_value.is_empty then return null
return return_value
end
end
lib/android/bundle/bundle.nit:427,1--668,3