当前位置: 首页>>代码示例>>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;未经允许,请勿转载。