Browse Source

Show the user-entered values in server, RSS and search site settings. Fixes #32.

pull/148/merge
Eric Kok 11 years ago
parent
commit
7f91d250be
  1. 3
      core/res/xml/pref_server.xml
  2. 37
      core/src/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java
  3. 2
      core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java

3
core/res/xml/pref_server.xml

@ -78,8 +78,7 @@
android:key="server_timeout" android:key="server_timeout"
android:title="@string/pref_timeout" android:title="@string/pref_timeout"
android:summary="@string/pref_timeout_info" android:summary="@string/pref_timeout_info"
android:inputType="numberSigned" android:inputType="numberSigned" />
android:defaultValue="8" />
<CheckBoxPreference <CheckBoxPreference
android:key="server_sslenabled" android:key="server_sslenabled"
android:title="@string/pref_sslenable" android:title="@string/pref_sslenable"

37
core/src/org/transdroid/core/gui/settings/KeyBoundPreferencesActivity.java

@ -16,6 +16,9 @@
*/ */
package org.transdroid.core.gui.settings; package org.transdroid.core.gui.settings;
import java.util.HashMap;
import java.util.Map;
import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.Extra;
@ -24,8 +27,10 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.text.method.PasswordTransformationMethod;
import com.actionbarsherlock.app.SherlockPreferenceActivity; import com.actionbarsherlock.app.SherlockPreferenceActivity;
@ -45,6 +50,7 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi
protected int key = -1; protected int key = -1;
private SharedPreferences sharedPrefs; private SharedPreferences sharedPrefs;
private Map<String, String> originalSummaries = new HashMap<String, String>();
/** /**
* Should be called during the activity {@link #onCreate(android.os.Bundle)} (but after super.onCreate(Bundle)) to * Should be called during the activity {@link #onCreate(android.os.Bundle)} (but after super.onCreate(Bundle)) to
@ -85,6 +91,7 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi
private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() { private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
showValueOnSummary(key);
onPreferencesChanged(); onPreferencesChanged();
} }
}; };
@ -131,9 +138,12 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi
// Update the loaded Preference with the actual preference key to load/store with // Update the loaded Preference with the actual preference key to load/store with
EditTextPreference pref = (EditTextPreference) findPreference(baseName); EditTextPreference pref = (EditTextPreference) findPreference(baseName);
pref.setKey(baseName + "_" + key); pref.setKey(baseName + "_" + key);
pref.setDependency(dependency == null? null: dependency + "_" + key); pref.setDependency(dependency == null ? null : dependency + "_" + key);
// Update the Preference by loading the current stored value into the EditText, if it exists // Update the Preference by loading the current stored value into the EditText, if it exists
pref.setText(sharedPrefs.getString(baseName + "_" + key, defValue)); pref.setText(sharedPrefs.getString(baseName + "_" + key, defValue));
// Remember the original descriptive summary and if we have a value, show that instead
originalSummaries.put(baseName + "_" + key, pref.getSummary() == null ? null : pref.getSummary().toString());
showValueOnSummary(baseName + "_" + key);
return pref; return pref;
} }
@ -171,7 +181,7 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi
// Update the loaded Preference with the actual preference key to load/store with // Update the loaded Preference with the actual preference key to load/store with
CheckBoxPreference pref = (CheckBoxPreference) findPreference(baseName); CheckBoxPreference pref = (CheckBoxPreference) findPreference(baseName);
pref.setKey(baseName + "_" + key); pref.setKey(baseName + "_" + key);
pref.setDependency(dependency == null? null: dependency + "_" + key); pref.setDependency(dependency == null ? null : dependency + "_" + key);
// Update the Preference by loading the current stored value into the Checkbox, if it exists // Update the Preference by loading the current stored value into the Checkbox, if it exists
pref.setChecked(sharedPrefs.getBoolean(baseName + "_" + key, defValue)); pref.setChecked(sharedPrefs.getBoolean(baseName + "_" + key, defValue));
return pref; return pref;
@ -201,7 +211,30 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi
pref.setKey(baseName + "_" + key); pref.setKey(baseName + "_" + key);
// Update the Preference by selecting the current stored value in the list, if it exists // Update the Preference by selecting the current stored value in the list, if it exists
pref.setValue(sharedPrefs.getString(baseName + "_" + key, defValue)); pref.setValue(sharedPrefs.getString(baseName + "_" + key, defValue));
// Remember the original descriptive summary and if we have a value, show that instead
originalSummaries.put(baseName + "_" + key, pref.getSummary() == null ? null : pref.getSummary().toString());
showValueOnSummary(baseName + "_" + key);
return pref; return pref;
} }
@SuppressWarnings("deprecation")
protected void showValueOnSummary(String prefKey) {
Preference pref = findPreference(prefKey);
if (sharedPrefs.contains(prefKey)
&& pref instanceof EditTextPreference
&& !(((EditTextPreference) pref).getEditText().getTransformationMethod() instanceof PasswordTransformationMethod)) {
// Non-password edit preferences show the user-entered value
pref.setSummary(sharedPrefs.getString(prefKey, ""));
return;
} else if (sharedPrefs.contains(prefKey) && pref instanceof ListPreference
&& ((ListPreference) pref).getValue() != null) {
// List preferences show the selected list value
ListPreference listPreference = (ListPreference) pref;
pref.setSummary(listPreference.getEntries()[listPreference.findIndexOfValue(listPreference.getValue())]);
return;
}
if (originalSummaries.containsKey(prefKey))
pref.setSummary(originalSummaries.get(prefKey));
}
} }

2
core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -61,7 +61,7 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity {
initTextPreference("server_localaddress"); initTextPreference("server_localaddress");
initTextPreference("server_localport"); initTextPreference("server_localport");
folder = initTextPreference("server_folder"); folder = initTextPreference("server_folder");
initTextPreference("server_timeout", "8"); initTextPreference("server_timeout");
initBooleanPreference("server_alarmfinished", true); initBooleanPreference("server_alarmfinished", true);
initBooleanPreference("server_alarmnew"); initBooleanPreference("server_alarmnew");
initListPreference("server_os", "type_linux"); initListPreference("server_os", "type_linux");

Loading…
Cancel
Save