Java tutorial
/** * Copyright 2015 ZhangQu Li * <p/> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.gdkm.sfk.utils.coreProgress; import com.squareup.okhttp.Interceptor; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.RequestBody; import com.squareup.okhttp.Response; import java.io.IOException; /** * * User:lizhangqu(513163535@qq.com) * Date:2015-09-02 * Time: 17:33 */ public class ProgressHelper { /** * OkHttpClient * @param client OkHttpClient * @param progressListener ? * @return ?OkHttpClientclone */ public static OkHttpClient addProgressResponseListener(OkHttpClient client, final ProgressResponseListener progressListener) { // OkHttpClient clone = client.clone(); // clone.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { // Response originalResponse = chain.proceed(chain.request()); //? return originalResponse.newBuilder() .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build(); } }); return clone; } /** * * @param requestBody RequestBody * @param progressRequestListener ? * @return ? */ public static ProgressRequestBody addProgressRequestListener(RequestBody requestBody, ProgressRequestListener progressRequestListener) { // return new ProgressRequestBody(requestBody, progressRequestListener); } }