Example usage for android.preference EditTextPreference setText

List of usage examples for android.preference EditTextPreference setText

Introduction

In this page you can find the example usage for android.preference EditTextPreference setText.

Prototype

public void setText(String text) 

Source Link

Document

Saves the text to the SharedPreferences .

Usage

From source file:com.mantz_it.rfanalyzer.SettingsFragment.java

/**
 * Will try to extract the file source preferences (frequency, sample rate, format) from the filename
 *//*from   w ww  .j  a v a2 s.c om*/
public void updateFileSourcePrefs() {
    EditTextPreference etp_filename = (EditTextPreference) findPreference(
            getString(R.string.pref_filesource_file));
    EditTextPreference etp_frequency = (EditTextPreference) findPreference(
            getString(R.string.pref_filesource_frequency));
    EditTextPreference etp_sampleRate = (EditTextPreference) findPreference(
            getString(R.string.pref_filesource_sampleRate));
    ListPreference lp_format = (ListPreference) findPreference(getString(R.string.pref_filesource_format));
    String filename = etp_filename.getText();

    // Format. Search for strings like hackrf, rtl-sdr, ...
    if (filename.matches(".*hackrf.*") || filename.matches(".*HackRF.*") || filename.matches(".*HACKRF.*")
            || filename.matches(".*hackrfone.*"))
        lp_format.setValue("0");
    if (filename.matches(".*rtlsdr.*") || filename.matches(".*rtl-sdr.*") || filename.matches(".*RTLSDR.*")
            || filename.matches(".*RTL-SDR.*"))
        lp_format.setValue("1");

    // Sampe Rate. Search for pattern XXXXXXXSps
    if (filename.matches(".*(_|-|\\s)([0-9]+)(sps|Sps|SPS).*"))
        etp_sampleRate.setText(filename.replaceFirst(".*(_|-|\\s)([0-9]+)(sps|Sps|SPS).*", "$2"));
    if (filename.matches(".*(_|-|\\s)([0-9]+)(msps|Msps|MSps|MSPS).*"))
        etp_sampleRate.setText(
                "" + Integer.valueOf(filename.replaceFirst(".*(_|-|\\s)([0-9]+)(msps|Msps|MSps|MSPS).*", "$2"))
                        * 1000000);

    // Frequency. Search for pattern XXXXXXXHz
    if (filename.matches(".*(_|-|\\s)([0-9]+)(hz|Hz|HZ).*"))
        etp_frequency.setText(filename.replaceFirst(".*(_|-|\\s)([0-9]+)(hz|Hz|HZ).*", "$2"));
    if (filename.matches(".*(_|-|\\s)([0-9]+)(mhz|Mhz|MHz|MHZ).*"))
        etp_frequency.setText(
                "" + Integer.valueOf(filename.replaceFirst(".*(_|-|\\s)([0-9]+)(mhz|Mhz|MHz|MHZ).*", "$2"))
                        * 1000000);
}

From source file:org.linphone.SettingsFragment.java

private void setPreferenceDefaultValueAndSummary(int pref, String value) {
    if (value != null) {
        EditTextPreference etPref = (EditTextPreference) findPreference(getString(pref));
        if (etPref != null) {
            etPref.setText(value);
            etPref.setSummary(value);/*from  w w w  . j ava 2  s.  c o m*/
        }
    }
}

From source file:org.linphone.SettingsFragment.java

