1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-11 19:24:06 +02:00

Refer to the Bluetooth scale as the user's scale

This in an attempt to improve the first user experience, see #253.
This commit is contained in:
Erik Johansson
2018-04-29 01:19:39 +02:00
parent 93e37038ea
commit 210ef6ee3c
18 changed files with 39 additions and 37 deletions

View File

@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
import android.net.Uri;
@@ -62,6 +63,24 @@ public class BluetoothPreferences extends PreferenceFragment {
private Handler handler = null;
private Map<String, BluetoothDevice> foundDevices = new HashMap<>();
private static final String formatDeviceName(String name, String address) {
if (name.isEmpty() || address.isEmpty()) {
return "-";
}
return String.format("%s [%s]", name, address);
}
private static final String formatDeviceName(BluetoothDevice device) {
return formatDeviceName(device.getName(), device.getAddress());
}
private String getCurrentDeviceName() {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
return formatDeviceName(
prefs.getString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, ""),
prefs.getString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, ""));
}
private void startBluetoothDiscovery() {
foundDevices.clear();
btScanner.removeAll();
@@ -177,12 +196,12 @@ public class BluetoothPreferences extends PreferenceFragment {
}
Preference prefBtDevice = new Preference(getActivity());
prefBtDevice.setTitle(device.getName() + " [" + device.getAddress() + "]");
prefBtDevice.setTitle(formatDeviceName(device));
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(getActivity(), device.getName());
if (btDevice != null) {
Timber.d("Found supported device '%s' (driver: %s, type: %d) [%s]",
device.getName(), btDevice.driverName(), device.getType(), device.getAddress());
Timber.d("Found supported device %s (driver: %s, type: %d)",
formatDeviceName(device), btDevice.driverName(), device.getType());
prefBtDevice.setOnPreferenceClickListener(new onClickListenerDeviceSelect());
prefBtDevice.setKey(device.getAddress());
prefBtDevice.setIcon(R.drawable.ic_bluetooth_connection_lost);
@@ -192,8 +211,8 @@ public class BluetoothPreferences extends PreferenceFragment {
prefBtDevice.getIcon().setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
}
else {
Timber.d("Found unsupported device '%s' (type: %d) [%s]",
device.getName(), device.getType(), device.getAddress());
Timber.d("Found unsupported device %s (type: %d)",
formatDeviceName(device), device.getType());
prefBtDevice.setIcon(R.drawable.ic_bluetooth_disabled);
prefBtDevice.setSummary(R.string.label_bt_device_no_support);
prefBtDevice.setEnabled(false);
@@ -231,6 +250,12 @@ public class BluetoothPreferences extends PreferenceFragment {
}
};
private void updateBtScannerSummary() {
// Set summary text and trigger data set changed to make UI update
btScanner.setSummary(getCurrentDeviceName());
((BaseAdapter)getPreferenceScreen().getRootAdapter()).notifyDataSetChanged();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -258,13 +283,7 @@ public class BluetoothPreferences extends PreferenceFragment {
}
});
String deviceName = btScanner.getSharedPreferences().getString(
PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, "-");
if (!deviceName.equals("-")) {
deviceName += " [" + btScanner.getSharedPreferences().getString(
PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, "") + "]";
}
btScanner.setSummary(deviceName);
updateBtScannerSummary();
// Dummy preference to make screen open
btScanner.addPreference(new Preference(getActivity()));
@@ -307,7 +326,7 @@ public class BluetoothPreferences extends PreferenceFragment {
private void getDebugInfo(final BluetoothDevice device) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Fetching info")
.setMessage("Please wait while we fetch extended info from the device...")
.setMessage("Please wait while we fetch extended info from your scale...")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@@ -345,9 +364,7 @@ public class BluetoothPreferences extends PreferenceFragment {
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, device.getName())
.apply();
// Set summary text and trigger data set changed to make UI update
btScanner.setSummary(preference.getTitle());
((BaseAdapter)getPreferenceScreen().getRootAdapter()).notifyDataSetChanged();
updateBtScannerSummary();
stopDiscoveryAndLeScan();
btScanner.getDialog().dismiss();

View File

@@ -104,7 +104,6 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Buscar bàscula en iniciar</string>
<string name="label_bluetooth_searching">Buscant bàscules Bluetooth</string>
<string name="label_device_type">Tipus de dispositiu</string>
<string name="label_enable_labels">Etiqueta en el punt de mesura</string>
<string name="label_enable_points">Mostreu un punt en la mesura</string>

View File

@@ -92,7 +92,6 @@
<string name="question_really_delete_user">Opravdu chcete smazat tohoto uživatele?</string>
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_device_type">Typ zařízení</string>
<string name="label_delete_confirmation">Potvrzení smazání</string>

View File

@@ -77,7 +77,6 @@
<string name="info_bluetooth_connection_successful">Verbindung hergestellt</string>
<string name="info_bluetooth_no_device">Kein Bluetooth Gerät gefunden</string>
<string name="info_bluetooth_try_connection">Verbinde mit:</string>
<string name="label_device_type">Gerätetyp</string>
<string name="info_bluetooth_init">Initializiere Bluetooth Gerät</string>
<string name="label_smartUserAssign">Intelligente Benutzer-Zuweisung</string>
<string name="default_value_reminder_notify_text">Zeit zum Wiegen</string>

View File

@@ -104,7 +104,6 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Conectar a la báscula al iniciar</string>
<string name="label_bluetooth_searching">Buscando básculas Bluetooth</string>
<string name="label_device_type">Tipo de dispositivo</string>
<string name="label_enable_labels">Etiqueta de datos</string>
<string name="label_enable_points">Punto de datos</string>

View File

@@ -96,7 +96,6 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Se connecter à une balance au lancement de l\'application</string>
<string name="label_device_type">Type d\'appareil</string>
<string name="label_enable_labels">Étiquette sur les données</string>
<string name="label_enable_points">Point de données</string>

View File

@@ -77,7 +77,6 @@
<string name="info_bluetooth_connection_error">予期しないBluetoothエラー</string>
<string name="info_bluetooth_connection_lost">Bluetooth接続が切断されました</string>
<string name="info_bluetooth_connection_successful">接続が確立しました</string>
<string name="label_device_type">デバイスタイプ</string>
<string name="info_bluetooth_init">Bluetooth接続を初期化する</string>
<string name="default_value_reminder_notify_text">体重測定の時間</string>
<string name="label_reminder">リマインダー</string>

View File

@@ -113,7 +113,6 @@
<string name="label_mergeWithLastMeasurement">Flett med foregående måling</string>
<string name="label_bluetooth_searching">Søker etter Blåtannsvekt</string>
<string name="label_bluetooth_searching_finished">Søk fullført</string>
<string name="label_device_type">Enhetstype</string>
<string name="label_enable_labels">Dataetikett</string>
<string name="label_enable_points">Datapunkt</string>

View File

@@ -106,7 +106,6 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Zoek naar weegschaal bij opstarten</string>
<string name="label_bluetooth_searching">Zoeken naar Bluetooth weegschalen</string>
<string name="label_device_type">Apparaat Type</string>
<string name="label_enable_labels">Label op gegevenspunt</string>
<string name="label_enable_points">Punt op gegevenspunt</string>

View File

@@ -113,7 +113,6 @@
<string name="label_mergeWithLastMeasurement">Scal z ostatnim pomiarem</string>
<string name="label_bluetooth_searching">Wyszukuje wagi Bluetooth</string>
<string name="label_bluetooth_searching_finished">Wyszukiwanie zakończone</string>
<string name="label_device_type">Rodzaj urządzenia</string>
<string name="label_enable_labels">Etykiety danych</string>
<string name="label_enable_points">Punkt danych</string>

View File

@@ -60,7 +60,6 @@
<string name="label_delete">Apagar</string>
<string name="label_delete_all">Apagar tudo</string>
<string name="label_delete_confirmation">Confirma remoção</string>
<string name="label_device_type">Tipo de dispositivo</string>
<string name="label_enable_labels">Etiquetas nos pontos de dados</string>
<string name="label_enable_points">Circular pontos de dados</string>
<string name="label_export">Exportar</string>

View File

@@ -113,7 +113,6 @@
<string name="label_mergeWithLastMeasurement">Adaugă la ultima măsurătoare</string>
<string name="label_bluetooth_searching">În curs de căutare a unui cântar Bluetooth</string>
<string name="label_bluetooth_searching_finished">Căutare încheiată</string>
<string name="label_device_type">Tip de aparat</string>
<string name="label_enable_labels">Etichetare date</string>
<string name="label_enable_points">Poziție</string>

View File

@@ -87,7 +87,6 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Vyhľadať váhu po spustení</string>
<string name="label_bluetooth_searching">Prebieha vyhľadávanie Bluetooth váhy</string>
<string name="label_device_type">Typ zariadenia</string>
<string name="label_enable_labels">Štítok na údajový bod</string>
<string name="label_enable_points">Bod na údajový bod</string>
<string name="label_delete_confirmation">Potvrďte vymazanie</string>

View File

@@ -103,8 +103,7 @@
<string name="question_really_delete_user">Ta bort användare?</string>
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Anslut till våg vid start</string>
<string name="label_bluetooth_searching">Söker efter Bluetooth-våg</string>
<string name="label_device_type">Enhetstyp</string>
<string name="label_bluetooth_searching">Söker efter din Bluetooth-våg</string>
<string name="label_enable_labels">Dataetikett</string>
<string name="label_enable_points">Datapunkt</string>
<string name="label_delete_confirmation">Borttagningsbekräftelse</string>
@@ -202,4 +201,5 @@
<string name="label_monthly">månadsvis</string>
<string name="label_development">Utveckling</string>
<string name="label_debug_log">Spara felsökningslogg till fil</string>
<string name="label_your_bluetooth_scale">Din Bluetooth-våg</string>
</resources>

View File

@@ -102,7 +102,6 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Baskülü aramaya baþlandý</string>
<string name="label_bluetooth_searching">Bluetooth Baskül aranýyor</string>
<string name="label_device_type">Cihaz Tipi</string>
<string name="label_enable_labels">Label on data point</string>
<string name="label_enable_points">Point on data point</string>

View File

@@ -111,7 +111,6 @@
<string name="label_mergeWithLastMeasurement">滙合舊有測量數值</string>
<string name="label_bluetooth_searching">藍芽量重器搜尋中</string>
<string name="label_bluetooth_searching_finished">搜尋完成</string>
<string name="label_device_type">器材類別</string>
<string name="label_enable_labels">數據標記</string>
<string name="label_enable_points">數據點</string>

View File

@@ -113,9 +113,8 @@
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Connect to scale on startup</string>
<string name="label_mergeWithLastMeasurement">Merge with last measurement</string>
<string name="label_bluetooth_searching">Searching for Bluetooth scales</string>
<string name="label_bluetooth_searching">Searching for your Bluetooth scale</string>
<string name="label_bluetooth_searching_finished">Search finished</string>
<string name="label_device_type">Device Type</string>
<string name="label_enable_labels">Data label</string>
<string name="label_enable_points">Data point</string>
@@ -219,4 +218,5 @@
<string name="label_click_to_help_add_support">Click here to help add support for it</string>
<string name="label_development">Development</string>
<string name="label_debug_log">Save debug log to file</string>
<string name="label_your_bluetooth_scale">Your Bluetooth scale</string>
</resources>

View File

@@ -2,9 +2,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
android:key="btScanner"
android:title="@string/label_device_type"
android:persistent="false">
</PreferenceScreen>
android:title="@string/label_your_bluetooth_scale"
android:persistent="false" />
<CheckBoxPreference
android:defaultValue="true"
android:key="mergeWithLastMeasurement"