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