Created
June 27, 2014 20:28
-
-
Save nseidm1/25a5f07f6b2681839cec to your computer and use it in GitHub Desktop.
Simple Event Bus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.project.vegassms.helpers; | |
| import java.io.Serializable; | |
| import java.util.Observable; | |
| import android.os.Handler; | |
| import android.os.Looper; | |
| import com.project.vegassms.Message; | |
| public class MessageBus extends Observable { | |
| public static MessageBus sInstance = new MessageBus(); | |
| private Handler mHandler = new Handler(Looper.getMainLooper()); | |
| private MessageBus(){} | |
| public static class Command implements Serializable { | |
| private static final long serialVersionUID = 2666408433969266145L; | |
| public static final int NEW_MESSAGE = 1; | |
| public static final int UPDATED_MESSAGE = 2; | |
| public static final int DELETE_MESSAGE = 3; | |
| public static final int NEW_CALL = 4; | |
| public int mCommand; | |
| public Message mMessage; | |
| public Command(int command, Message message) { | |
| mCommand = command; | |
| mMessage = message; | |
| } | |
| } | |
| //Always post messages on the UI thread | |
| public void sendMessage(final Command command) { | |
| mHandler.post(new Runnable() { | |
| @Override | |
| public void run() { | |
| setChanged(); | |
| notifyObservers(command); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment