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


Java FlowableOnSubscribe類代碼示例

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


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

示例1: insertSystemAlbumAndRefresh

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
/**
 * 插入到係統相冊, 並刷新係統相冊
 * @param imageUrl
 */
private static void insertSystemAlbumAndRefresh(final String imageUrl) {
    Flowable.create(new FlowableOnSubscribe<Object>() {
        @Override
        public void subscribe(FlowableEmitter<Object> e) throws Exception {
            File file = FileUtils.createFileFrom(imageUrl);
            String imageUri = MediaStore.Images.Media.insertImage(ApplicationProvider.IMPL.getApp().getContentResolver(), file.getAbsolutePath(), file.getName(), "圖片: " + file.getName());
            Log.d("_stone_", "insertSystemAlbumAndRefresh-subscribe: imageUri=" + imageUri);


            //講數據插入到係統圖庫, 在係統相冊APP中就可以看到保存的圖片了.
            //為了保險起見, 再同步一下係統圖庫
            syncAlbum(imageUrl);
        }
    }, BackpressureStrategy.BUFFER)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe();
}
 
開發者ID:stone100,項目名稱:SaveImage2SystemAlbum,代碼行數:23,代碼來源:AlbumManager.java

示例2: processImage

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
private void processImage(@NonNull final Bitmap bitmap) {
    //Create observable
    Flowable<List<Classifier.Recognition>> observable = Flowable
            .create(new FlowableOnSubscribe<List<Classifier.Recognition>>() {
                @Override
                public void subscribe(FlowableEmitter<List<Classifier.Recognition>> emitter) throws Exception {
                    emitter.onNext(mTensorFlowImageClassifier.recognizeImage(bitmap));
                }
            }, BackpressureStrategy.MISSING);

    //Create observer
    Consumer<List<Classifier.Recognition>> mTfProcessorObserver = new Consumer<List<Classifier.Recognition>>() {
        @Override
        public void accept(@io.reactivex.annotations.NonNull List<Classifier.Recognition> recognitions) throws Exception {
            //Write the result on socket.
            String resultStr = "";
            for (Classifier.Recognition result : recognitions)
                resultStr = resultStr + result.getTitle() + " " + result.getConfidence() + "<br/>";
            mSocketWriter.writeMessage(resultStr);

            //Remove previous disposables.
            mCompositeDisposable.clear();
        }
    };

    //Start the observable
    mCompositeDisposable.add(observable.observeOn(Schedulers.io())
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe(mTfProcessorObserver));
}
 
開發者ID:kevalpatel2106,項目名稱:robo-car,代碼行數:31,代碼來源:Controller.java

示例3: asyncMethod

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
private void asyncMethod(final ProceedingJoinPoint joinPoint) throws Throwable {

        Flowable.create(new FlowableOnSubscribe<Object>() {
                            @Override
                            public void subscribe(FlowableEmitter<Object> e) throws Exception {
                                Looper.prepare();
                                try {
                                    joinPoint.proceed();
                                } catch (Throwable throwable) {
                                    throwable.printStackTrace();
                                }
                                Looper.loop();
                            }
                        }
                , BackpressureStrategy.BUFFER)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe();
    }
 
開發者ID:fengzhizi715,項目名稱:SAF-AOP,代碼行數:20,代碼來源:AsyncAspect.java

示例4: doPullStreamPost

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
@Override
public Flowable doPullStreamPost(final IRequestEntity requestEntity, final File file) {

    Flowable flowable = DefaultFlowable.create(new FlowableOnSubscribe() {
        @Override
        public void subscribe(FlowableEmitter emitter) throws Exception {
            final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            Gson gson = new Gson();
            String json = gson.toJson(requestEntity);
            RequestBody body = RequestBody.create(JSON, json);
            Request request = new Request.Builder()
                    .url(mUrl)
                    .post(body)
                    .build();
            Response response = mClient.newCall(request).execute();
            if (response == null) {
                emitter.onError(new EmptyException());
                return;
            }
            recvFile(emitter, response, file);
            emitter.onComplete();
        }
    });
    return flowable;
}
 
開發者ID:xiaoxige,項目名稱:AutoNet,代碼行數:26,代碼來源:AutoNetRepoImpl.java

示例5: createYourOwnTibco

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
@Test
public void createYourOwnTibco() throws Exception {
    Flowable<String> flowable = Flowable.create(new FlowableOnSubscribe<String>() {
        @Override
        public void subscribe(FlowableEmitter<String> e) throws Exception {
            while (!e.isCancelled()) {
                long numberRecords = e.requested();
                System.out.println(numberRecords);
                if (numberRecords > 0) {
                }
            }
        }
    }, BackpressureStrategy.BUFFER);


    flowable.map(x -> x + "Yay!").subscribe(System.out::println);
}
 
開發者ID:dhinojosa,項目名稱:rxjavatraining,代碼行數:18,代碼來源:TibcoObservableTest.java

