lib & contrib: update imports
[nit.git] / lib / android / bundle / bundle.nit
index fde88af..e02702a 100644 (file)
@@ -19,7 +19,7 @@
 module bundle
 
 import serialization
-import json::serialization
+import json
 
 import platform
 import activities
@@ -63,7 +63,7 @@ extern class NativeBundle in "Java" `{ android.os.Bundle `}
        `}
        # FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
        fun put_char(key: JavaString, value: Char) in "Java" `{
-               self.putChar(key, value);
+               self.putChar(key, (char)value);
        `}
        fun put_short(key: JavaString, value: Int) in "Java" `{
                self.putShort(key, (short) value);
@@ -148,7 +148,7 @@ extern class NativeBundle in "Java" `{ android.os.Bundle `}
                char[] java_array = new char[(int)Array_of_Char_length(value)];
 
                for(int i=0; i < java_array.length; ++i)
-                       java_array[i] = Array_of_Char__index(value, i);
+                       java_array[i] = (char)Array_of_Char__index(value, i);
 
                self.putCharArray(key, java_array);
        `}
@@ -218,10 +218,10 @@ extern class NativeBundle in "Java" `{ android.os.Bundle `}
                return self.getByte(key, (byte) def_value);
        `}
        # FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
-       fun get_char(key: JavaString): Char in "Java" `{ return self.getChar(key); `}
+       fun get_char(key: JavaString): Char in "Java" `{ return (int)self.getChar(key); `}
        # FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
        fun get_char_with_def_value(key: JavaString, def_value: Char): Char in "Java" `{
-               return self.getChar(key, def_value);
+               return (int)self.getChar(key, (char)def_value);
        `}
        fun get_short(key: JavaString): Int in "Java" `{ return (short) self.getShort(key); `}
        fun get_short_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
@@ -335,7 +335,7 @@ extern class NativeBundle in "Java" `{ android.os.Bundle `}
                if (java_array == null) return nit_array;
 
                for(int i=0; i < java_array.length; ++i)
-                       Array_of_Char_add(nit_array, java_array[i]);
+                       Array_of_Char_add(nit_array, (int)java_array[i]);
 
                return nit_array;
        `}
@@ -425,7 +425,7 @@ end
 
 # A class mapping `String` keys to various value types
 class Bundle
-       private var native_bundle: NativeBundle = new NativeBundle is lazy
+       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
@@ -503,7 +503,7 @@ class Bundle
        # 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 `auto_serializable` or that it
+       # 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
@@ -520,7 +520,7 @@ class Bundle
        # 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 `auto_serializable` or that they
+       # 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]
@@ -543,13 +543,15 @@ class Bundle
        # 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(1)
-               var return_value = native_bundle.get_string(key.to_java_string).to_s
-               sys.jni_env.pop_local_frame
+               sys.jni_env.push_local_frame(2)
 
-               if return_value == "" then return null
+               var jstr = native_bundle.get_string(key.to_java_string)
+               var str = null
+               if not jstr.is_java_null then str = jstr.to_s
 
-               return return_value
+               sys.jni_env.pop_local_frame
+
+               return str
        end
 
        # Retrieves the `Bool` value corresponding to the given key