EventBus事件的简单封装

2018-04-08  本文已影响0人  flycode

Talk is Cheap.

public class AppEvent {
    private static AtomicInteger atomicInteger = new AtomicInteger(1000);
    // 标记生成
    public static int newTag() {
        return atomicInteger.incrementAndGet();
    }

    // 标记
    private int tag;
    // 传递数据
    public Object obj;

    private AppEvent(int tag) {
        this.tag = tag;
    }

    private AppEvent(int tag, Object obj) {
        this(tag);
        this.obj = obj;
    }

    /**
     * 有数据传输
     */
    public static AppEvent newInstance(int tag, Object obj) {
        return new AppEvent(tag, obj);
    }
    
     /**
     * 无数据传输
     */
    public static AppEvent newInstance(int tag) {
        return new AppEvent(tag);
    }

    /**
     * 事件匹配
     */
    public boolean match(int tag) {
        return this.tag == tag;
    }
}
上一篇下一篇

猜你喜欢

热点阅读