示例6: getTiles

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
/**
 * @param path the root directory containing files to be emitted
 * @param depth offset, where 1 == data directory, 2 == zoom directory, 3 == row, 4 == column
 * @return a stream of file references to data structured as the Google tiling scheme.
 */
public static Observable<File> getTiles(String path, int depth) {
  // programmer's note:
  // https://medium.com/we-are-yammer/converting-callback-async-calls-to-rxjava-ebc68bde5831
  // http://vlkan.com/blog/post/2016/07/20/rxjava-backpressure/
  // Essentially lots of way to skin this cat - e.g. onBackpressureBlock /
  // reactive pull

  return Flowable.create(new FlowableOnSubscribe<File>() {
    @Override
    public void subscribe(FlowableEmitter<File> subscriber) throws Exception {
      try {
        // warning: depth 4 is not really walking (semantics)
        walk(path, depth, subscriber);
        if (!subscriber.isCancelled()) {
          subscriber.onComplete();
        }
      } catch (final Exception ex) {
        if (!subscriber.isCancelled()) {
          subscriber.onError(ex);
        }
      }
    }
  }, BackpressureStrategy.BUFFER).toObservable();
}
 
開發者ID:OrdnanceSurvey,項目名稱:vt-support,代碼行數:30,代碼來源:FilesystemUtil.java

示例7: flowable

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
@Override
public Flowable<T> flowable(BackpressureStrategy mode) {
    return Flowable.create(new FlowableOnSubscribe<T>() {
        @Override
        public void subscribe(FlowableEmitter<T> emitter) throws Exception {
            final CloseableIterator<T> iterator = mCallable.call();
            try {
                while (!emitter.isCancelled() && iterator.hasNext()) {
                    emitter.onNext(iterator.next());
                }
                emitter.onComplete();
            } finally {
                iterator.close();
            }
        }
    }, mode);
}
 
開發者ID:DanielSerdyukov,項目名稱:alchemy,代碼行數:18,代碼來源:RxJava2Fetchable.java

示例8: createFlowable

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
@Override
public final Flowable<RxTaskMessage<T, U>> createFlowable() {
    return Flowable.create(new FlowableOnSubscribe<RxTaskMessage<T, U>>() {
        @Override
        public void subscribe(final FlowableEmitter<RxTaskMessage<T, U>> e) throws Exception {
            TaskLogger.v(TAG, "subscribe start");
            T innerResult = run(new TaskAgent<U>() {
                @Override
                public void publishProgress(U progressObject) {
                    TaskLogger.v(TAG, "onProgress");
                    e.onNext(RxTaskMessage.<T, U>createProgress(progressObject));
                }
            });
            e.onNext(RxTaskMessage.<T, U>createResult(innerResult));
            e.onComplete();
            TaskLogger.v(TAG, "subscribe end");
        }
    }, BackpressureStrategy.ERROR);
}
 
開發者ID:AutSoft,項目名稱:AxoloTL,代碼行數:20,代碼來源:BaseRunTask.java

示例9: queryProvinces

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
/**
 * 查詢全國所有的省,從數據庫查詢
 */
private void queryProvinces() {
    getToolbar().setTitle("選擇省份");
    Flowable.create((FlowableOnSubscribe<String>) emitter -> {
        if (provincesList.isEmpty()) {
            provincesList.addAll(WeatherDB.loadProvinces(DBManager.getInstance().getDatabase()));
        }
        dataList.clear();
        for (Province province : provincesList) {
            emitter.onNext(province.mProName);
        }
        emitter.onComplete();
    }, BackpressureStrategy.BUFFER)
        .compose(RxUtil.ioF())
        .compose(RxUtil.activityLifecycleF(this))
        .doOnNext(proName -> dataList.add(proName))
        .doOnComplete(() -> {
            mProgressBar.setVisibility(View.GONE);
            currentLevel = LEVEL_PROVINCE;
            mAdapter.notifyDataSetChanged();
        })
        .subscribe();
}
 
開發者ID:xcc3641,項目名稱:SeeWeather,代碼行數:26,代碼來源:ChoiceCityActivity.java

示例10: queryCities

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
/**
 * 查詢選中省份的所有城市,從數據庫查詢
 */
private void queryCities() {
    getToolbar().setTitle("選擇城市");
    dataList.clear();
    mAdapter.notifyDataSetChanged();

    Flowable.create((FlowableOnSubscribe<String>) emitter -> {
        cityList = WeatherDB.loadCities(DBManager.getInstance().getDatabase(), selectedProvince.mProSort);
        for (City city : cityList) {
            emitter.onNext(city.mCityName);
        }
        emitter.onComplete();
    }, BackpressureStrategy.BUFFER)
        .compose(RxUtil.ioF())
        .compose(RxUtil.activityLifecycleF(this))
        .doOnNext(proName -> dataList.add(proName))
        .doOnComplete(() -> {
            currentLevel = LEVEL_CITY;
            mAdapter.notifyDataSetChanged();
            mRecyclerView.smoothScrollToPosition(0);
        })
        .subscribe();
}
 
