org.simple.eventbus.EventBus Java Examples

The following examples show how to use org.simple.eventbus.EventBus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownLoadService.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void pause() {
        if (call != null) {
            call.cancel();
        } else {
            stopSelf();
            return;
        }
        getNotificationManager().cancel(1);
        EventBus.getDefault().post(videos.get(0).getId(), EventBusTags.CACHE_DOWNLOAD_CACNCEL);
        if (videos.size() > 0) {
            videos.remove(0);
            if (videos.size()>0){
                Intent intent = new Intent(this,DownLoadService.class);
                intent.putExtra(DownLoadService.VIDEOS_INFO,videos.get(0));
                onStart(intent,START_REDELIVER_INTENT);
            }else {
//                EventBus.getDefault().post(-1L, EventBusTags.CACHE_DOWNLOAD_CACNCEL);
                stopSelf();
            }
        } else {
            stopSelf();
        }
    }
 
Example #2
Source File: CacheDownLoadService.java    From Aurora with Apache License 2.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent.getBooleanExtra(PAUSE_DOWNLOAD, false)) {
        queue.pause();
        return START_REDELIVER_INTENT;
    }
    VideoDownLoadInfo video = (VideoDownLoadInfo) intent.getSerializableExtra(VIDEOS_INFO);
    EventBus.getDefault().postSticky(video,EventBusTags.CACHE_DOWNLOAD_BEGIN);
    videos.put(video.getId()+"",video);
    File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Sunny_Videos");
    if (!dir.exists()) {
        dir.mkdirs();
    }
    DaoMaster master = GreenDaoHelper.getInstance().create(video.getDbName()).getMaster();
    master.newSession().startAsyncSession().insertOrReplace(video);
    File file = new File(dir.getAbsolutePath(), video.getId() + ".mp4");
    BaseDownloadTask task = (FileDownloader.getImpl().create(video.getVideo().getPlayUrl()).setPath(file.getAbsolutePath()).setTag(video.getId()+""));
    task.setListener(new CommonDownloadListener());
    queue.enqueue(task);
    if (isInit){
        queue.resume();
        isInit = false;
    }
    return START_NOT_STICKY;
}
 
Example #3
Source File: BasisActivity.java    From FastLib with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDestroy() {
    if (isEventBusEnable()) {
        if (FastUtil.isClassExist(FastConstant.EVENT_BUS_CLASS)) {
            if (FastUtil.haveEventBusAnnotation(this)) {
                org.greenrobot.eventbus.EventBus.getDefault().unregister(this);
            }
        }
        if (FastUtil.isClassExist(FastConstant.ANDROID_EVENT_BUS_CLASS)) {
            EventBus.getDefault().unregister(this);
        }
    }
    super.onDestroy();
    if (mUnBinder != null) {
        mUnBinder.unbind();
    }
    mUnBinder = null;
    mContentView = null;
    mContext = null;
    mSavedInstanceState = null;
    mQuitAppControl = null;
    TAG = null;
}
 
Example #4
Source File: BasisActivity.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (isEventBusEnable()) {
        if (FastUtil.isClassExist(FastConstant.EVENT_BUS_CLASS)) {
            if (FastUtil.haveEventBusAnnotation(this)) {
                org.greenrobot.eventbus.EventBus.getDefault().register(this);
            }
        }
        if (FastUtil.isClassExist(FastConstant.ANDROID_EVENT_BUS_CLASS)) {
            EventBus.getDefault().register(this);
        }
    }
    super.onCreate(savedInstanceState);
    this.mSavedInstanceState = savedInstanceState;
    mContext = this;
    beforeSetContentView();
    mContentView = View.inflate(mContext, getContentLayout(), null);
    //解决StatusLayoutManager与SmartRefreshLayout冲突
    if (this instanceof IFastRefreshLoadView) {
        if (FastUtil.isClassExist(FastConstant.SMART_REFRESH_LAYOUT_CLASS)) {
            if (mContentView.getClass() == SmartRefreshLayout.class) {
                FrameLayout frameLayout = new FrameLayout(mContext);
                if (mContentView.getLayoutParams() != null) {
                    frameLayout.setLayoutParams(mContentView.getLayoutParams());
                }
                frameLayout.addView(mContentView);
                mContentView = frameLayout;
            }
        }
    }
    setContentView(mContentView);
    mUnBinder = ButterKnife.bind(this);
    mIsViewLoaded = true;
    beforeInitView(savedInstanceState);
    initView(savedInstanceState);
}
 
