Android Open Source - trip-chain-android Event Dispatcher






From Project

Back to project page trip-chain-android.

License

The source code is released under:

MIT License

If you think the Android project trip-chain-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fi.aalto.tripchain.receivers;
/*from  w w w .  j a  v  a2s  . c o  m*/
import java.util.ArrayList;
import java.util.List;

import android.location.Location;
import fi.aalto.tripchain.here.Address;
import fi.aalto.tripchain.route.Activity;

/**
 * Static class used to dispatch events globally.
 * Currently events are dispatched only in service
 * context.
 *
 */
public class EventDispatcher {
  private static List<EventListener> listeners = new ArrayList<EventListener>();
  
  /**
   * Subscribes events to listener.
   * @param listener
   */
  public synchronized static void subscribe(EventListener listener) {
    listeners.add(listener);
  }
  
  /**
   * Removes listener's subscription.
   */
  public synchronized void unsubscribe(EventListener listener) {
    listeners.remove(listener);
  }
  
  /**
   * Dispatches location event to listeners.
   */
  public static synchronized void onLocation(Location location) {
    for (EventListener el : listeners) {
      el.onLocation(location);
    }
  }

  /**
   * Dispatches activity event to listeners.
   */
  public static synchronized void onActivity(Activity activity) {
    for (EventListener el : listeners) {
      el.onActivity(activity);
    }
  }
  
  /**
   * Dispatches address event to listeners.
   */
  public static synchronized void onAddress(Address address) {
    for (EventListener el : listeners) {
      el.onAddress(address);
    }
  }
}




Java Source Code List

fi.aalto.tripchain.BackgroundService.java
fi.aalto.tripchain.Configuration.java
fi.aalto.tripchain.LoginActivity.java
fi.aalto.tripchain.MainActivity.java
fi.aalto.tripchain.StartFragment.java
fi.aalto.tripchain.TripFragment.java
fi.aalto.tripchain.receivers.ActivityReceiver.java
fi.aalto.tripchain.receivers.EventDispatcher.java
fi.aalto.tripchain.receivers.EventListener.java
fi.aalto.tripchain.receivers.LocationReceiver.java
fi.aalto.tripchain.receivers.Receiver.java
fi.aalto.tripchain.route.ActivityListener.java
fi.aalto.tripchain.route.Activity.java
fi.aalto.tripchain.route.LocationListener.java
fi.aalto.tripchain.route.RoadSegment.java
fi.aalto.tripchain.route.Roads.java
fi.aalto.tripchain.route.RouteSegment.java
fi.aalto.tripchain.route.Route.java
fi.aalto.tripchain.route.TripRecorder.java
fi.aalto.tripchain.route.Trip.java