예제 #1
0
  public static byte[] GetByteArrayFromInputStream(InputStream is) {

    try {
      int length;
      int size = 1024;
      byte[] buffer;

      if (is instanceof ByteArrayInputStream) {
        size = is.available();
        buffer = new byte[size];
        is.read(buffer, 0, size);
      } else {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        buffer = new byte[size];
        while ((length = is.read(buffer, 0, size)) != -1) {
          outputStream.write(buffer, 0, length);
        }

        buffer = outputStream.toByteArray();
      }
      return buffer;
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        is.close();
      } catch (Exception e) {
        tracer.warn(
            SessionLogcatAppender.MARKER_INTERNAL,
            "GetStringFromInputStream - could not close stream");
      }
    }

    return null;
  }
예제 #2
0
  /**
   * Loops through an input stream and converts it into a string, then closes the input stream
   *
   * @param is
   * @return
   */
  public static String GetStringFromInputStream(InputStream is) {
    String line;
    StringBuilder total = new StringBuilder();

    // Wrap a BufferedReader around the InputStream
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));

    // Read response until the end
    try {
      while ((line = rd.readLine()) != null) {
        total.append(line);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        is.close();
      } catch (Exception e) {
        tracer.warn(
            SessionLogcatAppender.MARKER_INTERNAL,
            "GetStringFromInputStream - could not close stream");
      }
    }

    // Return full string
    return total.toString();
  }
