当前位置: 首页>>代码示例>>Java>>正文


Java Action类代码示例

本文整理汇总了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();
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:22,代码来源:MarshmallowNetworkObservingStrategy.java

示例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();
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:17,代码来源:LollipopNetworkObservingStrategy.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxJavaTests.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RxJavaTests.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RxJavaTests.java

示例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();
                }
            }));
}
 
开发者ID:RikkaApps,项目名称:FCM-for-Mojo,代码行数:23,代码来源:ServerSettingsFragment.java

示例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();
                }
            }));
}
 
开发者ID:RikkaApps,项目名称:FCM-for-Mojo,代码行数:23,代码来源:ServerSettingsFragment.java

示例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);
}
 
开发者ID:ubiratansoares,项目名称:reactive-architectures-playground,代码行数:17,代码来源:ToogleRefreshTests.java

示例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();

}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:27,代码来源:TingPlayProcessor.java

示例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();
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:21,代码来源:NaviProcessor.java

示例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());
    }
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:31,代码来源:TakeUntilExampleActivity.java

示例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);
            }
        });
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:24,代码来源:MainActivity.java

示例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();
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:20,代码来源:VoiceMediator.java

示例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();

}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:27,代码来源:ChatAlbumListAdapter.java

示例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();
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:24,代码来源:AssistPresenter.java


注:本文中的io.reactivex.functions.Action类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。