@Test public void phoneStateChanges() { Application application = RuntimeEnvironment.application; TestSubscriber<PhoneStateChangedEvent> o = new TestSubscriber<>(); RxTelephonyManager.phoneStateChanges(application).subscribe(o); o.assertValues(); Intent intent1 = new Intent(ACTION_PHONE_STATE_CHANGED) .putExtra(EXTRA_STATE, EXTRA_INCOMING_NUMBER) .putExtra(EXTRA_INCOMING_NUMBER, "123-456-7890"); application.sendBroadcast(intent1); PhoneStateChangedEvent event1 = PhoneStateChangedEvent.create(EXTRA_INCOMING_NUMBER, "123-456-7890"); o.assertValues(event1); Intent intent2 = new Intent(ACTION_PHONE_STATE_CHANGED).putExtra(EXTRA_STATE, EXTRA_STATE_IDLE); application.sendBroadcast(intent2); PhoneStateChangedEvent event2 = PhoneStateChangedEvent.create(EXTRA_STATE_IDLE, null); o.assertValues(event1, event2); }
@CheckResult @NonNull public static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context) { checkNotNull(context, "context == null"); IntentFilter filter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); return RxBroadcastReceiver.create(context, filter) .map(new Func1<Intent, PhoneStateChangedEvent>() { @Override public PhoneStateChangedEvent call(Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); return PhoneStateChangedEvent.create(state, phoneNumber); } }); }
RxTelephonyManager { @CheckResult @NonNull public static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context) { checkNotNull(context, "context == null"); IntentFilter filter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); return RxBroadcastReceiver.create(context, filter) .map(new Func1<Intent, PhoneStateChangedEvent>() { @Override public PhoneStateChangedEvent call(Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); return PhoneStateChangedEvent.create(state, phoneNumber); } }); } }
RxTelephonyManager { @CheckResult @NonNull public static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context) { checkNotNull(context, "context == null"); IntentFilter filter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); return RxBroadcastReceiver.create(context, filter) .map(new Func1<Intent, PhoneStateChangedEvent>() { @Override public PhoneStateChangedEvent call(Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); return PhoneStateChangedEvent.create(state, phoneNumber); } }); } private  RxTelephonyManager(); }
RxTelephonyManager { @CheckResult @NonNull public static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context) { checkNotNull(context, "context == null"); IntentFilter filter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); return RxBroadcastReceiver.create(context, filter) .map(new Func1<Intent, PhoneStateChangedEvent>() { @Override public PhoneStateChangedEvent call(Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); return PhoneStateChangedEvent.create(state, phoneNumber); } }); } private  RxTelephonyManager(); @CheckResult @NonNull // static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context); }
RxTelephonyManager { @CheckResult @NonNull public static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context) { checkNotNull(context, "context == null"); IntentFilter filter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); return RxBroadcastReceiver.create(context, filter) .map(new Func1<Intent, PhoneStateChangedEvent>() { @Override public PhoneStateChangedEvent call(Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); return PhoneStateChangedEvent.create(state, phoneNumber); } }); } private  RxTelephonyManager(); @CheckResult @NonNull // static Observable<PhoneStateChangedEvent> phoneStateChanges(@NonNull final Context context);  }