private void initNetworkSettings() {
    initMediaEncryptionPreference(//from   w  ww.  j ava  2  s. com
            (ListPreference) findPreference(getString(R.string.pref_media_encryption_key)));

    ((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key)))
            .setChecked(mPrefs.isWifiOnlyEnabled());

    // Disable UPnP if ICE si enabled, or disable ICE if UPnP is enabled
    CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key));
    CheckBoxPreference upnp = (CheckBoxPreference) findPreference(getString(R.string.pref_upnp_enable_key));
    ice.setChecked(mPrefs.isIceEnabled());
    if (mPrefs.isIceEnabled()) {
        upnp.setEnabled(false);
    } else {
        upnp.setChecked(mPrefs.isUpnpEnabled());
        if (mPrefs.isUpnpEnabled()) {
            ice.setEnabled(false);
        }
    }

    CheckBoxPreference randomPort = (CheckBoxPreference) findPreference(
            getString(R.string.pref_transport_use_random_ports_key));
    randomPort.setChecked(mPrefs.isUsingRandomPort());

    // Disable sip port choice if port is random
    EditTextPreference sipPort = (EditTextPreference) findPreference(getString(R.string.pref_sip_port_key));
    sipPort.setEnabled(!randomPort.isChecked());
    sipPort.setSummary(mPrefs.getSipPort());
    sipPort.setText(mPrefs.getSipPort());

    EditTextPreference stun = (EditTextPreference) findPreference(getString(R.string.pref_stun_server_key));
    stun.setSummary(mPrefs.getStunServer());
    stun.setText(mPrefs.getStunServer());

    ((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key)))
            .setChecked(mPrefs.isPushNotificationEnabled());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_ipv6_key))).setChecked(mPrefs.isUsingIpv6());
}

From source file:github.popeen.dsub.fragments.SettingsFragment.java

private PreferenceScreen expandServer(final int instance) {
    final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context);
    screen.setTitle(R.string.settings_server_unused);
    screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance);

    final EditTextPreference serverNamePreference = new EditTextPreference(context);
    serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance);
    serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused));
    serverNamePreference.setTitle(R.string.settings_server_name);
    serverNamePreference.setDialogTitle(R.string.settings_server_name);

    if (serverNamePreference.getText() == null) {
        serverNamePreference.setText(getResources().getString(R.string.settings_server_unused));
    }//from w w w .  j  a va2s .com

    serverNamePreference.setSummary(serverNamePreference.getText());

    final EditTextPreference serverUrlPreference = new EditTextPreference(context);
    serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance);
    serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverUrlPreference.setDefaultValue("http://yourhost");
    serverUrlPreference.setTitle(R.string.settings_server_address);
    serverUrlPreference.setDialogTitle(R.string.settings_server_address);

    if (serverUrlPreference.getText() == null) {
        serverUrlPreference.setText("http://yourhost");
    }

    serverUrlPreference.setSummary(serverUrlPreference.getText());
    screen.setSummary(serverUrlPreference.getText());

    final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) {
        @Override
        protected void onAddEditTextToDialogView(View dialogView, final EditText editText) {
            super.onAddEditTextToDialogView(dialogView, editText);
            ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0);

            Button defaultButton = new Button(getContext());
            defaultButton.setText(internalSSIDDisplay);
            defaultButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    editText.setText(internalSSID);
                }
            });
            root.addView(defaultButton);
        }
    };
    serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance);
    serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid);
    serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid);

    final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context);
    serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance);
    serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverInternalUrlPreference.setDefaultValue("");
    serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText());

    final EditTextPreference serverUsernamePreference = new EditTextPreference(context);
    serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance);
    serverUsernamePreference.setTitle(R.string.settings_server_username);
    serverUsernamePreference.setDialogTitle(R.string.settings_server_username);

    final EditTextPreference serverPasswordPreference = new EditTextPreference(context);
    serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance);
    serverPasswordPreference.getEditText()
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    serverPasswordPreference.setSummary("***");
    serverPasswordPreference.setTitle(R.string.settings_server_password);
    final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context);
    serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance);
    serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance));
    serverSyncPreference.setSummary(R.string.settings_server_sync_summary);
    serverSyncPreference.setTitle(R.string.settings_server_sync);

    final Preference serverOpenBrowser = new Preference(context);
    serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER);
    serverOpenBrowser.setPersistent(false);
    serverOpenBrowser.setTitle(R.string.settings_server_open_browser);
    serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            openInBrowser(instance);
            return true;
        }
    });

    Preference serverRemoveServerPreference = new Preference(context);
    serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance);
    serverRemoveServerPreference.setPersistent(false);
    serverRemoveServerPreference.setTitle(R.string.settings_servers_remove);

    serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Reset values to null so when we ask for them again they are new
                            serverNamePreference.setText(null);
                            serverUrlPreference.setText(null);
                            serverUsernamePreference.setText(null);
                            serverPasswordPreference.setText(null);

                            // Don't use Util.getActiveServer since it is 0 if offline
                            int activeServer = Util.getPreferences(context)
                                    .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
                            for (int i = instance; i <= serverCount; i++) {
                                Util.removeInstanceName(context, i, activeServer);
                            }

                            serverCount--;
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
                            editor.commit();

                            removeCurrent();

                            SubsonicFragment parentFragment = context.getCurrentFragment();
                            if (parentFragment instanceof SettingsFragment) {
                                SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment;
                                serverSelectionFragment.checkForRemoved();
                            }
                        }
                    });

            return true;
        }
    });

    Preference serverTestConnectionPreference = new Preference(context);
    serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance);
    serverTestConnectionPreference.setPersistent(false);
    serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title);
    serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            testConnection(instance);
            return false;
        }
    });

    screen.addPreference(serverNamePreference);
    screen.addPreference(serverUrlPreference);
    screen.addPreference(serverInternalUrlPreference);
    screen.addPreference(serverLocalNetworkSSIDPreference);
    screen.addPreference(serverUsernamePreference);
    screen.addPreference(serverPasswordPreference);
    screen.addPreference(serverSyncPreference);
    screen.addPreference(serverTestConnectionPreference);
    screen.addPreference(serverOpenBrowser);
    screen.addPreference(serverRemoveServerPreference);

    return screen;
}

