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


Java Consumer類代碼示例

本文整理匯總了Java中io.reactivex.functions.Consumer的典型用法代碼示例。如果您正苦於以下問題:Java Consumer類的具體用法?Java Consumer怎麽用?Java Consumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: resultThrowingInOnSuccessDeliveredToPlugin

import io.reactivex.functions.Consumer; //導入依賴的package包/類
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:MaybeThrowingTest.java

示例2: toConsumer

import io.reactivex.functions.Consumer; //導入依賴的package包/類
/**
 * Adapt a {@link Sender} to rx-java's {@link Consumer}
 */
@SuppressWarnings("unchecked")
static <M extends Message, R> Consumer<List<SendingTask<M>>> toConsumer(final Sender<M, R> sender) {
  return new Consumer<List<SendingTask<M>>>() {
    @Override
    public void accept(List<SendingTask<M>> tasks) throws Exception {
      if (tasks.isEmpty()) return;
      logger.debug("Sending {} messages.", tasks.size());

      Object[] messageAndDeferred = SendingTask.unzipGeneric(tasks);
      final List<M> messages = (List<M>) messageAndDeferred[0];
      final List<Deferred> deferreds = (List<Deferred>) messageAndDeferred[1];

      try {
        List<R> result = sender.send(messages);
        Deferreds.resolveAll(result, deferreds);
      } catch (Throwable t) {
        Deferreds.rejectAll(MessageDroppedException.dropped(t, messages), deferreds, messages);
      }
    }
  };
}
 
開發者ID:tramchamploo,項目名稱:buffer-slayer,代碼行數:25,代碼來源:SenderConsumerBridge.java

示例3: doDeletingScriptFile

import io.reactivex.functions.Consumer; //導入依賴的package包/類
private void doDeletingScriptFile() {
    mScriptListWithProgressBarView.showProgressBar();
    Observable.fromPublisher(new Publisher<Boolean>() {
        @Override
        public void subscribe(Subscriber<? super Boolean> s) {
            s.onNext(PFile.deleteRecursively(mSelectedScriptFile));
        }
    }).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(@io.reactivex.annotations.NonNull Boolean deleted) throws Exception {
                    showMessage(deleted ? R.string.text_already_delete : R.string.text_delete_failed);
                    notifyScriptFileChanged();
                    onScriptFileOperated();
                }
            });
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:19,代碼來源:MyScriptListFragment.java

示例4: onCreate

import io.reactivex.functions.Consumer; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RxBeacon.with(this)
            //.addBeaconParser(RxBeaconParser.ESTIMOTE)
            .beaconsInRegion()
            .subscribe(new Consumer<RxBeaconRange>() {
                @Override
                public void accept(@NonNull RxBeaconRange rxBeaconRange) throws Exception {
                    Log.d("beaconsInRegion", rxBeaconRange.toString());
                }
            });

    //RxBeacon.with(this)
    //        .addBeaconParser("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")
    //        .monitor()
    //        .subscribe(new Consumer<RxBeaconMonitor>() {
    //            @Override
    //            public void accept(@NonNull RxBeaconMonitor rxBeaconMonitor) throws Exception {
    //                Log.d("monitor", rxBeaconMonitor.toString());
    //            }
    //        });
}
 
開發者ID:florent37,項目名稱:RxBeacon,代碼行數:26,代碼來源:MainActivity.java

示例5: onCardExhausted

import io.reactivex.functions.Consumer; //導入依賴的package包/類
@Override
public void onCardExhausted() {
    getCompositeDisposable().add(getDataManager()
            .getAllQuestions()
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<List<Question>>() {
                @Override
                public void accept(List<Question> questionList) throws Exception {
                    if (!isViewAttached()) {
                        return;
                    }

                    if (questionList != null) {
                        getMvpView().reloadQuestionnaire(questionList);
                    }
                }
            }));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:MainPresenter.java

示例6: map

import io.reactivex.functions.Consumer; //導入依賴的package包/類
private void map() {
    Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e.onNext(1);
            e.onNext(2);
            e.onNext(3);
        }
    }).map(new Function<Integer, String>() {
        @Override
        public String apply(Integer integer) throws Exception {
            return "This is result " + integer;
        }
    }).subscribe(new Consumer<String>() {
        @Override
        public void accept(String s) throws Exception {
            Log.e(MainActivity.TAG, "accept: " + Thread.currentThread().getName());
            info += s + "\n";
            tv.setText(info);
        }
    });
}
 
開發者ID:penghuanliang,項目名稱:Rxjava2.0Demo,代碼行數:23,代碼來源:MapActivity.java

示例7: loadSearchHistory

import io.reactivex.functions.Consumer; //導入依賴的package包/類
@Override
public void loadSearchHistory() {
    getCompositeDisposableHelper().addDisposable(getDataManager()
            .getSearchHistory()
            .compose(getCompositeDisposableHelper().<List<OrmHistory>>applySchedulers())
            .subscribe(new Consumer<List<OrmHistory>>() {
                @Override
                public void accept(List<OrmHistory> histories) throws Exception {
                    if (!histories.isEmpty()) {
                        getMvpView().showSearchHistory(histories);
                    } else {
                        getMvpView().showEmptySearchHistory();
                    }
                }
            }));
}
 
