/**
   * Parse and record tracking information. Uses known structure of tracking information fragment to
   * get the information, recording the agent information directly and returning the tracking
   * information as a whole.
   *
   * @return tracking information
   * @throws IOException if error reading document
   * @throws XmlPullParserException if parse error
   */
  protected TrackingData parseTracking() throws IOException, XmlPullParserException {

    // read id attribute from root element start tag
    TrackingData data = new TrackingData();
    parseStartTag(TRACKING_ELEMENT_NAME);
    data.m_id = attributeValue(ID_ATTRIBUTE_NAME);

    // read time as content of its own element
    data.m_time = parseElementContent(TIME_ELEMENT_NAME);

    // read seller agent information
    parseStartTag(SELLER_ELEMENT_NAME);
    data.m_seller = attributeValue(IDENT_ATTRIBUTE_NAME);
    data.m_isDirectSeller = "direct".equals(attributeValue(TYPE_ATTRIBUTE_NAME));
    parseEndTag(SELLER_ELEMENT_NAME);

    // read buyer agent information
    parseStartTag(BUYER_ELEMENT_NAME);
    data.m_buyer = attributeValue(IDENT_ATTRIBUTE_NAME);
    data.m_isDirectBuyer = "direct".equals(attributeValue(TYPE_ATTRIBUTE_NAME));
    parseEndTag(BUYER_ELEMENT_NAME);

    // read exchange identifier as content of its own element
    data.m_exchange = parseElementContent(EXCHANGE_ELEMENT_NAME);

    // finish with closing tag for root element
    parseEndTag(TRACKING_ELEMENT_NAME);

    // record agent information before returning
    AgentTrack.recordAgent(data.m_buyer, !data.m_isDirectBuyer, false);
    AgentTrack.recordAgent(data.m_seller, !data.m_isDirectSeller, true);
    return data;
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      TwoLineListItem twoLineListItem;

      if (convertView == null) {
        LayoutInflater inflater =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        twoLineListItem =
            (TwoLineListItem) inflater.inflate(android.R.layout.simple_list_item_2, null);
        twoLineListItem.getText1().setTextSize(14);
        twoLineListItem.getText2().setTextSize(12);
      } else {
        twoLineListItem = (TwoLineListItem) convertView;
      }

      TextView text1 = twoLineListItem.getText1();
      TextView text2 = twoLineListItem.getText2();

      TrackingData td = (TrackingData) getItem(position);
      text1.setText(td.toMain());
      text2.setText(td.toSub());

      return twoLineListItem;
    }
Ejemplo n.º 3
0
  public static void loadTrackings(Calendar c) {
    trackings.clear();

    File file = new File(getTrackingFile(c));
    if (!file.exists()) {
      log.warn(file + "does not exist");
      return;
    }

    log.info("Loading " + file);

    float[] results = new float[1];
    LineIterator li = null;
    try {
      li = Files.lineIterator(file);
      while (li.hasNext()) {
        String line = li.next();
        if (Strings.isEmpty(line)) {
          continue;
        }

        TrackingData td = Jsons.fromJson(line, TrackingData.class);
        TrackingData ltd = getLastLocation();
        if (ltd != null) {
          Location.distanceBetween(
              ltd.getLatitude(), ltd.getLongitude(), td.getLatitude(), td.getLongitude(), results);
          td.setDistance(results[0]);
          td.setSpeed(td.getDistance() / DateTimes.subSeconds(td.getDate(), ltd.getDate()));
        }
        trackings.add(td);
      }
    } catch (IOException e) {
      log.error(e);
    } finally {
      Streams.safeClose(li);
    }
  }
Ejemplo n.º 4
0
  public static boolean addLocation(Location location, Geocoder geocoder) {
    TrackingData ltd = getLastLocation();

    float distance = 0.0f;
    float speed = 0.0f;

    if (ltd != null) {
      float[] results = new float[1];
      Location.distanceBetween(
          ltd.getLatitude(),
          ltd.getLongitude(),
          location.getLatitude(),
          location.getLongitude(),
          results);

      distance = results[0];
      if (distance < 100) {
        log.debug("SKIP SAME " + location + ": " + distance);
        return false;
      }

      long delta = DateTimes.subSeconds(new Date(location.getTime()), ltd.getDate());
      // less than 30 minutes
      if (delta < 30 * 60) {
        speed = distance / delta;
        //				if (lastState == DetectedActivity.STILL) {
        //
        //				}
        // great than 120km/h
        if (speed >= 33) {
          log.debug("SKIP FAST " + location + ": " + distance);
          return false;
        }
      }
    }

    String address = "";
    try {
      List<Address> addresses =
          geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
      if (Collections.isNotEmpty(addresses)) {
        Address a = addresses.get(0);
        address = toAddress(a);
      }

      // if (ltd != null && Strings.isNotEmpty(address)) {
      // if (ltd.getAddress().equals(address)) {
      // log.debug("Skip (" + location + "): " + address);
      // return;
      // }
      // }
    } catch (Exception e) {
      // Catch network or other I/O problems.
      log.error(
          "Failed to get address of (" + location.getLatitude() + ", " + location.getLongitude(),
          e);
    }

    TrackingData td = new TrackingData();
    td.setDate(new Date(location.getTime()));
    td.setState(getBestState());
    td.setLatitude(location.getLatitude());
    td.setLongitude(location.getLongitude());
    td.setAddress(address);

    if (ltd != null) {
      float[] results = new float[1];
      Location.distanceBetween(
          ltd.getLatitude(), ltd.getLongitude(), td.getLatitude(), td.getLongitude(), results);
      td.setDistance(results[0]);
      td.setSpeed(td.getDistance() / DateTimes.subSeconds(td.getDate(), ltd.getDate()));
    }

    trackings.add(td);
    saveTrackingData(td);

    return true;
  }