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>(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>(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>(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[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[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[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[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[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[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[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[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[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[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 (int
) recv
.getInt
(key
, (int
) def_value
);
227 # FIXME: Get rid of the int cast as soon as the ffi is fixed
228 fun get_long(key: JavaString): Int in "Java" `{ return (int) recv.getLong(key); `}
229 # FIXME: Get rid of the int cast as soon as the ffi is fixed
230 fun get_long_with_def_value
(key
: JavaString, def_value
: Int): Int in "Java" `{
231 return (int) recv.getLong(key);
233 fun get_float
(key
: JavaString): Float in "Java" `{
234 return (float) recv.getFloat(key);
236 fun get_float_with_def_value
(key
: JavaString, def_value
: Float): Float in "Java" `{
237 return (float) recv.getFloat(key, (float) def_value);
239 fun get_double
(key
: JavaString): Float in "Java" `{ return recv.getDouble(key); `}
240 fun get_double_with_def_value(key: JavaString, def_value: Float): Float in "Java" `{
241 return recv
.getDouble
(key
, def_value
);
243 fun get_string(key: JavaString): JavaString in "Java" `{
244 return recv
.getString
(key
);
246 fun get_char_sequence(key: JavaString): JavaString in "Java" `{
247 return (String) recv
.getCharSequence
(key
);
249 fun get_bundle(key: JavaString): NativeBundle in "Java" `{
250 return recv
.getBundle
(key
);
252 fun get_integer_array_list(key: JavaString): Array[Int]
253 import Array[Int], Array[Int].add in "Java" `{
254 ArrayList<Integer> java_array
= recv
.getIntegerArrayList
(key
);
255 int nit_array
= new_Array_of_Int
();
257 if (java_array
== null) return nit_array
;
259 for (int element
: java_array
)
260 Array_of_Int_add(nit_array
, element
);
264 fun get_string_array_list(key: JavaString): Array[JavaString]
265 import Array[JavaString], Array[JavaString].add in "Java" `{
266 ArrayList<String> java_array
= recv
.getStringArrayList
(key
);
267 int nit_array
= new_Array_of_JavaString
();
269 if (java_array
== null) return nit_array
;
271 for (String element
: java_array
)
272 Array_of_JavaString_add(nit_array
, element
);
276 fun get_char_sequence_array_list(key: JavaString): Array[JavaString]
277 import Array[JavaString], Array[JavaString].add in "Java" `{
278 ArrayList<CharSequence> java_array
= recv
.getCharSequenceArrayList
(key
);
279 int nit_array
= new_Array_of_JavaString
();
281 if (java_array
== null) return nit_array
;
283 for (CharSequence element
: java_array
)
284 Array_of_JavaString_add(nit_array
, (String) element
);
288 fun get_boolean_array(key: JavaString): Array[Bool]
289 import Array[Bool], Array[Bool].add in "Java" `{
290 boolean
[] java_array
= recv
.getBooleanArray
(key
);
291 int nit_array
= new_Array_of_Bool
();
293 if (java_array
== null) return nit_array
;
295 for (int i
=0; i
< java_array
.length
; ++i
)
296 Array_of_Bool_add(nit_array
, java_array
[i
]);
300 fun get_byte_array(key: JavaString): Array[Int]
301 import Array[Int], Array[Int].add in "Java" `{
302 byte
[] java_array
= recv
.getByteArray
(key
);
303 int nit_array
= new_Array_of_Int
();
305 if (java_array
== null) return nit_array
;
307 for(int i
=0; i
< java_array
.length
; ++i
)
308 Array_of_Int_add(nit_array
, (int
) java_array
[i
]);
312 fun get_short_array(key: JavaString): Array[Int]
313 import Array[Int], Array[Int].add in "Java" `{
314 short
[] java_array
= recv
.getShortArray
(key
);
315 int nit_array
= new_Array_of_Int
();
317 if (java_array
== null) return nit_array
;
319 for(int i
=0; i
< java_array
.length
; ++i
)
320 Array_of_Int_add(nit_array
, (int
) java_array
[i
]);
324 fun get_char_array(key: JavaString): Array[Char]
325 import Array[Char], Array[Char].add in "Java" `{
326 char
[] java_array
= recv
.getCharArray
(key
);
327 int nit_array
= new_Array_of_Char
();
329 if (java_array
== null) return nit_array
;
331 for(int i
=0; i
< java_array
.length
; ++i
)
332 Array_of_Char_add(nit_array
, java_array
[i
]);
336 fun get_int_array(key: JavaString): Array[Int]
337 import Array[Int], Array[Int].add in "Java" `{
338 int
[] java_array
= recv
.getIntArray
(key
);
339 int nit_array
= new_Array_of_Int
();
341 if (java_array
== null) return nit_array
;
343 for(int i
=0; i
< java_array
.length
; ++i
)
344 Array_of_Int_add(nit_array
, java_array
[i
]);
348 # FIXME: Get rid of the int cast as soon as the ffi is fixed
349 fun get_long_array(key: JavaString): Array[Int]
350 import Array[Int], Array[Int].add in "Java" `{
351 long
[] java_array
= recv
.getLongArray
(key
);
352 int nit_array
= new_Array_of_Int
();
354 if (java_array
== null) return nit_array
;
356 for(int i
=0; i
< java_array
.length
; ++i
)
357 Array_of_Int_add(nit_array
, (int
) java_array
[i
]);
361 fun get_float_array(key: JavaString): Array[Float]
362 import Array[Float], Array[Float].add in "Java" `{
363 float
[] java_array
= recv
.getFloatArray
(key
);
364 int nit_array
= new_Array_of_Float
();
366 if (java_array
== null) return nit_array
;
368 for(int i
=0; i
< java_array
.length
; ++i
)
369 Array_of_Float_add(nit_array
, (double
) java_array
[i
]);
373 fun get_double_array(key: JavaString): Array[Float]
374 import Array[Float], Array[Float].add in "Java" `{
375 double
[] java_array
= recv
.getDoubleArray
(key
);
376 int nit_array
= new_Array_of_Float
();
378 if (java_array
== null) return nit_array
;
380 for(int i
=0; i
< java_array
.length
; ++i
)
381 Array_of_Float_add(nit_array
, java_array
[i
]);
385 fun get_string_array(key: JavaString): Array[JavaString]
386 import Array[JavaString], Array[JavaString].add in "Java" `{
387 String[] java_array
= recv
.getStringArray
(key
);
388 int nit_array
= new_Array_of_JavaString
();
390 if (java_array
== null) return nit_array
;
392 for(int i
=0; i
< java_array
.length
; ++i
)
393 Array_of_JavaString_add(nit_array
, java_array
[i
]);
397 fun get_char_sequence_array(key: JavaString): Array[JavaString]
398 import Array[JavaString], Array[JavaString].add in "Java" `{
399 CharSequence[] java_array
= recv
.getCharSequenceArray
(key
);
400 int nit_array
= new_Array_of_JavaString
();
402 if (java_array
== null) return nit_array
;
404 for(int i
=0; i
< java_array
.length
; ++i
)
405 Array_of_JavaString_add(nit_array
, (String) java_array
[i
]);
409 fun describe_contents: Int in "Java" `{ return recv.describeContents(); `}
410 fun to_string
: JavaString in "Java" `{ return recv.toString(); `}
413 # A class mapping `String` keys to various value types
415 private var native_bundle: NativeBundle
416 private var context: NativeActivity
420 self.context = app.native_activity
424 private fun set_vars(native_bundle: NativeBundle)
426 self.native_bundle = native_bundle.new_global_ref
429 private fun setup import context, set_vars in "Java" `{
430 Activity context
= (Activity) Bundle_context(recv
);
431 Bundle bundle
= new Bundle();
433 Bundle_set_vars(recv
, bundle
);
436 # Returns `true` if the Bundle contains this key
437 fun has(key: String): Bool
439 sys.jni_env.push_local_frame(1)
440 var return_value = native_bundle.contains_key(key.to_java_string)
441 sys.jni_env.pop_local_frame
445 # Returns the number of entries in the current `Bundle`
446 fun size: Int do return native_bundle.size
448 # Returns true if the current `Bundle` is empty
449 fun is_empty: Bool do return native_bundle.is_empty
452 fun clear do native_bundle.clear
454 # Removes the entry associated with the given key
455 fun remove(key: String)
457 sys.jni_env.push_local_frame(1)
458 native_bundle.remove(key.to_java_string)
459 sys.jni_env.pop_local_frame
462 # Returns a `HashSet[String]` containing every mapping keys in the current
464 fun keys: HashSet[String]
466 var javastring_set = native_bundle.key_set
467 var string_set = new HashSet[String]
469 for element in javastring_set do
470 string_set.add(element.to_s)
476 # Add key-value information by dynamically choosing the appropriate
477 # java method according to value type
478 # If there's already a value associated with this key, the new value
481 # To retrieve entries, you'll have to call the type corresponding method
482 # conforming to these rules :
484 # | Nit type | corresponding getter |
485 # |:----------------------|:--------------------------------|
487 # | `Float` | `double
` |
488 # | `Bool` | `bool
` |
489 # | `Char` | `char
` |
490 # ! `String` | `string
` |
491 # ! `Serializable` | `deserialize
` |
492 # ! `Array[Int]` | `array_of_long
` |
493 # ! `Array[Float]` | `array_of_double
` |
494 # ! `Array[Bool]` | `array_of_bool
` |
495 # ! `Array[Char]` | `array_of_char
` |
496 # ! `Array[String]` | `array_of_string
` |
497 # | `Array[Serializable]` | `deserialize_array
` |
498 fun []=(key: String, value: Serializable): Bundle
500 sys.jni_env.push_local_frame(1)
501 value.add_to_bundle(self.native_bundle, key.to_java_string)
502 sys.jni_env.pop_local_frame
506 # Retrieve an `Object` serialized via `[]=` function
507 # Returns `null` if there's no serialized object corresponding to the given key
508 # or if it's the wrong value type
509 # Make sure that the serialized object is `auto_serializable
` or that it
510 # redefines the appropriate methods. Refer to `Serializable` documentation
511 # for further details
512 fun deserialize(key: String): nullable Object
514 var serialized_string = self.string(key)
516 if serialized_string == null then return null
518 var deserializer = new JsonDeserializer(serialized_string)
520 return deserializer.deserialize
523 # Retrieve an `Array` of `Object` serialized via `[]=` function
524 # Returns `null` if there's no serialized `Array` corresponding to the given key
525 # or if it's the wrong value type
526 # Make sure that the serialized objects are `auto_serializable
` or that they
527 # redefine the appropriate methods. Refer to `Serializable` documentation
528 # for further details
529 fun deserialize_array(key: String): nullable Array[nullable Object]
531 var serialized_array = self.array_of_string(key)
533 if serialized_array == null then return null
535 var deserialized_array = new Array[nullable Object]
537 for serialized_element in serialized_array do
538 var deserializer = new JsonDeserializer(serialized_element)
539 deserialized_array.add(deserializer.deserialize)
542 return deserialized_array
545 # Retrieves the `String` value corresponding to the given key
546 # Returns `null` if none or if it's the wrong value type
547 fun string(key: String): nullable String
549 sys.jni_env.push_local_frame(1)
550 var return_value = native_bundle.get_string(key.to_java_string).to_s
551 sys.jni_env.pop_local_frame
553 if return_value == "" then return null
555 return return_value.to_s
558 # Retrieves the `Bool` value corresponding to the given key
559 # Returns the `def_value
` if none or if it's the wrong value type
560 fun bool(key: String, def_value: Bool): Bool
562 sys.jni_env.push_local_frame(1)
564 native_bundle.get_boolean_with_def_value(key.to_java_string, def_value)
565 sys.jni_env.pop_local_frame
569 # Retrieves the `Char` value corresponding to the given key
570 # Returns the `def_value
` if none or if it's the wrong value type
571 fun char(key: String, def_value: Char): Char
573 sys.jni_env.push_local_frame(1)
575 native_bundle.get_char_with_def_value(key.to_java_string, def_value)
576 sys.jni_env.pop_local_frame
580 # Retrieves the `Int` value corresponding to the given key
581 # Returns the `def_value
` if none or if it's the wrong value type
582 fun int(key: String, def_value: Int): Int
584 sys.jni_env.push_local_frame(1)
586 native_bundle.get_long_with_def_value(key.to_java_string, def_value)
587 sys.jni_env.pop_local_frame
591 # Retrieves the `Float` value corresponding to the given key
592 # Returns the `def_value
` if none or if it's the wrong value type
593 fun float(key: String, def_value: Float): Float
595 sys.jni_env.push_local_frame(1)
597 native_bundle.get_double_with_def_value(key.to_java_string, def_value)
598 sys.jni_env.pop_local_frame
602 # Retrieves the `Array[Float]` value corresponding to the given key
603 # Returns the `null` if none or if it's the wrong value type
604 fun array_of_float(key: String): nullable Array[Float]
606 sys.jni_env.push_local_frame(1)
607 var return_value = native_bundle.get_double_array(key.to_java_string)
608 sys.jni_env.pop_local_frame
610 if return_value.is_empty then return null
615 # Retrieves the `Array[Char]` value corresponding to the given key
616 # Returns the `null` if none or if it's the wrong value type
617 fun array_of_char(key: String): nullable Array[Char]
619 sys.jni_env.push_local_frame(1)
620 var return_value = native_bundle.get_char_array(key.to_java_string)
621 sys.jni_env.pop_local_frame
623 if return_value.is_empty then return null
627 # Retrieves the `Array[Int]` value corresponding to the given key
628 # Returns the `null` if none or if it's the wrong value type
629 fun array_of_int(key: String): nullable Array[Int]
631 sys.jni_env.push_local_frame(1)
632 var return_value = native_bundle.get_long_array(key.to_java_string)
633 sys.jni_env.pop_local_frame
635 if return_value.is_empty then return null
640 # Retrieves the `Array[Bool]` value corresponding to the given key
641 # Returns the `null` if none or if it's the wrong value type
642 fun array_of_bool(key: String): nullable Array[Bool]
644 sys.jni_env.push_local_frame(1)
645 var return_value = native_bundle.get_boolean_array(key.to_java_string)
646 sys.jni_env.pop_local_frame
648 if return_value.is_empty then return null
653 # Retrieves the `Array[String]` value corresponding to the given key
654 # Returns the `null` if none or if it's the wrong value type
655 fun array_of_string(key: String): nullable Array[String]
657 var string_array = new Array[String]
658 sys.jni_env.push_local_frame(1)
659 var return_value = native_bundle.get_string_array(key.to_java_string)
661 for element in return_value
663 string_array.add(element.to_s)
666 sys.jni_env.pop_local_frame
668 if return_value.is_empty then return null
674 redef class Serializable
675 # Called by `Bundle::[]=` to dynamically choose the appropriate method according
676 # to the value type to store
677 # Non-primitive Object (`String` excluded) will be stored as a serialized json `String`
678 # Refine your class to customize this method behaviour
679 protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)
681 sys.jni_env.push_local_frame(1)
682 var serialized_string = new StringOStream
683 var serializer = new JsonSerializer(serialized_string)
684 serializer.serialize(self)
686 bundle.put_string(key, serialized_string.to_s.to_java_string)
691 redef fun add_to_bundle(bundle, key)
693 bundle.put_long(key, self)
698 redef fun add_to_bundle(bundle, key)
700 bundle.put_char(key, self)
705 redef fun add_to_bundle(bundle, key)
707 bundle.put_double(key, self)
712 redef fun add_to_bundle(bundle, key)
714 bundle.put_boolean(key, self)
719 redef fun add_to_bundle(bundle, key)
721 bundle.put_string(key, self.to_java_string)
726 redef fun add_to_bundle(bundle, key)
728 if self isa Array[Bool] then
729 bundle.put_boolean_array(key, self)
730 else if self isa Array[Int] then
731 bundle.put_long_array(key, self)
732 else if self isa Array[Float] then
733 bundle.put_double_array(key, self)
734 else if self isa Array[Char] then
735 bundle.put_char_array(key, self)
736 else if self isa Array[String] then
737 sys.jni_env.push_local_frame(self.length)
738 var java_string_array = new Array[JavaString]
740 for element in self do
741 java_string_array.push(element.to_s.to_java_string)
744 bundle.put_string_array(key, java_string_array)
745 else if self isa Array[Serializable] then
746 sys.jni_env.push_local_frame(self.length)
747 var java_string_array = new Array[JavaString]
749 for element in self do
750 var serialized_string = new StringOStream
751 var serializer = new JsonSerializer(serialized_string)
752 serializer.serialize(element)
753 java_string_array.add(serialized_string.to_s.to_java_string)
756 bundle.put_string_array(key, java_string_array)