X-Git-Url: http://nitlanguage.org diff --git a/lib/android/intent/intent_api10.nit b/lib/android/intent/intent_api10.nit index d07a817..5312c15 100644 --- a/lib/android/intent/intent_api10.nit +++ b/lib/android/intent/intent_api10.nit @@ -18,10 +18,10 @@ # `android.content.Intent` for the android platform module intent_api10 -import native_app_glue +import dalvik import android::bundle import serialization -private import json_serialization +private import json::serialization in "Java" `{ import android.content.Intent; @@ -33,7 +33,8 @@ in "Java" `{ extern class NativeIntent in "Java" `{ android.content.Intent `} super JavaObject - redef type SELF: NativeIntent + + new in "Java" `{ return new Intent(); `} fun add_category(category: JavaString) in "Java" `{ recv.addCategory(category); `} fun add_flags(flags: Int) in "Java" `{ recv.addFlags((int)flags); `} @@ -627,28 +628,12 @@ end # Services allowing to launch an activity and start/stop services class Intent - protected var intent: NativeIntent - protected var context: NativeActivity - - init (app: App) - do - self.context = app.native_activity - setup - end - - private fun set_vars(intent: NativeIntent) do - self.intent = intent.new_global_ref - end - - private fun setup import context, intent, set_vars in "Java" `{ - Intent intent = new Intent(); - Intent_set_vars(recv, intent); - `} + protected var intent: NativeIntent = (new NativeIntent).new_global_ref is lazy # The general action to be performed # - # Example : - # ~~~ + # ~~~nitish + # # TODO better example # intent.action = intent_action.view.to_s # ~~~ fun action=(action: String) @@ -668,8 +653,8 @@ class Intent # Add category to the intent # Only activities providing all of the requested categories will be used # - # Example : - # ~~~ + # ~~~nitish + # # TODO better example # intent.add_category(intent_category.home.to_s) # ~~~ # Returns `self` allowing fluent programming @@ -721,8 +706,8 @@ class Intent # Add a flag to be used by the intent # - # Example : - # ~~~ + # ~~~nitish + # # TODO better example # intent.add_flags(intent_flag.activity_new_task) # ~~~ # Returns `self` allowing fluent programming @@ -1286,7 +1271,7 @@ class Intent # Returns `self` allowing fluent programming fun []=(name: String, value: nullable Serializable): Intent do - var serialized_string = new StringOStream + var serialized_string = new StringWriter var serializer = new JsonSerializer(serialized_string) serializer.serialize(value) @@ -1312,14 +1297,6 @@ class Intent sys.jni_env.pop_local_frame return self end - # Execute the intent and launch the appropriate application - fun launch_activity do context.start_activity(intent) - - # Start a service that will be running until the `stop_service` call - fun start_service do context.start_service(intent) - - # Stop service - fun stop_service do context.stop_service(intent) # Deletes intent global reference fun destroy do self.intent.delete_global_ref @@ -1329,17 +1306,17 @@ class Intent end redef extern class NativeActivity - fun start_activity(intent: NativeIntent) in "Java" `{ recv.startActivity(intent); `} - fun start_service(intent: NativeIntent) in "Java" `{ recv.startService(intent); `} - fun stop_service(intent: NativeIntent) in "Java" `{ recv.stopService(intent); `} + private fun start_activity(intent: NativeIntent) in "Java" `{ recv.startActivity(intent); `} + private fun start_service(intent: NativeIntent) in "Java" `{ recv.startService(intent); `} + private fun stop_service(intent: NativeIntent) in "Java" `{ recv.stopService(intent); `} end # Allows user to get values with enum-like syntax : `intent_action.main` -protected fun intent_action: Action do return once new Action +fun intent_action: Action do return once new Action # Allows user to get values with enum-like syntax : `intent_category.home` -protected fun intent_category: Category do return once new Category +fun intent_category: Category do return once new Category # Allows user to get values with enum-like syntax : `intent_flag.activity_brought_to_front` -protected fun intent_flag: Flag do return once new Flag +fun intent_flag: Flag do return once new Flag private class StringCopyArray var collection = new Array[String] @@ -1350,3 +1327,15 @@ private class StringCopyHashSet var collection = new HashSet[String] fun add(element: JavaString) do collection.add element.to_s end + +redef class App + + # Execute the intent and launch the appropriate application + fun start_activity(intent: Intent) do native_activity.start_activity(intent.intent) + + # Start a service that will be running until the `stop_service` call + fun start_service(intent: Intent) do native_activity.start_service(intent.intent) + + # Stop service + fun stop_service(intent: Intent) do native_activity.stop_service(intent.intent) +end