開發者ID:graviton57,項目名稱:TheNounProject,代碼行數:17,代碼來源:HomePresenter.java

示例8: requestLoadingList

import io.reactivex.functions.Consumer; //導入依賴的package包/類
public void requestLoadingList() {
    Observable.create(new ObservableOnSubscribe<List<ConfigBean>>() {
        @Override
        public void subscribe(ObservableEmitter<List<ConfigBean>> e) throws Exception {
            mModel = ConfigModel.getInstance(configView.getContext());
            e.onNext(mModel.getConfigList());
            mModel.setConfigCallback(ConfigPresenter.this);
        }
    })
            .observeOn(Schedulers.io())
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<List<ConfigBean>>() {
                @Override
                public void accept(List<ConfigBean> list) throws Exception {
                    configView.displayConfigList(list);
                }
            });

}
 
開發者ID:piyell,項目名稱:NeteaseCloudMusic,代碼行數:20,代碼來源:ConfigPresenter.java

示例9: checkVersion

import io.reactivex.functions.Consumer; //導入依賴的package包/類
public void checkVersion(){
    ZBHClient.getInstance()
            .create(ZBHServices.class, Constants.BASE_UPGRADE_URL)
            .getVersionInfo()
            .subscribeOn(Schedulers.io())//在子線程做請求處理
            .observeOn(AndroidSchedulers.mainThread())//回到主線程做數據處理
            .subscribe(new Consumer<VersionBean>() {
                @Override
                public void accept(VersionBean versionBean) throws Exception {
                    //彈出提示並更新
                    showUpgradeDialog(versionBean);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {

                }
            });
}
 
開發者ID:JunGeges,項目名稱:AliZhiBoHao,代碼行數:20,代碼來源:WebActivity.java

示例10: loadMore

import io.reactivex.functions.Consumer; //導入依賴的package包/類
@Override
public void loadMore(int start) {
    application.getRepertories()
            .getList(start, COUNT, null, RemoteApi.Status.RECRUITING, keywords, false)
            .subscribe(new Consumer<List<ProjectBean>>() {
                @Override
                public void accept(List<ProjectBean> projectBeen) throws Exception {
                    getView().addData(projectBeen);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    getView().loadMoreError(throwable);
                }
            });
}
 
開發者ID:ittianyu,項目名稱:POCenter,代碼行數:17,代碼來源:SearchPresenter.java

示例11: showKeyboard

import io.reactivex.functions.Consumer; //導入依賴的package包/類
/**
 * 彈出鍵盤(可能存在視圖尚未加載完成,需要延遲一段時間彈出)
 **/
public void showKeyboard() {
    Single.just(0)
            .delay(300, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSuccess(new Consumer<Integer>() {
                @Override
                public void accept(Integer integer) throws Exception {
                    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    edit.requestFocus();
                    imm.showSoftInput(edit, 0);
                }
            })
            .subscribeOn(Schedulers.io())
            .subscribe();

}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:20,代碼來源:RealTimeUpdateSearchBox.java

示例12: put

import io.reactivex.functions.Consumer; //導入依賴的package包/類
private void put() {
    AvenueNetClient.builder("put")
            .param("name", "putname")
            .build()
            .put()
            .subscribe(new Consumer<String>() {
                @Override
                public void accept(String s) throws Exception {
                    Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    Toast.makeText(MainActivity.this, throwable.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
}
 
開發者ID:QuincySx,項目名稱:AvenueNet,代碼行數:18,代碼來源:MainActivity.java

示例13: onBtnTakePictureClicked

import io.reactivex.functions.Consumer; //導入依賴的package包/類
@OnClick(R.id.btn_take_picture)
public void onBtnTakePictureClicked() {
    rxPermissions.request(Manifest.permission.CAMERA)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    if (aBoolean) {
                        openCamera();
                    } else {
                        ToastUtils.showShortToast("權限被拒絕");
                    }
                }

            });

}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:17,代碼來源:ImageActivity.java

示例14: externalStorage

import io.reactivex.functions.Consumer; //導入依賴的package包/類
public static void externalStorage(final RequestPermission requestPermission, final PickerContract.IPickerView view) {
    RxPermissions rxPermissions = new RxPermissions((Activity) view);
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (isPermissionsGranted) {
        requestPermission.onRequestPermissionSuccess();
    } else {
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(@NonNull Boolean aBoolean) throws Exception {
                        if (aBoolean) {
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage(((Activity) view).getResources().getString(R.string.request_permission_fail));
                        }
                    }
                });
    }
}
 
開發者ID:liuke2016,項目名稱:filepicker,代碼行數:24,代碼來源:Util.java

示例15: delayAndSwitchToState

import io.reactivex.functions.Consumer; //導入依賴的package包/類
private void delayAndSwitchToState(@ViewState int state) {
    disposable = Flowable.just(state)
            .delay(3000, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<Integer>() {
                @Override
                public void accept(Integer currentState) throws Exception {
                    stateView.setState(currentState);
                    if (currentState == ViewState.CONTENT) {
                        displayContents();
                        delayAndSwitchToState(ViewState.LOADING);
                    } else {
                        delayAndSwitchToState(ViewState.CONTENT);
                    }
                }
            });
}
 
開發者ID:elms1990,項目名稱:many-faced-view,代碼行數:18,代碼來源:CustomAnimationTestActivity.java


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