Search in sources :

Example 1 with UiThread

use of org.androidannotations.annotations.UiThread in project SunDay by iQuick.

the class WeatherUpdateService method updateTime.

@UiThread
void updateTime() {
    Date date = new Date();
    // 定义SimpleDateFormat对象
    remoteView.setTextViewText(R.id.tv_provider_time, DateUtil.getCurTime());
    remoteView.setTextViewText(R.id.tv_provider_week, DateUtil.getCurWeek());
    remoteView.setOnClickPendingIntent(R.id.rl_provider_widget, PendingIntent.getActivity(this, 0, new Intent(this, MainActivity_.class), 0));
    remoteView.setOnClickPendingIntent(R.id.ll_provider_right, PendingIntent.getBroadcast(this, 1, new Intent(ACTION_NEXT_CITY), 0));
    ComponentName componentName = new ComponentName(getApplication(), WeatherWidget.class);
    AppWidgetManager.getInstance(getApplication()).updateAppWidget(componentName, remoteView);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) Date(java.util.Date) UiThread(org.androidannotations.annotations.UiThread)

Example 2 with UiThread

use of org.androidannotations.annotations.UiThread in project SunDay by iQuick.

the class WeatherUpdateService method updateWeather.

@UiThread
void updateWeather() {
    if (mSunModel != null) {
        if (mSunModel.realtime.cityName != null)
            remoteView.setTextViewText(R.id.tv_provider_city, mSunModel.realtime.cityName);
        remoteView.setTextViewText(R.id.tv_provider_temp, mSunModel.realtime.weather.temp + "℃");
        remoteView.setTextViewText(R.id.tv_provider_weather, mSunModel.realtime.weather.info);
        remoteView.setImageViewResource(R.id.iv_provider_weather, WeatherUtil.getIcon(mSunModel.realtime.weather.info));
    }
    ComponentName componentName = new ComponentName(getApplication(), WeatherWidget.class);
    AppWidgetManager.getInstance(getApplication()).updateAppWidget(componentName, remoteView);
}
Also used : ComponentName(android.content.ComponentName) UiThread(org.androidannotations.annotations.UiThread)

Example 3 with UiThread

use of org.androidannotations.annotations.UiThread in project androidannotations by androidannotations.

the class UiThreadHandler method validate.

@Override
public void validate(Element element, ElementValidation valid) {
    super.validate(element, valid);
    coreValidatorHelper.usesEnqueueIfHasId(element, valid);
    UiThread annotation = element.getAnnotation(UiThread.class);
    long delay = annotation.delay();
    UiThread.Propagation propagation = annotation.propagation();
    if (delay != 0 && propagation == UiThread.Propagation.REUSE) {
        valid.addWarning("propagation=REUSE is ignored when using a delay");
    }
}
Also used : UiThread(org.androidannotations.annotations.UiThread)

Example 4 with UiThread

use of org.androidannotations.annotations.UiThread in project androidannotations by androidannotations.

the class UiThreadHandler method process.

@Override
public void process(Element element, EComponentHolder holder) throws Exception {
    ExecutableElement executableElement = (ExecutableElement) element;
    JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
    JBlock previousBody = codeModelHelper.removeBody(delegatingMethod);
    JDefinedClass anonymousRunnableClass = codeModelHelper.createDelegatingAnonymousRunnableClass(previousBody);
    UiThread annotation = element.getAnnotation(UiThread.class);
    long delay = annotation.delay();
    UiThread.Propagation propagation = annotation.propagation();
    if (delay == 0 && propagation == UiThread.Propagation.REUSE) {
        // Put in the check for the UI thread.
        addUIThreadCheck(delegatingMethod, previousBody, holder);
    }
    delegatingMethod.body().add(// 
    getJClass(UiThreadExecutor.class).staticInvoke(METHOD_RUN_TASK).arg(// 
    annotation.id()).arg(// 
    _new(anonymousRunnableClass)).arg(lit(delay)));
}
Also used : UiThreadExecutor(org.androidannotations.api.UiThreadExecutor) JDefinedClass(com.helger.jcodemodel.JDefinedClass) UiThread(org.androidannotations.annotations.UiThread) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 5 with UiThread

use of org.androidannotations.annotations.UiThread in project androidannotations by androidannotations.

the class MyActivity method showNotificationsDelayed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@UiThread(delay = 2000)
void showNotificationsDelayed() {
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    Notification notification = new Notification.Builder(this).setSmallIcon(R.drawable.icon).setContentTitle("My notification").setContentText("Hello, World!").setContentIntent(contentIntent).getNotification();
    notificationManager.notify(1, notification);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) UiThread(org.androidannotations.annotations.UiThread) TargetApi(android.annotation.TargetApi)

Aggregations

UiThread (org.androidannotations.annotations.UiThread)5 PendingIntent (android.app.PendingIntent)2 ComponentName (android.content.ComponentName)2 Intent (android.content.Intent)2 TargetApi (android.annotation.TargetApi)1 Notification (android.app.Notification)1 JBlock (com.helger.jcodemodel.JBlock)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JMethod (com.helger.jcodemodel.JMethod)1 Date (java.util.Date)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 UiThreadExecutor (org.androidannotations.api.UiThreadExecutor)1