當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。