Search in sources :

Example 1 with Background

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();
}
Also used : WeatherTodayModel(tk.woppo.sunday.model.WeatherTodayModel) SimpleWeatherModel(tk.woppo.sunday.model.SimpleWeatherModel) CurWeatherModel(tk.woppo.sunday.model.CurWeatherModel) WeatherModel(tk.woppo.sunday.model.WeatherModel) AreaModel(tk.woppo.sunday.model.city.AreaModel) Background(org.androidannotations.annotations.Background)

Example 2 with Background

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);
}
Also used : BackgroundExecutor(org.androidannotations.api.BackgroundExecutor) Background(org.androidannotations.annotations.Background) JDefinedClass(com.helger.jcodemodel.JDefinedClass) ExecutableElement(javax.lang.model.element.ExecutableElement) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) IJStatement(com.helger.jcodemodel.IJStatement) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

Background (org.androidannotations.annotations.Background)2 AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 IJStatement (com.helger.jcodemodel.IJStatement)1 JBlock (com.helger.jcodemodel.JBlock)1 JCatchBlock (com.helger.jcodemodel.JCatchBlock)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JInvocation (com.helger.jcodemodel.JInvocation)1 JMethod (com.helger.jcodemodel.JMethod)1 JTryBlock (com.helger.jcodemodel.JTryBlock)1 JVar (com.helger.jcodemodel.JVar)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 BackgroundExecutor (org.androidannotations.api.BackgroundExecutor)1 CurWeatherModel (tk.woppo.sunday.model.CurWeatherModel)1 SimpleWeatherModel (tk.woppo.sunday.model.SimpleWeatherModel)1 WeatherModel (tk.woppo.sunday.model.WeatherModel)1 WeatherTodayModel (tk.woppo.sunday.model.WeatherTodayModel)1 AreaModel (tk.woppo.sunday.model.city.AreaModel)1