/** 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"))); }
/** Gets user preferences, populates the AppSettings class. */ public static void PopulateAppSettings(Context context) { tracer.info("Getting preferences"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 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>(); listeners.add("gps"); listeners.add("network"); listeners.add("passive"); 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); } if (AppSettings.shouldUseImperial()) { AppSettings.setMinimumDistanceInMeters( Utilities.FeetToMeters(AppSettings.getMinimumDistanceInMeters())); AppSettings.setMinimumAccuracyInMeters( Utilities.FeetToMeters(AppSettings.getMinimumAccuracyInMeters())); } 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")); } else /* new log with each start */ { AppSettings.setNewFileOnceADay(false); AppSettings.setCustomFile(false); } AppSettings.setAutoSendEnabled(prefs.getBoolean("autosend_enabled", false)); AppSettings.setAutoEmailEnabled(prefs.getBoolean("autoemail_enabled", false)); if (Float.valueOf(prefs.getString("autosend_frequency", "0")) >= 8f) { SharedPreferences.Editor editor = prefs.edit(); editor.putString("autosend_frequency", "8"); editor.commit(); } AppSettings.setAutoSendDelay(Float.valueOf(prefs.getString("autosend_frequency", "0"))); 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.setOpenGTSEnabled(prefs.getBoolean("opengts_enabled", false)); AppSettings.setAutoOpenGTSEnabled(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.setAutoFtpEnabled(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.setGpsLoggerFolder( prefs.getString( "gpslogger_folder", Environment.getExternalStorageDirectory() + "/GPSLogger")); AppSettings.setFileNamePrefixSerial(prefs.getBoolean("new_file_prefix_serial", false)); String absoluteTimeoutString = prefs.getString("absolute_timeout", "0"); if (absoluteTimeoutString != null && absoluteTimeoutString.length() > 0) { AppSettings.setAbsoluteTimeout(Integer.valueOf(absoluteTimeoutString)); } else { AppSettings.setAbsoluteTimeout(0); } }