開發者ID:xcc3641,項目名稱:SeeWeather,代碼行數:26,代碼來源:ChoiceCityActivity.java

示例11: googleObservable

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
private Flowable<GoogleSignInResult> googleObservable(Activity activity) {
    return Flowable.create((FlowableOnSubscribe<ConnectionResult>) e -> {
            e.onNext(mGoogleApiClient.blockingConnect(GOOGLE_API_CONNECTION_TIMEOUT_SECONDS,
                TimeUnit.SECONDS));
            e.onComplete();
        },
        BackpressureStrategy.DROP)
        .subscribeOn(Schedulers.io())
        .flatMap(connectionResult -> {
            if (!connectionResult.isSuccess()) {
                return Flowable.error(new LoginException(LoginException.GOOGLE_ERROR,
                    connectionResult.getErrorCode(), connectionResult.getErrorMessage()));
            }
            return Flowable.create(new GoogleSubscriber(this), BackpressureStrategy.DROP);
        })
        .doOnSubscribe(subscription -> activity.startActivityForResult(getGoogleSingInIntent(),
            RC_SIGN_IN))
        .doOnTerminate(() -> {
            mGoogleApiClient.disconnect();
            mGoogleApiClient = null;
            mGoogleCallback = null;
        });
}
 
開發者ID:hijamoya,項目名稱:RxLogin,代碼行數:24,代碼來源:RxLogin.java

示例12: getRealmItems

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
public static <T extends RealmModel> Flowable<RealmResults<T>> getRealmItems(Class clazz, HashMap<String, String> map) {
    return Flowable.create(new FlowableOnSubscribe<RealmResults<T>>() {
        @Override
        public void subscribe(FlowableEmitter<RealmResults<T>> emitter)
                throws Exception {
            Realm realm = Realm.getDefaultInstance();
            RealmQuery<T> query = realm.where(clazz);
            if (map != null) {
                for (Map.Entry<String, String> entry : map.entrySet()) {
                    query.equalTo(entry.getKey(), entry.getValue());
                }
            }
            RealmResults<T> results = query.findAll();

            final RealmChangeListener<RealmResults<T>> listener = _realm -> {
                if (!emitter.isCancelled()) {
                    emitter.onNext(results);
                }
            };
            emitter.setDisposable(Disposables.fromRunnable(() -> {
                results.removeChangeListener(listener);
                realm.close();
            }));
            results.addChangeListener(listener);
            emitter.onNext(results);
        }
    }, BackpressureStrategy.LATEST);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:RealmHelper.java

示例13: createData

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
/**
 * 生成Flowable
 * @param <T>
 * @return
 */
public static <T> Flowable<T> createData(final T t) {
    return Flowable.create(new FlowableOnSubscribe<T>() {
        @Override
        public void subscribe(FlowableEmitter<T> emitter) throws Exception {
            try {
                emitter.onNext(t);
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.BUFFER);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RxUtil.java

示例14: save

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
private Publisher<DownloadStatus> save(final Response<ResponseBody> response) {
    return Flowable.create(new FlowableOnSubscribe<DownloadStatus>() {
        @Override
        public void subscribe(FlowableEmitter<DownloadStatus> e) throws Exception {
            record.save(e, response);
        }
    }, BackpressureStrategy.LATEST);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:DownloadType.java

示例15: from

import io.reactivex.FlowableOnSubscribe; //導入依賴的package包/類
@Override
public <E> Flowable<RealmList<E>> from(Realm realm, final RealmList<E> list) {
    final RealmConfiguration realmConfig = realm.getConfiguration();
    return Flowable.create(new FlowableOnSubscribe<RealmList<E>>() {
        @Override
        public void subscribe(final FlowableEmitter<RealmList<E>> emitter) throws Exception {
            // Gets instance to make sure that the Realm is open for as long as the
            // Observable is subscribed to it.
            final Realm observableRealm = Realm.getInstance(realmConfig);
            listRefs.get().acquireReference(list);
            final RealmChangeListener<RealmList<E>> listener = new RealmChangeListener<RealmList<E>>() {
                @Override
                public void onChange(RealmList<E> results) {
                    if (!emitter.isCancelled()) {
                        emitter.onNext(list);
                    }
                }
            };
            list.addChangeListener(listener);

            // Cleanup when stream is disposed
            emitter.setDisposable(Disposables.fromRunnable(new Runnable() {
                @Override
                public void run() {
                    list.removeChangeListener(listener);
                    observableRealm.close();
                    listRefs.get().releaseReference(list);
                }
            }));

            // Emit current value immediately
            emitter.onNext(list);

        }
    }, BACK_PRESSURE_STRATEGY);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:RealmObservableFactory.java


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