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


Java RxJava2CallAdapterFactory類代碼示例

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


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

示例1: setUp

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl("https://api.shodan.io/")
            .build();

    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(networkBehavior).build();

    BehaviorDelegate<ApiService> delegate = mockRetrofit.create(ApiService.class);
    apiRestMock = new ApiRestMock(delegate);
}
 
開發者ID:fooock,項目名稱:jshodan,代碼行數:15,代碼來源:ApiServiceTest.java

示例2: buildApiService

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
public static ApiService buildApiService() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient clientOkHttp = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://jsonplaceholder.typicode.com")
            .client(clientOkHttp)
            .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().create()))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();

    return retrofit.create(ApiService.class);
}
 
開發者ID:playmoweb,項目名稱:store2realm,代碼行數:18,代碼來源:ApiService.java

示例3: Api

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private Api() {
    HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
    logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
    Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .readTimeout(7676, TimeUnit.MILLISECONDS)
            .connectTimeout(7676, TimeUnit.MILLISECONDS)
            .addInterceptor(headInterceptor)
            .addInterceptor(logInterceptor)
            .addNetworkInterceptor(new HttpCacheInterceptor())
            .cache(cache)
            .build();

    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();

    retrofit = new Retrofit.Builder()
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl(C.BASE_URL)
            .build();
    service = retrofit.create(ApiService.class);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:Api.java

示例4: create

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private static Retrofit create() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    builder.readTimeout(10, TimeUnit.SECONDS);
    builder.connectTimeout(9, TimeUnit.SECONDS);
    builder.addNetworkInterceptor(new StethoInterceptor());

    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(interceptor);
    }

    return new Retrofit.Builder().baseUrl(ENDPOINT)
            .client(builder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RetrofitProvider.java

示例5: build

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private static Retrofit build(){
    if(null == retrofitInstance){
        synchronized (Retrofit.class){
            if(null == retrofitInstance){ // 雙重檢驗鎖,僅第一次調用時實例化
                retrofitInstance = new Retrofit.Builder()
                        // baseUrl總是以/結束,@URL不要以/開頭
                        .baseUrl(BuildConfig.API_SERVER_URL)
                        // 使用OkHttp Client
                        .client(buildOkHttpClient())
                        // 集成RxJava處理
                        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                        // 集成Gson轉換器
                        .addConverterFactory(buildGsonConverterFactory())
                        .build();
            }
        }
    }
    return retrofitInstance;
}
 
開發者ID:qiaop,項目名稱:basicapp,代碼行數:20,代碼來源:RetrofitHelper.java

示例6: RetrofitClient

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private RetrofitClient(){
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
            .sslSocketFactory(createSSLSocketFactory(),new TrustAllManager())//信任所有
            .addInterceptor(new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
                @Override
                public void log(String message) {
                    Log.i("okhttp32",message);
                }
            }).setLevel(HttpLoggingInterceptor.Level.BODY))
    ;

    mOkHttpClient = builder.build();
     mRetrofit = new Retrofit.Builder()
            .client(mOkHttpClient)
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(buildGson()))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
開發者ID:nowandfurure,項目名稱:richeditor,代碼行數:21,代碼來源:RetrofitClient.java

示例7: beforeEachTest

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Before public void beforeEachTest() {

        server = new MockWebServer();

        NumbersWebService numberAPI =
                new Retrofit.Builder()
                        .baseUrl(server.url("/").toString())
                        .addConverterFactory(GsonConverterFactory.create())
                        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                        .build()
                        .create(NumbersWebService.class);

        infrastructure = new TriviaInfrastructure(
                numberAPI,
                new TriviaGenerator(),
                new PayloadMapper(),
                new PayloadValidator(),
                Schedulers.trampoline() // non-concurrent integration on tests
        );
    }
 
開發者ID:ubiratansoares,項目名稱:reactive-architectures-playground,代碼行數:21,代碼來源:TriviaInfrastructureTests.java

示例8: provideRetrofit

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
/**
 * @param builder
 * @param client
 * @param httpUrl
 * @return
 * @author: jess
 * @date 8/30/16 1:15 PM
 * @description:提供retrofit
 */
@Singleton
@Provides
Retrofit provideRetrofit(Application application, @Nullable RetrofitConfiguration configuration, Retrofit.Builder builder, OkHttpClient client
        , HttpUrl httpUrl, Gson gson) {
    builder
            .baseUrl(httpUrl)//域名
            .client(client);//設置okhttp

    if (configuration != null)
        configuration.configRetrofit(application, builder);

    builder
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//使用rxjava
            .addConverterFactory(GsonConverterFactory.create(gson));//使用Gson
    return builder.build();
}
 
開發者ID:devzwy,項目名稱:NeiHanDuanZiTV,代碼行數:26,代碼來源:ClientModule.java

