18
18
import android .os .Handler ;
19
19
import android .os .Looper ;
20
20
import android .os .Message ;
21
- import android .os .Process ;
22
21
import com .lidroid .xutils .util .LogUtils ;
23
22
24
23
import java .util .concurrent .*;
@@ -45,6 +44,16 @@ public abstract class PriorityAsyncTask<Params, Progress, Result> implements Tas
45
44
private final AtomicBoolean mCancelled = new AtomicBoolean ();
46
45
private final AtomicBoolean mTaskInvoked = new AtomicBoolean ();
47
46
47
+ private Priority priority ;
48
+
49
+ public Priority getPriority () {
50
+ return priority ;
51
+ }
52
+
53
+ public void setPriority (Priority priority ) {
54
+ this .priority = priority ;
55
+ }
56
+
48
57
/**
49
58
* Creates a new asynchronous task. This constructor must be invoked on the UI thread.
50
59
*/
@@ -53,7 +62,7 @@ public PriorityAsyncTask() {
53
62
public Result call () throws Exception {
54
63
mTaskInvoked .set (true );
55
64
56
- android .os .Process .setThreadPriority (Process .THREAD_PRIORITY_BACKGROUND );
65
+ android .os .Process .setThreadPriority (android . os . Process .THREAD_PRIORITY_BACKGROUND );
57
66
//noinspection unchecked
58
67
return postResult (doInBackground (mParams ));
59
68
}
@@ -65,7 +74,7 @@ protected void done() {
65
74
try {
66
75
postResultIfNotInvoked (get ());
67
76
} catch (InterruptedException e ) {
68
- LogUtils .w ( e );
77
+ LogUtils .d ( e . getMessage () );
69
78
} catch (ExecutionException e ) {
70
79
throw new RuntimeException ("An error occured while executing doInBackground()" ,
71
80
e .getCause ());
@@ -185,6 +194,7 @@ protected void onCancelled() {
185
194
* @return <tt>true</tt> if task was cancelled before it completed
186
195
* @see #cancel(boolean)
187
196
*/
197
+ @ Override
188
198
public final boolean isCancelled () {
189
199
return mCancelled .get ();
190
200
}
@@ -280,18 +290,6 @@ public final PriorityAsyncTask<Params, Progress, Result> execute(Params... param
280
290
return executeOnExecutor (sDefaultExecutor , params );
281
291
}
282
292
283
- /**
284
- * @param priority
285
- * @param params The parameters of the task.
286
- * @return This instance of AsyncTask.
287
- * @throws IllegalStateException If execute has invoked.
288
- * @see #executeOnExecutor(java.util.concurrent.Executor, Object[])
289
- * @see #execute(Runnable)
290
- */
291
- public final PriorityAsyncTask <Params , Progress , Result > execute (Priority priority , Params ... params ) {
292
- return executeOnExecutor (sDefaultExecutor , priority , params );
293
- }
294
-
295
293
/**
296
294
* @param exec The executor to use.
297
295
* @param params The parameters of the task.
@@ -301,20 +299,6 @@ public final PriorityAsyncTask<Params, Progress, Result> execute(Priority priori
301
299
*/
302
300
public final PriorityAsyncTask <Params , Progress , Result > executeOnExecutor (Executor exec ,
303
301
Params ... params ) {
304
- return executeOnExecutor (exec , Priority .DEFAULT , params );
305
- }
306
-
307
- /**
308
- * @param exec The executor to use.
309
- * @param priority
310
- * @param params The parameters of the task.
311
- * @return This instance of AsyncTask.
312
- * @throws IllegalStateException If execute has invoked.
313
- * @see #execute(Object[])
314
- */
315
- public final PriorityAsyncTask <Params , Progress , Result > executeOnExecutor (Executor exec ,
316
- Priority priority ,
317
- Params ... params ) {
318
302
if (mExecuteInvoked ) {
319
303
throw new IllegalStateException ("Cannot execute task:"
320
304
+ " the task is already executed." );
0 commit comments