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());
}
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();
}
}
}
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() + ")");
}
}
}
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();
}
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()));
}
}
}
Aggregations