1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # A mapping class of `String` to various value types used by the
18 # Android API for various data exchange purposes
21 import native_app_glue
23 import json_serialization
26 import android.os.Bundle;
27 import android.app.Activity;
28 import java.util.ArrayList;
32 extern class NativeBundle in "Java" `{ android.os.Bundle `}
34 redef type SELF: NativeBundle
36 fun clone: JavaObject in "Java" `{ return recv.clone(); `}
37 fun size
: Int in "Java" `{ return recv.size(); `}
38 fun is_empty: Bool in "Java" `{ return recv.isEmpty(); `}
39 fun clear
in "Java" `{ recv.clear(); `}
40 fun contains_key(key: JavaString): Bool in "Java" `{ return recv.containsKey(key); `}
41 fun get
(key
: JavaString): JavaObject in "Java" `{ return recv.get(key); `}
42 fun remove(key: JavaString) in "Java" `{ recv.remove(key); `}
43 fun put_all
(bundle
: NativeBundle) in "Java" `{ recv.putAll(bundle); `}
44 fun key_set: HashSet[JavaString] import HashSet[JavaString],
45 HashSet[JavaString].add in "Java" `{
46 Set<String> java_set
= recv
.keySet
();
47 int nit_hashset
= new_HashSet_of_JavaString
();
49 for (String element
: java_set
)
50 HashSet_of_JavaString_add(nit_hashset
, element
);
54 fun has_file_descriptors: Bool in "Java" `{ return recv.hasFileDescriptors(); `}
55 fun put_boolean
(key
: JavaString, value
: Bool) in "Java" `{
56 recv.putBoolean(key, value);
58 fun put_byte
(key
: JavaString, value
: Int) in "Java" `{
59 recv.putByte(key, (byte) value);
61 fun put_char
(key
: JavaString, value
: Char) in "Java" `{
62 recv.putChar(key, value);
64 fun put_short
(key
: JavaString, value
: Int) in "Java" `{
65 recv.putShort(key, (short) value);
67 fun put_int
(key
: JavaString, value
: Int) in "Java" `{
68 recv.putInt(key, (int) value);
70 fun put_long
(key
: JavaString, value
: Int) in "Java" `{
71 recv.putLong(key, value);
73 fun put_float
(key
: JavaString, value
: Float) in "Java" `{
74 recv.putFloat(key, (float) value);
76 fun put_double
(key
: JavaString, value
: Float) in "Java" `{
77 recv.putDouble(key, value);
79 fun put_string
(key
: JavaString, value
: JavaString) in "Java" `{
80 recv.putString(key, value);
82 fun put_char_sequence
(key
: JavaString, value
: JavaString) in "Java" `{
83 recv.putCharSequence(key, value);
85 fun put_integer_array_list
(key
: JavaString, value
: Array[Int])
86 import Array[Int].length
, Array[Int].[] in "Java" `{
87 ArrayList<Integer> java_array =
88 new ArrayList<Integer>((int) Array_of_Int_length(value));
90 for(int i=0; i < java_array.size(); ++i)
91 java_array.add((int) Array_of_Int__index(value, i));
93 recv.putIntegerArrayList(key, java_array);
95 fun put_string_array_list
(key
: JavaString, value
: Array[JavaString])
96 import Array[JavaString].length
, Array[JavaString].[] in "Java" `{
97 ArrayList<String> java_array = new ArrayList<String>((int)Array_of_JavaString_length(value));
99 for(int i=0; i < java_array.size(); ++i)
100 java_array.add(Array_of_JavaString__index(value, i));
102 recv.putStringArrayList(key, java_array);
104 fun put_char_sequence_array_list
(key
: JavaString, value
: Array[JavaString])
105 import Array[JavaString].length
, Array[JavaString].[] in "Java" `{
106 ArrayList<CharSequence> java_array =
107 new ArrayList<CharSequence>((int)Array_of_JavaString_length(value));
109 for(int i=0; i < java_array.size(); ++i)
110 java_array.add(Array_of_JavaString__index(value, i));
112 recv.putCharSequenceArrayList(key, java_array);
114 fun put_boolean_array
(key
: JavaString, value
: Array[Bool])
115 import Array[Bool].length
, Array[Bool].[] in "Java" `{
116 boolean[] java_array = new boolean[(int)Array_of_Bool_length(value)];
118 for(int i=0; i < java_array.length; ++i)
119 java_array[i] = Array_of_Bool__index(value, i);
121 recv.putBooleanArray(key, java_array);
123 fun put_byte_array
(key
: JavaString, value
: Array[Int])
124 import Array[Int].length
, Array[Int].[] in "Java" `{
125 byte[] java_array = new byte[(int)Array_of_Int_length(value)];
127 for(int i=0; i < java_array.length; ++i)
128 java_array[i] = (byte) Array_of_Int__index(value, i);
130 recv.putByteArray(key, java_array);
132 fun put_short_array
(key
: JavaString, value
: Array[Int])
133 import Array[Int].length
, Array[Int].[] in "Java" `{
134 short[] java_array = new short[(int)Array_of_Int_length(value)];
136 for(int i=0; i < java_array.length; ++i)
137 java_array[i] = (short) Array_of_Int__index(value, i);
139 recv.putShortArray(key, java_array);
141 fun put_char_array
(key
: JavaString, value
: Array[Char])
142 import Array[Char].length
, Array[Char].[] in "Java" `{
143 char[] java_array = new char[(int)Array_of_Char_length(value)];
145 for(int i=0; i < java_array.length; ++i)
146 java_array[i] = Array_of_Char__index(value, i);
148 recv.putCharArray(key, java_array);
150 fun put_int_array
(key
: JavaString, value
: Array[Int])
151 import Array[Int].length
, Array[Int].[] in "Java" `{
152 int[] java_array = new int[(int)Array_of_Int_length(value)];
154 for(int i=0; i < java_array.length; ++i)
155 java_array[i] = (int) Array_of_Int__index(value, i);
157 recv.putIntArray(key, java_array);
159 fun put_long_array
(key
: JavaString, value
: Array[Int])
160 import Array[Int].length
, Array[Int].[] in "Java" `{
161 long[] java_array = new long[(int)Array_of_Int_length(value)];
163 for(int i=0; i < java_array.length; ++i)
164 java_array[i] = Array_of_Int__index(value, i);
166 recv.putLongArray(key, java_array);
168 fun put_float_array
(key
: JavaString, value
: Array[Float])
169 import Array[Float].length
, Array[Float].[] in "Java" `{
170 float[] java_array = new float[(int)Array_of_Float_length(value)];
172 for(int i=0; i < java_array.length; ++i)
173 java_array[i] = (float) Array_of_Float__index(value, i);
175 recv.putFloatArray(key, java_array);
177 fun put_double_array
(key
: JavaString, value
: Array[Float])
178 import Array[Float].length
, Array[Float].[] in "Java" `{
179 double[] java_array = new double[(int)Array_of_Float_length(value)];
181 for(int i=0; i < java_array.length; ++i)
182 java_array[i] = Array_of_Float__index(value, i);
184 recv.putDoubleArray(key, java_array);
186 fun put_string_array
(key
: JavaString, value
: Array[JavaString])
187 import Array[JavaString].length
, Array[JavaString].[] in "Java" `{
188 String[] java_array = new String[(int)Array_of_JavaString_length(value)];
190 for(int i=0; i < java_array.length; ++i)
191 java_array[i] = Array_of_JavaString__index(value, i);
193 recv.putStringArray(key, java_array);
195 fun put_char_sequence_array
(key
: JavaString, value
: Array[JavaString])
196 import Array[JavaString].length
, Array[JavaString].[] in "Java" `{
197 CharSequence[] java_array = new CharSequence[(int)Array_of_JavaString_length(value)];
199 for(int i=0; i < java_array.length; ++i)
200 java_array[i] = Array_of_JavaString__index(value, i);
202 recv.putCharSequenceArray(key, java_array);
204 fun put_bundle
(key
: JavaString, value
: NativeBundle) in "Java" `{
205 recv.putBundle(key, value);
207 fun get_boolean
(key
: JavaString): Bool in "Java" `{ return recv.getBoolean(key); `}
208 fun get_boolean_with_def_value(key: JavaString, def_value: Bool): Bool in "Java" `{
209 return recv
.getBoolean
(key
, def_value
);
211 fun get_byte(key: JavaString): Int in "Java" `{ return recv.getByte(key); `}
212 fun get_byte_with_def_value
(key
: JavaString, def_value
: Int): Int in "Java" `{
213 return recv.getByte(key, (byte) def_value);
215 fun get_char
(key
: JavaString): Char in "Java" `{ return recv.getChar(key); `}
216 fun get_char_with_def_value(key: JavaString, def_value: Char): Char in "Java" `{
217 return recv
.getChar
(key
, def_value
);
219 fun get_short(key: JavaString): Int in "Java" `{ return (short) recv.getShort(key); `}
220 fun get_short_with_def_value
(key
: JavaString, def_value
: Int): Int in "Java" `{
221 return (short) recv.getShort(key, (short) def_value);
223 fun get_int
(key
: JavaString): Int in "Java" `{ return recv.getInt(key); `}
224 fun get_int_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
225 return recv
.getInt
(key
, (int
) def_value
);
227 fun get_long(key: JavaString): Int in "Java" `{ return recv.getLong(key); `}
228 fun get_long_with_def_value
(key
: JavaString, def_value
: Int): Int in "Java" `{
229 return recv.getLong(key);
231 fun get_float
(key
: JavaString): Float in "Java" `{
232 return (float) recv.getFloat(key);
234 fun get_float_with_def_value
(key
: JavaString, def_value
: Float): Float in "Java" `{
235 return (float) recv.getFloat(key, (float) def_value);
237 fun get_double
(key
: JavaString): Float in "Java" `{ return recv.getDouble(key); `}
238 fun get_double_with_def_value(key: JavaString, def_value: Float): Float in "Java" `{
239 return recv
.getDouble
(key
, def_value
);
241 fun get_string(key: JavaString): JavaString in "Java" `{
242 return recv
.getString
(key
);
244 fun get_char_sequence(key: JavaString): JavaString in "Java" `{
245 return (String) recv
.getCharSequence
(key
);
247 fun get_bundle(key: JavaString): NativeBundle in "Java" `{
248 return recv
.getBundle
(key
);
250 fun get_integer_array_list(key: JavaString): Array[Int]
251 import Array[Int], Array[Int].add in "Java" `{
252 ArrayList<Integer> java_array
= recv
.getIntegerArrayList
(key
);
253 int nit_array
= new_Array_of_Int
();
255 if (java_array
== null) return nit_array
;
257 for (int element
: java_array
)
258 Array_of_Int_add(nit_array
, element
);
262 fun get_string_array_list(key: JavaString): Array[JavaString]
263 import Array[JavaString], Array[JavaString].add in "Java" `{
264 ArrayList<String> java_array
= recv
.getStringArrayList
(key
);
265 int nit_array
= new_Array_of_JavaString
();
267 if (java_array
== null) return nit_array
;
269 for (String element
: java_array
)
270 Array_of_JavaString_add(nit_array
, element
);
274 fun get_char_sequence_array_list(key: JavaString): Array[JavaString]
275 import Array[JavaString], Array[JavaString].add in "Java" `{
276 ArrayList<CharSequence> java_array
= recv
.getCharSequenceArrayList
(key
);
277 int nit_array
= new_Array_of_JavaString
();
279 if (java_array
== null) return nit_array
;
281 for (CharSequence element
: java_array
)
282 Array_of_JavaString_add(nit_array
, (String) element
);
286 fun get_boolean_array(key: JavaString): Array[Bool]
287 import Array[Bool], Array[Bool].add in "Java" `{
288 boolean
[] java_array
= recv
.getBooleanArray
(key
);
289 int nit_array
= new_Array_of_Bool
();
291 if (java_array
== null) return nit_array
;
293 for (int i
=0; i
< java_array
.length
; ++i
)
294 Array_of_Bool_add(nit_array
, java_array
[i
]);
298 fun get_byte_array(key: JavaString): Array[Int]
299 import Array[Int], Array[Int].add in "Java" `{
300 byte
[] java_array
= recv
.getByteArray
(key
);
301 int nit_array
= new_Array_of_Int
();
303 if (java_array
== null) return nit_array
;
305 for(int i
=0; i
< java_array
.length
; ++i
)
306 Array_of_Int_add(nit_array
, java_array
[i
]);
310 fun get_short_array(key: JavaString): Array[Int]
311 import Array[Int], Array[Int].add in "Java" `{
312 short
[] java_array
= recv
.getShortArray
(key
);
313 int nit_array
= new_Array_of_Int
();
315 if (java_array
== null) return nit_array
;
317 for(int i
=0; i
< java_array
.length
; ++i
)
318 Array_of_Int_add(nit_array
, java_array
[i
]);
322 fun get_char_array(key: JavaString): Array[Char]
323 import Array[Char], Array[Char].add in "Java" `{
324 char
[] java_array
= recv
.getCharArray
(key
);
325 int nit_array
= new_Array_of_Char
();
327 if (java_array
== null) return nit_array
;
329 for(int i
=0; i
< java_array
.length
; ++i
)
330 Array_of_Char_add(nit_array
, java_array
[i
]);
334 fun get_int_array(key: JavaString): Array[Int]
335 import Array[Int], Array[Int].add in "Java" `{
336 int
[] java_array
= recv
.getIntArray
(key
);
337 int nit_array
= new_Array_of_Int
();
339 if (java_array
== null) return nit_array
;
341 for(int i
=0; i
< java_array
.length
; ++i
)
342 Array_of_Int_add(nit_array
, java_array
[i
]);
346 # FIXME: Get rid of the int cast as soon as the ffi is fixed
347 fun get_long_array(key: JavaString): Array[Int]
348 import Array[Int], Array[Int].add in "Java" `{
349 long
[] java_array
= recv
.getLongArray
(key
);
350 int nit_array
= new_Array_of_Int
();
352 if (java_array
== null) return nit_array
;
354 for(int i
=0; i
< java_array
.length
; ++i
)
355 Array_of_Int_add(nit_array
, java_array
[i
]);
359 fun get_float_array(key: JavaString): Array[Float]
360 import Array[Float], Array[Float].add in "Java" `{
361 float
[] java_array
= recv
.getFloatArray
(key
);
362 int nit_array
= new_Array_of_Float
();
364 if (java_array
== null) return nit_array
;
366 for(int i
=0; i
< java_array
.length
; ++i
)
367 Array_of_Float_add(nit_array
, (double
) java_array
[i
]);
371 fun get_double_array(key: JavaString): Array[Float]
372 import Array[Float], Array[Float].add in "Java" `{
373 double
[] java_array
= recv
.getDoubleArray
(key
);
374 int nit_array
= new_Array_of_Float
();
376 if (java_array
== null) return nit_array
;
378 for(int i
=0; i
< java_array
.length
; ++i
)
379 Array_of_Float_add(nit_array
, java_array
[i
]);
383 fun get_string_array(key: JavaString): Array[JavaString]
384 import Array[JavaString], Array[JavaString].add in "Java" `{
385 String[] java_array
= recv
.getStringArray
(key
);
386 int nit_array
= new_Array_of_JavaString
();
388 if (java_array
== null) return nit_array
;
390 for(int i
=0; i
< java_array
.length
; ++i
)
391 Array_of_JavaString_add(nit_array
, java_array
[i
]);
395 fun get_char_sequence_array(key: JavaString): Array[JavaString]
396 import Array[JavaString], Array[JavaString].add in "Java" `{
397 CharSequence[] java_array
= recv
.getCharSequenceArray
(key
);
398 int nit_array
= new_Array_of_JavaString
();
400 if (java_array
== null) return nit_array
;
402 for(int i
=0; i
< java_array
.length
; ++i
)
403 Array_of_JavaString_add(nit_array
, (String) java_array
[i
]);
407 fun describe_contents: Int in "Java" `{ return recv.describeContents(); `}
408 fun to_string
: JavaString in "Java" `{ return recv.toString(); `}
411 # A class mapping `String` keys to various value types
413 private var native_bundle: NativeBundle
414 private var context: NativeActivity
418 self.context = app.native_activity
422 private fun set_vars(native_bundle: NativeBundle)
424 self.native_bundle = native_bundle.new_global_ref
427 private fun setup import context, set_vars in "Java" `{
428 Activity context
= (Activity) Bundle_context(recv
);
429 Bundle bundle
= new Bundle();
431 Bundle_set_vars(recv
, bundle
);
434 # Returns `true` if the Bundle contains this key
435 fun has(key: String): Bool
437 sys.jni_env.push_local_frame(1)
438 var return_value = native_bundle.contains_key(key.to_java_string)
439 sys.jni_env.pop_local_frame
443 # Returns the number of entries in the current `Bundle`
444 fun size: Int do return native_bundle.size
446 # Returns true if the current `Bundle` is empty
447 fun is_empty: Bool do return native_bundle.is_empty
450 fun clear do native_bundle.clear
452 # Removes the entry associated with the given key
453 fun remove(key: String)
455 sys.jni_env.push_local_frame(1)
456 native_bundle.remove(key.to_java_string)
457 sys.jni_env.pop_local_frame
460 # Returns a `HashSet[String]` containing every mapping keys in the current
462 fun keys: HashSet[String]
464 var javastring_set = native_bundle.key_set
465 var string_set = new HashSet[String]
467 for element in javastring_set do
468 string_set.add(element.to_s)
474 # Add key-value information by dynamically choosing the appropriate
475 # java method according to value type
476 # If there's already a value associated with this key, the new value
479 # To retrieve entries, you'll have to call the type corresponding method
480 # conforming to these rules :
482 # | Nit type | corresponding getter |
483 # |:----------------------|:--------------------------------|
485 # | `Float` | `double
` |
486 # | `Bool` | `bool
` |
487 # | `Char` | `char
` |
488 # ! `String` | `string
` |
489 # ! `Serializable` | `deserialize
` |
490 # ! `Array[Int]` | `array_of_long
` |
491 # ! `Array[Float]` | `array_of_double
` |
492 # ! `Array[Bool]` | `array_of_bool
` |
493 # ! `Array[Char]` | `array_of_char
` |
494 # ! `Array[String]` | `array_of_string
` |
495 # | `Array[Serializable]` | `deserialize_array
` |
496 fun []=(key: String, value: Serializable): Bundle
498 sys.jni_env.push_local_frame(1)
499 value.add_to_bundle(self.native_bundle, key.to_java_string)
500 sys.jni_env.pop_local_frame
504 # Retrieve an `Object` serialized via `[]=` function
505 # Returns `null` if there's no serialized object corresponding to the given key
506 # or if it's the wrong value type
507 # Make sure that the serialized object is `auto_serializable
` or that it
508 # redefines the appropriate methods. Refer to `Serializable` documentation
509 # for further details
510 fun deserialize(key: String): nullable Object
512 var serialized_string = self.string(key)
514 if serialized_string == null then return null
516 var deserializer = new JsonDeserializer(serialized_string)
518 return deserializer.deserialize
521 # Retrieve an `Array` of `Object` serialized via `[]=` function
522 # Returns `null` if there's no serialized `Array` corresponding to the given key
523 # or if it's the wrong value type
524 # Make sure that the serialized objects are `auto_serializable
` or that they
525 # redefine the appropriate methods. Refer to `Serializable` documentation
526 # for further details
527 fun deserialize_array(key: String): nullable Array[nullable Object]
529 var serialized_array = self.array_of_string(key)
531 if serialized_array == null then return null
533 var deserialized_array = new Array[nullable Object]
535 for serialized_element in serialized_array do
536 var deserializer = new JsonDeserializer(serialized_element)
537 deserialized_array.add(deserializer.deserialize)
540 return deserialized_array
543 # Retrieves the `String` value corresponding to the given key
544 # Returns `null` if none or if it's the wrong value type
545 fun string(key: String): nullable String
547 sys.jni_env.push_local_frame(1)
548 var return_value = native_bundle.get_string(key.to_java_string).to_s
549 sys.jni_env.pop_local_frame
551 if return_value == "" then return null
553 return return_value.to_s
556 # Retrieves the `Bool` value corresponding to the given key
557 # Returns the `def_value
` if none or if it's the wrong value type
558 fun bool(key: String, def_value: Bool): Bool
560 sys.jni_env.push_local_frame(1)
562 native_bundle.get_boolean_with_def_value(key.to_java_string, def_value)
563 sys.jni_env.pop_local_frame
567 # Retrieves the `Char` value corresponding to the given key
568 # Returns the `def_value
` if none or if it's the wrong value type
569 fun char(key: String, def_value: Char): Char
571 sys.jni_env.push_local_frame(1)
573 native_bundle.get_char_with_def_value(key.to_java_string, def_value)
574 sys.jni_env.pop_local_frame
578 # Retrieves the `Int` value corresponding to the given key
579 # Returns the `def_value
` if none or if it's the wrong value type
580 fun int(key: String, def_value: Int): Int
582 sys.jni_env.push_local_frame(1)
584 native_bundle.get_long_with_def_value(key.to_java_string, def_value)
585 sys.jni_env.pop_local_frame
589 # Retrieves the `Float` value corresponding to the given key
590 # Returns the `def_value
` if none or if it's the wrong value type
591 fun float(key: String, def_value: Float): Float
593 sys.jni_env.push_local_frame(1)
595 native_bundle.get_double_with_def_value(key.to_java_string, def_value)
596 sys.jni_env.pop_local_frame
600 # Retrieves the `Array[Float]` value corresponding to the given key
601 # Returns the `null` if none or if it's the wrong value type
602 fun array_of_float(key: String): nullable Array[Float]
604 sys.jni_env.push_local_frame(1)
605 var return_value = native_bundle.get_double_array(key.to_java_string)
606 sys.jni_env.pop_local_frame
608 if return_value.is_empty then return null
613 # Retrieves the `Array[Char]` value corresponding to the given key
614 # Returns the `null` if none or if it's the wrong value type
615 fun array_of_char(key: String): nullable Array[Char]
617 sys.jni_env.push_local_frame(1)
618 var return_value = native_bundle.get_char_array(key.to_java_string)
619 sys.jni_env.pop_local_frame
621 if return_value.is_empty then return null
625 # Retrieves the `Array[Int]` value corresponding to the given key
626 # Returns the `null` if none or if it's the wrong value type
627 fun array_of_int(key: String): nullable Array[Int]
629 sys.jni_env.push_local_frame(1)
630 var return_value = native_bundle.get_long_array(key.to_java_string)
631 sys.jni_env.pop_local_frame
633 if return_value.is_empty then return null
638 # Retrieves the `Array[Bool]` value corresponding to the given key
639 # Returns the `null` if none or if it's the wrong value type
640 fun array_of_bool(key: String): nullable Array[Bool]
642 sys.jni_env.push_local_frame(1)
643 var return_value = native_bundle.get_boolean_array(key.to_java_string)
644 sys.jni_env.pop_local_frame
646 if return_value.is_empty then return null
651 # Retrieves the `Array[String]` value corresponding to the given key
652 # Returns the `null` if none or if it's the wrong value type
653 fun array_of_string(key: String): nullable Array[String]
655 var string_array = new Array[String]
656 sys.jni_env.push_local_frame(1)
657 var return_value = native_bundle.get_string_array(key.to_java_string)
659 for element in return_value
661 string_array.add(element.to_s)
664 sys.jni_env.pop_local_frame
666 if return_value.is_empty then return null
672 redef class Serializable
673 # Called by `Bundle::[]=` to dynamically choose the appropriate method according
674 # to the value type to store
675 # Non-primitive Object (`String` excluded) will be stored as a serialized json `String`
676 # Refine your class to customize this method behaviour
677 protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)
679 sys.jni_env.push_local_frame(1)
680 var serialized_string = new StringOStream
681 var serializer = new JsonSerializer(serialized_string)
682 serializer.serialize(self)
684 bundle.put_string(key, serialized_string.to_s.to_java_string)
689 redef fun add_to_bundle(bundle, key)
691 bundle.put_long(key, self)
696 redef fun add_to_bundle(bundle, key)
698 bundle.put_char(key, self)
703 redef fun add_to_bundle(bundle, key)
705 bundle.put_double(key, self)
710 redef fun add_to_bundle(bundle, key)
712 bundle.put_boolean(key, self)
717 redef fun add_to_bundle(bundle, key)
719 bundle.put_string(key, self.to_java_string)
724 redef fun add_to_bundle(bundle, key)
726 if self isa Array[Bool] then
727 bundle.put_boolean_array(key, self)
728 else if self isa Array[Int] then
729 bundle.put_long_array(key, self)
730 else if self isa Array[Float] then
731 bundle.put_double_array(key, self)
732 else if self isa Array[Char] then
733 bundle.put_char_array(key, self)
734 else if self isa Array[String] then
735 sys.jni_env.push_local_frame(self.length)
736 var java_string_array = new Array[JavaString]
738 for element in self do
739 java_string_array.push(element.to_s.to_java_string)
742 bundle.put_string_array(key, java_string_array)
743 else if self isa Array[Serializable] then
744 sys.jni_env.push_local_frame(self.length)
745 var java_string_array = new Array[JavaString]
747 for element in self do
748 var serialized_string = new StringOStream
749 var serializer = new JsonSerializer(serialized_string)
750 serializer.serialize(element)
751 java_string_array.add(serialized_string.to_s.to_java_string)
754 bundle.put_string_array(key, java_string_array)