@Override
  public void bestLocationChanged(Location oldLocation, Location newLocation) {
    long currentTime = System.currentTimeMillis();

    LocationController cont = LocationController.getInstance(this.context);

    Log.d("HistoryController", "Best location updated! (hasGPSLock: " + cont.hasGPSLock() + ")");

    if (cont.hasGPSLock()) {
      if (stationaryLocationStart == null) {
        stationaryLocationStart = newLocation;
        stationaryLocationEnd = newLocation;
        stationaryLocationStartTime = currentTime;
      } else {
        Log.d(
            "HistoryController",
            "Distance from stationary point: " + stationaryLocationStart.distanceTo(newLocation));

        if (stationaryLocationStart.distanceTo(newLocation) < STATIONARY_RADIUS) {
          Log.d("HistoryController", "New location was within radius");

          stationaryLocationEnd = newLocation;
        } else {
          Log.d(
              "HistoryController",
              "New location out of radius (time delta: "
                  + (currentTime - stationaryLocationStartTime)
                  + ")");

          if (currentTime - stationaryLocationStartTime > STATIONARY_TIME) {
            Log.d(
                "HistoryController",
                "Stayed in previous location long enough, recording to history");

            HistoryItem item = new HistoryItem();
            item.date = stationaryLocationStartTime;
            item.elapsed_time = currentTime - stationaryLocationStartTime;
            item.latitude = stationaryLocationStart.getLatitude();
            item.longitude = stationaryLocationStart.getLongitude();

            historyStorage.put(item);

            //
            // Notify listeners
            //

            synchronized (this) {
              for (HistoryListener l : this.listeners) l.onNewHistoryItem(item);
            }
          }

          stationaryLocationStart = newLocation;
          stationaryLocationEnd = newLocation;
          stationaryLocationStartTime = currentTime;
        }
      }
    }
  }
Exemplo n.º 2
0
  @Override
  public void locationUpdate(Location update, boolean initial) {
    if (LocationController.isBetterLocation(update, mLastLocation)) {
      mLastLocation = update;
    }

    Log.d("Location SERVICE", "Location Update:" + update.toString());
    if (!initial) {
      mUpdateController.update(update);
      passiveLocationController.stop();
    }
  }
Exemplo n.º 3
0
  @Override
  public void onLocationUpdate(Map<String, User> reply) {
    NotificationManager mNotificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder myBuilder = new NotificationUtil().prepareBuilder(mContext);
    myBuilder.setNumber(reply.size());
    // mId allows you to update the notification later on.
    mNotificationManager.notify(NotificationUtil.NOTIFICATION_ID, myBuilder.build());

    for (User user : reply.values()) {
      passiveLocationController.addProximityAlert(user);
    }
  }
 public void stopRecording() {
   LocationController cont = LocationController.getInstance(this.context);
   cont.stopListening();
   cont.removeBestLocationListener(this);
 }
 public void startRecording() {
   LocationController cont = LocationController.getInstance(this.context);
   cont.startListening(90000, STATIONARY_RADIUS);
   cont.addBestLocationListener(this);
 }