Title: Android: Events Post by: mikebritton on April 05, 2011, 01:02:38 When trying to figure out how to send events from Activities to Mediators, I first created interface InteractionListener for the Mediator to implement: package com.britton.apps.puremvcboilerplate.view; Implementation in Mediator: @Override In my experimental app, Activity is subclassed as InteractionActivity (which could also be an abstract class): package com.britton.apps.puremvcboilerplate.view; And in ApplicationActivity, the subclass, where there's a Button ready to trigger this miraculous handler: private void initDisplay() { So now, any Activity that extends InteractionEmitterActivity can, by contract, send InteractionEvents to the Mediator actor. Here's the InteractionEvent: package com.britton.apps.puremvcboilerplate.view.event; I realize this is very Flex-like; in fact, I kept thinking about Signals when I wrote it! I've had success with them. Maybe that's another route. Mike Title: Re: Android: Events Post by: Tekool on April 06, 2011, 01:49:11 When working on my Currency app I used the standard Java java.util.Observable/java.util.Observer interfaces and made my Mediator implementing Observer. I dispatched a custom Event object. It wasn't a bad experience.
Title: Re: Android: Events Post by: puremvc on April 06, 2011, 07:27:08 @mike It certainly looks sensible, but there's a lot of boilerplate involved that would get old after awhile.
@tek could you show us the link to your currency app code here or some snippits to illustrate your approach. I think that's going to likely be the less labor intensive route. -=Cliff> Title: Re: Android: Events Post by: Tekool on April 06, 2011, 08:36:10 @puremvc Here it is: https://github.com/tekool/puremvc-android-currency-converter
There is an example of observer/Observable implementation I use in : Activity here (https://github.com/tekool/puremvc-android-currency-converter/blob/master/src/org/puremvc/java/demos/android/currencyconverter/converter/ConverterActivity.java) and its mediator there (https://github.com/tekool/puremvc-android-currency-converter/blob/master/src/org/puremvc/java/demos/android/currencyconverter/converter/view/ConverterActivityMediator.java) |