@Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == btRFIDDefaultDevLP) { String defaultDeviceAddress = newValue.toString(); String defaultDeviceName = ""; for (int i = 0; i < pairedBTDeviceAddresses.size(); i++) { if (pairedBTDeviceAddresses.get(i).equals(defaultDeviceAddress)) { defaultDeviceName = pairedBTDeviceNames.get(i).toString(); } } btRFIDDefaultDevLP.setSummary(defaultDeviceName); SharedPreferenceManager.setSharedPreference( this, SharedPreferenceManager.SP_DEFAULT_BT_RFID_DEVICE_ADDRESS, defaultDeviceAddress); } return true; }
private void loadSetPreferences() { String defaultBTRFIDDevice = SharedPreferenceManager.getSharedPreference( this, SharedPreferenceManager.SP_DEFAULT_BT_RFID_DEVICE_ADDRESS, BluetoothHandler.DEFAULT_BT_MAC_ADDRESS); String btRFIDDefaultDevName = null; btRFIDDefaultDevLP.setValue(defaultBTRFIDDevice); if (!defaultBTRFIDDevice.equals(BluetoothHandler.DEFAULT_BT_MAC_ADDRESS)) { if (pairedBTDeviceAddresses != null && pairedBTDeviceNames != null) { for (int i = 0; i < pairedBTDeviceAddresses.size(); i++) { if (pairedBTDeviceAddresses.get(i).equals(defaultBTRFIDDevice)) { btRFIDDefaultDevName = pairedBTDeviceNames.get(i).toString(); } } if (btRFIDDefaultDevName == null) { // means that the default rfid device is no longer paired with this device. // set the default device to no device defaultBTRFIDDevice = BluetoothHandler.DEFAULT_BT_MAC_ADDRESS; SharedPreferenceManager.setSharedPreference( this, SharedPreferenceManager.SP_DEFAULT_BT_RFID_DEVICE_ADDRESS, BluetoothHandler.DEFAULT_BT_MAC_ADDRESS); Log.w( TAG, "The saved default bluetooth RFID device is no longer paired with this device. Setting the default bluetooth RFID device to nothing"); } } } btRFIDDefaultDevLP.setValue(defaultBTRFIDDevice); if (btRFIDDefaultDevName != null) { btRFIDDefaultDevLP.setSummary(btRFIDDefaultDevName); } else { btRFIDDefaultDevLP.setSummary(getString(R.string.pref_bt_rfid_default_dev_summary)); } }