From source file:github.daneren2005.dsub.fragments.SettingsFragment.java

private PreferenceScreen expandServer(final int instance) {
    final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context);
    screen.setTitle(R.string.settings_server_unused);
    screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance);

    final EditTextPreference serverNamePreference = new EditTextPreference(context);
    serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance);
    serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused));
    serverNamePreference.setTitle(R.string.settings_server_name);
    serverNamePreference.setDialogTitle(R.string.settings_server_name);

    if (serverNamePreference.getText() == null) {
        serverNamePreference.setText(getResources().getString(R.string.settings_server_unused));
    }//ww w  .  j  ava 2 s .co  m

    serverNamePreference.setSummary(serverNamePreference.getText());

    final EditTextPreference serverUrlPreference = new EditTextPreference(context);
    serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance);
    serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverUrlPreference.setDefaultValue("http://yourhost");
    serverUrlPreference.setTitle(R.string.settings_server_address);
    serverUrlPreference.setDialogTitle(R.string.settings_server_address);

    if (serverUrlPreference.getText() == null) {
        serverUrlPreference.setText("http://yourhost");
    }

    serverUrlPreference.setSummary(serverUrlPreference.getText());
    screen.setSummary(serverUrlPreference.getText());

    final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) {
        @Override
        protected void onAddEditTextToDialogView(View dialogView, final EditText editText) {
            super.onAddEditTextToDialogView(dialogView, editText);
            ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0);

            Button defaultButton = new Button(getContext());
            defaultButton.setText(internalSSIDDisplay);
            defaultButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    editText.setText(internalSSID);
                }
            });
            root.addView(defaultButton);
        }
    };
    serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance);
    serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid);
    serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid);

    final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context);
    serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance);
    serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI);
    serverInternalUrlPreference.setDefaultValue("");
    serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address);
    serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText());

    final EditTextPreference serverUsernamePreference = new EditTextPreference(context);
    serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance);
    serverUsernamePreference.setTitle(R.string.settings_server_username);
    serverUsernamePreference.setDialogTitle(R.string.settings_server_username);

    final EditTextPreference serverPasswordPreference = new EditTextPreference(context);
    serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance);
    serverPasswordPreference.getEditText()
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    serverPasswordPreference.setSummary("***");
    serverPasswordPreference.setTitle(R.string.settings_server_password);

    final CheckBoxPreference serverTagPreference = new CheckBoxPreference(context);
    serverTagPreference.setKey(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance);
    serverTagPreference.setChecked(Util.isTagBrowsing(context, instance));
    serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary);
    serverTagPreference.setTitle(R.string.settings_browse_by_tags);
    serverPasswordPreference.setDialogTitle(R.string.settings_server_password);

    final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context);
    serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance);
    serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance));
    serverSyncPreference.setSummary(R.string.settings_server_sync_summary);
    serverSyncPreference.setTitle(R.string.settings_server_sync);

    final Preference serverOpenBrowser = new Preference(context);
    serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER);
    serverOpenBrowser.setPersistent(false);
    serverOpenBrowser.setTitle(R.string.settings_server_open_browser);
    serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            openInBrowser(instance);
            return true;
        }
    });

    Preference serverRemoveServerPreference = new Preference(context);
    serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance);
    serverRemoveServerPreference.setPersistent(false);
    serverRemoveServerPreference.setTitle(R.string.settings_servers_remove);

    serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Reset values to null so when we ask for them again they are new
                            serverNamePreference.setText(null);
                            serverUrlPreference.setText(null);
                            serverUsernamePreference.setText(null);
                            serverPasswordPreference.setText(null);

                            // Don't use Util.getActiveServer since it is 0 if offline
                            int activeServer = Util.getPreferences(context)
                                    .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
                            for (int i = instance; i <= serverCount; i++) {
                                Util.removeInstanceName(context, i, activeServer);
                            }

                            serverCount--;
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
                            editor.commit();

                            removeCurrent();

                            SubsonicFragment parentFragment = context.getCurrentFragment();
                            if (parentFragment instanceof SettingsFragment) {
                                SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment;
                                serverSelectionFragment.checkForRemoved();
                            }
                        }
                    });

            return true;
        }
    });

    Preference serverTestConnectionPreference = new Preference(context);
    serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance);
    serverTestConnectionPreference.setPersistent(false);
    serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title);
    serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            testConnection(instance);
            return false;
        }
    });

    screen.addPreference(serverNamePreference);
    screen.addPreference(serverUrlPreference);
    screen.addPreference(serverInternalUrlPreference);
    screen.addPreference(serverLocalNetworkSSIDPreference);
    screen.addPreference(serverUsernamePreference);
    screen.addPreference(serverPasswordPreference);
    screen.addPreference(serverTagPreference);
    screen.addPreference(serverSyncPreference);
    screen.addPreference(serverTestConnectionPreference);
    screen.addPreference(serverOpenBrowser);
    screen.addPreference(serverRemoveServerPreference);

    return screen;
}

