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


Java RxJava2CallAdapterFactory類代碼示例

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


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

示例1: init

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
/**
 * 初始化網絡通信服務
 */
public static void init() {
    // 指定緩存路徑,緩存大小100Mb
    Cache cache = new Cache(new File(App.app.getCacheDir(), "HttpCache"),
            1024 * 1024 * 100);
    OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache)
            .retryOnConnectionFailure(true)
            .addInterceptor(sLoggingInterceptor)
            .addInterceptor(sRewriteCacheControlInterceptor)
            .addNetworkInterceptor(sRewriteCacheControlInterceptor)
            .connectTimeout(10, TimeUnit.SECONDS)
            .build();

    Retrofit retrofit = new Retrofit.Builder()
            .client(okHttpClient)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .baseUrl(BASEURL)
            .build();

    baseApi = retrofit.create(IBaseApi.class);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:RetrofitService.java

示例2: init

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
/**
 * 初始化網絡通信服務
 */
public static void init() {
    // 指定緩存路徑,緩存大小100Mb
    Cache cache = new Cache(new File(MyApplication.myApplication.getCacheDir(), "HttpCache"),
            1024 * 1024 * 100);
    OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache)
            .retryOnConnectionFailure(true)
            .addInterceptor(sLoggingInterceptor)
            .addInterceptor(sRewriteCacheControlInterceptor)
            .addNetworkInterceptor(sRewriteCacheControlInterceptor)
            .connectTimeout(10, TimeUnit.SECONDS)
            .build();

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

示例3: getApiClient

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

        OkHttpClient.Builder client = new OkHttpClient.Builder();
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        client.addInterceptor(loggingInterceptor);

        OkHttpClient myClient = client.build();

        if (BuildConfig.DEBUG) {
            IdlingResources.registerOkHttp(myClient);
        }

        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl(BuildConfig.BASE_URL)
                .client(myClient)
                .addConverterFactory(RaveConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        return retrofit.create(ApiClient.class);
    }
 
開發者ID:iamBedant,項目名稱:InstantAppStarter,代碼行數:24,代碼來源:AppApiHelper.java

示例4: testSearch

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Test
    public void testSearch() throws IOException {
        RemoteApi remoteApi = new Retrofit.Builder()
                .baseUrl(URL_BASE)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())
                .client(UnsafeOkHttpUtils.getClient())
                .build()
                .create(RemoteApi.class);
        remoteApi.getList(0, 20, null, 0, new String[]{"微信"})
                .subscribe(new Consumer<ResponseBody>() {
                    @Override
                    public void accept(ResponseBody responseBody) throws Exception {
                        String string = responseBody.string();
                        System.out.println(string);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });

    }
 
開發者ID:ittianyu,項目名稱:POCenter,代碼行數:25,代碼來源:ExampleUnitTest.java

示例5: apply

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            server.start();

            retrofit = new Retrofit.Builder()
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(new GsonService().getGsonConverterFactory())
                    .baseUrl(server.url("").toString())
                    .client(new HttpService(context).getHttpClient())
                    .build();

            base.evaluate();

            server.shutdown();
        }
    };
}
 
開發者ID:CoreFloDev,項目名稱:OpenChat,代碼行數:21,代碼來源:ApiTestRule.java