예제 #3
0
  /** Gets user preferences, populates the AppSettings class. */
  public static void PopulateAppSettings(Context context) {

    tracer.debug("Getting preferences");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    AppSettings.setHideNotificationButtons(prefs.getBoolean("hide_notification_buttons", false));

    AppSettings.setUseImperial(prefs.getBoolean("useImperial", false));

    AppSettings.setLogToKml(prefs.getBoolean("log_kml", false));

    AppSettings.setLogToGpx(prefs.getBoolean("log_gpx", true));

    AppSettings.setLogToPlainText(prefs.getBoolean("log_plain_text", false));

    AppSettings.setLogToNmea(prefs.getBoolean("log_nmea", false));

    AppSettings.setLogToCustomUrl(prefs.getBoolean("log_customurl_enabled", false));
    AppSettings.setCustomLoggingUrl(prefs.getString("log_customurl_url", ""));

    AppSettings.setLogToOpenGts(prefs.getBoolean("log_opengts", false));

    Set<String> listeners = new HashSet<String>(GetListeners());
    AppSettings.setChosenListeners(prefs.getStringSet("listeners", listeners));

    String minimumDistanceString = prefs.getString("distance_before_logging", "0");

    if (minimumDistanceString != null && minimumDistanceString.length() > 0) {
      AppSettings.setMinimumDistanceInMeters(Integer.valueOf(minimumDistanceString));
    } else {
      AppSettings.setMinimumDistanceInMeters(0);
    }

    String minimumAccuracyString = prefs.getString("accuracy_before_logging", "0");

    if (minimumAccuracyString != null && minimumAccuracyString.length() > 0) {
      AppSettings.setMinimumAccuracyInMeters(Integer.valueOf(minimumAccuracyString));
    } else {
      AppSettings.setMinimumAccuracyInMeters(0);
    }

    String minimumSecondsString = prefs.getString("time_before_logging", "60");

    if (minimumSecondsString != null && minimumSecondsString.length() > 0) {
      AppSettings.setMinimumSeconds(Integer.valueOf(minimumSecondsString));
    } else {
      AppSettings.setMinimumSeconds(60);
    }

    AppSettings.setKeepFix(prefs.getBoolean("keep_fix", false));

    String retryIntervalString = prefs.getString("retry_time", "60");

    if (retryIntervalString != null && retryIntervalString.length() > 0) {
      AppSettings.setRetryInterval(Integer.valueOf(retryIntervalString));
    } else {
      AppSettings.setRetryInterval(60);
    }

    /**
     * New file creation preference: onceaday, custom file (static), every time the service starts
     */
    AppSettings.setNewFileCreation(prefs.getString("new_file_creation", "onceaday"));

    if (AppSettings.getNewFileCreation().equals("onceaday")) {
      AppSettings.setNewFileOnceADay(true);
      AppSettings.setCustomFile(false);
    } else if (AppSettings.getNewFileCreation().equals("custom")
        || AppSettings.getNewFileCreation().equals("static")) {
      AppSettings.setCustomFile(true);
      AppSettings.setCustomFileName(prefs.getString("new_file_custom_name", "gpslogger"));
      AppSettings.setAskCustomFileNameEachTime(prefs.getBoolean("new_file_custom_each_time", true));
    } else /* new log with each start */ {
      AppSettings.setNewFileOnceADay(false);
      AppSettings.setCustomFile(false);
    }

    AppSettings.setAutoSendEnabled(prefs.getBoolean("autosend_enabled", false));

    AppSettings.setEmailAutoSendEnabled(prefs.getBoolean("autoemail_enabled", false));

    try {
      AppSettings.setAutoSendDelay(
          Float.valueOf(prefs.getString("autosend_frequency_minutes", "60")));
    } catch (Exception e) {
      AppSettings.setAutoSendDelay(60f);
    }

    AppSettings.setAutoSendWhenIPressStop(
        prefs.getBoolean("autosend_frequency_whenstoppressed", false));

    AppSettings.setSmtpServer(prefs.getString("smtp_server", ""));
    AppSettings.setSmtpPort(prefs.getString("smtp_port", "25"));
    AppSettings.setSmtpSsl(prefs.getBoolean("smtp_ssl", true));
    AppSettings.setSmtpUsername(prefs.getString("smtp_username", ""));
    AppSettings.setSmtpPassword(prefs.getString("smtp_password", ""));
    AppSettings.setAutoEmailTargets(prefs.getString("autoemail_target", ""));
    AppSettings.setDebugToFile(prefs.getBoolean("debugtofile", false));
    AppSettings.setShouldSendZipFile(prefs.getBoolean("autosend_sendzip", true));
    AppSettings.setSmtpFrom(prefs.getString("smtp_from", ""));
    AppSettings.setOpenGtsAutoSendEnabled(prefs.getBoolean("autoopengts_enabled", false));
    AppSettings.setOpenGTSServer(prefs.getString("opengts_server", ""));
    AppSettings.setOpenGTSServerPort(prefs.getString("opengts_server_port", ""));
    AppSettings.setOpenGTSServerCommunicationMethod(
        prefs.getString("opengts_server_communication_method", ""));
    AppSettings.setOpenGTSServerPath(prefs.getString("autoopengts_server_path", ""));
    AppSettings.setOpenGTSDeviceId(prefs.getString("opengts_device_id", ""));
    AppSettings.setOpenGTSAccountName(prefs.getString("opengts_accountname", ""));

    AppSettings.setGDocsAutoSendEnabled(prefs.getBoolean("gdocs_enabled", false));
    AppSettings.setDropboxAutoSendEnabled(prefs.getBoolean("dropbox_enabled", false));
    AppSettings.setOsmAutoSendEnabled(prefs.getBoolean("osm_enabled", false));

    AppSettings.setFtpAutoSendEnabled(prefs.getBoolean("autoftp_enabled", false));
    AppSettings.setFtpServerName(prefs.getString("autoftp_server", ""));
    AppSettings.setFtpUsername(prefs.getString("autoftp_username", ""));
    AppSettings.setFtpPassword(prefs.getString("autoftp_password", ""));
    AppSettings.setFtpDirectory(prefs.getString("autoftp_directory", "GPSLogger"));
    AppSettings.setFtpPort(Integer.valueOf(prefs.getString("autoftp_port", "21")));
    AppSettings.setFtpUseFtps(prefs.getBoolean("autoftp_useftps", false));
    AppSettings.setFtpProtocol(prefs.getString("autoftp_ssltls", ""));
    AppSettings.setFtpImplicit(prefs.getBoolean("autoftp_implicit", false));

    AppSettings.setOwnCloudAutoSendEnabled(prefs.getBoolean("owncloud_enabled", false));
    AppSettings.setOwnCloudServerName(prefs.getString("owncloud_server", ""));
    AppSettings.setOwnCloudUsername(prefs.getString("owncloud_username", ""));
    AppSettings.setOwnCloudPassword(prefs.getString("owncloud_password", ""));
    AppSettings.setOwnCloudDirectory(prefs.getString("owncloud_directory", "/gpslogger"));

    AppSettings.setGpsLoggerFolder(
        prefs.getString(
            "gpslogger_folder", Utilities.GetDefaultStorageFolder(context).getAbsolutePath()));
    AppSettings.setFileNamePrefixSerial(prefs.getBoolean("new_file_prefix_serial", false));

    String absoluteTimeoutString = prefs.getString("absolute_timeout", "120");

    if (absoluteTimeoutString != null && absoluteTimeoutString.length() > 0) {
      AppSettings.setAbsoluteTimeout(Integer.valueOf(absoluteTimeoutString));
    } else {
      AppSettings.setAbsoluteTimeout(120);
    }

    AppSettings.setGoogleDriveFolderName(
        prefs.getString("gdocs_foldername", "GPSLogger for Android"));

    AppSettings.setShouldNotLogIfUserIsStill(
        prefs.getBoolean("activityrecognition_dontlogifstill", false));

    AppSettings.setAdjustAltitudeFromGeoIdHeight(
        prefs.getBoolean("altitude_subtractgeoidheight", false));
    AppSettings.setSubtractAltitudeOffset(
        Integer.valueOf(prefs.getString("altitude_subtractoffset", "0")));
  }