本文整理匯總了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);
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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()));
}
示例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);
}
示例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);
}
示例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()
);
}