| 21478 |
rajender |
1 |
/*
|
|
|
2 |
* Copyright (C) 2011 The Android Open Source Project
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
package com.android.volley.toolbox;
|
|
|
18 |
|
|
|
19 |
import android.os.Handler;
|
|
|
20 |
import android.os.Looper;
|
|
|
21 |
|
|
|
22 |
import com.android.volley.Cache;
|
|
|
23 |
import com.android.volley.NetworkResponse;
|
|
|
24 |
import com.android.volley.Request;
|
|
|
25 |
import com.android.volley.Response;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* A synthetic request used for clearing the cache.
|
|
|
29 |
*/
|
|
|
30 |
public class ClearCacheRequest extends Request<Object> {
|
|
|
31 |
private final Cache mCache;
|
|
|
32 |
private final Runnable mCallback;
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Creates a synthetic request for clearing the cache.
|
|
|
36 |
* @param cache Cache to clear
|
|
|
37 |
* @param callback Callback to make on the main thread once the cache is clear,
|
|
|
38 |
* or null for none
|
|
|
39 |
*/
|
|
|
40 |
public ClearCacheRequest(Cache cache, Runnable callback) {
|
|
|
41 |
super(Method.GET, null, null);
|
|
|
42 |
mCache = cache;
|
|
|
43 |
mCallback = callback;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
@Override
|
|
|
47 |
public boolean isCanceled() {
|
|
|
48 |
// This is a little bit of a hack, but hey, why not.
|
|
|
49 |
mCache.clear();
|
|
|
50 |
if (mCallback != null) {
|
|
|
51 |
Handler handler = new Handler(Looper.getMainLooper());
|
|
|
52 |
handler.postAtFrontOfQueue(mCallback);
|
|
|
53 |
}
|
|
|
54 |
return true;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
@Override
|
|
|
58 |
public Priority getPriority() {
|
|
|
59 |
return Priority.IMMEDIATE;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
protected Response<Object> parseNetworkResponse(NetworkResponse response) {
|
|
|
64 |
return null;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
protected void deliverResponse(Object response) {
|
|
|
69 |
}
|
|
|
70 |
}
|