Java Code Examples for com.android.volley.Request#setTag()

The following examples show how to use com.android.volley.Request#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestManager.java    From JianDan with Apache License 2.0 6 votes vote down vote up
public static void addRequest(Request<?> request, Object tag) {
    if (tag != null) {
        request.setTag(tag);
    }
    //给每个请求重设超时、重试次数
    request.setRetryPolicy(new DefaultRetryPolicy(
            OUT_TIME,
            TIMES_OF_RETRY,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    mRequestQueue.add(request);

    if (BuildConfig.DEBUG) {
        Logger.d(request.getUrl());
    }

}
 
Example 2
Source File: RequestManager.java    From JianDan_OkHttp with Apache License 2.0 6 votes vote down vote up
public static void addRequest(Request<?> request, Object tag) {
    if (tag != null) {
        request.setTag(tag);
    }
    //给每个请求重设超时、重试次数
    request.setRetryPolicy(new DefaultRetryPolicy(
            OUT_TIME,
            TIMES_OF_RETRY,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    mRequestQueue.add(request);

    if (BuildConfig.DEBUG) {
        Logger.d(request.getUrl());
    }

}
 
Example 3
Source File: HttpTools.java    From volley with Apache License 2.0 5 votes vote down vote up
/**
 * 发送http请求
 * @param request
 */
public <T> void sendRequest(Request<T> request) {
	if (sRequestQueue == null) {
        sRequestQueue = Volley.newNoCacheRequestQueue(mContext);
    }
	request.setTag(this);
    sRequestQueue.add(request);
}
 
Example 4
Source File: SoasApplication.java    From soas with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the specified request to the global queue using the Default TAG.
 *
 * @param context A context used for creating cache dir.
 * @param request Request to be executed.
 */
public static <T> void addToRequestQueue(Context context, Request<T> request) {
    // Use default request tag.
    request.setTag(DEFAULT_REQUEST_TAG);

    getRequestQueue(context).add(request);
}
 
Example 5
Source File: HttpService.java    From AndroidCacheFoundation with Apache License 2.0 5 votes vote down vote up
/**
 * 往全局队列里加入一个新的http请求
 *
 * @param request
 * @param tag     请求tag, 可以通过tag取消请求
 */
public <T> void addToRequestQueue(Request<T> request, String tag) {
    request.setTag(TextUtils.isEmpty(tag) ? DEFAULT_HTTP_TAG : tag);
    VolleyLog.d("Adding request to queue: %s", request.getUrl());
    if (this.httpQueue != null) {
        this.httpQueue.add(request);

    } else {
        Log.d(TAG, "http queue null");
    }


}
 
Example 6
Source File: CircleOf6Application.java    From OpenCircle with GNU General Public License v3.0 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}
 
Example 7
Source File: CircleOf6Application.java    From OpenCircle with GNU General Public License v3.0 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    // set the default tag if tag is empty
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}
 
Example 8
Source File: ImageLoader.java    From volley with Apache License 2.0 4 votes vote down vote up
/**
     * Issues a bitmap request with the given URL if that image is not available
     * in the cache, and returns a bitmap container that contains all of the data
     * relating to the request (as well as the default image if the requested
     * image is not available).
     * @param requestUrl The url of the remote image
     * @param imageListener The listener to call when the remote image is loaded
     * @param maxWidth The maximum width of the returned image.
     * @param maxHeight The maximum height of the returned image.
     * @return A container object that contains all of the properties of the request, as well as
     *     the currently available image (default if remote is not loaded).
     */
    public ImageContainer get(Context context, String requestUrl, ImageListener imageListener, LoadingListener loadingListener,
            int maxWidth, int maxHeight) {
        // only fulfill requests that were initiated from the main thread.
        throwIfNotOnMainThread();

        final String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight);

        // Try to look up the request in the cache of remote images.
        
        Bitmap cachedBitmap = mCache.getBitmap(cacheKey); 
        if (cachedBitmap != null) {
            // Return the cached bitmap.
            ImageContainer container = new ImageContainer(cachedBitmap, requestUrl, null, null);
            imageListener.onResponse(container, true);
            return container;
        }

        // The bitmap did not exist in the cache, fetch it!
        final ImageContainer imageContainer =
                new ImageContainer(null, requestUrl, cacheKey, imageListener);
        imageContainer.mLoadingListener = loadingListener;

        // Update the caller to let them know that they should use the default bitmap.
        imageListener.onResponse(imageContainer, true);

        // Check to see if a request is already in-flight.
        BatchedImageRequest request = mInFlightRequests.get(cacheKey);
        
        if (request != null) {
            // If it is, add this request to the list of listeners.
            request.addContainer(imageContainer);
            return imageContainer;
        }

        // The request is not already in flight. Send the new request to the network and
        // track it.
        
        Request<?> newRequest =
            new ImageRequest(context, requestUrl, new Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    onGetImageSuccess(cacheKey, response);
                }
            }, maxWidth, maxHeight,
            Config.RGB_565, new ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    onGetImageError(cacheKey, error);
                }
            });
        newRequest.setTag(context);
        if (loadingListener != null) {
            newRequest.setLoadingListener(new LoadingListener() {

                @Override
                public void onLoading(long count, long current) {
                    onLoadImage(cacheKey, count, current);
                }
            });
        }
//        LogUtils.d("ning1", "ImageContainer get newRequest");
        mRequestQueue.add(newRequest);
        mInFlightRequests.put(cacheKey,
                new BatchedImageRequest(newRequest, imageContainer));
        return imageContainer;
    }
 
Example 9
Source File: AppController.java    From Trivia-Knowledge with Apache License 2.0 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}
 
Example 10
Source File: AppController.java    From ImageSliderWithSwipes with Apache License 2.0 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}
 
Example 11
Source File: HttpClient.java    From zap-android with MIT License 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    req.setTag(tag);
    getRequestQueue().add(req);
}
 
Example 12
Source File: AppController.java    From protrip with MIT License 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    // set the default tag if tag is empty
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}
 
Example 13
Source File: VolleyUtils.java    From 1Rramp-Android with MIT License 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req) {
  req.setTag(TAG);
  getRequestQueue(baseContext).add(req);
}
 
Example 14
Source File: RequestManager.java    From ting with Apache License 2.0 4 votes vote down vote up
public static void addRequest(Request<?> request, Object tag){
    if(tag != null) {
        request.setTag(tag);
    }
    mRequestQueue.add(request);
}
 
Example 15
Source File: AppController.java    From video-player with MIT License 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    // set the default tag if tag is empty
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}
 
Example 16
Source File: AppController.java    From video-player with MIT License 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}
 
Example 17
Source File: MyApplication.java    From openshop.io-android with MIT License 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req, String tag) {
    // set the default tag if tag is empty
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    getRequestQueue().add(req);
}
 
Example 18
Source File: NetworkHelper.java    From IceNet with Apache License 2.0 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    req.setRetryPolicy(retryPolicy());
    getRequestQueue().add(req);
}
 
Example 19
Source File: BaseApplication.java    From BigApp_WordPress_Android with Apache License 2.0 4 votes vote down vote up
public <T> void addToRequestQueue(Request<T> req) {
    req.setTag(TAG);
    getRequestQueue().add(req);
}
 
Example 20
Source File: HttpClientRequest.java    From lunzi with Apache License 2.0 2 votes vote down vote up
/**
 * Adds a request to the Volley request queue
 *
 * @param request is the request to add to the Volley queuest
 * @param tag     is the tag identifying the request
 */
public <T> void addRequest(Request<T> request, String tag) {
    request.setTag(tag);
    getRequestQueue().add(request);
}