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


Java RxJavaCallAdapterFactory類代碼示例

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


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

示例1: getRetrofit

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
public static RetrofitInterface getRetrofit(String email, String password) {

        String credentials = email + ":" + password;
        String basic = "Basic " + Base64.encodeToString(credentials.getBytes(),Base64.NO_WRAP);
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        httpClient.addInterceptor(chain -> {

            Request original = chain.request();
            Request.Builder builder = original.newBuilder()
                    .addHeader("Authorization", basic)
                    .method(original.method(),original.body());
            return  chain.proceed(builder.build());

        });

        RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());

        return new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .client(httpClient.build())
                .addCallAdapterFactory(rxAdapter)
                .addConverterFactory(GsonConverterFactory.create())
                .build().create(RetrofitInterface.class);
    }
 
開發者ID:EdwardAlexis,項目名稱:Sistema-de-Comercializacion-Negocios-Jhordan,代碼行數:26,代碼來源:NetworkUtil.java

示例2: retrofit

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
public static Retrofit retrofit() {
    if (mRetrofit == null) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        if (BuildConfig.DEBUG) {
            // Log信息攔截器
            HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            //設置 Debug Log 模式
            builder.addInterceptor(loggingInterceptor);
        }
        OkHttpClient okHttpClient = builder.build();
        mRetrofit = new Retrofit.Builder()
                .baseUrl(ApiStores2.URL_BASE)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
    }
    return mRetrofit;
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:22,代碼來源:AppClient2.java

示例3: HttpService

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
private HttpService() {
    //手動創建一個OkHttpClient並設置超時時間
    OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
    httpClientBuilder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    httpClientBuilder.addInterceptor(interceptor).build();

    retrofit = new Retrofit.Builder()
            .client(httpClientBuilder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .baseUrl(BASE_URL)
            .build();
}
 
開發者ID:didikee,項目名稱:cnBetaGeek,代碼行數:17,代碼來源:HttpService.java

示例4: getRetrofit

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
/**
 * 獲取通用配置的Retrofit實例,同時提供數據轉換工廠定製,與攔截器定製
 * @param context Application對應的context:getApplicationContext
 * @param baseUrl 服務器接口url通用部分
 * @param converterFactory 定製的數據轉換工廠
 * @param interceptor 定製的攔截器
 * @return
 */
protected static Retrofit getRetrofit(
        Context context, String baseUrl, Converter.Factory converterFactory, Interceptor interceptor) {
    if (null == mRetrofit) {
        if (null == mOkHttpClient) {
            mOkHttpClient = OkHttpUtils.getOkHttpClient(context, interceptor);
        }

        Retrofit.Builder builder = new Retrofit.Builder();
        // 設置服務器路徑Url通用部分
        builder.baseUrl(baseUrl);
        // 添加數據轉換工廠,支持自定義數據轉換工廠,默認使用Gson
        if (converterFactory != null) {
            builder.addConverterFactory(converterFactory);
        } else {
            builder.addConverterFactory(GsonConverterFactory.create());
        }
        // 添加回調工廠,采用RxJava
        builder.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
        // 設置使用OkHttp網絡請求庫
        builder.client(mOkHttpClient);
        mRetrofit = builder.build();
    }

    return mRetrofit;
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:34,代碼來源:AbsRetrofit.java

示例5: createRetrofitService

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
public static <T> T createRetrofitService(final Class<T> clazz, final String endPoint) {
    // Logs
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    final Retrofit restAdapter = new Retrofit.Builder()
            .baseUrl(endPoint)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .client(new OkHttpClient.Builder()
                    .addInterceptor(interceptor)
                    .build())
            .build();

    return restAdapter.create(clazz);
}
 
開發者ID:Sar777,項目名稱:GitHubRxJava,代碼行數:17,代碼來源:ServiceFactory.java

示例6: HttpRequestFactory

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
public HttpRequestFactory() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);

    OkHttpClient okHttpClient =
            new OkHttpClient.Builder().connectTimeout(TIMEOUT, TimeUnit.SECONDS)
                    .readTimeout(TIMEOUT, TimeUnit.SECONDS)
                    .writeTimeout(TIMEOUT, TimeUnit.SECONDS)
                    .cache(getCache())
                    .addInterceptor(logging)
                    .addNetworkInterceptor(mTokenInterceptor)
                    //應用攔截器,用於離線緩存
                    .addInterceptor(mCacheInterceptor)
                    //網絡攔截器,用於在線緩存
                    .addNetworkInterceptor(mCacheInterceptor)
                    .addNetworkInterceptor(new StethoInterceptor())
                    .build();

    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.FanFou.FANFOU_API_URL)
            .addConverterFactory(ResponseConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(okHttpClient)
            .build();

    mServiceFactory = retrofit.create(ApiFactory.class);
}
 
