public boolean onPreferenceChange(Preference preference, Object newValue) { String path = (String) newValue; if(!UploaderSink.validatePath(path)) { String error = "Invalid target URL \"" + path + "\" -- must be an absolute URL " + "with http:// prefix"; Toast.makeText(getApplicationContext(), error, Toast.LENGTH_SHORT).show(); Log.w(TAG, error); mUploadingPreference.setChecked(false); } updateSummary(preference, newValue); return true; } };
private void setUploadingStatus(boolean enabled) { Log.i(TAG, "Setting uploading to " + enabled); if(enabled) { String path = getPreferenceString(R.string.uploading_path_key); if(!UploaderSink.validatePath(path)) { String error = "Target URL in preferences not valid " + "-- not starting uploading a trace"; Log.w(TAG, error); SharedPreferences.Editor editor = getPreferences().edit(); editor.putBoolean(getString(R.string.uploading_checkbox_key), false); editor.commit(); } else { if(mUploader != null) { stopUploading(); } try { mUploader = new UploaderSink(getContext(), path); } catch(DataSinkException e) { Log.w(TAG, "Unable to add uploader sink", e); return; } getVehicleManager().addSink(mUploader); } } else { stopUploading(); } }