From source file:com.aware.Aware_Preferences.java

/**
 * Developer UI options/*from   ww  w . j  av  a  2s  .c  o  m*/
 * - Debug flag
 * - Debug tag
 * - AWARE updates
 * - Device ID
 */
private void developerOptions() {
    final CheckBoxPreference debug_flag = (CheckBoxPreference) findPreference(Aware_Preferences.DEBUG_FLAG);
    debug_flag
            .setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true"));
    debug_flag.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.DEBUG = debug_flag.isChecked();
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG, debug_flag.isChecked());
            return true;
        }
    });

    final EditTextPreference debug_tag = (EditTextPreference) findPreference(Aware_Preferences.DEBUG_TAG);
    debug_tag.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG));
    debug_tag.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.TAG = (String) newValue;
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG, (String) newValue);
            return true;
        }
    });

    final CheckBoxPreference auto_update = (CheckBoxPreference) findPreference(
            Aware_Preferences.AWARE_AUTO_UPDATE);
    auto_update.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE).equals("true"));

    PackageInfo awareInfo = null;
    try {
        awareInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    auto_update.setSummary("Current version is " + ((awareInfo != null) ? awareInfo.versionCode : "???"));
    auto_update.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE,
                    auto_update.isChecked());
            return true;
        }
    });

    final CheckBoxPreference debug_db_slow = (CheckBoxPreference) findPreference(
            Aware_Preferences.DEBUG_DB_SLOW);
    debug_db_slow.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true"));
    debug_db_slow.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW,
                    debug_db_slow.isChecked());
            return true;
        }
    });

    final EditTextPreference device_id = (EditTextPreference) findPreference(Aware_Preferences.DEVICE_ID);
    device_id.setSummary("UUID: " + Aware.getSetting(getApplicationContext(), DEVICE_ID));
    device_id.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
    device_id.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, (String) newValue);
            device_id.setSummary(
                    "UUID: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
            return true;
        }
    });
}

