Search in sources :

Example 1 with EventCenter

use of com.github.obsessive.library.eventbus.EventCenter in project SimplifyReader by chentao0707.

the class PhoneCallReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (null == intent) {
        return;
    }
    String action = intent.getAction();
    if (action.equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
        EventBus.getDefault().post(new EventCenter(Constants.EVENT_STOP_PLAY_MUSIC));
    } else {
        final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(new PhoneStateListener() {

            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                super.onCallStateChanged(state, incomingNumber);
                switch(state) {
                    case TelephonyManager.CALL_STATE_OFFHOOK:
                    case TelephonyManager.CALL_STATE_RINGING:
                        EventBus.getDefault().post(new EventCenter(Constants.EVENT_STOP_PLAY_MUSIC));
                        break;
                    case TelephonyManager.CALL_STATE_IDLE:
                        EventBus.getDefault().post(new EventCenter(Constants.EVENT_START_PLAY_MUSIC));
                        break;
                }
            }
        }, PhoneStateListener.LISTEN_CALL_STATE);
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) EventCenter(com.github.obsessive.library.eventbus.EventCenter) PhoneStateListener(android.telephony.PhoneStateListener)

Example 2 with EventCenter

use of com.github.obsessive.library.eventbus.EventCenter in project SimplifyReader by chentao0707.

the class PlayerActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    EventBus.getDefault().post(new EventCenter(Constants.EVENT_STOP_PLAY_MUSIC));
}
Also used : EventCenter(com.github.obsessive.library.eventbus.EventCenter)

Example 3 with EventCenter

use of com.github.obsessive.library.eventbus.EventCenter in project SimplifyReader by chentao0707.

the class PlayerActivity method onPause.

@Override
protected void onPause() {
    super.onPause();
    EventBus.getDefault().post(new EventCenter(Constants.EVENT_START_PLAY_MUSIC));
}
Also used : EventCenter(com.github.obsessive.library.eventbus.EventCenter)

Aggregations

EventCenter (com.github.obsessive.library.eventbus.EventCenter)3 PhoneStateListener (android.telephony.PhoneStateListener)1 TelephonyManager (android.telephony.TelephonyManager)1