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


Java ScalarsConverterFactory類代碼示例

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


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

示例1: setUp

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
@Before
public void setUp() throws IOException {
    mMockServer = new MockWebServer();
    mMockServer.start();
    Retrofit retrofit = (new Retrofit.Builder().baseUrl(mMockServer.url("").toString())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())).build();
    CivifyLoginService civifyLoginService = retrofit.create(CivifyLoginService.class);
    CivifyMeService civifyMeService = retrofit.create(CivifyMeService.class);
    SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
    mSharedPreferences = mock(SharedPreferences.class);
    mLoginFinishedCallbackMock = mock(LoginFinishedCallback.class);
    when(mSharedPreferences.edit()).thenReturn(editor);
    mUser = new User("username", "name", "surname",
            "email", "password", "password");
    mLoginAdapter =
            new LoginAdapterImpl(civifyLoginService, civifyMeService, mSharedPreferences);
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:19,代碼來源:LoginAdapterImplTest.java

示例2: provideCall

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的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

示例3: dealApiReqest

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
public void dealApiReqest(BaseApi baseApi) {
//                創建一個OkHttpClient
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                CommonSubscriber commonSubscriber = new CommonSubscriber(baseApi, mOnNextListenerSoftReference, mRxAppCompatActivitySoftReference);
                builder.addInterceptor(new CacheInterceptor()).connectTimeout(baseApi.getConnectedTime(), TimeUnit.SECONDS)
                        .writeTimeout(baseApi.getWritedOutTime(), TimeUnit.SECONDS).addNetworkInterceptor(new CacheInterceptor())
                        .cache(new Cache(CustomApplication.getInstance().getCacheDir(), 10 * 1024 * 1024));
                Retrofit retrofit = new Retrofit.Builder().client(builder.build()).baseUrl(baseApi.getBaseUrl()).addConverterFactory(ScalarsConverterFactory.create())
                        .addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
//                        .build();
//                這裏原理是通過Java的動態代理創建接口的實例
                HttpService httpService = retrofit.create(HttpService.class);
                Observable observable = baseApi.getObservable(httpService);
                observable.retryWhen(new RetryWhenNetWorkException()).subscribeOn(Schedulers.io()).unsubscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread()).map(baseApi).subscribe(commonSubscriber);
        }
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:17,代碼來源:CommonHttpManager.java

示例4: start

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的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

示例5: HttpManager

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的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

示例6: createService

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
/**
 * Create service
 * @param key OwO API key
 * @param endpoint Endpoint URL, defaults to {@link OwO#DEFAULT_ENDPOINT} when null
 * @param uploadUrl Upload URL, defaults to {@link OwO#DEFAULT_UPLOAD_URL} when null
 * @return service
 */
private static OwOService createService(@NotNull final String key, @Nullable String endpoint, @Nullable final String uploadUrl) {
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            HttpUrl url = request.url().newBuilder().addQueryParameter("key", key).build();
            return chain.proceed(request.newBuilder().header("User-Agent", USER_AGENT).url(url).build());
        }
    }).build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpoint == null ? DEFAULT_ENDPOINT : endpoint)
            .client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().registerTypeAdapter(OwOFile.class, new JsonDeserializer<OwOFile>() {
                @Override
                public OwOFile deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
                    return new Gson().fromJson(json.getAsJsonObject().get("files").getAsJsonArray().get(0), OwOFile.class).setFullUrl(uploadUrl == null ? DEFAULT_UPLOAD_URL : uploadUrl);
                }}).create()))
            .build();

    return retrofit.create(OwOService.class);
}
 
開發者ID:whats-this,項目名稱:owo.java,代碼行數:31,代碼來源:OwO.java

示例7: getRetrofitService

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
/**
 * 獲取retrofitService
 *
 * @param context
 * @param baseUrl
 * @return
 */
public static RetrofitHttpService getRetrofitService(Context context, String baseUrl) {
    if (TextUtils.isEmpty(baseUrl)) {
        throw new NullPointerException("BASE_URL can not be null");
    }

    OkHttpClient client = RequestAgent.getOkHttpClient(context.getApplicationContext(), baseUrl, null);

    Retrofit.Builder builder = new Retrofit.Builder();

    builder.addConverterFactory(ScalarsConverterFactory.create());

    if (!baseUrl.endsWith("/")) {
        baseUrl += "/";
    }

    Retrofit retrofit = builder
            .baseUrl(baseUrl)
            .client(client).build();

    return retrofit.create(RetrofitHttpService.class);
}
 
