diff --git a/app/src/main/java/io/syng/activity/SettingsActivity.java b/app/src/main/java/io/syng/activity/SettingsActivity.java index 0144e85..56b2d4f 100644 --- a/app/src/main/java/io/syng/activity/SettingsActivity.java +++ b/app/src/main/java/io/syng/activity/SettingsActivity.java @@ -38,9 +38,8 @@ public class SettingsActivity extends PreferenceActivity { @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); setupSimplePreferencesScreen(); } @@ -59,7 +58,8 @@ public class SettingsActivity extends PreferenceActivity { // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); - bindPreferenceSummaryToValue(findPreference("runningMode")); + bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_json_rpc_server_key))); + bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_running_mode_key))); /* // Add 'notifications' preferences, and a corresponding header. PreferenceCategory fakeHeader = new PreferenceCategory(this); @@ -83,6 +83,45 @@ public class SettingsActivity extends PreferenceActivity { */ } + private void bindPreferenceSummaryToValue(Preference preference) { + // Set the listener to watch for value changes. + preference.setOnPreferenceChangeListener(mBindPreferenceSummaryToValueListener); + + // Trigger the listener immediately with the preference's + // current value. + mBindPreferenceSummaryToValueListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.getContext()) + .getString(preference.getKey(), "")); + } + + private Preference.OnPreferenceChangeListener mBindPreferenceSummaryToValueListener = + new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object value) { + String stringValue = value.toString(); + String key = preference.getKey(); + + if (preference instanceof ListPreference) { + // For list preferences, look up the correct display value in + // the preference's 'entries' list. + ListPreference listPreference = (ListPreference) preference; + int index = listPreference.findIndexOfValue(stringValue); + + // Set the summary to reflect the new value. + preference.setSummary( + index >= 0 + ? listPreference.getEntries()[index] + : null); + } else if (key.equals(getString(R.string.pref_json_rpc_server_key))) { + preference.setSummary("Current server address is " + stringValue); + } else { + preference.setSummary(stringValue); + } + return true; + } + }; + /** * {@inheritDoc} */ @@ -126,30 +165,7 @@ public class SettingsActivity extends PreferenceActivity { * A preference value change listener that updates the preference's summary * to reflect its new value. */ - private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object value) { - String stringValue = value.toString(); - if (preference instanceof ListPreference) { - // For list preferences, look up the correct display value in - // the preference's 'entries' list. - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); - - // Set the summary to reflect the new value. - preference.setSummary( - index >= 0 - ? listPreference.getEntries()[index] - : null); - } else { - // For all other preferences, set the summary to the value's - // simple string representation. - preference.setSummary(stringValue); - } - return true; - } - }; /** * Binds a preference's summary to its value. More specifically, when the @@ -158,19 +174,9 @@ public class SettingsActivity extends PreferenceActivity { * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * - * @see #sBindPreferenceSummaryToValueListener + * @see #mBindPreferenceSummaryToValueListener */ - private static void bindPreferenceSummaryToValue(Preference preference) { - // Set the listener to watch for value changes. - preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); - // Trigger the listener immediately with the preference's - // current value. - sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } // /** // * This fragment shows general preferences only. It is used when the diff --git a/app/src/main/java/io/syng/util/PrefsUtil.java b/app/src/main/java/io/syng/util/PrefsUtil.java index 4a07555..f97d5db 100644 --- a/app/src/main/java/io/syng/util/PrefsUtil.java +++ b/app/src/main/java/io/syng/util/PrefsUtil.java @@ -3,7 +3,9 @@ package io.syng.util; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.preference.PreferenceManager; import android.support.annotation.DrawableRes; +import android.support.annotation.StringRes; import java.util.ArrayList; @@ -13,18 +15,18 @@ import io.syng.entity.Profile; public final class PrefsUtil { - private final static String SHARED_PREFERENCES_FILE = "test"; - private static final String PROFILES_KEY = "pref_profile_key"; private static final String FIRST_LAUNCH_KEY = "first_launch_key"; private static final String CURRENT_PROFILE_KEY = "current_profile"; private static PrefsUtil sInstance; + private final Context mContext; private SharedPreferences mPreferences; private PrefsUtil(Context context) { - mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + mPreferences = PreferenceManager.getDefaultSharedPreferences(context); + mContext = context; } public static void initialize(Context context) { @@ -49,6 +51,10 @@ public final class PrefsUtil { return getInstance().mPreferences; } + private static String getString(@StringRes int resourceId) { + return getInstance().mContext.getString(resourceId); + } + private static void saveProfiles(ArrayList profiles) { try { getEditor().putString(PROFILES_KEY, ObjectSerializer.serialize(profiles)).commit(); @@ -119,4 +125,8 @@ public final class PrefsUtil { return getPrefs().getInt(profileId, R.drawable.bg0_resized); } + public static String getJsonRPCServerAddress() { + return getPrefs().getString(getString(R.string.pref_json_rpc_server_key), getString(R.string.pref_json_rpc_server_default)); + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ec8a5b8..a40f6c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,9 +1,9 @@ - Syng + + Syng Open Navigation Drawer Close Navigation Drawer - ProfileManagerActivity Add Profile Profiles @@ -16,17 +16,14 @@ Save Cancel Import - Manage Profiles - - Syng Import Wallet OK Import json wallet Import hex encoded private key - The specified file was not found. - Error reading specified file. - Invalid wallet or password. + The specified file was not found + Error reading specified file + Invalid wallet or password Invalid url diff --git a/app/src/main/res/values/strings_activity_settings.xml b/app/src/main/res/values/strings_settings.xml similarity index 79% rename from app/src/main/res/values/strings_activity_settings.xml rename to app/src/main/res/values/strings_settings.xml index e7f35b6..50dfb64 100644 --- a/app/src/main/res/values/strings_activity_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -7,22 +7,22 @@ General Sync in background - Enable syncing blockchain in background - + Enable syncing blockchain in background Sync only on wifi - Sync blockchain only on wifi - + Sync blockchain only on wifi Display name John Smith Running Mode + Full Client Light Client Json RPC Client + 1 2 @@ -41,6 +41,7 @@ 6 hours Never + 15 30 @@ -49,4 +50,12 @@ 360 -1 + + + default address + pref_json_rpc_server_key + JSON-RPC server address + runningMode + + diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index a4befe9..4748536 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -1,24 +1,33 @@ + + + + + android:positiveButtonText="@null" + android:title="@string/pref_title_running_mode"/> + android:title="@string/pref_title_sync_in_background"/> + android:title="@string/pref_title_sync_only_on_wifi"/>