From f20e590efd34a9a68f30a7b562cc4f9d396c24a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 26 Jan 2015 06:58:37 -0500 Subject: [PATCH] lib/android: Bundle do not need a context or to import native_app_glue MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- examples/mnit_simple/src/test_bundle.nit | 12 ++++++------ lib/android/bundle/bundle.nit | 28 ++++++++-------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/examples/mnit_simple/src/test_bundle.nit b/examples/mnit_simple/src/test_bundle.nit index 5bfc8d2..37c79bb 100644 --- a/examples/mnit_simple/src/test_bundle.nit +++ b/examples/mnit_simple/src/test_bundle.nit @@ -31,13 +31,13 @@ redef class App fun test_bundle do - var bundle = new Bundle(self) - + var bundle = new Bundle + bundle["anInt"] = 1 bundle["aFloat"] = 1.1 bundle["aString"] = "A string" bundle["aBool"] = true - + var int_array = new Array[Int] var bool_array = new Array[Bool] @@ -60,7 +60,7 @@ redef class App assert bundle.string("wrongString") == null assert bundle.bool("aBool", false) assert bundle.bool("wrongBool", false) == false - + var int_array_test = bundle.array_of_int("anArrayOfInt") var bool_array_test = bundle.array_of_bool("anArrayOfBool") @@ -71,7 +71,7 @@ redef class App assert bool_array_test[i] == value value = not value end - + assert bundle.size == 6 assert bundle.has("aBool") assert not bundle.is_empty @@ -97,7 +97,7 @@ redef class App var deserialized_point_array = bundle.deserialize_array("anArrayOfPoint") - for i in [0..5] do + for i in [0..5] do var point = new Point(i, i) assert deserialized_point_array[i].to_s == point.to_s end diff --git a/lib/android/bundle/bundle.nit b/lib/android/bundle/bundle.nit index 5b01369..68713ad 100644 --- a/lib/android/bundle/bundle.nit +++ b/lib/android/bundle/bundle.nit @@ -18,10 +18,12 @@ # Android API for various data exchange purposes module bundle -import native_app_glue import serialization import json_serialization +import platform +import activities + in "Java" `{ import android.os.Bundle; import android.app.Activity; @@ -32,6 +34,8 @@ in "Java" `{ extern class NativeBundle in "Java" `{ android.os.Bundle `} super JavaObject + new in "Java" `{ return new Bundle(); `} + fun clone: JavaObject in "Java" `{ return recv.clone(); `} fun size: Int in "Java" `{ return recv.size(); `} fun is_empty: Bool in "Java" `{ return recv.isEmpty(); `} @@ -421,26 +425,10 @@ end # A class mapping `String` keys to various value types class Bundle - private var native_bundle: NativeBundle - private var context: NativeActivity - - init(app: App) - do - self.context = app.native_activity - setup - end + private var native_bundle: NativeBundle = new NativeBundle is lazy - private fun set_vars(native_bundle: NativeBundle) - do - self.native_bundle = native_bundle.new_global_ref - end - - private fun setup import context, set_vars in "Java" `{ - Activity context = (Activity) Bundle_context(recv); - Bundle bundle = new Bundle(); - - Bundle_set_vars(recv, bundle); - `} + # 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 -- 1.7.9.5