Switch to EmailAsyncTask

Also remove the isCancelled test in onPostExecute, where it should
never return true.

Change-Id: Ica2b07db22d73769c2ead5f232f4890bd3bb87da
This commit is contained in:
Makoto Onuki 2011-06-28 19:31:23 -07:00
parent 6cf76d94c8
commit 4a893e60b4
6 changed files with 34 additions and 34 deletions

View File

@ -441,6 +441,15 @@ public class Utility {
cancelTask(task, true);
}
/**
* Cancel an {@link EmailAsyncTask}. If it's already running, it'll be interrupted.
*/
public static void cancelTaskInterrupt(EmailAsyncTask<?, ?, ?> task) {
if (task != null) {
task.cancel(true);
}
}
/**
* Cancel an {@link AsyncTask}.
*

View File

@ -23,10 +23,10 @@ import com.android.emailcommon.Logging;
import com.android.emailcommon.mail.MessagingException;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.utility.EmailAsyncTask;
import com.android.emailcommon.utility.Utility;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.util.Log;
@ -97,7 +97,7 @@ public class MailboxFinder {
}
mStarted = true;
mTask = new FindMailboxTask(true);
mTask.execute();
mTask.executeParallel();
}
/**
@ -141,7 +141,7 @@ public class MailboxFinder {
} else if (progress == 100) {
// Mailbox list updated, look for mailbox again...
mTask = new FindMailboxTask(false);
mTask.execute();
mTask.executeParallel();
}
}
}
@ -150,7 +150,7 @@ public class MailboxFinder {
* Async task for finding a single mailbox by type. If a mailbox of a type is not found,
* and {@code okToRecurse} is true, we update the mailbox list and try looking again.
*/
private class FindMailboxTask extends AsyncTask<Void, Void, Long> {
private class FindMailboxTask extends EmailAsyncTask<Void, Void, Long> {
private final boolean mOkToRecurse;
private static final int RESULT_MAILBOX_FOUND = 0;
@ -165,6 +165,7 @@ public class MailboxFinder {
* Special constructor to cache some local info
*/
public FindMailboxTask(boolean okToRecurse) {
super(null);
mOkToRecurse = okToRecurse;
}
@ -200,9 +201,6 @@ public class MailboxFinder {
@Override
protected void onPostExecute(Long mailboxId) {
if (isCancelled()) {
return;
}
switch (mResult) {
case RESULT_ACCOUNT_SECURITY_HOLD:
Log.w(Logging.LOG_TAG, "MailboxFinder: Account security hold.");

View File

@ -762,7 +762,7 @@ public class MessageListFragment extends ListFragment
@Override
protected void onPostExecute(Integer type) {
if (isCancelled() || type == null) {
if (type == null) {
return;
}
mCallback.onMessageOpen(mMessageId, mMessageMailboxId, getMailboxId(), type);

View File

@ -18,13 +18,14 @@ package com.android.email.activity;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Message;
import com.android.emailcommon.utility.EmailAsyncTask;
import com.android.emailcommon.utility.EmailAsyncTask.Tracker;
import com.android.emailcommon.utility.Utility;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Handler;
/**
@ -138,7 +139,7 @@ public class MessageOrderManager {
*/
/* package */ void startQuery() {
mLoadMessageListTask = new LoadMessageListTask();
mLoadMessageListTask.execute();
mLoadMessageListTask.executeParallel();
}
private void cancelTask() {
@ -264,32 +265,27 @@ public class MessageOrderManager {
/**
* Task to open a Cursor on a worker thread.
*/
private class LoadMessageListTask extends AsyncTask<Void, Void, Cursor> {
@Override
protected Cursor doInBackground(Void... params) {
Cursor c = openNewCursor();
if (isCancelled()) {
c.close();
c = null;
}
return c;
private class LoadMessageListTask extends EmailAsyncTask<Void, Void, Cursor> {
public LoadMessageListTask() {
super(null);
}
@Override
protected void onCancelled() {
protected Cursor doInBackground(Void... params) {
return openNewCursor();
}
@Override
protected void onCancelled(Cursor cursor) {
if (cursor != null) {
cursor.close();
}
onCursorOpenDone(null);
}
@Override
protected void onPostExecute(Cursor cursor) {
if (mClosed || isCancelled()) { // Is this really necessary??
if (cursor != null) {
cursor.close();
}
onCancelled();
} else {
onCursorOpenDone(cursor);
}
onCursorOpenDone(cursor);
}
}

View File

@ -1059,9 +1059,6 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
@Override
protected void onPostExecute(Message message) {
if (isCancelled()) {
return;
}
if (message == null) {
resetView();
mCallback.onMessageNotExists();
@ -1157,7 +1154,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
@Override
protected void onPostExecute(String[] results) {
if (results == null || isCancelled()) {
if (results == null) {
if (mErrorLoadingMessageBody) {
Utility.showToast(getActivity(), R.string.error_loading_message_body);
}
@ -1190,7 +1187,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
@Override
protected void onPostExecute(Attachment[] attachments) {
try {
if (isCancelled() || attachments == null) {
if (attachments == null) {
return;
}
boolean htmlChanged = false;

View File

@ -742,7 +742,7 @@ class UIControllerTwoPane extends UIControllerBase implements
*/
@Override
protected void onPostExecute(Boolean isCurrentMailboxRefreshable) {
if (isCancelled() || isCurrentMailboxRefreshable == null) {
if (isCurrentMailboxRefreshable == null) {
return;
}
if (isCurrentMailboxRefreshable) {