use of org.androidannotations.annotations.Background in project SunDay by iQuick.
the class HomeFragment method getDataFromDB.
/**
* 从数据库中获取数据
*/
@Background
void getDataFromDB() {
for (AreaModel model : App.getMyArea()) {
WeatherModel weatherModel = mWeatherDB.query(model.getWeatherCode());
WeatherTodayModel weatherTodayModel = mTodayDB.query(model.getWeatherCode());
if (weatherModel != null) {
mWeatherModels.add(weatherModel);
mSimpleWeatherModels.add(weatherModel.toSimpleWeatherList());
}
if (weatherTodayModel != null)
mWeatherTodayModels.add(weatherTodayModel);
}
// 更新列表
updateWeatherList();
}
use of org.androidannotations.annotations.Background in project androidannotations by androidannotations.
the class BackgroundHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(delegatingMethod);
JDefinedClass anonymousTaskClass = getCodeModel().anonymousClass(BackgroundExecutor.Task.class);
JMethod executeMethod = anonymousTaskClass.method(JMod.PUBLIC, getCodeModel().VOID, "execute");
executeMethod.annotate(Override.class);
// Catch exception in user code
JTryBlock tryBlock = executeMethod.body()._try();
tryBlock.body().add(previousMethodBody);
JCatchBlock catchBlock = tryBlock._catch(getClasses().THROWABLE);
JVar caughtException = catchBlock.param("e");
IJStatement uncaughtExceptionCall = //
getClasses().THREAD.staticInvoke(//
"getDefaultUncaughtExceptionHandler").invoke(//
"uncaughtException").arg(//
getClasses().THREAD.staticInvoke("currentThread")).arg(caughtException);
catchBlock.body().add(uncaughtExceptionCall);
Background annotation = element.getAnnotation(Background.class);
String id = annotation.id();
long delay = annotation.delay();
String serial = annotation.serial();
AbstractJClass backgroundExecutorClass = getJClass(BackgroundExecutor.class);
JInvocation newTask = _new(anonymousTaskClass).arg(lit(id)).arg(lit(delay)).arg(lit(serial));
JInvocation executeCall = backgroundExecutorClass.staticInvoke("execute").arg(newTask);
delegatingMethod.body().add(executeCall);
}
Aggregations