mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-23 00:33:09 +02:00
implemented a BLE scanner for selecting a Bluetooth device
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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<String> 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());
|
||||
|
@@ -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<String> hwAddresses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean nextInitCmd(int stateNr) {
|
||||
return false;
|
||||
|
@@ -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<String> hwAddresses() {
|
||||
ArrayList<String> hwAddresses = new ArrayList<>();
|
||||
hwAddresses.add("C8B21E");
|
||||
|
||||
return hwAddresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBluetoothDataRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic, int status) {
|
||||
}
|
||||
|
@@ -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<String> 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;
|
||||
}
|
||||
|
@@ -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<String> 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;
|
||||
}
|
||||
|
||||
|
@@ -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<String> 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();
|
||||
|
@@ -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<String> 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) {
|
||||
|
||||
|
@@ -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() {
|
||||
|
@@ -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<String, String> 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<String, String> 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<String> btEntries = new ArrayList();
|
||||
ArrayList<String> 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() + "<br>" +
|
||||
getResources().getString(R.string.label_bt_device_support) + ":" + "<br>";
|
||||
|
||||
if (btCom.initSupported()) {
|
||||
summary += getResources().getString(R.string.label_bt_device_initialization) + ": " + getResources().getString(R.string.label_yes)+ "<br>";
|
||||
} else {
|
||||
summary += getResources().getString(R.string.label_bt_device_initialization) + ": " + getResources().getString(R.string.label_no)+ "<br>";
|
||||
}
|
||||
|
||||
if (btCom.transferSupported()) {
|
||||
summary += getResources().getString(R.string.label_bt_device_data_transfer) + ": " + getResources().getString(R.string.label_yes)+ "<br>";
|
||||
} else {
|
||||
summary += getResources().getString(R.string.label_bt_device_data_transfer) + ": " + getResources().getString(R.string.label_no)+ "<br>";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@
|
||||
<string name="label_days_left">Tage übrig</string>
|
||||
<string name="label_delete">Löschen</string>
|
||||
<string name="label_delete_all">Alles löschen</string>
|
||||
<string name="label_device_name">Gerätename</string>
|
||||
<string name="label_enable_labels">Notiz auf den Datenpunkt</string>
|
||||
<string name="label_export">Exportieren</string>
|
||||
<string name="label_fat">Körperfettanteil</string>
|
||||
@@ -116,10 +115,6 @@
|
||||
<string name="error_value_required">Wert ist erforderlich</string>
|
||||
<string name="title_statistics">Statistiken</string>
|
||||
<string name="label_cancel">Abbrechen</string>
|
||||
<string name="label_bt_device_data_history">Bt Waage Datenhistorie</string>
|
||||
<string name="label_bt_device_data_transfer">Bt Waage Datentransfer</string>
|
||||
<string name="label_bt_device_initialization">Bt Waage Initialisierung</string>
|
||||
<string name="label_bt_device_support">Folgendes wird unterstützt</string>
|
||||
<string name="label_backup">Datensicherung</string>
|
||||
<string name="label_exportBackup">Exportiere Datensicherung</string>
|
||||
<string name="label_importBackup">Importiere Datensicherung</string>
|
||||
@@ -131,4 +126,9 @@
|
||||
<string name="info_enter_goal_weight">Gebe dein Gewicht in deiner Einheit an</string>
|
||||
<string name="error_initial_weight_required">Fehler Anfangsgewicht ist erforderlich</string>
|
||||
<string name="label_average_data">Berechne Durchschnitt pro Tag/Monat</string>
|
||||
<string name="label_bt_device_no_support">Gerät wird nicht unterstützt</string>
|
||||
<string name="label_goal_line">Ziellinie</string>
|
||||
<string name="label_regression_line">Gewichtsregressionsgerade</string>
|
||||
<string name="label_regression_line_degree">Regressions Polynomgrad</string>
|
||||
<string name="label_bluetooth_searching">Suche nach Bluetooth Waagen</string>
|
||||
</resources>
|
@@ -106,7 +106,6 @@
|
||||
|
||||
<string name="label_bluetooth_title">Bluetooth</string>
|
||||
<string name="label_bluetooth_enable">Rechercher une balance au lancement de l\'application</string>
|
||||
<string name="label_device_name">Nom de l\'appareil</string>
|
||||
<string name="label_device_type">Type d\'appareil</string>
|
||||
|
||||
<string name="label_enable_labels">Étiquette sur point de données</string>
|
||||
|
@@ -45,7 +45,6 @@
|
||||
<string name="label_bluetooth_enable">起動時に体重計を探索します</string>
|
||||
<string name="label_last_month">過去30日</string>
|
||||
<string name="label_last_week">過去7日</string>
|
||||
<string name="label_device_name">デバイス名</string>
|
||||
<string name="error_exporting">エクスポートに失敗しました</string>
|
||||
<string name="error_importing">インポートに失敗しました</string>
|
||||
<string name="error_body_height_required">身長が必要です</string>
|
||||
|
@@ -66,9 +66,6 @@
|
||||
<string name="label_bluetooth_title">Bluetooth</string>
|
||||
<string name="label_bmi">IMC</string>
|
||||
<string name="label_body_height">Altura</string>
|
||||
<string name="label_bt_device_data_history">Histórico de dados da balança bt</string>
|
||||
<string name="label_bt_device_data_transfer">Transferência de dados da balança bt</string>
|
||||
<string name="label_bt_device_initialization">Inicialização da balança bt</string>
|
||||
<string name="label_cancel">Cancelar</string>
|
||||
<string name="label_comment">Comentário</string>
|
||||
<string name="label_date">Data</string>
|
||||
@@ -77,7 +74,6 @@
|
||||
<string name="label_delete">Deletar</string>
|
||||
<string name="label_delete_all">Deletar tudo</string>
|
||||
<string name="label_delete_confirmation">Confirmar deleção</string>
|
||||
<string name="label_device_name">Nome do dispositivo</string>
|
||||
<string name="label_device_type">Tipo do dispositivo</string>
|
||||
<string name="label_enable_labels">Etiquetas nos pontos de dados</string>
|
||||
<string name="label_enable_points">Circular pontos de dados</string>
|
||||
@@ -105,7 +101,7 @@
|
||||
<string name="label_ok">OK</string>
|
||||
<string name="label_not_found">não encontrado</string>
|
||||
<string name="label_regression_line">Linha de tendência de peso</string>
|
||||
<string name="label_regression_line_order">Exponente da tendência</string>
|
||||
<string name="label_regression_line_degree">Exponente da tendência</string>
|
||||
<string name="label_reminder">Lembrete</string>
|
||||
<string name="label_reminder_notify_text">Título da notificação</string>
|
||||
<string name="label_reminder_time">Hora</string>
|
||||
|
@@ -109,7 +109,7 @@
|
||||
|
||||
<string name="label_bluetooth_title">Bluetooth</string>
|
||||
<string name="label_bluetooth_enable">Search for scale on startup</string>
|
||||
<string name="label_device_name">Device Name</string>
|
||||
<string name="label_bluetooth_searching">Searching for Bluetooth scales</string>
|
||||
<string name="label_device_type">Device Type</string>
|
||||
|
||||
<string name="label_enable_labels">Label on data point</string>
|
||||
@@ -138,10 +138,7 @@
|
||||
<string name="Friday">Friday</string>
|
||||
<string name="Saturday">Saturday</string>
|
||||
<string name="Sunday">Sunday</string>
|
||||
<string name="label_bt_device_initialization">Bt scale initialization</string>
|
||||
<string name="label_bt_device_data_transfer">Bt scale data transfer</string>
|
||||
<string name="label_bt_device_data_history">Bt scale data history</string>
|
||||
<string name="label_bt_device_support">Following will supported</string>
|
||||
<string name="label_bt_device_no_support">device not supported</string>
|
||||
<string name="label_exportBackup">Export backup</string>
|
||||
<string name="label_importBackup">Import backup</string>
|
||||
<string name="label_backup">Backup</string>
|
||||
@@ -151,7 +148,7 @@
|
||||
<string name="label_initial_weight">Initial weight</string>
|
||||
<string name="label_average_data">Calculate average per day/month</string>
|
||||
<string name="label_regression_line">Regression weight line</string>
|
||||
<string name="label_regression_line_order">Regression order</string>
|
||||
<string name="label_regression_line_degree">Regression polynom degree</string>
|
||||
<string name="label_goal_line">Goal line</string>
|
||||
|
||||
|
||||
|
@@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListPreference android:title="@string/label_device_type" android:key="btDeviceTypes" android:defaultValue="0"/>
|
||||
<EditTextPreference android:title="@string/label_device_name" android:key="btDeviceName" android:defaultValue="openScale_MCU"/>
|
||||
<PreferenceScreen
|
||||
android:key="btScanner"
|
||||
android:title="@string/label_device_type"
|
||||
android:persistent="false">
|
||||
<Preference android:key="0" android:title="@string/label_bluetooth_searching"/>
|
||||
</PreferenceScreen>
|
||||
<CheckBoxPreference android:title="@string/label_bluetooth_enable" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="btEnable" android:defaultValue="false"/>
|
||||
<CheckBoxPreference android:title="@string/label_smartUserAssign" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="smartUserAssign" android:defaultValue="false"/>
|
||||
<CheckBoxPreference android:title="@string/label_ignoreOutOfRange" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="ignoreOutOfRange" android:enabled="false" android:defaultValue="false"/>
|
||||
|
@@ -6,5 +6,5 @@
|
||||
<CheckBoxPreference android:title="@string/label_average_data" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="averageData" android:defaultValue="true" />
|
||||
<CheckBoxPreference android:title="@string/label_goal_line" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="goalLine" android:defaultValue="true" />
|
||||
<CheckBoxPreference android:title="@string/label_regression_line" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="regressionLine" android:defaultValue="false" />
|
||||
<EditTextPreference android:title="@string/label_regression_line_order" android:key="regressionLineOrder" android:defaultValue="1" />
|
||||
<EditTextPreference android:title="@string/label_regression_line_degree" android:key="regressionLineOrder" android:defaultValue="1" />
|
||||
</PreferenceScreen>
|
Reference in New Issue
Block a user