blitz-research / monkey

Blitz Research Monkey Source
226 stars 59 forks source link

android target: activity result callback #26

Closed adamredwoods closed 11 years ago

adamredwoods commented 11 years ago

this is to allow the android target to be expanded by custom modules that need onActivityResultCallback() when using Activity Intents. good for cameras, IAP, contact lists, etc.

tested with camera, seems to work ok.

coders still need to modify manifest.xml.

blitz-research commented 11 years ago

Just been looking into similar stuff for Xaron...

Isn't it possible to create multiple activities? Wouldn't this be a better approach as opposed to playing 'catch up kludge' with all the possible things might want to do with an activity?

Or do some things have to happen in the main activity?

Another alternative is to let users 'name' the main activity class, so a module can extend AndroidGame with it's own MonkeyGame-like class. The main issue here is that the trans builder gets a little more complicated.

adamredwoods commented 11 years ago

Isn't it possible to create multiple activities?

probably. i gave a quick attempt but was unsuccessful. this route seemed a little simpler, especially since it's basically a helper class for those wanting to extend monkey.

it's up to you, if you can find an example that makes sense, might be just as simple.

blitz-research commented 11 years ago

Ok, merged, tidied up a bit and pushed back to develop!

I'd still like a more general purpose solution to 'how do you take over the Activity?', but this will do for now...

blitz-research commented 11 years ago

I'm actually warming to the approach a lot...

A few thoughts:

Just some ideas...

On Wed, Jul 3, 2013 at 2:47 PM, AdamRedwoods notifications@github.comwrote:

probably. i gave a quick attempt but was unsuccessful. this route seemed a little simpler, especially since it's basically a helper class for those wanting to extend monkey.

it's up to you, if you can find an example that makes sense, might be just as simple.

— Reply to this email directly or view it on GitHubhttps://github.com/blitz-research/monkey/pull/26#issuecomment-20392541 .

adamredwoods commented 11 years ago

a more complete IActivityDelegate which contains a bunch of methods that may be useful to modules, eg: OnPause, OnRestart etc. Perhaps everything in the 'protected methods' section here:

true, after looking at Xaron's IAP, it needs to access the OnDestroy() as well to clean up properly.

AddActivityDelegate instead of SetActivityDelegate - otherwise, how will people be able to use both IAP and camera?

my original thought was that the onActivityResultCallback would basically be controlled like a state machine, one activity delegate at a time, thus why i originally chose "SetActivity". but if you have a better idea, go with it. i just don't want you to run into too much maintenance upkeep.

blitz-research commented 11 years ago

onActivityResultCallback would basically be controlled like a state machine, one activity delegate at a time,

Not quite sure what you mean there, but I was thinking of maintaining a list of ActivityDelegates, so when OnPause happens, each delegate gets it's OnPause method called.

This way, both IAP and camera modules can call AddActivityDelegate (without having to be aware of each other) and both will get their OnPause (and OnActivityResult etc) methods called when an OnPause etc happens. Just like an EventListener system.

Sound OK?

i just don't want you to run into too much maintenance upkeep.

Hopefully, this will keep everyone who wants to 'hook' Activity happy with no extra effort from me - beyond perhaps having to add new methods to ActivityDelegate every now and then.

On Wed, Jul 3, 2013 at 6:48 PM, AdamRedwoods notifications@github.comwrote:

a more complete IActivityDelegate which contains a bunch of methods that may be useful to modules, eg: OnPause, OnRestart etc. Perhaps everything in the 'protected methods' section here:

true, after looking at Xaron's IAP, it needs to access the OnDestroy() as well to clean up properly.

AddActivityDelegate instead of SetActivityDelegate - otherwise, how will people be able to use both IAP and camera?

my original thought was that the onActivityResultCallback would basically be controlled like a state machine, one activity delegate at a time, thus why i originally chose "SetActivity". but if you have a better idea, go with it. i just don't want you to run into too much maintenance upkeep.

— Reply to this email directly or view it on GitHubhttps://github.com/blitz-research/monkey/pull/26#issuecomment-20398462 .

adamredwoods commented 11 years ago

This way, both IAP and camera modules can call AddActivityDelegate

ok, i get it, makes sense.

blitz-research commented 11 years ago

Pushed new version to develop branch - haven't actually tried it yet, but things compile/run as usual!

Can you let me know if it looks OK/works?

Also, apps that implement onActivityResult will have to make sure to check it's their result in case multiple delegates have been added - not sure how this can be done...?

I've provided methods for app lifecycle stuff as well as onActivityResult. Could add more but would like to play it safe initially. More can be added as people need them.

On Thu, Jul 4, 2013 at 7:23 AM, AdamRedwoods notifications@github.comwrote:

This way, both IAP and camera modules can call AddActivityDelegate

ok, i get it, makes sense.

— Reply to this email directly or view it on GitHubhttps://github.com/blitz-research/monkey/pull/26#issuecomment-20439214 .

adamredwoods commented 11 years ago

ok works. cleaner. put the Android Camera Intent test code here: http://monkeycoder.co.nz/Community/posts.php?topic=5502

apps that implement onActivityResult will have to make sure to check it's their result

i think one way would be to return a unique id from AddActivityDelegate() to avoid duplicates. but i dont know if it's really needed, since usually only one activityforresult is executed at one time....?

blitz-research commented 11 years ago

Latest release has a new method BBAndroidGame.AllocateActivityResultRequestCode()

Use this to allocate in integer 'request code' that can be used when starting intent, so onActivityResult handlers can teel which result is 'theirs'.

See brl/native/monkeystore.android.java for example.