Last active
August 12, 2017 15:43
-
-
Save omaraflak/a9ca984210548a4bdb92efa6911230f4 to your computer and use it in GitHub Desktop.
This file contains 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 me.aflak.test; | |
import android.app.Service; | |
import android.content.Intent; | |
import android.os.IBinder; | |
import android.support.annotation.Nullable; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Omar on 12/08/17. | |
*/ | |
public class OOService extends Service { | |
private static List<String> events = new ArrayList<>(); | |
private static List<OnEventListener> eventListeners = new ArrayList<>(); | |
private static List<String> actions = new ArrayList<>(); | |
private static List<OnEventListener> actionListeners = new ArrayList<>(); | |
@Nullable @Override | |
public IBinder onBind(Intent intent) { | |
return null; | |
} | |
public void emit(String event, Object ...o) { | |
int index = events.indexOf(event); | |
if(index!=-1){ | |
eventListeners.get(index).onEvent(o); | |
} | |
} | |
public static void subscribe(String event, OnEventListener listener){ | |
events.add(event); | |
eventListeners.add(listener); | |
} | |
public static void action(String action, Object ...o){ | |
int index = actions.indexOf(action); | |
if(index!=-1){ | |
actionListeners.get(index).onEvent(o); | |
} | |
} | |
public void bind(String action, OnEventListener listener){ | |
actions.add(action); | |
actionListeners.add(listener); | |
} | |
public interface OnEventListener{ | |
void onEvent(Object ...o); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment