Esempio n. 1
0
  public static String GetFormattedCustomFileName(String baseName) {

    Time t = new Time();
    t.setToNow();

    String finalFileName = baseName;
    finalFileName =
        finalFileName.replaceAll("(?i)%ser", String.valueOf(Utilities.GetBuildSerial()));
    finalFileName = finalFileName.replaceAll("(?i)%hour", String.valueOf(t.hour));
    finalFileName = finalFileName.replaceAll("(?i)%min", String.valueOf(t.minute));
    finalFileName = finalFileName.replaceAll("(?i)%year", String.valueOf(t.year));
    finalFileName = finalFileName.replaceAll("(?i)%month", String.valueOf(t.month + 1));
    finalFileName = finalFileName.replaceAll("(?i)%day", String.valueOf(t.monthDay));
    return finalFileName;
  }
Esempio n. 2
0
  public static void ConfigureLogbackDirectly(Context context) {
    try {
      // reset the default context (which may already have been initialized)
      // since we want to reconfigure it
      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
      lc.reset();

      // final String LOG_DIR = "/sdcard/GPSLogger";
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
      final String LOG_DIR =
          prefs.getString(
              "gpslogger_folder", Utilities.GetDefaultStorageFolder(context).getAbsolutePath());

      GpsRollingFileAppender<ILoggingEvent> rollingFileAppender =
          new GpsRollingFileAppender<ILoggingEvent>();
      rollingFileAppender.setAppend(true);
      rollingFileAppender.setContext(lc);

      // OPTIONAL: Set an active log file (separate from the rollover files).
      // If rollingPolicy.fileNamePattern already set, you don't need this.
      rollingFileAppender.setFile(LOG_DIR + "/debuglog.txt");
      rollingFileAppender.setLazy(true);

      TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy =
          new TimeBasedRollingPolicy<ILoggingEvent>();
      rollingPolicy.setFileNamePattern(LOG_DIR + "/debuglog.%d.txt");
      rollingPolicy.setMaxHistory(3);
      rollingPolicy.setParent(rollingFileAppender); // parent and context required!
      rollingPolicy.setContext(lc);
      rollingPolicy.start();

      rollingFileAppender.setRollingPolicy(rollingPolicy);

      PatternLayoutEncoder encoder = new PatternLayoutEncoder();
      encoder.setPattern("%d{HH:mm:ss} %-5p %class{0}.%method:%L - %m%n");
      encoder.setContext(lc);
      encoder.start();

      rollingFileAppender.setEncoder(encoder);
      rollingFileAppender.start();

      // setup LogcatAppender
      PatternLayoutEncoder encoder2 = new PatternLayoutEncoder();
      encoder2.setContext(lc);
      encoder2.setPattern("%method:%L - %m%n");
      encoder2.start();

      LogcatAppender logcatAppender = new LogcatAppender();
      logcatAppender.setContext(lc);
      logcatAppender.setEncoder(encoder2);
      logcatAppender.start();

      SessionLogcatAppender sessionAppender = new SessionLogcatAppender();
      sessionAppender.setContext(lc);
      sessionAppender.start();

      // add the newly created appenders to the root logger;
      // qualify Logger to disambiguate from org.slf4j.Logger
      ch.qos.logback.classic.Logger root =
          (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
      root.addAppender(rollingFileAppender);
      root.addAppender(logcatAppender);
      root.addAppender(sessionAppender);

    } catch (Exception ex) {
      System.out.println("Could not configure logging!");
    }
  }
Esempio n. 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")));
  }