public void updateNotification() { if (!Preferences.isNotificationEnabled() || !playServicesAvailable) return; String title = null; String subtitle = null; long time = 0; if ((this.lastPublishedLocation != null) && Preferences.isNotificationLocationEnabled()) { time = this.lastPublishedLocationTime.getTime(); if ((this.lastPublishedLocation.getGeocoder() != null) && Preferences.isNotificationGeocoderEnabled()) { title = this.lastPublishedLocation.toString(); } else { title = this.lastPublishedLocation.toLatLonString(); } } else { title = this.context.getString(R.string.app_name); } subtitle = ServiceLocator.getStateAsString(this.context) + " | " + ServiceBroker.getStateAsString(this.context); notificationBuilder.setContentTitle(title); notificationBuilder .setSmallIcon(R.drawable.ic_notification) .setContentText(subtitle) .setPriority(android.support.v4.app.NotificationCompat.PRIORITY_MIN); if (time != 0) notificationBuilder.setWhen(this.lastPublishedLocationTime.getTime()); this.notification = notificationBuilder.build(); this.context.startForeground(Defaults.NOTIFCATION_ID, this.notification); }
/** @category NOTIFICATION HANDLING */ private void handleNotification() { Log.v(this.toString(), "handleNotification()"); this.context.stopForeground(true); if (this.notificationManager != null) this.notificationManager.cancelAll(); if (Preferences.isNotificationEnabled() || !playServicesAvailable) createNotification(); }
public void onEvent(Events.PublishSuccessfull e) { Log.v(this.toString(), "Publish successful"); if ((e.getExtra() != null) && (e.getExtra() instanceof LocationMessage)) { LocationMessage l = (LocationMessage) e.getExtra(); this.lastPublishedLocation = l.getLocation(); this.lastPublishedLocationTime = l.getLocation().getDate(); if (Preferences.isNotificationGeocoderEnabled() && (l.getLocation().getGeocoder() == null)) (new ReverseGeocodingTask(this.context, this.handler)) .execute(new GeocodableLocation[] {l.getLocation()}); updateNotification(); if (Preferences.notificationTickerOnPublish() && !l.doesSupressTicker()) updateTicker(this.context.getString(R.string.statePublished)); } }
public void onEvent(Events.WaypointTransition e) { if (Preferences.notificationOnGeofenceTransition()) { if (e.getTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) updateTicker( this.context.getString(R.string.transitionEntering) + " " + e.getWaypoint().getDescription()); else updateTicker( this.context.getString(R.string.transitionLeaving) + " " + e.getWaypoint().getDescription()); } }
public void linkContact(Contact c, long contactId) { if (Preferences.isContactLinkCloudStorageEnabled()) { Log.e(this.toString(), "Saving a ContactLink to the cloud is not yet supported"); return; } Log.v( this.toString(), "Creating ContactLink from " + c.getTopic() + " to contactId " + contactId); ContactLink cl = new ContactLink(c.getTopic(), contactId); App.getContactLinkDao().insertOrReplace(cl); updateContact(c); EventBus.getDefault().postSticky(new Events.ContactUpdated(c)); }
public void updateTicker(String text) { Log.v(this.toString(), "Updating ticker with " + text); notificationBuilder.setTicker(text + ((this.even = this.even ? false : true) ? " " : "")); notificationBuilder.setSmallIcon(R.drawable.ic_notification); this.notificationManager.notify(Defaults.NOTIFCATION_ID, notificationBuilder.build()); // Clear ticker notificationBuilder.setTicker(null); this.notificationManager.notify(Defaults.NOTIFCATION_ID, notificationBuilder.build()); // if the notification is not enabled, the ticker will create an empty // one that we get rid of if (!Preferences.isNotificationEnabled()) this.notificationManager.cancel(Defaults.NOTIFCATION_ID); }
private long getContactId(Contact c) { if (Preferences.isContactLinkCloudStorageEnabled()) return getContactIdFromCloud(c); else return getContactIdFromLocalStorage(c); }