From source file:com.aware.Aware_Preferences.java

/**
 * Temperature module settings UI//from   w w w  . j a v  a 2  s .  c  o  m
 */
private void temperature() {
    final PreferenceScreen temp_pref = (PreferenceScreen) findPreference("temperature");
    Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_TEMPERATURE);
    if (temp != null) {
        temp_pref.setSummary(
                temp_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA"));
    } else {
        temp_pref.setSummary(temp_pref.getSummary().toString().replace("*", ""));
    }

    final CheckBoxPreference temperature = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_TEMPERATURE);
    temperature.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE).equals("true"));
    temperature.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (mSensorMgr.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                temperature.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_TEMPERATURE,
                    temperature.isChecked());
            if (temperature.isChecked()) {
                framework.startTemperature();
            } else {
                framework.stopTemperature();
            }
            return true;
        }
    });

    final EditTextPreference frequency_temperature = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_TEMPERATURE);
    frequency_temperature
            .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE));
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE).length() > 0) {
        frequency_temperature
                .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE)
                        + " microseconds");
    }
    frequency_temperature.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_TEMPERATURE,
                    (String) newValue);
            frequency_temperature.setSummary((String) newValue + " microseconds");
            framework.startTemperature();
            return true;
        }
    });
}

From source file:com.aware.Aware_Preferences.java

/**
 * MQTT module settings UI//from   w w w  . j a va2  s .c  o m
 */
private void mqtt() {

    final CheckBoxPreference mqtt = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_MQTT);
    mqtt.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_MQTT).equals("true"));
    mqtt.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER).length() == 0) {
                showDialog(DIALOG_ERROR_MISSING_PARAMETERS);
                mqtt.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MQTT, false);
                return false;
            } else {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_MQTT, mqtt.isChecked());
                if (mqtt.isChecked()) {
                    framework.startMQTT();
                } else {
                    framework.stopMQTT();
                }
                return true;
            }
        }
    });

    final EditTextPreference mqttServer = (EditTextPreference) findPreference(Aware_Preferences.MQTT_SERVER);
    mqttServer.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER));
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER).length() > 0) {
        mqttServer.setSummary(
                "Server: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER));
    }
    mqttServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_SERVER, (String) newValue);
            mqttServer.setSummary("Server: " + (String) newValue);
            return true;
        }
    });

    final EditTextPreference mqttPort = (EditTextPreference) findPreference(Aware_Preferences.MQTT_PORT);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT).length() > 0) {
        mqttPort.setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT));
    }
    mqttPort.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT));
    mqttPort.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_PORT, (String) newValue);
            return true;
        }
    });

    final EditTextPreference mqttUsername = (EditTextPreference) findPreference(
            Aware_Preferences.MQTT_USERNAME);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME).length() > 0) {
        mqttUsername.setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME));
    }
    mqttUsername.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME));
    mqttUsername.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_USERNAME, (String) newValue);
            return true;
        }
    });

    final EditTextPreference mqttPassword = (EditTextPreference) findPreference(
            Aware_Preferences.MQTT_PASSWORD);
    mqttPassword.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PASSWORD));
    mqttPassword.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_PASSWORD, (String) newValue);
            return true;
        }
    });

    final EditTextPreference mqttKeepAlive = (EditTextPreference) findPreference(
            Aware_Preferences.MQTT_KEEP_ALIVE);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE).length() > 0) {
        mqttKeepAlive.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE) + " seconds");
    }
    mqttKeepAlive.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE));
    mqttKeepAlive.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_KEEP_ALIVE, (String) newValue);
            mqttKeepAlive.setSummary((String) newValue + " seconds");
            return true;
        }
    });

    final EditTextPreference mqttQoS = (EditTextPreference) findPreference(Aware_Preferences.MQTT_QOS);
    mqttQoS.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_QOS));
    mqttQoS.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_QOS, (String) newValue);
            return true;
        }
    });

    final EditTextPreference mqttProtocol = (EditTextPreference) findPreference(
            Aware_Preferences.MQTT_PROTOCOL);
    mqttProtocol.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MQTT_PROTOCOL));
    mqttProtocol.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MQTT_PROTOCOL, (String) newValue);
            return true;
        }
    });
}

