示例#1
0
  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);
  }
示例#2
0
  /** @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();
  }
示例#3
0
  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));
    }
  }
示例#4
0
 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());
   }
 }
示例#5
0
  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));
  }
示例#6
0
  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);
  }
示例#7
0
 private long getContactId(Contact c) {
   if (Preferences.isContactLinkCloudStorageEnabled()) return getContactIdFromCloud(c);
   else return getContactIdFromLocalStorage(c);
 }