示例6: provideVideoApi

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
@Provides
@PerApplication
static VideoApi provideVideoApi(Gson gson, OkHttpClient okHttpClient) {

    OkHttpClient.Builder httpClientBuilder = okHttpClient.newBuilder();

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

    return new Retrofit.Builder()
            .baseUrl(BuildConfig.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
            .callFactory(httpClientBuilder.build())
            .build().create(VideoApi.class);
}
 
開發者ID:aprochukhan,項目名稱:Android-MVVM-Example,代碼行數:20,代碼來源:NetModule.java

示例7: DownloadManager

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
public DownloadManager() {
    mRetrofit = new Retrofit.Builder()
            .baseUrl(NodeBB.BASE_URL)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(new OkHttpClient.Builder()
                    .addInterceptor(chain -> {
                        Request request = chain.request();
                        Response response = chain.proceed(request);
                        int tryCount = 0;
                        while (!response.isSuccessful() && tryCount < RETRY_COUNT) {
                            tryCount++;
                            response = chain.proceed(request);
                        }
                        return response;
                    })
                    .build()
            )
            .build();
    mDownloadApi = mRetrofit.create(DownloadApi.class);
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:21,代碼來源:DownloadManager.java

示例8: createRetrofit

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
private Retrofit createRetrofit() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    builder.readTimeout(60, TimeUnit.SECONDS);
    builder.connectTimeout(60, TimeUnit.SECONDS);
    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        //addNetworkInterceptor有何區別
        builder.addInterceptor(interceptor);
    }
    return new Retrofit.Builder().baseUrl("www.example.com")
            .client(builder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
開發者ID:Pingsh,項目名稱:Mix,代碼行數:17,代碼來源:MainActivity.java

示例9: RetrofitBuilder

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

		HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
		// set your desired log level
		logging.setLevel(HttpLoggingInterceptor.Level.BASIC);

		OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
		// add your other interceptors …

		// add logging as last interceptor
		httpClient.addInterceptor(logging);

		Retrofit retrofit = new Retrofit.Builder()
				.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
				.baseUrl(BASE_URL)
				.addConverterFactory(GsonConverterFactory.create())
				.client(httpClient.build())
				.build();
        apiService = retrofit.create(MyRetroInterface.class);
    }
 
開發者ID:vaibhavsh82,項目名稱:VSPER,代碼行數:21,代碼來源:RetrofitBuilder.java

示例10: getClient

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
public static Retrofit getClient(String url) {
    if (retrofit==null) {
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
                .connectTimeout(6000, TimeUnit.SECONDS)
                .readTimeout(6000, TimeUnit.SECONDS)
                .addInterceptor(logging);

        retrofit = new Retrofit.Builder()
                .baseUrl(url)
                .client(okHttpClientBuilder.build())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}
 
開發者ID:mukesh4u,項目名稱:AndroidMVP,代碼行數:20,代碼來源:ApiClient.java

示例11: newRetrofit

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
public Retrofit newRetrofit(String url) {
    // 拿到Retrofit實例
    return new Retrofit.Builder()
            .baseUrl("http://gank.io/")

            //引入Gson解析庫 ,就可以直接以實體的形式拿到返回值
            //.addConverterFactory(GsonConverterFactory.create())

            //加入我們自定義的Gson解析庫,就可以更友好的處理錯誤
            .addConverterFactory(CstGsonConverterFactory.create())

            .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
            //將我們客製化的OkHttp實例傳入
            .client(mOkHttpClient)
            .build();
}
 
開發者ID:mcxtzhang,項目名稱:csdn-retrofit,代碼行數:17,代碼來源:RetrofitManager.java

示例12: buildRetrofit

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
/**
 * Method to create a new Retrofit instance
 * Add the API key {@link MoviesApiInterceptor#intercept(Interceptor.Chain)}
 * Show debug information only in DEBUG build
 *
 * @return Retrofit - used for building API calls
 */
public static Retrofit buildRetrofit() {
    OkHttpClient.Builder httpClient =
            new OkHttpClient.Builder();
    httpClient.addInterceptor(new MoviesApiInterceptor());

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

    return new Retrofit.Builder()
            .baseUrl(MOVIEDB_BASE_URL)
            .client(httpClient.build())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}
 
開發者ID:dilipkumar4813,項目名稱:movie-android,代碼行數:26,代碼來源:NetworkUtils.java

示例13: createGithubService

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
public static RfEtestApi createGithubService(final String githubToken, final String urlx) {


        Retrofit.Builder builder = new Retrofit.Builder().addCallAdapterFactory(RxJava2CallAdapterFactory.create())
              .addConverterFactory(GsonConverterFactory.create())
              .baseUrl(urlx);
              //.baseUrl("http://www.eshoptest.sk");
              //.baseUrl("https://api.github.com");

        if (!TextUtils.isEmpty(githubToken)) {

            OkHttpClient client = new OkHttpClient.Builder().addInterceptor(chain -> {
                Request request = chain.request();
                Request newReq = request.newBuilder()
                      .addHeader("Authorization", format("token %s", githubToken))
                      .build();
                return chain.proceed(newReq);
            }).build();

            builder.client(client);
        }

        return builder.build().create(RfEtestApi.class);
    }
 
開發者ID:eurosecom,項目名稱:Attendance,代碼行數:25,代碼來源:RfEtestService.java

示例14: createGithubService

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
public static RfGithubApi createGithubService(final String githubToken) {
    Retrofit.Builder builder = new Retrofit.Builder().addCallAdapterFactory(RxJava2CallAdapterFactory.create())
          .addConverterFactory(GsonConverterFactory.create())
          .baseUrl("https://api.github.com");

    if (!TextUtils.isEmpty(githubToken)) {

        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(chain -> {
            Request request = chain.request();
            Request newReq = request.newBuilder()
                  .addHeader("Authorization", format("token %s", githubToken))
                  .build();
            return chain.proceed(newReq);
        }).build();

        builder.client(client);
    }

    return builder.build().create(RfGithubApi.class);
}
 
開發者ID:eurosecom,項目名稱:Attendance,代碼行數:21,代碼來源:RfGithubService.java

示例15: PTPVApiClient

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //導入依賴的package包/類
/**
 * Initializes the API client.
 */
private PTPVApiClient() {
    // -----------------------------------------------------------------------------------------
    // Create a new Retrofit instance and build the API client based on it
    // -----------------------------------------------------------------------------------------
    Retrofit mRetrofit = new Retrofit.Builder()
            .baseUrl(WS_URL)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    this.mPtpvApi = mRetrofit.create(PTPVApi.class);
}
 
開發者ID:PayTpv,項目名稱:ANDROID-SDK,代碼行數:15,代碼來源:PTPVApiClient.java


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