2010-05-24 18:35:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.android.email;
|
|
|
|
|
|
|
|
import com.android.email.Controller.Result;
|
|
|
|
import com.android.email.mail.MessagingException;
|
|
|
|
|
2010-06-01 21:09:11 +00:00
|
|
|
import android.os.Handler;
|
2010-05-24 18:35:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A {@link Result} that wraps another {@link Result} and makes sure methods gets called back
|
|
|
|
* on the UI thread.
|
|
|
|
*/
|
2010-06-07 21:03:40 +00:00
|
|
|
public class ControllerResultUiThreadWrapper<T extends Result> extends Result {
|
2010-06-01 21:09:11 +00:00
|
|
|
private final Handler mHandler;
|
|
|
|
private final T mWrappee;
|
2010-05-24 18:35:43 +00:00
|
|
|
|
2010-06-01 21:09:11 +00:00
|
|
|
public ControllerResultUiThreadWrapper(Handler handler, T wrappee) {
|
|
|
|
mHandler = handler;
|
2010-05-24 18:35:43 +00:00
|
|
|
mWrappee = wrappee;
|
|
|
|
}
|
|
|
|
|
2010-06-01 21:09:11 +00:00
|
|
|
public T getWrappee() {
|
|
|
|
return mWrappee;
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:03:40 +00:00
|
|
|
@Override
|
2010-05-24 18:35:43 +00:00
|
|
|
public void loadAttachmentCallback(final MessagingException result, final long messageId,
|
|
|
|
final long attachmentId, final int progress) {
|
2010-06-01 21:09:11 +00:00
|
|
|
mHandler.post(new Runnable() {
|
2010-05-24 18:35:43 +00:00
|
|
|
public void run() {
|
|
|
|
mWrappee.loadAttachmentCallback(result, messageId, attachmentId, progress);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:03:40 +00:00
|
|
|
@Override
|
2010-05-24 18:35:43 +00:00
|
|
|
public void loadMessageForViewCallback(final MessagingException result,
|
|
|
|
final long messageId, final int progress) {
|
2010-06-01 21:09:11 +00:00
|
|
|
mHandler.post(new Runnable() {
|
2010-05-24 18:35:43 +00:00
|
|
|
public void run() {
|
|
|
|
mWrappee.loadMessageForViewCallback(result, messageId, progress);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:03:40 +00:00
|
|
|
@Override
|
2010-05-24 18:35:43 +00:00
|
|
|
public void sendMailCallback(final MessagingException result, final long accountId,
|
|
|
|
final long messageId, final int progress) {
|
2010-06-01 21:09:11 +00:00
|
|
|
mHandler.post(new Runnable() {
|
2010-05-24 18:35:43 +00:00
|
|
|
public void run() {
|
|
|
|
mWrappee.sendMailCallback(result, accountId, messageId, progress);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:03:40 +00:00
|
|
|
@Override
|
2010-05-24 18:35:43 +00:00
|
|
|
public void serviceCheckMailCallback(final MessagingException result, final long accountId,
|
|
|
|
final long mailboxId, final int progress, final long tag) {
|
2010-06-01 21:09:11 +00:00
|
|
|
mHandler.post(new Runnable() {
|
2010-05-24 18:35:43 +00:00
|
|
|
public void run() {
|
|
|
|
mWrappee.serviceCheckMailCallback(result, accountId, mailboxId, progress, tag);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:03:40 +00:00
|
|
|
@Override
|
2010-05-24 18:35:43 +00:00
|
|
|
public void updateMailboxCallback(final MessagingException result, final long accountId,
|
|
|
|
final long mailboxId, final int progress, final int numNewMessages) {
|
2010-06-01 21:09:11 +00:00
|
|
|
mHandler.post(new Runnable() {
|
2010-05-24 18:35:43 +00:00
|
|
|
public void run() {
|
|
|
|
mWrappee.updateMailboxCallback(result, accountId, mailboxId, progress,
|
|
|
|
numNewMessages);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-07 21:03:40 +00:00
|
|
|
@Override
|
2010-05-24 18:35:43 +00:00
|
|
|
public void updateMailboxListCallback(final MessagingException result, final long accountId,
|
|
|
|
final int progress) {
|
2010-06-01 21:09:11 +00:00
|
|
|
mHandler.post(new Runnable() {
|
2010-05-24 18:35:43 +00:00
|
|
|
public void run() {
|
|
|
|
mWrappee.updateMailboxListCallback(result, accountId, progress);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-06-04 00:48:18 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void deleteAccountCallback(final long accountId) {
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mWrappee.deleteAccountCallback(accountId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-05-24 18:35:43 +00:00
|
|
|
}
|