Example #5
Source File: UiUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转界面3
 *
 * @param
 */
public static void startActivity(Intent content) {
    Message message = new Message();
    message.what = START_ACTIVITY;
    message.obj = content;
    EventBus.getDefault().post(message, APPMANAGER_MESSAGE);
}
 
Example #6
Source File: ActivityDelegateImpl.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    if (iActivity != null && iActivity.useEventBus())//如果要使用eventbus请将此方法返回true
        EventBus.getDefault().unregister(mActivity);
    this.iActivity = null;
    this.mActivity = null;
}
 
Example #7
Source File: ConstactFragment.java    From AndroidEventBus with Apache License 2.0 5 votes vote down vote up
private void initListView() {
    mAdapter = new ArrayAdapter<User>(getActivity(),
            android.R.layout.simple_list_item_1, mConstacts);
    mListView.setAdapter(mAdapter);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // 点击用户,发布消息,
            // tag为MenuFragment.CLICK_TAG,接收函数在MenuFragment的updateClickUserName中
            EventBus.getDefault().post(mConstacts.get(position), MenuFragment.CLICK_TAG);
        }
    });
}
 
Example #8
Source File: BasePresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    //将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用
    if (mRootView != null && mRootView instanceof LifecycleOwner) {
        ((LifecycleOwner) mRootView).getLifecycle().addObserver(this);
        if (mModel!= null && mModel instanceof LifecycleObserver){
            ((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel);
        }
    }
    if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
        EventBus.getDefault().register(this);//注册 Eventbus
}
 
Example #9
Source File: SplashActivity.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    if (isInit){
            weatherView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if ((Boolean) SharedPreferencesUtils.getParam(SplashActivity.this,Constants.SETTING_SPLASH,false)){
                        weatherView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                isAnimated = true;
                                EventBus.getDefault().post("gotomain",EventBusTags.JUMP_TO_HOME);
                            }
                        },500);
                    }else {
                        weatherView.startAnim();
                        weatherView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                isAnimated = true;
                                EventBus.getDefault().post("gotomain",EventBusTags.JUMP_TO_HOME);
                            }
                        }, 3000);
                    }
                }
            }, 200);
        isInit = false;
    }else {
        EventBus.getDefault().post("gotomain",EventBusTags.JUMP_TO_HOME);
    }
}
 
Example #10
Source File: MenuFragment.java    From AndroidEventBus with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    while (!this.isInterrupted()) {
        // 从子线程发布消息
        EventBus.getDefault().post(getName());

        try {
            Thread.sleep(1000 * mIndex + 3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
Example #11
Source File: SplashActivity.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void setData(List<Category> list) {
    if (!StringUtils.isEmpty(list)){
        this.list.addAll(list);
    }
    isDataLoad = true;
    EventBus.getDefault().post("gotomain",EventBusTags.JUMP_TO_HOME);
}
 
Example #12
Source File: ConstactFragment.java    From AndroidEventBus with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mListView = (ListView) inflater.inflate(R.layout.list_fragment, container, false);

    mockDatas();
    initListView();

    EventBus.getDefault().register(this);
    return mListView;
}
 
Example #13
Source File: MainActivity.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_CHOOSE && resultCode == MatisseActivity.RESULT_OK) {
        String path = Matisse.obtainPathResult(data).get(0);
        EventBus.getDefault().post(path, EventBusTags.MINE_FRAGMENT_SET_FACE_PIC);
    }
}
 
Example #14
Source File: BaseActivity.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    EventBus.getDefault().unregister(this);
    super.onDestroy();
    Log.d(TAG, "lifecycle_onDestroy_isFinishing" + isFinishing());
    if (mUnBinder != null) {
        mUnBinder.unbind();
    }
    mContext = null;
    mUnBinder = null;
    mContentView = null;
    titleBar = null;
    TAG = null;
    mNavigationViewHelper = null;
}
 
Example #15
Source File: EventBusActivity.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView(Bundle var1) {
    findViewById(R.id.btn_sendEventBus).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EventBus.getDefault().post(2, "switchTab");
            finish();
        }
    });
}
 
Example #16
Source File: BasisFragment.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    if (isEventBusEnable()) {
        if (FastUtil.isClassExist(FastConstant.EVENT_BUS_CLASS)) {
            if (FastUtil.haveEventBusAnnotation(this)) {
                org.greenrobot.eventbus.EventBus.getDefault().unregister(this);
            }
        }
        if (FastUtil.isClassExist(FastConstant.ANDROID_EVENT_BUS_CLASS)) {
            EventBus.getDefault().unregister(this);
        }
    }
    super.onDestroy();
}
 
