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


Java Observable.defer方法代码示例

本文整理汇总了Java中io.reactivex.Observable.defer方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.defer方法的具体用法?Java Observable.defer怎么用?Java Observable.defer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.defer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMetadata

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<Metadata> getMetadata() {
  return Observable.defer(() -> {
    final File metadata = new File(directory, "config.json");
    try {
      if (metadata.exists()) {
        final String raw = FileUtils.readFileToString(metadata, "UTF-8");
        final Metadata result = new Metadata.Builder().setTileJson(raw).build();
        return Observable.just(result);
      }
    } catch (final IOException ex) {
      throw Exceptions.propagate(ex);
    }
    return Observable.empty();
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:17,代码来源:StorageImpl.java

示例2: getCachedTranslationListObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
Observable<TranslationList> getCachedTranslationListObservable(final boolean forceDownload) {
  return Observable.defer(new Callable<ObservableSource<? extends TranslationList>>() {
    @Override
    public ObservableSource<TranslationList> call() throws Exception {
      boolean isCacheStale = System.currentTimeMillis() -
          quranSettings.getLastUpdatedTranslationDate() > Constants.MIN_TRANSLATION_REFRESH_TIME;
      if (forceDownload || isCacheStale) {
        return Observable.empty();
      }

      try {
        File cachedFile = getCachedFile();
        if (cachedFile.exists()) {
          Moshi moshi = new Moshi.Builder().build();
          JsonAdapter<TranslationList> jsonAdapter = moshi.adapter(TranslationList.class);
          return Observable.just(jsonAdapter.fromJson(Okio.buffer(Okio.source(cachedFile))));
        }
      } catch (Exception e) {
        Crashlytics.logException(e);
      }
      return Observable.empty();
    }
  });
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:25,代码来源:TranslationManagerPresenter.java

示例3: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
        Observable<Integer> source = Observable.defer(() ->
                Observable.range(start, count));
        source.subscribe(i -> System.out.println("Observer 1: " + i));
//modify count
        count = 10;
        source.subscribe(i -> System.out.println("Observer 2: " + i));
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:9,代码来源:Ch2_25.java

示例4: brandDeferObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<String> brandDeferObservable() {
    return Observable.defer(new Callable<ObservableSource<? extends String>>() {
        @Override
        public ObservableSource<? extends String> call() throws Exception {
            return Observable.just(brand);
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Car.java

示例5: sampleObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
static Observable<String> sampleObservable() {
    return Observable.defer(new Callable<ObservableSource<? extends String>>() {
        @Override
        public ObservableSource<? extends String> call() throws Exception {
            // Do some long running operation
            SystemClock.sleep(2000);
            return Observable.just("one", "two", "three", "four", "five");
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:DisposableExampleActivity.java

示例6: sampleObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
static Observable<String> sampleObservable() {
    return Observable.defer(new Callable<ObservableSource<? extends String>>() {
      @Override public ObservableSource<? extends String> call() throws Exception {
            // Do some long running operation
            SystemClock.sleep(5000);
            return Observable.just("one", "two", "three", "four", "five");
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:MainActivity.java

示例7: compressToFileAsObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
/**
 * 使用defer操作符 待订阅后再开始压缩任务
 * @param file
 * @return
 */
public Observable<File> compressToFileAsObservable(final File file) {
    return Observable.defer(new Callable<ObservableSource<? extends File>>() {
        @Override
        public Observable<File> call() {
            return Observable.just(compressToFile(file));
        }
    });
}
 
开发者ID:liu-xiao-dong,项目名称:JD-Test,代码行数:14,代码来源:ImageCompressor.java

示例8: compressToBitmapAsObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
public Observable<Bitmap> compressToBitmapAsObservable(final File file) {
    return Observable.defer(new Callable<ObservableSource<? extends Bitmap>>() {
        @Override
        public Observable<Bitmap> call() {
            return Observable.just(compressToBitmap(file));
        }
    });
}
 
开发者ID:liu-xiao-dong,项目名称:JD-Test,代码行数:9,代码来源:ImageCompressor.java

示例9: fakeImageSearch

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<SearchResultContainer> fakeImageSearch() {
    return Observable.defer(new Callable<ObservableSource<? extends SearchResultContainer>>() {
        @Override
        public ObservableSource<? extends SearchResultContainer> call() throws Exception {
            ArrayList<SearchItem> items = new ArrayList<>();

            items.add(new SearchItem(new ItemImage("http://media.cntraveler.com/photos/542333488614701924e124a9/master/w_775," +
                    "c_limit/italy-food-intro-1.jpg")));
            items.add(new SearchItem(new ItemImage("http://i.ndtvimg.com/i/2016-03/bruschetta-625_625x350_41459344513.jpg")));
            items.add(new SearchItem(new ItemImage("https://s-media-cache-ak0.pinimg" +
                    ".com/originals/bd/1f/89/bd1f899131e589e3e8ca30784e6320d4.jpg")));
            items.add(new SearchItem(new ItemImage("http://az616578.vo.msecnd.net/files/2016/10/01/636109138160187836348256689_food2.jpg")));
            items.add(new SearchItem(new ItemImage("http://media.cntraveler.com/photos/542333488614701924e124a8/master/w_775," +
                    "c_limit/italy-food-bigoli-2.jpg")));
            items.add(new SearchItem(new ItemImage("http://foodsofitalybedford.co.uk/communities/6/000/001/507/226//images/5770578.jpg")));
            items.add(new SearchItem(new ItemImage("http://www.mytorontoscoop.com/rsz_lasagna%20(2).jpg")));
            items.add(new SearchItem(new ItemImage("http://www.italian-feelings.com/wp-content/uploads/2016/02/nord-sud-940x625.jpg")));
            items.add(new SearchItem(new ItemImage("http://www.ndtv.com/cooks/images/pasta-carbonara-ritu-dalmia_article.jpg")));
            items.add(new SearchItem(new ItemImage("http://www.morningadvertiser.co" +
                    ".uk/var/plain_site/storage/images/publications/hospitality/morningadvertiser.co" +
                    ".uk/pub-food/good-food-guide-editor-calls-for-more-veggie-options-on-pub-menus/8422626-1-eng-GB/Good-Food-Guide-editor" +
                    "-calls-for-more-veggie-options-on-pub-menus.jpg")));
            items.add(new SearchItem(new ItemImage("https://static.independent.co" +
                    ".uk/s3fs-public/styles/article_small/public/thumbnails/image/2016/12/19/18/sush0istock-gkrphoto.jpg")));
            items.add(new SearchItem(new ItemImage("http://www.2sfg" +
                    ".com/globalassets/corporate/home-page/2sisters-food-group-roast-banner5.jpg")));
            items.add(new SearchItem(new ItemImage("http://www.oghmapartners.com/wp-content/uploads/2017/05/1417931965.jpg")));

            return Observable.just(new SearchResultContainer(items)).delay(3, TimeUnit.SECONDS);
        }
    });
}
 
开发者ID:dvdciri,项目名称:DeepImagePreview-Project,代码行数:33,代码来源:SearchResultHandler.java

示例10: test1

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public void test1() {
    Log.i(TAG, "test1() Defer simple demo, call() twice");
    Observable<String> observable = Observable.defer(new Callable<ObservableSource<String>>() {
        @Override
        public ObservableSource<String> call() throws Exception {
            Log.d(TAG, "call()");
            return new ObservableSource<String>() {
                @Override
                public void subscribe(@NonNull Observer<? super String> observer) {
                    Log.d(TAG, "subscribe()");
                    for (int i = 0; i < 3; i++) {
                        observer.onNext(String.valueOf(i));
                    }
                }
            };
        }
    });

    for (int time = 0; time < 2; time++) {
        observable.subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                Log.d(TAG, "accept() s: " + s);
            }
        });
    }
}
 
开发者ID:afunx,项目名称:RxJava4AndroidDemos,代码行数:29,代码来源:Defer.java

示例11: sampleObservable

import io.reactivex.Observable; //导入方法依赖的package包/类
static Observable<String> sampleObservable() {
    return Observable.defer(new Callable<ObservableSource<? extends String>>() {
        @Override
        public ObservableSource<? extends String> call() throws Exception {
            SystemClock.sleep(5000);
            return Observable.just("one", "two", "three", "four", "five");
        }
    });
}
 
开发者ID:jinseongho,项目名称:RxAndroidExample,代码行数:10,代码来源:MainActivity.java

示例12: getMaxZoomLevel

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<Integer> getMaxZoomLevel() {
  return Observable.defer(() -> {
    final int[] zoomLevels = getZoomLevels();
    return zoomLevels.length > 0 ? Observable.just(zoomLevels[zoomLevels.length - 1])
        : Observable.empty();
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:9,代码来源:StorageImpl.java

示例13: getMinZoomLevel

import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Observable<Integer> getMinZoomLevel() {
  return Observable.defer(() -> {
    final int[] zoomLevels = getZoomLevels();
    return zoomLevels.length > 0 ? Observable.just(zoomLevels[0]) : Observable.empty();
  });
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:8,代码来源:StorageImpl.java

示例14: connection

import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<WebSocket> connection() {
    return Observable.defer(() -> httpClient
            .websocketStream(config().getInteger(CFG_PORT), config().getString(CFG_IP), SC2API_URI)
            .toObservable());
}
 
开发者ID:ocraft,项目名称:ocraft-s2client,代码行数:6,代码来源:S2ClientVerticle.java


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