開發者ID:jingle1267,項目名稱:AndroidRequest,代碼行數:29,代碼來源:RequestAgent.java

示例8: createDefaultAdapter

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
public void createDefaultAdapter() {
  Gson gson = new GsonBuilder()
    .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
    .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter())
    .create();

  okBuilder = new OkHttpClient.Builder();

  String baseUrl = "https://api.us-east-1.mbedcloud.com";
  if(!baseUrl.endsWith("/"))
    baseUrl = baseUrl + "/";

  adapterBuilder = new Retrofit
    .Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(ScalarsConverterFactory.create())
    .addConverterFactory(GsonCustomConverterFactory.create(gson));
}
 
開發者ID:ARMmbed,項目名稱:mbed-cloud-sdk-java,代碼行數:20,代碼來源:ApiClient.java

示例9: createDefaultAdapter

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
public void createDefaultAdapter() {
  Gson gson = new GsonBuilder()
    .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
    .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter())
    .create();

  okBuilder = new OkHttpClient.Builder();

  String baseUrl = "http://api.us-east-1.mbedcloud.com";
  if(!baseUrl.endsWith("/"))
    baseUrl = baseUrl + "/";

  adapterBuilder = new Retrofit
    .Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(ScalarsConverterFactory.create())
    .addConverterFactory(GsonCustomConverterFactory.create(gson));
}
 
開發者ID:ARMmbed,項目名稱:mbed-cloud-sdk-java,代碼行數:20,代碼來源:ApiClient.java

示例10: SlackReporter

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
private SlackReporter(String apiKey, boolean logEnabled) {
    mIsLogEnabled = logEnabled;
    mApiKey = apiKey;

    Retrofit.Builder builder = new Retrofit.Builder();
    builder.baseUrl("https://hooks.slack.com")
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create());

    if (mIsLogEnabled) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
        builder.client(client);
    }

    Retrofit sRetrofit = builder.build();
    sService = sRetrofit.create(SlackMessageReportService.class);
}
 
開發者ID:suhanlee,項目名稱:SlackMessage,代碼行數:20,代碼來源:SlackReporter.java

示例11: ServicesManager

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
private ServicesManager() {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.WEATHER_BASE_URL)
            .client(builder.build())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    weatherInfoService = retrofit.create(WeatherInfoService.class);

    mNameMap.put("CN10101", "北京");
    mNameMap.put("CN10102", "上海");
    mNameMap.put("CN10103", "天津");
    mNameMap.put("CN10104", "重慶");
    mNameMap.put("CN10132", "香港");
    mNameMap.put("CN10133", "澳門");
}
 
開發者ID:ZeusChan,項目名稱:LittleFreshWeather,代碼行數:21,代碼來源:ServicesManager.java

示例12: createNetEasyService

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
private static NetEasyApi createNetEasyService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(NETEASY_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(NetEasyApi.class);
    }
 
開發者ID:huyongli,項目名稱:TigerVideo,代碼行數:19,代碼來源:RetrofitFactory.java

示例13: createTtKbService

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
private static TtKbApi createTtKbService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(TTKB_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(TtKbApi.class);
    }
 
開發者ID:huyongli,項目名稱:TigerVideo,代碼行數:19,代碼來源:RetrofitFactory.java

示例14: createIFengService

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
private static IFengApi createIFengService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(IFENG_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(IFengApi.class);
    }
 
開發者ID:huyongli,項目名稱:TigerVideo,代碼行數:19,代碼來源:RetrofitFactory.java

示例15: onCreate

import retrofit2.converter.scalars.ScalarsConverterFactory; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_retrofit1);
    ButterKnife.bind(this);
    //01:獲取Retrofit對象
    mRetrofit = new Retrofit.Builder()
            //02采用鏈式結構綁定Base url
            .baseUrl(ApiStores.API_SERVER_URL)
            // 注意:字符創解析器要放在Gson解析器前麵,不然無法解析字符串
            //使用工廠模式創建字符串解析器
            .addConverterFactory(ScalarsConverterFactory.create())
            //使用工廠模式創建Gson的解析器
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    //04獲取API接口的實現類的實例對象
    mApiStores = mRetrofit.create(ApiStores.class);

}
 
開發者ID:sdwfqin,項目名稱:AndroidSamples,代碼行數:20,代碼來源:Retrofit1Activity.java


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