From source file:com.aware.Aware_Preferences.java

/**
 * Webservices module settings UI/*  w w w.  jav a 2 s  .  com*/
 */
private void webservices() {
    final CheckBoxPreference webservice = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_WEBSERVICE);
    webservice.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE).equals("true"));
    webservice.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() == 0) {
                showDialog(DIALOG_ERROR_MISSING_PARAMETERS);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE, false);
                webservice.setChecked(false);
                return false;
            } else {
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE,
                        webservice.isChecked());
                if (webservice.isChecked()
                        && Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER).length() > 0) {
                    //setup and send data
                    Intent study_config = new Intent(getApplicationContext(), StudyConfig.class);
                    study_config.putExtra("study_url",
                            Aware.getSetting(getApplicationContext(), WEBSERVICE_SERVER));
                    startService(study_config);
                }
                return true;
            }
        }
    });

    final EditTextPreference webservice_server = (EditTextPreference) findPreference(
            Aware_Preferences.WEBSERVICE_SERVER);
    webservice_server.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER));
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER).length() > 0) {
        webservice_server.setSummary(
                "Server: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER));
    }
    webservice_server.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER, (String) newValue);
            webservice_server.setSummary("Server: " + (String) newValue);
            return true;
        }
    });

    final CheckBoxPreference webservice_wifi_only = (CheckBoxPreference) findPreference(
            Aware_Preferences.WEBSERVICE_WIFI_ONLY);
    webservice_wifi_only.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY).equals("true"));
    webservice_wifi_only.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY,
                    webservice_wifi_only.isChecked());
            return true;
        }
    });

    final EditTextPreference frequency_webservice = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_WEBSERVICE);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE).length() > 0) {
        frequency_webservice.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE) + " minutes");
    }
    frequency_webservice
            .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE));
    frequency_webservice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE,
                    (String) newValue);
            frequency_webservice.setSummary((String) newValue + " minutes");
            return true;
        }
    });

    final ListPreference clean_old_data = (ListPreference) findPreference(FREQUENCY_CLEAN_OLD_DATA);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA).length() > 0) {
        String freq = Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA);
        if (freq.equals("0")) {
            clean_old_data.setSummary("Never");
        } else if (freq.equals("1")) {
            clean_old_data.setSummary("Weekly");
        } else if (freq.equals("2")) {
            clean_old_data.setSummary("Monthly");
        }
    }
    clean_old_data.setDefaultValue(Aware.getSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA));
    clean_old_data.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), FREQUENCY_CLEAN_OLD_DATA, (String) newValue);
            if (((String) newValue).equals("0")) {
                clean_old_data.setSummary("Never");
            } else if (((String) newValue).equals("1")) {
                clean_old_data.setSummary("Weekly");
            } else if (((String) newValue).equals("2")) {
                clean_old_data.setSummary("Monthly");
            }
            return true;
        }
    });
}

From source file:com.aware.Aware_Preferences.java

/**
 * WiFi module settings UI/*from  w w w  .jav  a2s  .  co m*/
 */
private void wifi() {
    final CheckBoxPreference wifi = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_WIFI);
    wifi.setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WIFI).equals("true"));
    wifi.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_WIFI, wifi.isChecked());
            if (wifi.isChecked()) {
                framework.startWiFi();
            } else {
                framework.stopWiFi();
            }
            return true;
        }
    });

    final EditTextPreference wifiInterval = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_WIFI);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI).length() > 0) {
        wifiInterval.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI) + " seconds");
    }
    wifiInterval.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI));
    wifiInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WIFI, (String) newValue);
            wifiInterval.setSummary((String) newValue + " seconds");
            framework.startWiFi();
            return true;
        }
    });
}