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


Java ObservableOnSubscribe類代碼示例

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


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

示例1: onHandleParseHTML

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
@Override
public void onHandleParseHTML(final String url) {
    mView.showLoading(true);
    Observable.create(new ObservableOnSubscribe<ArrayList<ArticleItem>>() {
        @Override
        public void subscribe(ObservableEmitter<ArrayList<ArticleItem>> e) throws Exception {
            ArrayList<ArticleItem> list = new ArrayList<>();
            Document doc = Jsoup.connect(url).get();
            Elements ul = doc.getElementsByClass("list_line");
            for (Element u : ul) {
                Elements li = u.getElementsByTag("li");
                for (Element l : li) {
                    String text = l.getElementsByTag("a").text();
                    String href = l.getElementsByTag("a").attr("href");
                    String time = l.getElementsByTag("span").text();
                    list.add(new ArticleItem(text, href, time));
                }
            }
            e.onNext(list);
        }
    })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<ArrayList<ArticleItem>>() {
                @Override
                public void accept(@NonNull ArrayList<ArticleItem> articleItems) throws Exception {
                    mView.showList(articleItems);
                    mView.showLoading(false);
                }
            });
}
 
開發者ID:InnoFang,項目名稱:PartyBuildingStudies,代碼行數:32,代碼來源:NewsPresenter.java

示例2: beaconsInRegion

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
public Observable<RxBeaconRange> beaconsInRegion() {
    return startup()
            .flatMap(new Function<Boolean, ObservableSource<RxBeaconRange>>() {
                @Override
                public ObservableSource<RxBeaconRange> apply(@NonNull Boolean aBoolean) throws Exception {
                    return Observable.create(new ObservableOnSubscribe<RxBeaconRange>() {
                        @Override
                        public void subscribe(@NonNull final ObservableEmitter<RxBeaconRange> objectObservableEmitter) throws Exception {
                            beaconManager.addRangeNotifier(new RangeNotifier() {
                                @Override
                                public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
                                    objectObservableEmitter.onNext(new RxBeaconRange(collection, region));
                                }
                            });
                            beaconManager.startRangingBeaconsInRegion(getRegion());
                        }
                    });
                }
            });
}
 
開發者ID:florent37,項目名稱:RxBeacon,代碼行數:21,代碼來源:RxBeacon.java

示例3: getObservable

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
private Observable<Integer> getObservable() {
    return Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
            // send events with simulated time wait
            Thread.sleep(0);
            emitter.onNext(1); // skip
            emitter.onNext(2); // deliver
            Thread.sleep(505);
            emitter.onNext(3); // skip
            Thread.sleep(99);
            emitter.onNext(4); // skip
            Thread.sleep(100);
            emitter.onNext(5); // skip
            emitter.onNext(6); // deliver
            Thread.sleep(305);
            emitter.onNext(7); // deliver
            Thread.sleep(510);
            emitter.onComplete();
        }
    });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:ThrottleLastExampleActivity.java

示例4: insertRecipes

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
public void insertRecipes(@NonNull final ArrayList<Recipe> recipes, Observer<Integer> observer){
    Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            ContentValues[] contentValues = new ContentValues[recipes.size()];
            for (int i = 0; i < recipes.size(); ++i) {
                contentValues[i] = buildContentValuesFromRecipe(recipes.get(i));
            }
            int recipesAdded = mContext.getContentResolver().bulkInsert(RecipesContract.RecipeEntry.CONTENT_URI, contentValues);
            if (recipesAdded != 0){
                e.onNext(recipesAdded);
            } else {
                e.onError(new NullPointerException("Failed to insert"));
            }
            e.onComplete();
        }
    }).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(observer);
}
 
開發者ID:harrynp,項目名稱:BakingApp,代碼行數:21,代碼來源:RecipeDatabaseHelper.java

示例5: createResults

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
private Observable<List<Task>> createResults(QuerySelector<DbTask> querySelector) {
    return Observable.create((ObservableOnSubscribe<List<Task>>) emitter -> {
        Realm realm = Realm.getDefaultInstance();
        final RealmResults<DbTask> dbTasks = querySelector.createQuery(realm);
        final RealmChangeListener<RealmResults<DbTask>> realmChangeListener = element -> {
            if(element.isLoaded() && !emitter.isDisposed()) {
                List<Task> tasks = mapFrom(element);
                if(!emitter.isDisposed()) {
                    emitter.onNext(tasks);
                }
            }
        };
        emitter.setDisposable(Disposables.fromAction(() -> {
            if(dbTasks.isValid()) {
                dbTasks.removeChangeListener(realmChangeListener);
            }
            realm.close();
        }));
        dbTasks.addChangeListener(realmChangeListener);
    }).subscribeOn(looperScheduler.getScheduler()).unsubscribeOn(looperScheduler.getScheduler());
}
 
開發者ID:Zhuinden,項目名稱:simple-stack,代碼行數:22,代碼來源:TaskRepository.java

示例6: getObservable

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
private Observable<Integer> getObservable() {
    return Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
            // send events with simulated time wait
            //1(drop)--(400s<500s)---2(pass)---(600s>500s)---3(drop)---(100s<500s)---4(pass)---(605s>500s)---5(pass)---510s
            emitter.onNext(1); // skip
            Thread.sleep(400);
            emitter.onNext(2); // deliver
            Thread.sleep(600);
            emitter.onNext(3); // skip
            Thread.sleep(100);
            emitter.onNext(4); // deliver
            Thread.sleep(605);
            emitter.onNext(5); // deliver
            Thread.sleep(510);
            emitter.onComplete();
        }
    });
}
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:21,代碼來源:DebounceExampleActivity.java

