List of usage examples for android.preference CheckBoxPreference setChecked
public void setChecked(boolean checked)
From source file:com.aware.Aware_Preferences.java
/** * Accelerometer module settings UI//w w w. ja v a 2s . c o m */ private void accelerometer() { final PreferenceScreen accel_pref = (PreferenceScreen) findPreference("accelerometer"); Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (temp != null) { accel_pref.setSummary( accel_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA")); } else { accel_pref.setSummary(accel_pref.getSummary().toString().replace("*", "")); } final CheckBoxPreference accelerometer = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_ACCELEROMETER); accelerometer.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_ACCELEROMETER).equals("true")); accelerometer.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (mSensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); accelerometer.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ACCELEROMETER, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_ACCELEROMETER, accelerometer.isChecked()); if (accelerometer.isChecked()) { framework.startAccelerometer(); } else { framework.stopAccelerometer(); } return true; } }); final EditTextPreference frequency_accelerometer = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_ACCELEROMETER); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_ACCELEROMETER).length() > 0) { frequency_accelerometer .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_ACCELEROMETER) + " microseconds"); } frequency_accelerometer .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_ACCELEROMETER)); frequency_accelerometer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_ACCELEROMETER, (String) newValue); frequency_accelerometer.setSummary((String) newValue + " microseconds"); framework.startAccelerometer(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Network module settings UI/*from w ww . j a v a 2 s .c om*/ */ private void network() { final CheckBoxPreference network_traffic = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_NETWORK_TRAFFIC); network_traffic.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_TRAFFIC).equals("true")); network_traffic.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_TRAFFIC, network_traffic.isChecked()); if (network_traffic.isChecked()) { framework.startTraffic(); } else { framework.stopTraffic(); } return true; } }); final EditTextPreference frequencyTraffic = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_NETWORK_TRAFFIC); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_NETWORK_TRAFFIC).length() > 0) { frequencyTraffic.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_NETWORK_TRAFFIC) + " seconds"); } frequencyTraffic .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_NETWORK_TRAFFIC)); frequencyTraffic.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_NETWORK_TRAFFIC, (String) newValue); frequencyTraffic.setSummary((String) newValue + " seconds"); if (network_traffic.isChecked()) { framework.startTraffic(); } return true; } }); final CheckBoxPreference network = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_NETWORK_EVENTS); network.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_EVENTS).equals("true")); network.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NETWORK_EVENTS, network.isChecked()); if (network.isChecked()) { framework.startNetwork(); } else { framework.stopNetwork(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Linear Accelerometer module settings UI *//*from www . ja va 2 s . c o m*/ private void linear_accelerometer() { final PreferenceScreen linear_pref = (PreferenceScreen) findPreference("linear_accelerometer"); Sensor temp = mSensorMgr.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); if (temp != null) { linear_pref.setSummary( linear_pref.getSummary().toString().replace("*", " - Power: " + temp.getPower() + " mA")); } else { linear_pref.setSummary(linear_pref.getSummary().toString().replace("*", "")); } final CheckBoxPreference linear_accelerometer = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_LINEAR_ACCELEROMETER); linear_accelerometer.setChecked(Aware .getSetting(getApplicationContext(), Aware_Preferences.STATUS_LINEAR_ACCELEROMETER).equals("true")); linear_accelerometer.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (mSensorMgr.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION) == null) { showDialog(DIALOG_ERROR_MISSING_SENSOR); linear_accelerometer.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LINEAR_ACCELEROMETER, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LINEAR_ACCELEROMETER, linear_accelerometer.isChecked()); if (linear_accelerometer.isChecked()) { framework.startLinearAccelerometer(); } else { framework.stopLinearAccelerometer(); } return true; } }); final EditTextPreference frequency_linear_accelerometer = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_LINEAR_ACCELEROMETER); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LINEAR_ACCELEROMETER) .length() > 0) { frequency_linear_accelerometer.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LINEAR_ACCELEROMETER) + " microseconds"); } frequency_linear_accelerometer.setText( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LINEAR_ACCELEROMETER)); frequency_linear_accelerometer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LINEAR_ACCELEROMETER, (String) newValue); frequency_linear_accelerometer.setSummary((String) newValue + " microseconds"); framework.startLinearAccelerometer(); return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * MQTT module settings UI/*from w w w.j a v a2 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//from w w w . j a v a 2s . c o m */ 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
/** * Applications module settings UI/* ww w . ja v a 2 s . co m*/ */ private void applications() { final CheckBoxPreference notifications = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_NOTIFICATIONS); notifications.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS).equals("true")); notifications.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (isAccessibilityServiceActive() && notifications.isChecked()) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS, notifications.isChecked()); notifications.setChecked(true); framework.startApplications(); return true; } if (!isAccessibilityServiceActive()) { showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY); } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS, false); notifications.setChecked(false); return false; } }); final CheckBoxPreference crashes = (CheckBoxPreference) findPreference(Aware_Preferences.STATUS_CRASHES); crashes.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES).equals("true")); crashes.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (isAccessibilityServiceActive() && crashes.isChecked()) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES, crashes.isChecked()); crashes.setChecked(true); framework.startApplications(); return true; } if (!isAccessibilityServiceActive()) { showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY); } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES, false); crashes.setChecked(false); return false; } }); final CheckBoxPreference applications = (CheckBoxPreference) findPreference("status_applications"); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS).equals("true") && !isAccessibilityServiceActive()) { showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS, false); framework.stopApplications(); } applications.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS).equals("true")); applications.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (isAccessibilityServiceActive() && applications.isChecked()) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS, true); applications.setChecked(true); framework.startApplications(); return true; } else { if (!isAccessibilityServiceActive()) { showDialog(Aware_Preferences.DIALOG_ERROR_ACCESSIBILITY); } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_APPLICATIONS, false); applications.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_NOTIFICATIONS, false); notifications.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_CRASHES, false); crashes.setChecked(false); framework.stopApplications(); return false; } } }); final EditTextPreference frequency_applications = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_APPLICATIONS); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_APPLICATIONS).length() > 0) { frequency_applications .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_APPLICATIONS) + " seconds"); } frequency_applications .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_APPLICATIONS)); frequency_applications.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_APPLICATIONS, (String) newValue); frequency_applications.setSummary((String) newValue + " seconds"); framework.startApplications(); return true; } }); final CheckBoxPreference installations = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_INSTALLATIONS); installations.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_INSTALLATIONS).equals("true")); installations.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_INSTALLATIONS, installations.isChecked()); if (installations.isChecked()) { framework.startInstallations(); } else { framework.stopInstallations(); } return true; } }); }
From source file:com.aware.Aware_Preferences.java
/** * Location module settings UI/*from w w w.j a v a2s. c o m*/ */ private void locations() { final CheckBoxPreference location_gps = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_LOCATION_GPS); location_gps.setChecked( Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS).equals("true")); location_gps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE); List<String> providers = localMng.getAllProviders(); if (!providers.contains(LocationManager.GPS_PROVIDER)) { showDialog(DIALOG_ERROR_MISSING_SENSOR); location_gps.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS, location_gps.isChecked()); if (location_gps.isChecked()) { framework.startLocations(); } else { framework.stopLocations(); } return true; } }); final CheckBoxPreference location_network = (CheckBoxPreference) findPreference( Aware_Preferences.STATUS_LOCATION_NETWORK); location_network.setChecked(Aware .getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK).equals("true")); location_network.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE); List<String> providers = localMng.getAllProviders(); if (!providers.contains(LocationManager.NETWORK_PROVIDER)) { showDialog(DIALOG_ERROR_MISSING_SENSOR); location_gps.setChecked(false); Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK, false); return false; } Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK, location_network.isChecked()); if (location_network.isChecked()) { framework.startLocations(); } else { framework.stopLocations(); } return true; } }); final EditTextPreference gpsInterval = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_LOCATION_GPS); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS).length() > 0) { gpsInterval .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS) + " seconds"); } gpsInterval.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS)); gpsInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS, (String) newValue); gpsInterval.setSummary((String) newValue + " seconds"); framework.startLocations(); return true; } }); final EditTextPreference networkInterval = (EditTextPreference) findPreference( Aware_Preferences.FREQUENCY_LOCATION_NETWORK); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK).length() > 0) { networkInterval.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK) + " seconds"); } networkInterval .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK)); networkInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK, (String) newValue); networkInterval.setSummary((String) newValue + " seconds"); framework.startLocations(); return true; } }); final EditTextPreference gpsAccuracy = (EditTextPreference) findPreference( Aware_Preferences.MIN_LOCATION_GPS_ACCURACY); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY).length() > 0) { gpsAccuracy.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY) + " meters"); } gpsAccuracy.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY)); gpsAccuracy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY, (String) newValue); gpsAccuracy.setSummary((String) newValue + " meters"); framework.startLocations(); return true; } }); final EditTextPreference networkAccuracy = (EditTextPreference) findPreference( Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY) .length() > 0) { networkAccuracy.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY) + " meters"); } networkAccuracy.setText( Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY)); networkAccuracy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY, (String) newValue); networkAccuracy.setSummary((String) newValue + " meters"); framework.startLocations(); return true; } }); final EditTextPreference expirateTime = (EditTextPreference) findPreference( Aware_Preferences.LOCATION_EXPIRATION_TIME); if (Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME).length() > 0) { expirateTime.setSummary( Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME) + " seconds"); } expirateTime.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME)); expirateTime.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Aware.setSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME, (String) newValue); expirateTime.setSummary((String) newValue + " seconds"); framework.startLocations(); return true; } }); }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
/** * Refresh the preferences./*from ww w . jav a2s. co m*/ */ private void refreshDisplay() { boolean isConnected = Matrix.getInstance(getActivity()).isConnected(); Context appContext = getActivity().getApplicationContext(); PreferenceManager preferenceManager = getPreferenceManager(); // refresh the avatar UserAvatarPreference avatarPreference = (UserAvatarPreference) preferenceManager .findPreference(PreferencesManager.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY); avatarPreference.refreshAvatar(); avatarPreference.setEnabled(isConnected); // refresh the display name final EditTextPreference displaynamePref = (EditTextPreference) preferenceManager .findPreference(PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY); displaynamePref.setSummary(mSession.getMyUser().displayname); displaynamePref.setText(mSession.getMyUser().displayname); displaynamePref.setEnabled(isConnected); // change password final EditTextPreference changePasswordPref = (EditTextPreference) preferenceManager .findPreference(PreferencesManager.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY); changePasswordPref.setEnabled(isConnected); // update the push rules SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(appContext); BingRuleSet rules = mSession.getDataHandler().pushRules(); GcmRegistrationManager gcmMgr = Matrix.getInstance(appContext).getSharedGCMRegistrationManager(); for (String resourceText : mPushesRuleByResourceId.keySet()) { Preference preference = preferenceManager.findPreference(resourceText); if (null != preference) { if (preference instanceof BingRulePreference) { BingRulePreference bingRulePreference = (BingRulePreference) preference; bingRulePreference .setEnabled((null != rules) && isConnected && gcmMgr.areDeviceNotificationsAllowed()); bingRulePreference.setBingRule(mSession.getDataHandler().pushRules() .findDefaultRule(mPushesRuleByResourceId.get(resourceText))); } else if (preference instanceof CheckBoxPreference) { CheckBoxPreference switchPreference = (CheckBoxPreference) preference; if (resourceText.equals(PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)) { switchPreference.setChecked(gcmMgr.areDeviceNotificationsAllowed()); } else if (resourceText.equals(PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY)) { switchPreference.setChecked(gcmMgr.isScreenTurnedOn()); switchPreference.setEnabled(gcmMgr.areDeviceNotificationsAllowed()); } else { switchPreference.setEnabled((null != rules) && isConnected); switchPreference.setChecked(preferences.getBoolean(resourceText, false)); } } } } // If notifications are disabled for the current user account or for the current user device // The others notifications settings have to be disable too boolean areNotifAllowed = rules != null && rules.findDefaultRule(BingRule.RULE_ID_DISABLE_ALL) != null && rules.findDefaultRule(BingRule.RULE_ID_DISABLE_ALL).isEnabled; Preference notificationSoundPreference = preferenceManager .findPreference(PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY); notificationSoundPreference.setEnabled(!areNotifAllowed && gcmMgr.areDeviceNotificationsAllowed()); Preference notificationPrivacyPreference = preferenceManager .findPreference(PreferencesManager.SETTINGS_NOTIFICATION_PRIVACY_PREFERENCE_KEY); if (notificationPrivacyPreference != null) { notificationPrivacyPreference .setEnabled(!areNotifAllowed && gcmMgr.areDeviceNotificationsAllowed() && gcmMgr.useGCM()); } }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
/** * Build the cryptography preference section. * * @param aMyDeviceInfo the device info/*from ww w . j av a2s .c o m*/ */ private void refreshCryptographyPreference(final DeviceInfo aMyDeviceInfo) { final String userId = mSession.getMyUserId(); final String deviceId = mSession.getCredentials().deviceId; VectorCustomActionEditTextPreference cryptoInfoTextPreference; // device name if ((null != aMyDeviceInfo) && !TextUtils.isEmpty(aMyDeviceInfo.display_name)) { cryptoInfoTextPreference = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_NAME_PREFERENCE_KEY); if (null != cryptoInfoTextPreference) { cryptoInfoTextPreference.setSummary(aMyDeviceInfo.display_name); cryptoInfoTextPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { displayDeviceRenameDialog(aMyDeviceInfo); return true; } }); cryptoInfoTextPreference.setOnPreferenceLongClickListener( new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() { @Override public boolean onPreferenceLongClick(Preference preference) { VectorUtils.copyToClipboard(getActivity(), aMyDeviceInfo.display_name); return true; } }); } } // crypto section: device ID if (!TextUtils.isEmpty(deviceId)) { cryptoInfoTextPreference = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY); if (null != cryptoInfoTextPreference) { cryptoInfoTextPreference.setSummary(deviceId); cryptoInfoTextPreference.setOnPreferenceLongClickListener( new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() { @Override public boolean onPreferenceLongClick(Preference preference) { VectorUtils.copyToClipboard(getActivity(), deviceId); return true; } }); } VectorCustomActionEditTextPreference exportPref = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_ENCRYPTION_EXPORT_E2E_ROOM_KEYS_PREFERENCE_KEY); exportPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { exportKeys(); return true; } }); VectorCustomActionEditTextPreference importPref = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_ENCRYPTION_IMPORT_E2E_ROOM_KEYS_PREFERENCE_KEY); importPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { importKeys(); return true; } }); } // crypto section: device key (fingerprint) if (!TextUtils.isEmpty(deviceId) && !TextUtils.isEmpty(userId)) { mSession.getCrypto().getDeviceInfo(userId, deviceId, new SimpleApiCallback<MXDeviceInfo>() { @Override public void onSuccess(final MXDeviceInfo deviceInfo) { if ((null != deviceInfo) && !TextUtils.isEmpty(deviceInfo.fingerprint()) && (null != getActivity())) { VectorCustomActionEditTextPreference cryptoInfoTextPreference = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_KEY_PREFERENCE_KEY); if (null != cryptoInfoTextPreference) { cryptoInfoTextPreference.setSummary(deviceInfo.fingerprint()); cryptoInfoTextPreference.setOnPreferenceLongClickListener( new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() { @Override public boolean onPreferenceLongClick(Preference preference) { VectorUtils.copyToClipboard(getActivity(), deviceInfo.fingerprint()); return true; } }); } } } }); } // encrypt to unverified devices final CheckBoxPreference sendToUnverifiedDevicesPref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY); if (null != sendToUnverifiedDevicesPref) { sendToUnverifiedDevicesPref.setChecked(false); mSession.getCrypto().getGlobalBlacklistUnverifiedDevices(new SimpleApiCallback<Boolean>() { @Override public void onSuccess(Boolean status) { sendToUnverifiedDevicesPref.setChecked(status); } }); sendToUnverifiedDevicesPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { mSession.getCrypto().getGlobalBlacklistUnverifiedDevices(new SimpleApiCallback<Boolean>() { @Override public void onSuccess(Boolean status) { if (sendToUnverifiedDevicesPref.isChecked() != status) { mSession.getCrypto().setGlobalBlacklistUnverifiedDevices( sendToUnverifiedDevicesPref.isChecked(), new SimpleApiCallback<Void>() { @Override public void onSuccess(Void info) { } }); } } }); return true; } }); } }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context appContext = getActivity().getApplicationContext(); // retrieve the arguments Bundle args = getArguments();//from www .j av a 2 s.c o m String matrixId = args.getString(ARG_MATRIX_ID); mSession = Matrix.getInstance(appContext).getSession(matrixId); // sanity checks if ((null == mSession) || !mSession.isAlive()) { getActivity().finish(); return; } // define the layout addPreferencesFromResource(R.xml.vector_settings_preferences); if (null == mPushesRuleByResourceId) { mPushesRuleByResourceId = new HashMap<>(); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY, BingRule.RULE_ID_DISABLE_ALL); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, DUMMY_RULE); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY, DUMMY_RULE); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY, BingRule.RULE_ID_CONTAIN_DISPLAY_NAME); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CONTAINING_MY_USER_NAME_PREFERENCE_KEY, BingRule.RULE_ID_CONTAIN_USER_NAME); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY, BingRule.RULE_ID_ONE_TO_ONE_ROOM); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY, BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_INVITED_TO_ROOM_PREFERENCE_KEY, BingRule.RULE_ID_INVITE_ME); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_CALL_INVITATIONS_PREFERENCE_KEY, BingRule.RULE_ID_CALL); mPushesRuleByResourceId.put(PreferencesManager.SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY, BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS); } UserAvatarPreference avatarPreference = (UserAvatarPreference) findPreference( PreferencesManager.SETTINGS_PROFILE_PICTURE_PREFERENCE_KEY); avatarPreference.setSession(mSession); avatarPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { onUpdateAvatarClick(); return false; } }); EditTextPreference passwordPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY); passwordPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { onPasswordUpdateClick(); return false; } }); EditTextPreference notificationRingTonePreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_NOTIFICATION_RINGTONE_SELECTION_PREFERENCE_KEY); notificationRingTonePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); if (null != PreferencesManager.getNotificationRingTone(getActivity())) { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, PreferencesManager.getNotificationRingTone(getActivity())); } getActivity().startActivityForResult(intent, REQUEST_NOTIFICATION_RINGTONE); return false; } }); refreshNotificationRingTone(); EditTextPreference notificationPrivacyPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_NOTIFICATION_PRIVACY_PREFERENCE_KEY); if (notificationPrivacyPreference != null) { notificationPrivacyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(NotificationPrivacyActivity.getIntent(getActivity())); return true; } }); refreshNotificationPrivacy(); } // application version VectorCustomActionEditTextPreference versionTextPreference = (VectorCustomActionEditTextPreference) findPreference( PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY); if (null != versionTextPreference) { versionTextPreference.setSummary(VectorUtils.getApplicationVersion(appContext)); versionTextPreference.setOnPreferenceLongClickListener( new VectorCustomActionEditTextPreference.OnPreferenceLongClickListener() { @Override public boolean onPreferenceLongClick(Preference preference) { VectorUtils.copyToClipboard(appContext, VectorUtils.getApplicationVersion(appContext)); return true; } }); } // olm version EditTextPreference olmTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_OLM_VERSION_PREFERENCE_KEY); if (null != olmTextPreference) { olmTextPreference.setSummary( Matrix.getInstance(appContext).getDefaultSession().getCryptoVersion(appContext, false)); } // user account EditTextPreference accountIdTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_LOGGED_IN_PREFERENCE_KEY); if (null != accountIdTextPreference) { accountIdTextPreference.setSummary(mSession.getMyUserId()); } // home server EditTextPreference homeServerTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_HOME_SERVER_PREFERENCE_KEY); if (null != homeServerTextPreference) { homeServerTextPreference.setSummary(mSession.getHomeServerConfig().getHomeserverUri().toString()); } // identity server EditTextPreference identityServerTextPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_IDENTITY_SERVER_PREFERENCE_KEY); if (null != identityServerTextPreference) { identityServerTextPreference .setSummary(mSession.getHomeServerConfig().getIdentityServerUri().toString()); } // terms & conditions EditTextPreference termConditionsPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_APP_TERM_CONDITIONS_PREFERENCE_KEY); if (null != termConditionsPreference) { termConditionsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayAppTac(); return false; } }); } // Themes ListPreference themePreference = (ListPreference) findPreference(ThemeUtils.APPLICATION_THEME_KEY); if (null != themePreference) { themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue instanceof String) { VectorApp.updateApplicationTheme((String) newValue); getActivity().startActivity(getActivity().getIntent()); getActivity().finish(); return true; } else { return false; } } }); } // privacy policy EditTextPreference privacyPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_PRIVACY_POLICY_PREFERENCE_KEY); if (null != privacyPreference) { privacyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayAppPrivacyPolicy(); return false; } }); } // third party notice EditTextPreference thirdPartyNotices = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_THIRD_PARTY_NOTICES_PREFERENCE_KEY); if (null != thirdPartyNotices) { thirdPartyNotices.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayThirdPartyLicenses(); return false; } }); } // copyright EditTextPreference copyrightNotices = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_COPYRIGHT_PREFERENCE_KEY); if (null != copyrightNotices) { copyrightNotices.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { VectorUtils.displayAppCopyright(); return false; } }); } // update keep medias period final EditTextPreference keepMediaPeriodPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_MEDIA_SAVING_PERIOD_KEY); if (null != keepMediaPeriodPreference) { keepMediaPeriodPreference .setSummary(PreferencesManager.getSelectedMediasSavingPeriodString(getActivity())); keepMediaPeriodPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()) .setSingleChoiceItems(PreferencesManager.getMediasSavingItemsChoicesList(getActivity()), PreferencesManager.getSelectedMediasSavingPeriod(getActivity()), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int n) { PreferencesManager.setSelectedMediasSavingPeriod(getActivity(), n); d.cancel(); keepMediaPeriodPreference.setSummary(PreferencesManager .getSelectedMediasSavingPeriodString(getActivity())); } }) .show(); return false; } }); } // clear medias cache final EditTextPreference clearMediaCachePreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY); if (null != clearMediaCachePreference) { MXMediasCache.getCachesSize(getActivity(), new SimpleApiCallback<Long>() { @Override public void onSuccess(Long size) { if (null != getActivity()) { clearMediaCachePreference .setSummary(android.text.format.Formatter.formatFileSize(getActivity(), size)); } } }); clearMediaCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { displayLoadingView(); AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mSession.getMediasCache().clear(); Glide.get(getActivity()).clearDiskCache(); return null; } @Override protected void onPostExecute(Void result) { hideLoadingView(); MXMediasCache.getCachesSize(getActivity(), new SimpleApiCallback<Long>() { @Override public void onSuccess(Long size) { clearMediaCachePreference.setSummary( android.text.format.Formatter.formatFileSize(getActivity(), size)); } }); } }; try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (Exception e) { Log.e(LOG_TAG, "## mSession.getMediasCache().clear() failed " + e.getMessage()); task.cancel(true); hideLoadingView(); } return false; } }); } // clear cache final EditTextPreference clearCachePreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_CLEAR_CACHE_PREFERENCE_KEY); if (null != clearCachePreference) { MXSession.getApplicationSizeCaches(getActivity(), new SimpleApiCallback<Long>() { @Override public void onSuccess(Long size) { if (null != getActivity()) { clearCachePreference .setSummary(android.text.format.Formatter.formatFileSize(getActivity(), size)); } } }); clearCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { displayLoadingView(); Matrix.getInstance(appContext).reloadSessions(appContext); return false; } }); } final EditTextPreference displaynamePref = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY); displaynamePref.setSummary(mSession.getMyUser().displayname); displaynamePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { onDisplayNameClick((null == newValue) ? null : ((String) newValue).trim()); return false; } }); final VectorSwitchPreference urlPreviewPreference = (VectorSwitchPreference) findPreference( PreferencesManager.SETTINGS_SHOW_URL_PREVIEW_KEY); urlPreviewPreference.setChecked(mSession.isURLPreviewEnabled()); urlPreviewPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if ((null != newValue) && ((boolean) newValue != mSession.isURLPreviewEnabled())) { displayLoadingView(); mSession.setURLPreviewStatus((boolean) newValue, new ApiCallback<Void>() { @Override public void onSuccess(Void info) { urlPreviewPreference.setChecked(mSession.isURLPreviewEnabled()); hideLoadingView(); } private void onError(String errorMessage) { if (null != getActivity()) { Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show(); } onSuccess(null); } @Override public void onNetworkError(Exception e) { onError(e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { onError(e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { onError(e.getLocalizedMessage()); } }); } return false; } }); // push rules for (String resourceText : mPushesRuleByResourceId.keySet()) { final Preference preference = findPreference(resourceText); if (null != preference) { if (preference instanceof CheckBoxPreference) { preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValueAsVoid) { // on some old android APIs, // the callback is called even if there is no user interaction // so the value will be checked to ensure there is really no update. onPushRuleClick(preference.getKey(), (boolean) newValueAsVoid); return true; } }); } else if (preference instanceof BingRulePreference) { final BingRulePreference bingRulePreference = (BingRulePreference) preference; bingRulePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new AlertDialog.Builder(getActivity()).setSingleChoiceItems( bingRulePreference.getBingRuleStatuses(), bingRulePreference.getRuleStatusIndex(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int index) { BingRule rule = bingRulePreference.createRule(index); d.cancel(); if (null != rule) { displayLoadingView(); mSession.getDataHandler().getBingRulesManager().updateRule( bingRulePreference.getRule(), rule, new BingRulesManager.onBingRuleUpdateListener() { private void onDone() { refreshDisplay(); hideLoadingView(); } @Override public void onBingRuleUpdateSuccess() { onDone(); } @Override public void onBingRuleUpdateFailure( String errorMessage) { if (null != getActivity()) { Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show(); } onDone(); } }); } } }).show(); return true; } }); } } } // background sync tuning settings // these settings are useless and hidden if the app is registered to the GCM push service final GcmRegistrationManager gcmMgr = Matrix.getInstance(appContext).getSharedGCMRegistrationManager(); if (gcmMgr.useGCM() && gcmMgr.hasRegistrationToken()) { // Hide the section PreferenceScreen preferenceScreen = getPreferenceScreen(); PreferenceCategory backgroundSyncCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY); PreferenceCategory backgroundSyncDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY); preferenceScreen.removePreference(backgroundSyncDivider); preferenceScreen.removePreference(backgroundSyncCategory); } else { mSyncRequestTimeoutPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY); mSyncRequestDelayPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY); final CheckBoxPreference useBackgroundSyncPref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY); if (null != useBackgroundSyncPref) { final GcmRegistrationManager.ThirdPartyRegistrationListener listener = new GcmRegistrationManager.ThirdPartyRegistrationListener() { @Override public void onThirdPartyRegistered() { hideLoadingView(); } @Override public void onThirdPartyRegistrationFailed() { hideLoadingView(); } @Override public void onThirdPartyUnregistered() { hideLoadingView(); } @Override public void onThirdPartyUnregistrationFailed() { hideLoadingView(); } }; if (null != useBackgroundSyncPref) { useBackgroundSyncPref.setChecked(gcmMgr.isBackgroundSyncAllowed()); useBackgroundSyncPref .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object aNewValue) { final boolean newValue = (boolean) aNewValue; if (newValue != gcmMgr.isBackgroundSyncAllowed()) { gcmMgr.setBackgroundSyncAllowed(newValue); } displayLoadingView(); Matrix.getInstance(VectorSettingsPreferencesFragment.this.getActivity()) .getSharedGCMRegistrationManager().forceSessionsRegistration(listener); return true; } }); } } } mUserSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_USER_SETTINGS_PREFERENCE_KEY); mContactSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_CONTACT_PREFERENCE_KEYS); mPushersSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY); mPushersSettingsDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_NOTIFICATIONS_TARGET_DIVIDER_PREFERENCE_KEY); mIgnoredUserSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_IGNORED_USERS_PREFERENCE_KEY); mIgnoredUserSettingsCategoryDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_IGNORE_USERS_DIVIDER_PREFERENCE_KEY); mDevicesListSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_DEVICES_LIST_PREFERENCE_KEY); mDevicesListSettingsCategoryDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_DEVICES_DIVIDER_PREFERENCE_KEY); mCryptographyCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_CRYPTOGRAPHY_PREFERENCE_KEY); mCryptographyCategoryDivider = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_CRYPTOGRAPHY_DIVIDER_PREFERENCE_KEY); mLabsCategory = (PreferenceCategory) findPreference(PreferencesManager.SETTINGS_LABS_PREFERENCE_KEY); mGroupsFlairCategory = (PreferenceCategory) findPreference(PreferencesManager.SETTINGS_GROUPS_FLAIR_KEY); // preference to start the App info screen, to facilitate App permissions access Preference applicationInfoLInkPref = findPreference(APP_INFO_LINK_PREFERENCE_KEY); applicationInfoLInkPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (null != getActivity()) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromParts("package", appContext.getPackageName(), null); intent.setData(uri); getActivity().getApplicationContext().startActivity(intent); } return true; } }); // Contacts setContactsPreferences(); // user interface preferences setUserInterfacePreferences(); final CheckBoxPreference useCryptoPref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_PREFERENCE_KEY); final Preference cryptoIsEnabledPref = findPreference( PreferencesManager.SETTINGS_ROOM_SETTINGS_LABS_END_TO_END_IS_ACTIVE_PREFERENCE_KEY); cryptoIsEnabledPref.setEnabled(false); if (!mSession.isCryptoEnabled()) { useCryptoPref.setChecked(false); mLabsCategory.removePreference(cryptoIsEnabledPref); } else { mLabsCategory.removePreference(useCryptoPref); } useCryptoPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValueAsVoid) { if (TextUtils.isEmpty(mSession.getCredentials().deviceId)) { new AlertDialog.Builder(getActivity()) .setMessage(R.string.room_settings_labs_end_to_end_warnings) .setPositiveButton(R.string.logout, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); CommonActivityUtils.logout(getActivity()); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); useCryptoPref.setChecked(false); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); useCryptoPref.setChecked(false); } }).create().show(); } else { boolean newValue = (boolean) newValueAsVoid; if (mSession.isCryptoEnabled() != newValue) { displayLoadingView(); mSession.enableCrypto(newValue, new ApiCallback<Void>() { private void refresh() { if (null != getActivity()) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { hideLoadingView(); useCryptoPref.setChecked(mSession.isCryptoEnabled()); if (mSession.isCryptoEnabled()) { mLabsCategory.removePreference(useCryptoPref); mLabsCategory.addPreference(cryptoIsEnabledPref); } } }); } } @Override public void onSuccess(Void info) { useCryptoPref.setEnabled(false); refresh(); } @Override public void onNetworkError(Exception e) { useCryptoPref.setChecked(false); } @Override public void onMatrixError(MatrixError e) { useCryptoPref.setChecked(false); } @Override public void onUnexpectedError(Exception e) { useCryptoPref.setChecked(false); } }); } } return true; } }); // SaveMode Managment final CheckBoxPreference dataSaveModePref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_DATA_SAVE_MODE_PREFERENCE_KEY); dataSaveModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { List<MXSession> sessions = Matrix.getMXSessions(getActivity()); for (MXSession session : sessions) { session.setUseDataSaveMode((boolean) newValue); } return true; } }); // Analytics tracking managment final CheckBoxPreference useAnalyticsModePref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_USE_ANALYTICS_KEY); // On if the analytics tracking is activated useAnalyticsModePref.setChecked(PreferencesManager.useAnalytics(appContext)); useAnalyticsModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { PreferencesManager.setUseAnalytics(appContext, (boolean) newValue); return true; } }); // Rageshake Managment final CheckBoxPreference useRageShakeModePref = (CheckBoxPreference) findPreference( PreferencesManager.SETTINGS_USE_RAGE_SHAKE_KEY); final boolean mIsUsedRageShake = PreferencesManager.useRageshake(appContext); useRageShakeModePref.setChecked(mIsUsedRageShake); useRageShakeModePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { PreferencesManager.setUseRageshake(appContext, (boolean) newValue); return true; } }); // deactivate account EditTextPreference deactivateAccountPref = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_DEACTIVATE_ACCOUNT_KEY); if (null != deactivateAccountPref) { deactivateAccountPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(DeactivateAccountActivity.Companion.getIntent(getActivity())); return false; } }); } addButtons(); refreshPushersList(); refreshEmailsList(); refreshPhoneNumbersList(); refreshIgnoredUsersList(); refreshDevicesList(); refreshGroupFlairsList(); }