Exemplo n.º 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);
  }
Exemplo n.º 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();
  }
Exemplo n.º 3
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);
  }