Search in sources :

Example 6 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project Pokemap by omkarmoghe.

the class PokemonNotificationService method onEvent.

@Subscribe
public void onEvent(CatchablePokemonEvent event) {
    List<CatchablePokemon> catchablePokemon = event.getCatchablePokemon();
    LatLng location = locationManager.getLocation();
    Location myLoc = new Location("");
    myLoc.setLatitude(location.latitude);
    myLoc.setLongitude(location.longitude);
    builder.setContentText(getString(R.string.notification_service_pokemon_near, catchablePokemon.size()));
    builder.setStyle(null);
    if (!catchablePokemon.isEmpty()) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(getString(R.string.notification_service_pokemon_in_area, catchablePokemon.size()));
        Set<PokemonIdOuterClass.PokemonId> showablePokemonIDs = preffs.getShowablePokemonIDs();
        for (CatchablePokemon cp : catchablePokemon) {
            //Only show the notification if the Pokemon is in the preference list
            if (showablePokemonIDs.contains(cp.getPokemonId())) {
                Location pokeLocation = new Location("");
                pokeLocation.setLatitude(cp.getLatitude());
                pokeLocation.setLongitude(cp.getLongitude());
                long remainingTime = cp.getExpirationTimestampMs() - System.currentTimeMillis();
                String pokeName = PokemonIdUtils.getLocalePokemonName(getApplicationContext(), cp.getPokemonId().name());
                long remTime = TimeUnit.MILLISECONDS.toMinutes(remainingTime);
                int dist = (int) Math.ceil(pokeLocation.distanceTo(myLoc));
                inboxStyle.addLine(getString(R.string.notification_service_inbox_line, pokeName, remTime, dist));
            }
        }
        builder.setStyle(inboxStyle);
    }
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(notificationId, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) NotificationCompat(android.support.v4.app.NotificationCompat) LatLng(com.google.android.gms.maps.model.LatLng) Location(android.location.Location) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 7 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project Pokemap by omkarmoghe.

the class MapWrapperFragment method onEvent.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(MarkerUpdate event) {
    if (mSelectedMarker != null) {
        Marker marker = mSelectedMarker.getMarker();
        if (marker.isInfoWindowShown()) {
            long time = mSelectedMarker.getCatchablePokemon().getExpirationTimestampMs() - System.currentTimeMillis();
            marker.setSnippet(getExpirationBreakdown(time));
            marker.showInfoWindow();
        }
    }
}
Also used : Marker(com.google.android.gms.maps.model.Marker) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 8 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project EventBus by greenrobot.

the class EventBusAnnotationProcessor method writeCreateSubscriberMethods.

private void writeCreateSubscriberMethods(BufferedWriter writer, List<ExecutableElement> methods, String callPrefix, String myPackage) throws IOException {
    for (ExecutableElement method : methods) {
        List<? extends VariableElement> parameters = method.getParameters();
        TypeMirror paramType = getParamTypeMirror(parameters.get(0), null);
        TypeElement paramElement = (TypeElement) processingEnv.getTypeUtils().asElement(paramType);
        String methodName = method.getSimpleName().toString();
        String eventClass = getClassString(paramElement, myPackage) + ".class";
        Subscribe subscribe = method.getAnnotation(Subscribe.class);
        List<String> parts = new ArrayList<>();
        parts.add(callPrefix + "(\"" + methodName + "\",");
        String lineEnd = "),";
        if (subscribe.priority() == 0 && !subscribe.sticky()) {
            if (subscribe.threadMode() == ThreadMode.POSTING) {
                parts.add(eventClass + lineEnd);
            } else {
                parts.add(eventClass + ",");
                parts.add("ThreadMode." + subscribe.threadMode().name() + lineEnd);
            }
        } else {
            parts.add(eventClass + ",");
            parts.add("ThreadMode." + subscribe.threadMode().name() + ",");
            parts.add(subscribe.priority() + ",");
            parts.add(subscribe.sticky() + lineEnd);
        }
        writeLine(writer, 3, parts.toArray(new String[parts.size()]));
        if (verbose) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Indexed @Subscribe at " + method.getEnclosingElement().getSimpleName() + "." + methodName + "(" + paramElement.getSimpleName() + ")");
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 9 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project WordPress-Android by wordpress-mobile.

the class StatsActivity method onSiteChanged.

// FluxC events
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteChanged(OnSiteChanged event) {
    // "Reload" current site from the db, would be smarter if the OnSiteChanged provided the list of changed sites.
    SiteModel site = mSiteStore.getSiteByLocalId(mSite.getId());
    if (site != null) {
        mSite = site;
    }
    // Make sure the update site is accessible
    checkIfSiteHasAccessibleStats(mSite);
    // Refresh Stats
    refreshStatsFromCurrentDate();
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 10 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project ride-read-android by Ride-Read.

the class ProfileFragment method onRefreshMyMap.

@Subscribe(threadMode = MAIN, sticky = true)
public void onRefreshMyMap(RefreshMyMapEvent event) {
    EventBus.getDefault().removeStickyEvent(RefreshMyMapEvent.class);
    List<Moment> moments = event.mMoments;
    if (!ListUtils.isEmpty(moments)) {
        mAMap.clear();
        for (Moment momentItem : moments) {
            addSignInMarker(new LatLng(momentItem.getLatitude(), momentItem.getLongitude()));
        }
    }
}
Also used : Moment(com.rideread.rideread.data.result.Moment) LatLng(com.amap.api.maps.model.LatLng) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

Subscribe (org.greenrobot.eventbus.Subscribe)43 Intent (android.content.Intent)7 SiteModel (org.wordpress.android.fluxc.model.SiteModel)5 NotificationManager (android.app.NotificationManager)3 NotificationCompat (android.support.v4.app.NotificationCompat)3 Activity (android.app.Activity)2 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 AspectPermission (com.yydcdut.note.aspect.permission.AspectPermission)2 CategoryCreateEvent (com.yydcdut.note.bus.CategoryCreateEvent)2 CategoryDeleteEvent (com.yydcdut.note.bus.CategoryDeleteEvent)2 CategoryEditEvent (com.yydcdut.note.bus.CategoryEditEvent)2 CategoryMoveEvent (com.yydcdut.note.bus.CategoryMoveEvent)2 CategoryUpdateEvent (com.yydcdut.note.bus.CategoryUpdateEvent)2 PhotoNoteCreateEvent (com.yydcdut.note.bus.PhotoNoteCreateEvent)2 PhotoNoteDeleteEvent (com.yydcdut.note.bus.PhotoNoteDeleteEvent)2 UserImageEvent (com.yydcdut.note.bus.UserImageEvent)2 Category (com.yydcdut.note.entity.Category)2 ContextLife (com.yydcdut.note.injector.ContextLife)2