開發者ID:betroy,項目名稱:xifan,代碼行數:27,代碼來源:HttpRequestFactory.java

示例7: retrofit

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
@Provides Retrofit retrofit() {
  OkHttpClient client = new OkHttpClient.Builder()
      .addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
          return chain.proceed(
              chain.request()
                  .newBuilder()
                  .addHeader("Authorization", "Client-ID " + ImgurService.CLIENT_ID)
                  .build());
        }
      })
      .build();
  return new Retrofit.Builder()
      .client(client)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .baseUrl("https://api.imgur.com/3/")
      .build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ApiModule.java

示例8: ApiManager

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
private ApiManager() {

        /**
         * 設置請求超時時間為5秒
         */
        mOkHttpClient = new OkHttpClient.Builder()
                .connectTimeout(5000, TimeUnit.MILLISECONDS)
                .readTimeout(5000, TimeUnit.MILLISECONDS)
                .writeTimeout(5000, TimeUnit.MILLISECONDS).build();

        //.addConverterFactory(fastJsonConverterFactory)
        mRetrofit = new Retrofit.Builder()
                .client(mOkHttpClient)
                .baseUrl("https://i.play.163.com/")
                .addConverterFactory(GsonConverterFactory.create())
                //.addConverterFactory(fastJsonConverterFactory)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
    }
 
開發者ID:Jay-Ping,項目名稱:newIPlay,代碼行數:20,代碼來源:ApiManager.java

示例9: createService

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
@NonNull
private static <S> S createService(@NonNull Class<S> s, @NonNull String token,
        @NonNull String secret) {
    final GsonConverterFactory serializer = GsonConverterFactory.create(
            new GsonBuilder().registerTypeAdapterFactory(JSONModelTypeAdapterFactory.create())
                    .create());

    final OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
    OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(
            Config.CONSUMER_KEY, Config.CONSUMER_SECRET);
    consumer.setTokenWithSecret(token, secret);
    httpClient.addInterceptor(new SigningInterceptor(consumer));

    final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(Config.HTTP_LOG_LEVEL);
    httpClient.addInterceptor(loggingInterceptor);

    final Retrofit client = new Retrofit.Builder().baseUrl(Config.HOST)
            .addConverterFactory(serializer)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(httpClient.build())
            .build();
    return client.create(s);
}
 
開發者ID:jsaund,項目名稱:RxUploader,代碼行數:25,代碼來源:Service.java

示例10: provideCall

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
@Provides
@Singleton
Retrofit provideCall() {
    OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(App.getTwitterKey(),
            App.getTwitterSecret());
    consumer.setTokenWithSecret(
            App.getApplicationInstance().getTwitterSession().getAuthToken().token,
            App.getApplicationInstance().getTwitterSession().getAuthToken().secret);

    Retrofit.Builder builder =
            new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create());

    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(new SigningInterceptor(consumer))
            .addNetworkInterceptor(new StethoInterceptor())
            .build();

    return builder.client(client).build();
}
 
開發者ID:beraldofilippo,項目名稱:TWStreaming,代碼行數:24,代碼來源:NetworkModule.java

示例11: getProtocore

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
default ProtoCore getProtocore() {
    Gson gson = NetworkUtilities.getGson();
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(getSatispayContext().getBaseUrl())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(
                    getProtocoreHttpClientProvider().getProtocoreClient(
                            getSatispayContext(),
                            getSecurePersistenceManager(),
                            getSessionManager(),
                            getSdkDeviceInfo()
                    )
            )
            .build();
    return retrofit.create(ProtoCore.class);
}
 
