Back to project page openhds-tablet.
The source code is released under:
OPENHDS PLATFORM OPENSOURCE LICENSE AGREEMENT Copyright (c) 2013 University of Southern Maine. All rights reserved. Redistribution and use in source and binary forms, with or without mo...
If you think the Android project openhds-tablet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.openhds.mobile.activity; /* w w w. j a v a 2 s. co m*/ import org.openhds.mobile.R; import org.openhds.mobile.utilities.UrlUtils; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.PreferenceActivity; import android.widget.Toast; public class ServerPreferencesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { public static String INTEROP_SERVER = "interopserver"; public static String OPENHDS_KEY_SERVER = "openhdsserver"; public static String OPENHDS_KEY_USERNAME = "openhdsusername"; public static String OPENHDS_KEY_PASSWORD = "openhdspassword"; @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.preferences); setTitle(getString(R.string.app_name) + " > " + getString(R.string.configureDatabase)); updateInterop(INTEROP_SERVER); updateServer(OPENHDS_KEY_SERVER); updateUsername(OPENHDS_KEY_USERNAME); updatePassword(OPENHDS_KEY_PASSWORD); } private void updateInterop(String server) { @SuppressWarnings("deprecation") EditTextPreference etp = (EditTextPreference) this.getPreferenceScreen().findPreference(server); String s = etp.getText().trim(); if (UrlUtils.isValidUrl(s)) { etp.setText(s); etp.setSummary(s); } else { etp.setText((String) etp.getSummary()); Toast.makeText(getApplicationContext(), getString(R.string.url_error), Toast.LENGTH_SHORT).show(); } } @SuppressWarnings("deprecation") private void updateServer(String server) { EditTextPreference etp = (EditTextPreference) this.getPreferenceScreen().findPreference(server); String s = etp.getText().trim(); if (UrlUtils.isValidUrl(s)) { etp.setText(s); etp.setSummary(s); } else { etp.setText((String) etp.getSummary()); Toast.makeText(getApplicationContext(), getString(R.string.url_error), Toast.LENGTH_SHORT).show(); } } @SuppressWarnings("deprecation") private void updateUsername(String username) { EditTextPreference etp = (EditTextPreference) this.getPreferenceScreen().findPreference(username); etp.setSummary(etp.getText()); } @SuppressWarnings("deprecation") private void updatePassword(String password) { EditTextPreference etp = (EditTextPreference) this.getPreferenceScreen().findPreference(password); etp.setText(etp.getText()); } public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(INTEROP_SERVER)) updateServer(INTEROP_SERVER); else if (key.equals(OPENHDS_KEY_SERVER)) updateServer(OPENHDS_KEY_SERVER); else if (key.equals(OPENHDS_KEY_USERNAME)) updateUsername(OPENHDS_KEY_USERNAME); else if (key.equals(OPENHDS_KEY_PASSWORD)) updatePassword(OPENHDS_KEY_PASSWORD); } }