Beispiel #1
0
  private void uploadWiperStatus(
      Latitude latitude, Longitude longitude, final WindshieldWiperStatus wiperStatus) {
    double latitudeValue;
    double longitudeValue;
    boolean wiperStatusValue;
    latitudeValue = latitude.getValue().doubleValue();
    longitudeValue = longitude.getValue().doubleValue();
    wiperStatusValue = wiperStatus.getValue().booleanValue();

    if (!wiperStatusValue) {
      Log.d(TAG, "Wipers are off -- not uploading");
      return;
    }

    StringBuilder uriBuilder = new StringBuilder(WUNDERGROUND_URL);
    // TODO need to update API to accept boolean instead of speed
    int wiperSpeed = 0;
    if (wiperStatusValue) {
      wiperSpeed = 1;
    }
    uriBuilder.append("?wiperspd=" + wiperSpeed);
    uriBuilder.append("&lat=" + latitudeValue);
    uriBuilder.append("&lon=" + longitudeValue);
    final String finalUri = uriBuilder.toString();

    new Thread(
            new Runnable() {
              public void run() {
                final HttpClient client = new DefaultHttpClient();
                HttpGet request = new HttpGet(finalUri);
                try {
                  HttpResponse response = client.execute(request);
                  final int statusCode = response.getStatusLine().getStatusCode();
                  if (statusCode != HttpStatus.SC_OK) {
                    Log.w(TAG, "Error " + statusCode + " while uploading wiper status");
                  } else {
                    Log.d(TAG, "Wiper status (" + wiperStatus + ") uploaded " + "successfully");
                  }
                } catch (IOException e) {
                  Log.w(TAG, "Error while uploading wiper status", e);
                }
              }
            })
        .start();
  }