示例9: provideAuthRetrofit

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Override
public Single<RetrofitWrapper> provideAuthRetrofit() {
    return Single.fromCallable(() -> {

        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)
                .addInterceptor(HttpLogger.DEFAULT_LOGGING_INTERCEPTOR);

        ProxyUtil.applyProxyConfig(builder, proxySettings.getActiveProxy());
        Gson gson = new GsonBuilder().create();

        final Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://oauth.vk.com/")
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(builder.build())
                .build();

        return RetrofitWrapper.wrap(retrofit, false);
    });
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:22,代碼來源:OtherVkRetrofitProvider.java

示例10: provideRetrofit

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Singleton
@Provides
Retrofit provideRetrofit(@Nullable RetrofitConfiguration configuration,
                         Retrofit.Builder builder, OkHttpClient client, HttpUrl httpUrl) {
    builder
            //domain name
            .baseUrl(httpUrl)
            //Set okhttp
            .client(client)
            //TODO: to use use LiveData
            //.addCallAdapterFactory(new LiveDataCallAdapterFactory())
            //use rxjava
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            //use Gson
            .addConverterFactory(GsonConverterFactory.create());
    if (configuration != null)
        configuration.configRetrofit(mApplication, builder);
    return builder.build();
}
 
開發者ID:goutham106,項目名稱:GmArchMvvm,代碼行數:20,代碼來源:ClientModule.java

示例11: RetrofitUtils

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
/**
 * 實際由getInstance() 進行調用創建
 */
private RetrofitUtils() {
    // 創建 OKHttpClient
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(this.DEFAULT_TIME_OUT, TimeUnit.SECONDS)//設置全局請求的連接超時時間,默認為15s
            .writeTimeout(this.DEFAULT_READ_TIME_OUT, TimeUnit.SECONDS)//寫操作 超時時間
            .readTimeout(this.DEFAULT_READ_TIME_OUT, TimeUnit.SECONDS);//設置全局請求的數據讀取超時時間,默認為30s
    // 向okhttp中添加公共參數攔截器
    builder.addInterceptor(mBaseInterceptor != null ? mBaseInterceptor : BaseInterceptor.getDefault());
    //創建okhttp實例
    OkHttpClient client = builder.build();
    //配置你的Gson,在不同環境下gson對Data的轉化可能不一樣,這裏使用統一的格式
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd hh:mm:ss").create();

    // 創建Retrofit,將gson和okhttp加入進來
    mRetrofit = new Retrofit.Builder().baseUrl(this.BASE_URL)//設置基礎域名。網絡請求由此拚接(注意:需要/結尾,且此處與單獨有相同路徑時會智能糾錯:www/api/+api/xxx會糾錯為www/api/xxx)
            .addConverterFactory(GsonConverterFactory.create(gson))//設置json返回消息的解析庫(這裏使用gson)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//此在與RxJava聯用時才使用
            .client(client)//配置okhttp配置。可無(為空時,retrofit會使用默認配置)
            .build();
}
 
開發者ID:JJS-CN,項目名稱:JBase,代碼行數:24,代碼來源:RetrofitUtils.java

示例12: init

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private void init() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()
            .setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient client = new OkHttpClient()
            .newBuilder()
            .addInterceptor(interceptor)
            .build();

    service = new Retrofit.Builder()
            .baseUrl("https://api.github.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(client)
            .build()
            .create(GitHubService.class);
}
 
開發者ID:qingmei2,項目名稱:RxFamilyUsage-Android,代碼行數:18,代碼來源:GitHubServiceManager.java

示例13: onRefresh

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Override
public void onRefresh() {
    String baseUrl = "http://gank.io/api/";
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();

    ApiService apiService = retrofit.create(ApiService.class);
    apiService.getClassifyData("福利", 1)
            .map(new BaseResFunc<List<Gank>>())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(mObserver);

}
 
開發者ID:wheat7,項目名稱:Cashew,代碼行數:18,代碼來源:GirlFragment.java

示例14: HttpManager

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private HttpManager() {

        OkHttpClient.Builder okHttpClientBuild = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS);

        OkHttpClient okHttpClient = okHttpClientBuild.build();

        mApi = new Retrofit.Builder()
                .baseUrl("http://image.baidu.com/")
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2WithProgressCallAdapterFactory.createAsync())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync())
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(FileConverterFactory.create())
                .build()
                .create(Api.class);

    }
 
開發者ID:imfms,項目名稱:retrofit-rxjava-request-with-progress,代碼行數:19,代碼來源:HttpManager.java

示例15: initWithBaseUrl

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private void initWithBaseUrl(String baseUrl){
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(5000, TimeUnit.MILLISECONDS)
            .readTimeout(5000, TimeUnit.MILLISECONDS)
            .writeTimeout(5000, TimeUnit.MILLISECONDS)
            .addInterceptor(loggingInterceptor)
            .build();

    retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
開發者ID:TORU0239,項目名稱:ViperUsage,代碼行數:19,代碼來源:ApiBase.java


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