+
+ /**
+ * Create the preference for allow adding new accounts
+ */
+ private void createAddAccountPreference() {
+ Preference addAccountPref = new Preference(this);
+ addAccountPref.setKey("add_account");
+ addAccountPref.setTitle(getString(R.string.prefs_add_account));
+ mAccountsPrefCategory.addPreference(addAccountPref);
+
+ addAccountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ AccountManager am = AccountManager.get(getApplicationContext());
+ am.addAccount(MainApp.getAccountType(), null, null, null, Preferences.this, null, null);
+ return true;
+ }
+ });
+
+ }
+
+ /**
+ * Update the upload path checking that it is a correct path
+ * @param uploadPath: path write by user
+ * @return String: uploadPath
+ */
+ private String updateInstantUploadPath(String uploadPath) {
+ String slashString = "/";
+
+ // If slashes are duplicated, replace them for only one slash
+ uploadPath = uploadPath.replaceAll("/+", slashString);
+
+ // Remove last slash from path
+ if (uploadPath.length() > 0 && uploadPath.charAt(uploadPath.length()-1) == slashString.charAt(0)) {
+ uploadPath = uploadPath.substring(0, uploadPath.length()-1);
+ }
+
+ if (uploadPath.isEmpty()) { // Set default instant upload path
+ uploadPath = getString(R.string.instant_upload_path);
+ }else {
+ if (!uploadPath.startsWith(slashString)) { // Add initial slash on path if necessary
+ uploadPath = slashString.concat(uploadPath);
+ }
+ }
+ return uploadPath;
+ }
+
+ /**
+ * Load upload path set on preferences
+ */
+ private void loadInstantUploadPath() {
+ SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ mUploadPath = appPrefs.getString("instant_upload_path", getString(R.string.instant_upload_path));
+ }
+
+ /**
+ * Save the "Instant Upload Path" on preferences
+ */
+ private void saveInstantUploadPathOnPreferences() {
+ SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ SharedPreferences.Editor editor = appPrefs.edit();
+ editor.putString("instant_upload_path", mUploadPath);
+ editor.commit();
+ }