当前位置: 首页>>代码示例>>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;未经允许,请勿转载。