amitshekhariitbhu / RxJava2-Android-Samples

RxJava 2 Android Examples - How to use RxJava 2 in Android
https://outcomeschool.com
Apache License 2.0
4.96k stars 1.06k forks source link

Could you please add a complicated event bus(rxbus/rxbroadcast) sample? #14

Closed insomniatt closed 7 years ago

insomniatt commented 7 years ago

Like Music Player steps: step1(listen to audio headphone jack plug in/plug out by system broadcast receiver) step2(open Music Player Activity/view when head jack plugged in) step3.1(listen to Play Button to Play Music | change to play UI(set textview1 to "play music")) step3.2(listen to Pause Button to Pause Music | change to pause UI (set textview2 to "pause music")) step4(when headphone jack plug out to Stop Music | change to stop UI (set textview3 to "stop music"))

amitshekhariitbhu commented 7 years ago

@insomniatt sure, I will add it soon.

Thanks Amit Shekhar

insomniatt commented 7 years ago

public class MusicBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case Intent.ACTION_HEADSET_PLUG: if (!intent.hasExtra("state")) { return; } int state = intent.getIntExtra("state", -1); final int STATE_AUDIO_JACK_PLUG_OUT = 0; final int STATE_AUDIO_JACK_PLUG_IN =1; case STATE_AUDIO_JACK_PLUG_IN: handlePlugIn(); break; case STATE_AUDIO_JACK_PLUG_OUT: handlePlugOut(); break; } break;

insomniatt commented 7 years ago

@amitshekhariitbhu https://github.com/cantrowitz/RxBroadcast This is the RxBroadcast implement.

amitshekhariitbhu commented 7 years ago

@insomniatt awesome

amitshekhariitbhu commented 7 years ago

The simple example is here https://github.com/amitshekhariitbhu/RxJava2-Android-Samples/blob/master/app/src/main/java/com/rxjava2/android/samples/ui/rxbus/RxBusActivity.java