diff --git a/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java b/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java index 93f52380..2d21318e 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java @@ -349,15 +349,24 @@ public class OpenScale { return scaleDB.getScaleDataOfYear(selectedUserId, year); } - public void startSearchingForBluetooth(int btScales, String deviceName, Handler callbackBtHandler) { + public boolean startSearchingForBluetooth(String deviceName, Handler callbackBtHandler) { Log.d("OpenScale", "Bluetooth Server started! I am searching for device ..."); - btCom = BluetoothCommunication.getBtDevice(context, btScales); - btCom.registerCallbackHandler(callbackBtHandler); - btDeviceName = deviceName; + for (BluetoothCommunication.BT_DEVICE_ID btScaleID : BluetoothCommunication.BT_DEVICE_ID.values()) { + btCom = BluetoothCommunication.getBtDevice(context, btScaleID); - btCom.startSearching(btDeviceName); - } + if (btCom.checkDeviceName(deviceName)) { + btCom.registerCallbackHandler(callbackBtHandler); + btDeviceName = deviceName; + + btCom.startSearching(btDeviceName); + + return true; + } + } + + return false; + } public void stopSearchingForBluetooth() { if (btCom != null) { diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java index 2e7b7ba7..95b8c2e0 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java @@ -29,7 +29,6 @@ import android.util.Log; import com.health.openscale.core.datatypes.ScaleData; -import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.UUID; @@ -39,6 +38,7 @@ public abstract class BluetoothCommunication { BT_CONNECTION_LOST, BT_NO_DEVICE_FOUND, BT_UNEXPECTED_ERROR, BT_SCALE_MESSAGE }; public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE} + public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE} protected Context context; @@ -72,22 +72,22 @@ public abstract class BluetoothCommunication { * Create and return a new Bluetooth object. * * @param context In which context should the Bluetooth device created - * @param i the specific number of which Bluetooth device should be created (correspond to "deviceTypes" key in BluetoothPreferences) + * @param btDeviceID the specific device ID of which Bluetooth device should be created * @return created object specified by the number i otherwise null */ - public static BluetoothCommunication getBtDevice(Context context, int i) { - switch (i) { - case 0: + public static BluetoothCommunication getBtDevice(Context context, BT_DEVICE_ID btDeviceID) { + switch (btDeviceID) { + case CUSTOM_OPENSCALE: return new BluetoothCustomOpenScale(context); - case 1: + case MI_SCALE_V1: return new BluetoothMiScale(context); - case 2: + case SANITAS_SBF70: return new BluetoothSanitasSbf70(context); - case 3: + case MEDISANA_BS444: return new BluetoothMedisanaBS444(context); - case 4: + case DIGOO_DGS038H: return new BluetoothDigooDGSO38H(context); - case 5: + case EXCELVANT_CF369BLE: return new BluetoothExcelvanCF369BLE(context); } @@ -142,30 +142,17 @@ public abstract class BluetoothCommunication { } /** - * Is the Bluetooth initialized process supported. + * Check if the a device name is supported of the scale * - * @return true if it supported otherwise false + * @param btDeviceName the device name that is checked + * @return true if it valid otherwise false */ - public boolean initSupported() { - return true; - } + public boolean checkDeviceName(String btDeviceName) { + if (btDeviceName.toLowerCase().equals(defaultDeviceName().toLowerCase())) { + return true; + } - /** - * Is the Bluetooth transfer process supported. - * - * @return true if it supported otherwise false - */ - public boolean transferSupported() { - return true; - } - - /** - * Is the Bluetooth history process supported. - * - * @return true if it supported otherwise false - */ - public boolean historySupported() { - return true; + return false; } /** @@ -177,15 +164,6 @@ public abstract class BluetoothCommunication { return true; } - /** - * Should the device name checked while searching for a Bluetooth device. - * - * @return true if device name is checked otherwise false - */ - public boolean isDeviceNameCheck() { - return true; - } - /** * Return the Bluetooth device name * @@ -200,16 +178,6 @@ public abstract class BluetoothCommunication { */ abstract public String defaultDeviceName(); - /** - * Return all hardware addresses of the Bluetooth device. - * - * The format should be the first six hex values of a known Bluetooth hardware address without any colon e.g. 12:AB:65:12:34:52 becomes "12AB65" - * @note add hw address "FFFFFF" to skip check - * - * @return a list of all hardware addresses that are known for this device. - */ - abstract public ArrayList hwAddresses(); - /** * State machine for the initialization process of the Bluetooth device. * @@ -435,21 +403,13 @@ public abstract class BluetoothCommunication { return; } - for (int i = 0; i < hwAddresses().size(); i++) { - if (device.getAddress().replace(":", "").toUpperCase().startsWith(hwAddresses().get(i)) || hwAddresses().get(i) == "FFFFFF") { - if (isDeviceNameCheck()) { - if (!device.getName().toLowerCase().equals(btDeviceName.toLowerCase())) { - return; - } - } + if (device.getName().toLowerCase().equals(btDeviceName.toLowerCase())) { + Log.d("BluetoothCommunication", btDeviceName + " found trying to connect..."); - Log.d("BluetoothCommunication", btDeviceName + " found trying to connect..."); + bluetoothGatt = device.connectGatt(context, false, gattCallback); - bluetoothGatt = device.connectGatt(context, false, gattCallback); - - searchHandler.removeCallbacksAndMessages(null); - btAdapter.stopLeScan(scanCallback); - } + searchHandler.removeCallbacksAndMessages(null); + btAdapter.stopLeScan(scanCallback); } } catch (Exception e) { setBtStatus(BT_STATUS_CODE.BT_UNEXPECTED_ERROR, e.getMessage()); diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java index 9aec2dbe..386ca836 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java @@ -27,7 +27,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Set; import java.util.UUID; @@ -53,11 +52,6 @@ public class BluetoothCustomOpenScale extends BluetoothCommunication { return "openScale_MCU"; } - @Override - public ArrayList hwAddresses() { - return null; - } - @Override boolean nextInitCmd(int stateNr) { return false; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java index 372dbc82..7455386e 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java @@ -25,7 +25,6 @@ import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleData; import com.health.openscale.core.datatypes.ScaleUser; -import java.util.ArrayList; import java.util.Date; import java.util.UUID; @@ -48,14 +47,6 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication { return "Mengii"; } - @Override - public ArrayList hwAddresses() { - ArrayList hwAddresses = new ArrayList<>(); - hwAddresses.add("C8B21E"); - - return hwAddresses; - } - @Override public void onBluetoothDataRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic, int status) { } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF369BLE.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF369BLE.java index 0479a482..2f2f2eae 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF369BLE.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF369BLE.java @@ -24,13 +24,13 @@ import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleData; import com.health.openscale.core.datatypes.ScaleUser; -import java.util.ArrayList; import java.util.Date; import java.util.UUID; public class BluetoothExcelvanCF369BLE extends BluetoothCommunication { private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("f000ffc0-0451-4000-b000-000000000000"); private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000FFF0-0000-1000-8000-00805f9b34fb"); + private final UUID WEIGHT_CUSTOM0_CHARACTERISTIC = UUID.fromString("0000FFF4-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); public BluetoothExcelvanCF369BLE(Context context) { @@ -44,28 +44,14 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication { @Override public String defaultDeviceName() { - return "CF369BLE"; - } - - @Override - public boolean historySupported() { - return false; - } - - - @Override - public ArrayList hwAddresses() { - ArrayList hwAddresses = new ArrayList(); - hwAddresses.add("FFFFFF"); - - return hwAddresses; + return "Electronic Scale"; } @Override boolean nextInitCmd(int stateNr) { switch (stateNr) { case 0: - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG); + setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_CUSTOM0_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG); break; default: return false; @@ -105,6 +91,10 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication { writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, configBytes); break; + case 1: + byte[] invokeCmd = new byte[]{(byte)0x01, (byte)0x00}; + writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_CUSTOM0_CHARACTERISTIC, invokeCmd); + break; default: return false; } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java index 29722e43..de39559a 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java @@ -21,7 +21,6 @@ import android.content.Context; import com.health.openscale.core.datatypes.ScaleData; -import java.util.ArrayList; import java.util.Date; import java.util.UUID; @@ -52,25 +51,11 @@ public class BluetoothMedisanaBS444 extends BluetoothCommunication { } @Override - public boolean isDeviceNameCheck() { - return false; - } + public boolean checkDeviceName(String btDeviceName) { + if (btDeviceName.startsWith("013197")) { + return true; + } - @Override - public ArrayList hwAddresses() { - ArrayList hwAddresses = new ArrayList(); - hwAddresses.add("E454EB"); - hwAddresses.add("F13A88"); - hwAddresses.add("C9A68A"); - hwAddresses.add("D60211"); - hwAddresses.add("DB2FF6"); - hwAddresses.add("DA45CF"); - hwAddresses.add("CD9D0C"); - - return hwAddresses; - } - - public boolean initSupported() { return false; } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java index 82535bbd..ae6245ef 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java @@ -27,7 +27,6 @@ import com.health.openscale.core.datatypes.ScaleData; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; @@ -57,16 +56,6 @@ public class BluetoothMiScale extends BluetoothCommunication { return "MI_SCALE"; } - @Override - public ArrayList hwAddresses() { - ArrayList hwAddresses = new ArrayList(); - hwAddresses.add("880F10"); - hwAddresses.add("C80F10"); - hwAddresses.add("F9C28E"); - - return hwAddresses; - } - @Override public void onBluetoothDataRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic, int status) { byte[] data = gattCharacteristic.getValue(); diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java index 5d782e58..976df3e7 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java @@ -27,13 +27,12 @@ import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleData; import com.health.openscale.core.datatypes.ScaleUser; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; import java.text.SimpleDateFormat; -import java.io.ByteArrayOutputStream; +import java.util.Arrays; import java.util.Collections; import java.util.TreeSet; import java.util.UUID; @@ -120,24 +119,6 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication { return "SANITAS SBF70"; } - @Override - public ArrayList hwAddresses() { - ArrayList hwAddresses = new ArrayList(); - hwAddresses.add("FFFFFF"); - - return hwAddresses; - } - - @Override - public boolean initSupported() { - return true; - } - - @Override - public boolean historySupported() { - return true; - } - @Override boolean nextInitCmd(int stateNr) { diff --git a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java index 46c32b43..39feed8b 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java @@ -182,10 +182,9 @@ public class MainActivity extends ActionBarActivity implements SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String deviceName = prefs.getString("btDeviceName", "MI_SCALE"); - int deviceType = Integer.parseInt(prefs.getString("btDeviceTypes", "0")); // Check if Bluetooth 4.x is available - if (BluetoothCommunication.getBtDevice(getApplicationContext(), deviceType).isBLE()) { + if (deviceName != "openScale_MCU") { if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { setBluetoothStatusIcon(R.drawable.ic_bluetooth_disabled); Toast.makeText(getApplicationContext(), "Bluetooth 4.x " + getResources().getString(R.string.info_is_not_available), Toast.LENGTH_SHORT).show(); @@ -197,7 +196,9 @@ public class MainActivity extends ActionBarActivity implements setBluetoothStatusIcon(R.drawable.ic_bluetooth_searching); OpenScale.getInstance(getApplicationContext()).stopSearchingForBluetooth(); - OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(deviceType, deviceName, callbackBtHandler); + if (!OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(deviceName, callbackBtHandler)) { + Toast.makeText(getApplicationContext(), deviceName + " " + getResources().getString(R.string.label_bt_device_no_support), Toast.LENGTH_SHORT).show(); + } } private final Handler callbackBtHandler = new Handler() { diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothPreferences.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothPreferences.java index ebee1833..21ddcb28 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothPreferences.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothPreferences.java @@ -15,8 +15,11 @@ */ package com.health.openscale.gui.preferences; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; @@ -24,42 +27,109 @@ import android.preference.MultiSelectListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; -import android.text.Html; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; +import android.widget.BaseAdapter; import com.health.openscale.R; import com.health.openscale.core.bluetooth.BluetoothCommunication; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; -import static com.health.openscale.core.bluetooth.BluetoothCommunication.getBtDevice; - public class BluetoothPreferences extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String PREFERENCE_KEY_BLUETOOTH_DEVICE_TYPE = "btDeviceTypes"; - private static final String PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME = "btDeviceName"; private static final String PREFERENCE_KEY_BLUETOOTH_SMARTUSERASSIGN = "smartUserAssign"; private static final String PREFERENCE_KEY_BLUETOOTH_IGNOREOUTOFRANGE = "ignoreOutOfRange"; + private static final String PREFERENCE_KEY_BLUETOOTH_SCANNER = "btScanner"; - private ListPreference deviceTypes; - private EditTextPreference deviceName; private CheckBoxPreference smartAssignEnable; private CheckBoxPreference ignoreOutOfRangeEnable; + private PreferenceScreen btScanner; + + private BluetoothAdapter btAdapter = null; + private Handler searchHandler = null; + private BluetoothAdapter.LeScanCallback scanCallback = null; + + private Map foundDevices = new HashMap<>(); + + public void startSearching() { + foundDevices.clear(); + + if (scanCallback == null) + { + scanCallback = new BluetoothAdapter.LeScanCallback() + { + @Override + public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) { + if (device.getName() == null) { + return; + } + foundDevices.put(device.getAddress(), device.getName()); + + btScanner.removeAll(); + + for (Map.Entry entry : foundDevices.entrySet()) + { + if (getActivity() != null) { + Preference prefBtDevice = new Preference(getActivity().getBaseContext()); + prefBtDevice.setSummary(entry.getKey()); + + for (BluetoothCommunication.BT_DEVICE_ID btScaleID : BluetoothCommunication.BT_DEVICE_ID.values()) { + BluetoothCommunication btDevice = BluetoothCommunication.getBtDevice(getActivity().getBaseContext(), btScaleID); + + if (btDevice.checkDeviceName(entry.getValue())) { + prefBtDevice.setOnPreferenceClickListener(new onClickListenerDeviceSelect()); + prefBtDevice.setKey(entry.getKey()); + prefBtDevice.setIcon(R.drawable.ic_bluetooth_connection_lost); + prefBtDevice.setTitle(entry.getValue() + " [" + btDevice.deviceName() + "]"); + break; + } else { + prefBtDevice.setIcon(R.drawable.ic_bluetooth_disabled); + prefBtDevice.setTitle(entry.getValue() + " [" + getResources().getString(R.string.label_bt_device_no_support) + "]"); + } + } + + btScanner.addPreference(prefBtDevice); + } + } + } + }; + } + + + searchHandler.postDelayed(new Runnable() + { + @Override + public void run() + { + btAdapter.stopLeScan(scanCallback); + } + }, 10000); + + btAdapter.startLeScan(scanCallback); + } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + btAdapter = BluetoothAdapter.getDefaultAdapter(); + searchHandler = new Handler(); + addPreferencesFromResource(R.xml.bluetooth_preferences); - deviceTypes = (ListPreference)findPreference(PREFERENCE_KEY_BLUETOOTH_DEVICE_TYPE); - deviceName = (EditTextPreference)findPreference(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME); smartAssignEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_BLUETOOTH_SMARTUSERASSIGN); ignoreOutOfRangeEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_BLUETOOTH_IGNOREOUTOFRANGE); + btScanner = (PreferenceScreen) findPreference(PREFERENCE_KEY_BLUETOOTH_SCANNER); - deviceTypes.setOnPreferenceChangeListener(new deviceTypeOnPreferenceChangeListener()); + btScanner.setOnPreferenceClickListener(new onClickListenerScannerSelect()); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); + btScanner.setSummary(prefs.getString("btDeviceName", "-")); - updateBluetoothPreferences(); initSummary(getPreferenceScreen()); } @@ -74,29 +144,6 @@ public class BluetoothPreferences extends PreferenceFragment implements SharedPr } } - public void updateBluetoothPreferences() { - int i = 0; - - ArrayList btEntries = new ArrayList(); - ArrayList btEntryValues = new ArrayList(); - - while (true) { - BluetoothCommunication btCom = getBtDevice(getActivity().getApplicationContext(), i); - - if (btCom == null) { - break; - } - - btEntries.add(btCom.deviceName()); - btEntryValues.add(String.valueOf(i)); - - i++; - } - - deviceTypes.setEntries(btEntries.toArray(new CharSequence[btEntries.size()])); - deviceTypes.setEntryValues(btEntryValues.toArray(new CharSequence[btEntryValues.size()])); - } - @Override public void onResume() { super.onResume(); @@ -125,34 +172,7 @@ public class BluetoothPreferences extends PreferenceFragment implements SharedPr if (p instanceof ListPreference) { ListPreference listPref = (ListPreference) p; - int i = Integer.parseInt(listPref.getValue()); - - BluetoothCommunication btCom = BluetoothCommunication.getBtDevice(getActivity().getApplicationContext(), i); - - String summary = new String(); - - summary += listPref.getEntry() + "
" + - getResources().getString(R.string.label_bt_device_support) + ":" + "
"; - - if (btCom.initSupported()) { - summary += getResources().getString(R.string.label_bt_device_initialization) + ": " + getResources().getString(R.string.label_yes)+ "
"; - } else { - summary += getResources().getString(R.string.label_bt_device_initialization) + ": " + getResources().getString(R.string.label_no)+ "
"; - } - - if (btCom.transferSupported()) { - summary += getResources().getString(R.string.label_bt_device_data_transfer) + ": " + getResources().getString(R.string.label_yes)+ "
"; - } else { - summary += getResources().getString(R.string.label_bt_device_data_transfer) + ": " + getResources().getString(R.string.label_no)+ "
"; - } - - if (btCom.historySupported()) { - summary += getResources().getString(R.string.label_bt_device_data_history) + ": " + getResources().getString(R.string.label_yes); - } else { - summary += getResources().getString(R.string.label_bt_device_data_history) + ": " + getResources().getString(R.string.label_no); - } - - p.setSummary(Html.fromHtml(summary)); + p.setSummary(listPref.getTitle()); } if (p instanceof EditTextPreference) { @@ -181,17 +201,26 @@ public class BluetoothPreferences extends PreferenceFragment implements SharedPr } } - private class deviceTypeOnPreferenceChangeListener implements Preference.OnPreferenceChangeListener { - + private class onClickListenerScannerSelect implements Preference.OnPreferenceClickListener { @Override - public boolean onPreferenceChange(Preference p, Object o) { - int i = Integer.parseInt((String)o); + public boolean onPreferenceClick(Preference preference) { + startSearching(); + return true; + } + } - BluetoothCommunication btCom = BluetoothCommunication.getBtDevice(getActivity().getApplicationContext(), i); + private class onClickListenerDeviceSelect implements Preference.OnPreferenceClickListener { + @Override + public boolean onPreferenceClick(Preference preference) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); - deviceName.setSummary(btCom.defaultDeviceName()); - deviceName.setText(btCom.defaultDeviceName()); + prefs.edit().putString("btHwAddress", preference.getKey()).commit(); + prefs.edit().putString("btDeviceName", foundDevices.get(preference.getKey())).commit(); + btScanner.setSummary(preference.getTitle()); + ((BaseAdapter)getPreferenceScreen().getRootAdapter()).notifyDataSetChanged(); // hack to change the summary text + + btScanner.getDialog().dismiss(); return true; } } diff --git a/android_app/app/src/main/res/values-de/strings.xml b/android_app/app/src/main/res/values-de/strings.xml index edd24752..0f6a980e 100644 --- a/android_app/app/src/main/res/values-de/strings.xml +++ b/android_app/app/src/main/res/values-de/strings.xml @@ -40,7 +40,6 @@ Tage übrig Löschen Alles löschen - Gerätename Notiz auf den Datenpunkt Exportieren Körperfettanteil @@ -116,10 +115,6 @@ Wert ist erforderlich Statistiken Abbrechen - Bt Waage Datenhistorie - Bt Waage Datentransfer - Bt Waage Initialisierung - Folgendes wird unterstützt Datensicherung Exportiere Datensicherung Importiere Datensicherung @@ -131,4 +126,9 @@ Gebe dein Gewicht in deiner Einheit an Fehler Anfangsgewicht ist erforderlich Berechne Durchschnitt pro Tag/Monat + Gerät wird nicht unterstützt + Ziellinie + Gewichtsregressionsgerade + Regressions Polynomgrad + Suche nach Bluetooth Waagen \ No newline at end of file diff --git a/android_app/app/src/main/res/values-fr/strings.xml b/android_app/app/src/main/res/values-fr/strings.xml index 9b1a801c..da6f8632 100644 --- a/android_app/app/src/main/res/values-fr/strings.xml +++ b/android_app/app/src/main/res/values-fr/strings.xml @@ -106,7 +106,6 @@ Bluetooth Rechercher une balance au lancement de l\'application - Nom de l\'appareil Type d\'appareil Étiquette sur point de données diff --git a/android_app/app/src/main/res/values-ja/strings.xml b/android_app/app/src/main/res/values-ja/strings.xml index 7839541c..fd95cb3f 100644 --- a/android_app/app/src/main/res/values-ja/strings.xml +++ b/android_app/app/src/main/res/values-ja/strings.xml @@ -45,7 +45,6 @@ 起動時に体重計を探索します 過去30日 過去7日 - デバイス名 エクスポートに失敗しました インポートに失敗しました 身長が必要です diff --git a/android_app/app/src/main/res/values-pt/strings.xml b/android_app/app/src/main/res/values-pt/strings.xml index 2a16293e..962d17b4 100644 --- a/android_app/app/src/main/res/values-pt/strings.xml +++ b/android_app/app/src/main/res/values-pt/strings.xml @@ -66,9 +66,6 @@ Bluetooth IMC Altura - Histórico de dados da balança bt - Transferência de dados da balança bt - Inicialização da balança bt Cancelar Comentário Data @@ -77,7 +74,6 @@ Deletar Deletar tudo Confirmar deleção - Nome do dispositivo Tipo do dispositivo Etiquetas nos pontos de dados Circular pontos de dados @@ -105,7 +101,7 @@ OK não encontrado Linha de tendência de peso - Exponente da tendência + Exponente da tendência Lembrete Título da notificação Hora diff --git a/android_app/app/src/main/res/values/strings.xml b/android_app/app/src/main/res/values/strings.xml index 47f00449..c4923aa3 100644 --- a/android_app/app/src/main/res/values/strings.xml +++ b/android_app/app/src/main/res/values/strings.xml @@ -109,7 +109,7 @@ Bluetooth Search for scale on startup - Device Name + Searching for Bluetooth scales Device Type Label on data point @@ -138,10 +138,7 @@ Friday Saturday Sunday - Bt scale initialization - Bt scale data transfer - Bt scale data history - Following will supported + device not supported Export backup Import backup Backup @@ -151,7 +148,7 @@ Initial weight Calculate average per day/month Regression weight line - Regression order + Regression polynom degree Goal line diff --git a/android_app/app/src/main/res/xml/bluetooth_preferences.xml b/android_app/app/src/main/res/xml/bluetooth_preferences.xml index c47107f3..7a8cc53b 100644 --- a/android_app/app/src/main/res/xml/bluetooth_preferences.xml +++ b/android_app/app/src/main/res/xml/bluetooth_preferences.xml @@ -1,7 +1,11 @@ - - + + + diff --git a/android_app/app/src/main/res/xml/graph_preferences.xml b/android_app/app/src/main/res/xml/graph_preferences.xml index 1a55d731..4fa78e1a 100644 --- a/android_app/app/src/main/res/xml/graph_preferences.xml +++ b/android_app/app/src/main/res/xml/graph_preferences.xml @@ -6,5 +6,5 @@ - + \ No newline at end of file