當前位置: 首頁>>代碼示例>>Java>>正文


Java PublishSubject.onNext方法代碼示例

本文整理匯總了Java中io.reactivex.subjects.PublishSubject.onNext方法的典型用法代碼示例。如果您正苦於以下問題:Java PublishSubject.onNext方法的具體用法?Java PublishSubject.onNext怎麽用?Java PublishSubject.onNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.subjects.PublishSubject的用法示例。


在下文中一共展示了PublishSubject.onNext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onRequestPermissionsResult

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        Log.i("","onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
開發者ID:ChangWeiBa,項目名稱:AesExoPlayer,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例2: monitor

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
private void monitor(InputStream input, PublishSubject<String> subject) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding));
    final int BUFFERSIZE = 4096;
    char[] buffer = new char[BUFFERSIZE];
    while (true) {
        try {
            if (Thread.interrupted()) {
                subject.onComplete();
                return;
            }
            int read = reader.read(buffer, 0, BUFFERSIZE);
            if (read == -1) {
                subject.onComplete();
                return;
            }

            subject.onNext(new String(buffer, 0, read));
        } catch (IOException e) {
            subject.onError(e);
            return;
        }
    }
}
 
開發者ID:Microsoft,項目名稱:java-debug,代碼行數:24,代碼來源:ProcessConsole.java

示例3: eventOutOfLifecycle

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void eventOutOfLifecycle() {
    PublishSubject<String> stream = PublishSubject.create();
    PublishSubject<String> lifecycle = PublishSubject.create();

    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    // Event is out of lifecycle, but this just results in completing the stream
    lifecycle.onNext("destroy");
    stream.onNext("1");

    testObserver.assertNoValues();
    testObserver.assertComplete();
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:17,代碼來源:OutsideLifecycleExceptionTest.java

示例4: doSomeWork

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
private void doSomeWork() {

        PublishSubject<Integer> source = PublishSubject.create();
        ConnectableObservable<Integer> connectableObservable = source.replay(3); // bufferSize = 3 to retain 3 values to replay
        connectableObservable.connect(); // connecting the connectableObservable

        connectableObservable.subscribe(getFirstObserver());

        source.onNext(1);
        source.onNext(2);
        source.onNext(3);
        source.onNext(4);
        source.onComplete();

        /*
         * it will emit 2, 3, 4 as (count = 3), retains the 3 values for replay
         */
        connectableObservable.subscribe(getSecondObserver());

    }
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:21,代碼來源:ReplayExampleActivity.java

示例5: onRequestPermissionsResult

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = (grantResults[i] == PackageManager.PERMISSION_GRANTED) && (PermissionChecker.checkSelfPermission(getContext(), permissions[i]) == PermissionChecker.PERMISSION_GRANTED);
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
開發者ID:CodyyAndroid,項目名稱:RxPermissions,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例6: onRequestPermissionsResult

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
void onRequestPermissionsResult(String permissions[], int[] grantResults, boolean[] shouldShowRequestPermissionRationale) {
    for (int i = 0, size = permissions.length; i < size; i++) {
        log("onRequestPermissionsResult  " + permissions[i]);
        // Find the corresponding subject
        PublishSubject<Permission> subject = mSubjects.get(permissions[i]);
        if (subject == null) {
            // No subject found
            Log.e(RxPermissions.TAG, "RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.");
            return;
        }
        mSubjects.remove(permissions[i]);
        boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED;
        subject.onNext(new Permission(permissions[i], granted, shouldShowRequestPermissionRationale[i]));
        subject.onComplete();
    }
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:17,代碼來源:RxPermissionsFragment.java

示例7: doSomeWork

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
/**
 * PublishSubject隻會把在訂閱發生的時間點之後來自原始Observable的數據發射給觀察者。
 * 需要注意的是,PublishSubject可能會一創建完成就立刻開始發射數據(除非你可以阻止它發生),
 * 因此這裏有一個風險:在Subject被創建後到有觀察者訂閱它之前這個時間段內,一個或多個數據可能會丟失。
 * 如果要確保來自原始Observable的所有數據都被分發:
 * 1.使用Create創建那個Observable以便手動給它引入"冷"Observable的行為(當所有觀察者都已經訂閱時才開始發射數據)
 * 2.改用ReplaySubject。
 *
 * 如果原始的Observable因為發生了一個錯誤而終止,PublishSubject將不會發射任何數據,隻是簡單的向前傳遞這個錯誤通知。
 */
private void doSomeWork() {

    PublishSubject<Integer> source = PublishSubject.create();

    source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete

    source.onNext(1);
    source.onNext(2);
    source.onNext(3);

    /*
     * it will emit 4 and onComplete for second observer also.
     */
    source.subscribe(getSecondObserver());

    source.onNext(4);
    source.onComplete();
}
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:29,代碼來源:PublishSubjectExampleActivity.java

示例8: onUserQuery_2subsequentQueriesProvided_shouldPost2EventsWithQueryString

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void onUserQuery_2subsequentQueriesProvided_shouldPost2EventsWithQueryString() {
  // given
  TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
  PublishSubject<String> userQueryIntents = PublishSubject.create();
  given(view.queryInput$()).willReturn(userQueryIntents);
  UserQueryPresenter presenter = new UserQueryPresenter(Sink.of(userQuery$));
  presenter.start(view);

  // when
  userQueryIntents.onNext("foo");
  userQueryIntents.onNext("bar");

  // then
  userQuery$.assertValueCount(2);
  List<UserQueryEvent> events = userQuery$.values();
  assertThat(events)
      .extracting(UserQueryEvent::getQuery)
      .containsExactly("foo", "bar");
}
 
開發者ID:xemantic,項目名稱:github-users,代碼行數:21,代碼來源:UserQueryPresenterTest.java

示例9: onUserQueryEvent_emptyQueryString_shouldDoNothingWithView

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void onUserQueryEvent_emptyQueryString_shouldDoNothingWithView() {
  // given
  PublishSubject<UserQueryEvent> userQuery$ = PublishSubject.create();
  UserListPresenter presenter = new UserListPresenter(
      userQuery$,
      userService,
      () -> mock(UserView.class),
      () -> mock(UserPresenter.class),
      DEFAULT_PAGE_SIZE,
      DEFAULT_USER_SEARCH_LIMIT
  );
  presenter.start(view);
  UserQueryEvent event = new UserQueryEvent(" "); // empty string

  // when
  userQuery$.onNext(event);

  // then
  verifyNoMoreInteractions(view, userService);
}
 
開發者ID:xemantic,項目名稱:github-users,代碼行數:22,代碼來源:UserListPresenterTest.java

示例10: rxActivity_delaySubscription_shouldIgnoreOtherEvents

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void rxActivity_delaySubscription_shouldIgnoreOtherEvents() {
  ActivityController<EmptyActivity> activityController = buildActivity(EmptyActivity.class);
  final RibActivity activity = activityController.get();

  final PublishSubject<Object> subject = PublishSubject.create();
  AndroidRecordingRx2Observer<Object> o = new AndroidRecordingRx2Observer<>();
  subject
      .hide()
      .delaySubscription(
          activity
              .lifecycle()
              .filter(
                  new Predicate<ActivityLifecycleEvent>() {
                    @Override
                    public boolean test(ActivityLifecycleEvent activityEvent) throws Exception {
                      return activityEvent.getType() == ActivityLifecycleEvent.Type.RESUME;
                    }
                  }))
      .subscribe(o);

  subject.onNext(new Object());
  activityController.create();
  subject.onNext(new Object());
  o.assertNoMoreEvents();
  activityController.start();
  subject.onNext(new Object());
  o.assertNoMoreEvents();
  activityController.postCreate(null);
  subject.onNext(new Object());
  o.assertNoMoreEvents();
  activityController.resume();
  subject.onNext(new Object());
  assertThat(o.takeNext()).isNotNull();
  o.assertNoMoreEvents();
}
 
開發者ID:uber,項目名稱:RIBs,代碼行數:37,代碼來源:RibActivityTest.java

示例11: eventThrowsBadException

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void eventThrowsBadException() {
    PublishSubject<String> stream = PublishSubject.create();
    PublishSubject<String> lifecycle = PublishSubject.create();

    TestObserver<String> testObserver = stream
        .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS))
        .test();

    // We get an error from the function for this lifecycle event
    lifecycle.onNext("ick");
    stream.onNext("1");

    testObserver.assertNoValues();

    // We only want to check for our IllegalArgumentException, but may have
    // to wade through a CompositeException to get at it.
    testObserver.assertError(new Predicate<Throwable>() {
        @Override
        public boolean test(Throwable throwable) throws Exception {
            if (throwable instanceof CompositeException) {
                CompositeException ce = (CompositeException) throwable;
                for (Throwable t : ce.getExceptions()) {
                    if (t instanceof IllegalArgumentException) {
                        return true;
                    }
                }
            }

            return false;
        }
    });
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:34,代碼來源:OutsideLifecycleExceptionTest.java

示例12: main

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observer<Long> observer=new Observer<Long>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("It's Done");
			
		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			throwable.printStackTrace();
			
		}

		@Override
		public void onNext(Long value) {
			// TODO Auto-generated method stub
			System.out.println(":"+value);
		}

		@Override
		public void onSubscribe(Disposable disposable) {
			// TODO Auto-generated method stub
			System.out.println("onSubscribe");
			
		}
	};

	PublishSubject< Long> publishSubject=PublishSubject.create();
	publishSubject.onNext(1L);
	publishSubject.onNext(2l);
	publishSubject.subscribe(observer);
	publishSubject.onNext(10l);
	publishSubject.onNext(20l);
	publishSubject.onComplete();
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:41,代碼來源:Demo_PublishSubject.java