開發者ID:satispay,項目名稱:in-store-api-java-sdk,代碼行數:18,代碼來源:ProtoCoreProvider.java

示例12: onCreate

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example);

    mTv= (TextView) findViewById(R.id.tv);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://api.github.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(new OkHttpClient())
            .build();

    GitHubService service=retrofit.create(GitHubService.class);

    service.contributors1("square", "retrofit")
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(s-> mTv.setText(s.toString()));
}
 
開發者ID:374901588,項目名稱:Retrofit2Demo,代碼行數:22,代碼來源:Example1Activity.java

示例13: JiraService

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
public JiraService(final Site jiraSite) {
  this.jiraSite = jiraSite;

  final ConnectionPool CONNECTION_POOL = new ConnectionPool(5, 60, TimeUnit.SECONDS);

  OkHttpClient httpClient = new OkHttpClient.Builder()
      .connectTimeout(jiraSite.getTimeout(), TimeUnit.MILLISECONDS)
      .readTimeout(10000, TimeUnit.MILLISECONDS).connectionPool(CONNECTION_POOL)
      .retryOnConnectionFailure(true).addInterceptor(new SigningInterceptor(jiraSite)).build();

  final ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(new JodaModule());
  this.jiraEndPoints = new Retrofit.Builder().baseUrl(this.jiraSite.getUrl().toString())
      .addConverterFactory(JacksonConverterFactory.create(mapper))
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create()).client(httpClient).build()
      .create(JiraEndPoints.class);
}
 
開發者ID:jenkinsci,項目名稱:jira-steps-plugin,代碼行數:18,代碼來源:JiraService.java

示例14: start

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
public void start(final DownInfo info) {
//                如果消息實體為空,或正在下載,則返回
                if (info == null || mDownInfoMap.get(info.getUrl()) != null) return;
                DownLoadSubscriber<DownInfo> downLoadSubscriber = new DownLoadSubscriber<>(info);
                mDownInfoMap.put(info.getUrl(), downLoadSubscriber);
//                HttpService service;
//                增加一個攔截器,用於獲取數據的進度回調
                DownLoadInterceptor interceptor = new DownLoadInterceptor(downLoadSubscriber);
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                builder.connectTimeout(info.getConnectedTime(), TimeUnit.SECONDS).addInterceptor(interceptor);
                Retrofit retrofit = new Retrofit.Builder().
                        addConverterFactory(ScalarsConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
                        baseUrl(CommonUtils.getBaseUrl(info.getUrl())).client(builder.build()).build();
                HttpService service = retrofit.create(HttpService.class);
                info.setHttpService(service);
                service.download("bytes=" + info.getReadLength() + "-", info.getUrl()).subscribeOn(Schedulers.io())
                        .unsubscribeOn(Schedulers.io()).retryWhen(new RetryWhenNetWorkException()).map(new Func1<ResponseBody, DownInfo>() {
                        @Override
                        public DownInfo call(ResponseBody responseBody) {
                                FileUtil.writeToCache(responseBody, info.getSavedFilePath(), info.getReadLength(), info.getTotalLength());
//                                這裏進行轉化
                                return info;
                        }
                }).observeOn(AndroidSchedulers.mainThread()).subscribe(downLoadSubscriber);
        }
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:26,代碼來源:HttpDownLoadManager.java

示例15: newService

import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; //導入依賴的package包/類
@NonNull
public static GoogleSpeechService newService() {
    return new GoogleSpeechServiceImpl(
            new Retrofit.Builder()
                    .baseUrl(HOST_SPEECH_API)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .addConverterFactory(new GoogleSpeechServiceConverterFactory())
                    .build()
                    .create(SpeechApi.class),
            new Retrofit.Builder()
                    .baseUrl(HOST_SUPPORTED_LANGUAGE_API)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .addConverterFactory(new GoogleSpeechServiceConverterFactory())
                    .build()
                    .create(SupportedLanguageApi.class),
            new AuthenticationSpeechApiBridgeCache()
    );
}
 
開發者ID:powdream,項目名稱:google-speech-api-android,代碼行數:19,代碼來源:GoogleSpeechServiceFactory.java


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