Example #17
Source File: FragmentDelegateImpl.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    if (iFragment != null && iFragment.useEventBus())//如果要使用eventbus请将此方法返回true
        EventBus.getDefault().unregister(mFragment);//注册到事件主线
    this.mUnbinder = null;
    this.mFragmentManager = null;
    this.mFragment = null;
    this.iFragment = null;
}
 
Example #18
Source File: MenuFragment.java    From AndroidEventBus with Apache License 2.0 5 votes vote down vote up
/**
 * 发布参数是List<T>类型的事件, 接收函数为@{@see #subcribeList(List)}
 */
private void postListData() {
    List<User> userLisr = new ArrayList<User>();
    for (int i = 0; i < 5; i++) {
        userLisr.add(new User("user - " + i));
    }

    EventBus.getDefault().post(userLisr);
}
 
Example #19
Source File: ActivityDelegateImpl.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    //如果要使用eventbus请将此方法返回true
    if (iActivity.useEventBus()) {
        //注册到事件主线
        EventBus.getDefault().register(mActivity);
    }
    //Dagger.Android 依赖注入
    if (iActivity.injectable()) {
        AndroidInjection.inject(mActivity);
    }
}
 
Example #20
Source File: ActivityDelegateImpl.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    //如果要使用eventbus请将此方法返回true
    if (iActivity.useEventBus()) {
        EventBus.getDefault().unregister(mActivity);
    }
    this.iActivity = null;
    this.mActivity = null;
}
 
Example #21
Source File: AppManager.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
/**
 * 释放资源
 */
public void release() {
    EventBus.getDefault().unregister(this);
    mActivityList.clear();
    mHandleListener = null;
    mActivityList = null;
    mCurrentActivity = null;
    mApplication = null;
}
 
Example #22
Source File: BaseService.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
    unDisposeAll();
    this.mCompositeDisposable = null;
}
 
Example #23
Source File: BaseViewModel.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
@Override
public void onStart() {
    if (useEventBus()) {
        //注册eventbus
        EventBus.getDefault().register(this);
    }
}
 
Example #24
Source File: BaseViewModel.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCleared() {
    super.onCleared();
    if (useEventBus()) {
        //解除注册eventbus
        EventBus.getDefault().unregister(this);
    }
    // TODO: 2017/8/2
}
 
Example #25
Source File: UiUtils.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 用snackbar显示
 *
 * @param text
 */
public static void SnackbarText(String text) {
    Message message = new Message();
    message.what = SHOW_SNACKBAR;
    message.obj = text;
    message.arg1 = 0;
    EventBus.getDefault().post(message, APPMANAGER_MESSAGE);
}
 
Example #26
Source File: UiUtils.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 用snackbar长时间显示
 *
 * @param text
 */
public static void SnackbarTextWithLong(String text) {
    Message message = new Message();
    message.what = SHOW_SNACKBAR;
    message.obj = text;
    message.arg1 = 1;
    EventBus.getDefault().post(message, APPMANAGER_MESSAGE);
}
 
Example #27
Source File: UiUtils.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转界面3
 *
 * @param
 * @param homeActivityClass
 */
public static void startActivity(Class homeActivityClass) {
    Message message = new Message();
    message.what = START_ACTIVITY;
    message.obj = homeActivityClass;
    EventBus.getDefault().post(message, APPMANAGER_MESSAGE);
}
 
Example #28
Source File: UiUtils.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转界面3
 *
 * @param
 */
public static void startActivity(Intent content) {
    Message message = new Message();
    message.what = START_ACTIVITY;
    message.obj = content;
    EventBus.getDefault().post(message, APPMANAGER_MESSAGE);
}
 
Example #29
Source File: SubscriberMethodHunterTest.java    From AndroidEventBus with Apache License 2.0 5 votes vote down vote up
public void testFindPrimitiveParamMethod() {
    mHunter.findSubcribeMethods(object);
    List<Subscription> subscriptions = EventBus.getDefault().getSubscriberMap()
            .get(new EventType(Integer.class));
    assertEquals(1, subscriptions.size());
    assertEquals(object, subscriptions.get(0).subscriber);
}
 
Example #30
Source File: StickyActivity.java    From AndroidEventBus with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sticky_activity);

    nameTv = (TextView) findViewById(R.id.name_tv);
    ageTv = (TextView) findViewById(R.id.age_tv);

    EventBus.getDefault().registerSticky(this);
}