示例13: test_PublishSubject

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void test_PublishSubject() {
	PublishSubject<Long> publishSubject = PublishSubject.create();
	publishSubject.onNext(1L);
	publishSubject.onNext(2l);
	Assert.assertFalse(publishSubject.hasObservers());

	TestObserver<Long> testObserver = publishSubject.test(true);
	Assert.assertFalse(publishSubject.hasObservers());
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:11,代碼來源:Test_test_operator.java

示例14: demo4

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
private void demo4() {
    PublishSubject<Integer> observable = PublishSubject.create();

    observable.toFlowable(BackpressureStrategy.MISSING)
            .buffer(10)
            .observeOn(Schedulers.computation())
            .subscribe(v -> log("s", v.toString()), this::log);

    for (int i = 0; i < 1000000; i++) {
        observable.onNext(i);
    }
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:13,代碼來源:MainActivity.java

示例15: onCall_observablePublishesEvent_shouldExecuteSubscriberCall

import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void onCall_observablePublishesEvent_shouldExecuteSubscriberCall() throws Exception {
  // given
  PublishSubject<String> subject = PublishSubject.create();
  TestPresenter presenter = new TestPresenter();
  presenter.on(subject).call(subscriber);

  // when
  subject.onNext("foo");

  // then
  verify(subscriber).accept("foo");
  verifyNoMoreInteractions(subscriber);
}
 
開發者ID:xemantic,項目名稱:github-users,代碼行數:15,代碼來源:PresenterTest.java


注:本文中的io.reactivex.subjects.PublishSubject.onNext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。