示例7: getAllIcons

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
public Disposable getAllIcons() {
    return Observable.create(new ObservableOnSubscribe<IconBean>() {
        @Override
        public void subscribe(@NonNull ObservableEmitter<IconBean> e) throws Exception {
            XmlResourceParser xml = mView.getResources().getXml(R.xml.drawable);

            while (xml.getEventType() != XmlResourceParser.END_DOCUMENT) {
                if (xml.getEventType() == XmlPullParser.START_TAG) {
                    if (xml.getName().startsWith("item")) {
                        IconBean bean = new IconBean();

                        String iconName = xml.getAttributeValue(null, "drawable");
                        bean.id = mView.getResources().getIdentifier(
                                iconName, "drawable", BuildConfig.APPLICATION_ID);
                        bean.name = iconName;

                        e.onNext(bean);
                    }
                }
                xml.next();
            }
            e.onComplete();
        }
    }).toList().subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<List<IconBean>>() {
                @Override
                public void accept(List<IconBean> list) throws Exception {
                    mView.onLoadData(list);
                }
            });
}
 
開發者ID:iAcn,項目名稱:MBEStyle,代碼行數:33,代碼來源:IconShowPresenter.java

示例8: map

import io.reactivex.ObservableOnSubscribe; //導入依賴的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

示例9: test

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
public void test()
{
    Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception
        {
            e.onNext(1);
        }
    }).subscribe(new Consumer<Integer>() {
        @Override
        public void accept(Integer integer) throws Exception
        {
            System.out.println(integer);
        }
    });
}
 
開發者ID:Ayvytr,項目名稱:OKHttpLoggingInterceptor,代碼行數:17,代碼來源:NetTest.java

示例10: doRxJavaWork

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
private void doRxJavaWork() {
    Observable.create(new ObservableOnSubscribe<Integer>() {
        @Override
        public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
            for (;;) { // 無限循環發送事件
                emitter.onNext(Integer.MAX_VALUE);
            }
        }
    }).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<Integer>() {
                @Override
                public void accept(Integer integer) throws Exception {
                    Log.d(TAG, "" + integer);
                }
            });
}
 
開發者ID:RyanHuen,項目名稱:GetStartRxJava2.0,代碼行數:18,代碼來源:UnlimitPostActivity.java

示例11: getObservable

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
public Observable<String> getObservable() {
        return Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("Today's news update");
                e.onNext("Today's topic is Study");
                e.onComplete();
            }
        });
        /* 下麵兩個方法作用類似,just 的內部調用的就是 fromArray */
//     return Observable.just("Topic 1", "Heat 1", "News");
//     return Observable.fromArray("Topic 1", "Heat 1", "News");
        /* 隻能發送一個數據 */
        /*return Observable.fromCallable(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "Topic is Study";
            }
        });*/
    }
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:21,代碼來源:BasicTest.java

示例12: requestLoadingList

import io.reactivex.ObservableOnSubscribe; //導入依賴的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

示例13: with

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
public static Observable<View> with(final View view) {
    return Observable.create(new ObservableOnSubscribe<View>() {
        @Override
        public void subscribe(@NonNull final ObservableEmitter<View> e) throws Exception {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View value) {
                            e.onNext(value);
                        }
                    });
                }
            });
        }
    });
}
 
開發者ID:florent37,項目名稱:AndroidMVPresenter,代碼行數:19,代碼來源:RxClick.java

示例14: getAlbumByCate

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
/**
 * 按一級分類查找專輯
 **/
private Observable<List<Album>> getAlbumByCate(String cateId, int calc_dimension) {
    final Map<String, String> params = new HashMap<>();
    params.put(DTransferConstants.CATEGORY_ID, cateId);
    params.put(DTransferConstants.CALC_DIMENSION, String.valueOf(calc_dimension));
    return Observable.create(new ObservableOnSubscribe<List<Album>>() {
        @Override
        public void subscribe(final ObservableEmitter<List<Album>> e) throws Exception {
            CommonRequest.getAlbumList(params, new IDataCallBack<AlbumList>() {
                @Override
                public void onSuccess(AlbumList albumList) {
                    //onNext的參數不允許為null
                    e.onNext(albumList.getAlbums());
                    e.onComplete();
                }

                @Override
                public void onError(int i, String s) {
                    e.onError(new Throwable(i + " " + s));
                }
            });
        }
    }).subscribeOn(Schedulers.io());
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:27,代碼來源:TingPlayProcessor.java

示例15: getAlbumByKeyWord

import io.reactivex.ObservableOnSubscribe; //導入依賴的package包/類
/**
 * 按關鍵詞查找專輯
 **/
private Observable<List<Album>> getAlbumByKeyWord(String keyword, String cateId, int calc_dimension) {
    final Map<String, String> params = new HashMap<>();
    params.put(DTransferConstants.SEARCH_KEY, keyword);
    params.put(DTransferConstants.CATEGORY_ID, cateId);
    params.put(DTransferConstants.CALC_DIMENSION, String.valueOf(calc_dimension));
    return Observable.create(new ObservableOnSubscribe<List<Album>>() {
        @Override
        public void subscribe(final ObservableEmitter<List<Album>> e) throws Exception {
            CommonRequest.getSearchedAlbums(params, new IDataCallBack<SearchAlbumList>() {
                @Override
                public void onSuccess(SearchAlbumList searchAlbumList) {
                    e.onNext(searchAlbumList.getAlbums());
                    e.onComplete();
                }

                @Override
                public void onError(int i, String s) {
                    e.onError(new Throwable(i + " " + s));
                }
            });
        }
    })
            .subscribeOn(Schedulers.io());
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:28,代碼來源:TingPlayProcessor.java


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