本文整理汇总了Java中io.reactivex.functions.Action类的典型用法代码示例。如果您正苦于以下问题:Java Action类的具体用法?Java Action怎么用?Java Action使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Action类属于io.reactivex.functions包,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: observeNetworkConnectivity
import io.reactivex.functions.Action; //导入依赖的package包/类
@Override public Observable<Connectivity> observeNetworkConnectivity(final Context context) {
final String service = Context.CONNECTIVITY_SERVICE;
final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
networkCallback = createNetworkCallback(context);
registerIdleReceiver(context);
final NetworkRequest request =
new NetworkRequest.Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
.build();
manager.registerNetworkCallback(request, networkCallback);
return connectivitySubject.toFlowable(BackpressureStrategy.LATEST).doOnCancel(new Action() {
@Override public void run() {
tryToUnregisterCallback(manager);
tryToUnregisterReceiver(context);
}
}).startWith(Connectivity.create(context)).distinctUntilChanged().toObservable();
}
示例2: observeNetworkConnectivity
import io.reactivex.functions.Action; //导入依赖的package包/类
@Override public Observable<Connectivity> observeNetworkConnectivity(final Context context) {
final String service = Context.CONNECTIVITY_SERVICE;
final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
return Observable.create(new ObservableOnSubscribe<Connectivity>() {
@Override public void subscribe(ObservableEmitter<Connectivity> subscriber) throws Exception {
networkCallback = createNetworkCallback(subscriber, context);
final NetworkRequest networkRequest = new NetworkRequest.Builder().build();
manager.registerNetworkCallback(networkRequest, networkCallback);
}
}).doOnDispose(new Action() {
@Override public void run() {
tryToUnregisterCallback(manager);
}
}).startWith(Connectivity.create(context)).distinctUntilChanged();
}
示例3: realmList_closeInDoOnUnsubscribe
import io.reactivex.functions.Action; //导入依赖的package包/类
@Test
@UiThreadTest
public void realmList_closeInDoOnUnsubscribe() {
realm.beginTransaction();
RealmList<Dog> list = realm.createObject(AllTypes.class).getColumnRealmList();
realm.commitTransaction();
Flowable<RealmList<Dog>> observable = list.asFlowable().doOnCancel(new Action() {
@Override
public void run() throws Exception {
realm.close();
}
});
subscription = observable.subscribe(new Consumer<RealmList<Dog>>() {
@Override
public void accept(RealmList<Dog> ignored) throws Exception {
}
});
subscription.dispose();
assertTrue(realm.isClosed());
}
示例4: dynamicRealmResults_closeInDoOnUnsubscribe
import io.reactivex.functions.Action; //导入依赖的package包/类
@Test
@UiThreadTest
public void dynamicRealmResults_closeInDoOnUnsubscribe() {
final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
Flowable<RealmResults<DynamicRealmObject>> flowable = dynamicRealm.where(AllTypes.CLASS_NAME).findAll().asFlowable()
.doOnCancel(new Action() {
@Override
public void run() throws Exception {
dynamicRealm.close();
}
});
subscription = flowable.subscribe(new Consumer<RealmResults<DynamicRealmObject>>() {
@Override
public void accept(RealmResults<DynamicRealmObject> ignored) throws Exception {
}
});
subscription.dispose();
assertTrue(dynamicRealm.isClosed());
}
示例5: realmObject_closeInDoOnUnsubscribe
import io.reactivex.functions.Action; //导入依赖的package包/类
@Test
@UiThreadTest
public void realmObject_closeInDoOnUnsubscribe() {
realm.beginTransaction();
realm.createObject(AllTypes.class);
realm.commitTransaction();
Flowable<AllTypes> flowable = realm.where(AllTypes.class).findFirst().<AllTypes>asFlowable()
.doOnCancel(new Action() {
@Override
public void run() throws Exception {
realm.close();
}
});
subscription = flowable.subscribe(new Consumer<AllTypes>() {
@Override
public void accept(AllTypes ignored) throws Exception {
}
});
subscription.dispose();
assertTrue(realm.isClosed());
}
示例6: restart
import io.reactivex.functions.Action; //导入依赖的package包/类
private void restart() {
mCompositeDisposable.add(FFMService.restart()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doFinally(new Action() {
@Override
public void run() throws Exception {
findPreference("restart_webqq").setEnabled(true);
}
})
.subscribe(new Consumer<FFMResult>() {
@Override
public void accept(FFMResult ffmResult) throws Exception {
Toast.makeText(getContext(), "Succeed.", Toast.LENGTH_SHORT).show();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Toast.makeText(getContext(), "Network error:\n" + throwable.getMessage(), Toast.LENGTH_SHORT).show();
}
}));
}
示例7: stop
import io.reactivex.functions.Action; //导入依赖的package包/类
private void stop() {
mCompositeDisposable.add(FFMService.stop()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doFinally(new Action() {
@Override
public void run() throws Exception {
findPreference("stop_webqq").setEnabled(true);
}
})
.subscribe(new Consumer<FFMResult>() {
@Override
public void accept(FFMResult ffmResult) throws Exception {
Toast.makeText(getContext(), "Succeed.", Toast.LENGTH_SHORT).show();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Toast.makeText(getContext(), "Network error:\n" + throwable.getMessage(), Toast.LENGTH_SHORT).show();
}
}));
}
示例8: beforeEachTest
import io.reactivex.functions.Action; //导入依赖的package包/类
@Before public void beforeEachTest() {
MockitoAnnotations.initMocks(this);
ToogleRefreshView view = new ToogleRefreshView() {
@Override public Action disableRefresh() {
return disableRefresh;
}
@Override public Action enableRefresh() {
return enableRefresh;
}
};
toogler = new RefreshToogle<>(view, uiScheduler);
}
示例9: synthesizeAndShowResp
import io.reactivex.functions.Action; //导入依赖的package包/类
/**
* 合成并显示回复文本
**/
private void synthesizeAndShowResp(final List<Track> tracks, String content, final int finalPlayIndex) {
EventBus.getDefault().post(new ChatMsgEvent(new ResponseMsg(content), null, null, null));
SynthesizerBase.get().startSpeakAbsolute(content)
.doOnNext(new Consumer<SpeechMsg>() {
@Override
public void accept(SpeechMsg speechMsg) throws Exception {
if (speechMsg.state() == SpeechMsg.State.OnBegin)
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_START));
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_END));
if (tracks != null)
XmlyManager.get().getPlayer().playList(tracks, finalPlayIndex);
}
})
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.subscribe();
}
示例10: speakAndAheadReturn
import io.reactivex.functions.Action; //导入依赖的package包/类
/**
* 合成文本并提前返回
**/
private void speakAndAheadReturn(String text, SpeechMsgBuilder msgBuilder) {
/* 将回复文本发送到聊天列表 */
EventBus.getDefault().post(new ChatMsgEvent(new ResponseMsg(text), null, null, null));
/* 合成回复文本 */
msgBuilder.setText(text).setForceLocalEngine(true);
SynthesizerBase.get().startSpeakAbsolute(msgBuilder.build())
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
EventBus.getDefault().post(new NavigateEvent(NavigateEvent.START_NAVI));
}
})
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.subscribe();
}
示例11: doSomeWork
import io.reactivex.functions.Action; //导入依赖的package包/类
/**
* takeUntil与skipUntil操作符作用相反,订阅并开始发射原始Observable,它还监视你提供的第二个Observable。
* 如果第二个Observable发射了一项数据或者发射了一个终止通知( onError通知或一个onComplete通知),
* TakeUntil返回的Observable会停止发射原始Observable并终止。
*/
private void doSomeWork() {
if (!isRunning) {
Observable
.interval(1, TimeUnit.SECONDS)
.take(6)
.takeUntil(Observable.just(10).delay(3, TimeUnit.SECONDS))
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
isRunning = true;
}
})
.doOnTerminate(new Action() {
@Override
public void run() throws Exception {
isRunning = false;
}
})
// Run on a background thread
.subscribeOn(Schedulers.io())
// Be notified on the main thread
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getObserver());
}
}
示例12: onStart
import io.reactivex.functions.Action; //导入依赖的package包/类
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
// Using automatic unsubscription, this should determine that the correct time to
// unsubscribe is onStop (the opposite of onStart).
Observable.interval(1, TimeUnit.SECONDS)
.doOnDispose(new Action() {
@Override
public void run() throws Exception {
Log.i(TAG, "Unsubscribing subscription from onStart()");
}
})
.compose(this.<Long>bindToLifecycle())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long num) throws Exception {
Log.i(TAG, "Started in onStart(), running until in onStop(): " + num);
}
});
}
示例13: speak
import io.reactivex.functions.Action; //导入依赖的package包/类
private void speak(SpeechMsgBuilder msgBuilder, final boolean isAnim) {
SynthesizerBase.get().startSpeakAbsolute(msgBuilder.build())
.doOnNext(new Consumer<SpeechMsg>() {
@Override
public void accept(SpeechMsg speechMsg) throws Exception {
if (speechMsg.state() == SpeechMsg.State.OnBegin && isAnim)
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_START));
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_END));
}
})
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.subscribe();
}
示例14: synthesizeAndShowResp
import io.reactivex.functions.Action; //导入依赖的package包/类
/**
* 合成并显示回复文本
**/
private void synthesizeAndShowResp(final List<Track> tracks, String content, final int finalPlayIndex) {
EventBus.getDefault().post(new ChatMsgEvent(new ResponseMsg(content), null, null, null));
IflySynthesizer.get().startSpeakAbsolute(content)
.doOnNext(new Consumer<SpeechMsg>() {
@Override
public void accept(SpeechMsg speechMsg) throws Exception {
if (speechMsg.state() == SpeechMsg.State.OnBegin)
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_START));
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_END));
if (tracks != null)
XmPlayerManager.getInstance(mContext).playList(tracks, finalPlayIndex);
}
})
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.subscribe();
}
示例15: showAndSpeak
import io.reactivex.functions.Action; //导入依赖的package包/类
/**
* 发送回复文本文本视图并合成声音
**/
private void showAndSpeak(SpeechMsgBuilder builder) {
EventBus.getDefault().post(new ChatMsgEvent(new ResponseMsg(builder.getText()), null, null, null));
IflySynthesizer.getInstance().startSpeakAbsolute(builder.build())
.doOnNext(new Consumer<SpeechMsg>() {
@Override
public void accept(SpeechMsg speechMsg) throws Exception {
if (speechMsg.state() == SpeechMsg.State.OnBegin)
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_START));
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_END));
}
})
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.computation())
.subscribe();
}