1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-20 23:41:45 +02:00

add an option for searching a Bluetooth scale on startup

This commit is contained in:
OliE
2016-12-21 09:46:57 +01:00
parent 4b0c2c20f6
commit 33ed28cbbb
6 changed files with 28 additions and 41 deletions

View File

@@ -98,7 +98,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />

View File

@@ -56,8 +56,8 @@ public class MainActivity extends ActionBarActivity implements
*/ */
private SectionsPagerAdapter mSectionsPagerAdapter; private SectionsPagerAdapter mSectionsPagerAdapter;
private static boolean firstAppStart = false; private static boolean firstAppStart = true;
private static int bluetoothStatusIcon = 0; private static int bluetoothStatusIcon = R.drawable.bluetooth_disabled;
private static MenuItem bluetoothStatus; private static MenuItem bluetoothStatus;
/** /**
@@ -127,10 +127,12 @@ public class MainActivity extends ActionBarActivity implements
bluetoothStatus = menu.findItem(R.id.action_bluetooth_status); bluetoothStatus = menu.findItem(R.id.action_bluetooth_status);
// Just search for a bluetooth device just once at the start of the app SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!firstAppStart) {
// Just search for a bluetooth device just once at the start of the app and if start preference enabled
if (firstAppStart && prefs.getBoolean("btEnable", false)) {
invokeSearchBluetoothDevice(); invokeSearchBluetoothDevice();
firstAppStart = true; firstAppStart = false;
} else { } else {
// Set current bluetooth status icon while e.g. orientation changes // Set current bluetooth status icon while e.g. orientation changes
setBluetoothStatusIcon(bluetoothStatusIcon); setBluetoothStatusIcon(bluetoothStatusIcon);
@@ -155,9 +157,9 @@ public class MainActivity extends ActionBarActivity implements
if (id == R.id.action_bluetooth_status) { if (id == R.id.action_bluetooth_status) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("btEnable", false) && BluetoothAdapter.getDefaultAdapter().isEnabled()) { if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
String deviceName = prefs.getString("btDeviceName", "MI_SCALE"); String deviceName = prefs.getString("btDeviceName", "MI_SCALE");
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_reconnection) + " " + deviceName, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_connection) + " " + deviceName, Toast.LENGTH_SHORT).show();
invokeSearchBluetoothDevice(); invokeSearchBluetoothDevice();
} else { } else {
setBluetoothStatusIcon(R.drawable.bluetooth_disabled); setBluetoothStatusIcon(R.drawable.bluetooth_disabled);
@@ -183,26 +185,22 @@ public class MainActivity extends ActionBarActivity implements
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(prefs.getBoolean("btEnable", false)) { String deviceName = prefs.getString("btDeviceName", "MI_SCALE");
String deviceName = prefs.getString("btDeviceName", "MI_SCALE"); String deviceType = prefs.getString("btDeviceTypes", "0");
String deviceType = prefs.getString("btDeviceTypes", "0");
// Check if Bluetooth 4.x is available // Check if Bluetooth 4.x is available
if (Integer.parseInt(deviceType) == BluetoothCommunication.BT_MI_SCALE) { if (Integer.parseInt(deviceType) == BluetoothCommunication.BT_MI_SCALE) {
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
setBluetoothStatusIcon(R.drawable.bluetooth_disabled); setBluetoothStatusIcon(R.drawable.bluetooth_disabled);
Toast.makeText(getApplicationContext(), "Bluetooth 4.x " + getResources().getString(R.string.info_is_not_available), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Bluetooth 4.x " + getResources().getString(R.string.info_is_not_available), Toast.LENGTH_SHORT).show();
return; return;
}
} }
setBluetoothStatusIcon(R.drawable.bluetooth_searching);
OpenScale.getInstance(getApplicationContext()).stopSearchingForBluetooth();
OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(Integer.parseInt(deviceType), deviceName, callbackBtHandler);
} else {
setBluetoothStatusIcon(R.drawable.bluetooth_disabled);
} }
setBluetoothStatusIcon(R.drawable.bluetooth_searching);
OpenScale.getInstance(getApplicationContext()).stopSearchingForBluetooth();
OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(Integer.parseInt(deviceType), deviceName, callbackBtHandler);
} }
private final Handler callbackBtHandler = new Handler() { private final Handler callbackBtHandler = new Handler() {

View File

@@ -135,16 +135,6 @@ private void updatePrefSummary(Preference p) {
EditTextPreference editTextPref = (EditTextPreference) p; EditTextPreference editTextPref = (EditTextPreference) p;
p.setSummary(editTextPref.getText()); p.setSummary(editTextPref.getText());
} }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(prefs.getBoolean("btEnable", true))
{
findPreference("btDeviceName").setEnabled(true);
findPreference("btDeviceTypes").setEnabled(true);
} else {
findPreference("btDeviceName").setEnabled(false);
findPreference("btDeviceTypes").setEnabled(false);
}
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) protected void onActivityResult(int requestCode, int resultCode, Intent data)

View File

@@ -38,7 +38,7 @@
<string name="info_your_weight">Dein Gewicht war</string> <string name="info_your_weight">Dein Gewicht war</string>
<string name="label_add">Hinzufügen</string> <string name="label_add">Hinzufügen</string>
<string name="label_birthday">Geburtstag</string> <string name="label_birthday">Geburtstag</string>
<string name="label_bluetooth_enable">Suche nach Bluetooth Waage</string> <string name="label_bluetooth_enable">Suche nach Waage beim Start</string>
<string name="label_bluetooth_title">Bluetooth</string> <string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bmi">BMI</string> <string name="label_bmi">BMI</string>
<string name="label_body_height">Körpergröße</string> <string name="label_body_height">Körpergröße</string>
@@ -101,7 +101,7 @@
<string name="info_bluetooth_connection_lost">Bluetooth Verbindung verloren</string> <string name="info_bluetooth_connection_lost">Bluetooth Verbindung verloren</string>
<string name="info_bluetooth_connection_successful">Verbindung erfolgreich hergestellt</string> <string name="info_bluetooth_connection_successful">Verbindung erfolgreich hergestellt</string>
<string name="info_bluetooth_no_device">Kein Bluetooth Gerät gefunden</string> <string name="info_bluetooth_no_device">Kein Bluetooth Gerät gefunden</string>
<string name="info_bluetooth_try_reconnection">Versuche Verbindung herzustellen zu</string> <string name="info_bluetooth_try_connection">Versuche Verbindung herzustellen zu</string>
<string name="label_device_type">Gerätetyp</string> <string name="label_device_type">Gerätetyp</string>
<string name="info_bluetooth_init">Initializiere Bluetooth Gerät</string> <string name="info_bluetooth_init">Initializiere Bluetooth Gerät</string>
</resources> </resources>

View File

@@ -42,7 +42,7 @@
<string name="label_title_last_measurement">最終の計測</string> <string name="label_title_last_measurement">最終の計測</string>
<string name="label_goal_date_is">目標期日は</string> <string name="label_goal_date_is">目標期日は</string>
<string name="label_delete_all">全てデリート</string> <string name="label_delete_all">全てデリート</string>
<string name="label_bluetooth_enable">Bluetoothの体重計を探索す</string> <string name="label_bluetooth_enable">起動時に体重計を探索しま</string>
<string name="label_last_month">過去30日</string> <string name="label_last_month">過去30日</string>
<string name="label_last_week">過去7日</string> <string name="label_last_week">過去7日</string>
<string name="label_device_name">デバイス名</string> <string name="label_device_name">デバイス名</string>
@@ -98,7 +98,7 @@
<string name="label_whr">ウエストヒップ比</string> <string name="label_whr">ウエストヒップ比</string>
<string name="action_bluetooth_status">Bluetoothステータス</string> <string name="action_bluetooth_status">Bluetoothステータス</string>
<string name="info_bluetooth_no_device">Bluetooth接続を確立できなかった場合</string> <string name="info_bluetooth_no_device">Bluetooth接続を確立できなかった場合</string>
<string name="info_bluetooth_try_reconnection">接続しようとしています</string> <string name="info_bluetooth_try_connection">接続しようとしています</string>
<string name="info_bluetooth_connection_error">Bluetoothに予期しないエラーがあります</string> <string name="info_bluetooth_connection_error">Bluetoothに予期しないエラーがあります</string>
<string name="info_bluetooth_connection_lost">Bluetooth接続を失いました</string> <string name="info_bluetooth_connection_lost">Bluetooth接続を失いました</string>
<string name="info_bluetooth_connection_successful">接続に成功しました</string> <string name="info_bluetooth_connection_successful">接続に成功しました</string>

View File

@@ -92,7 +92,7 @@
<string name="info_is_not_available">is not available</string> <string name="info_is_not_available">is not available</string>
<string name="info_delete_bluetooth_data">Clear all Bluetooth data</string> <string name="info_delete_bluetooth_data">Clear all Bluetooth data</string>
<string name="info_delete_bluetooth_data_success">Bluetooth data was successful cleared</string> <string name="info_delete_bluetooth_data_success">Bluetooth data was successful cleared</string>
<string name="info_bluetooth_try_reconnection">Trying to reconnect to</string> <string name="info_bluetooth_try_connection">Trying to connect to</string>
<string name="info_bluetooth_connection_lost">Lost Bluetooth connection.</string> <string name="info_bluetooth_connection_lost">Lost Bluetooth connection.</string>
<string name="info_bluetooth_no_device">No Bluetooth device found</string> <string name="info_bluetooth_no_device">No Bluetooth device found</string>
<string name="info_bluetooth_connection_successful">Connection successful established</string> <string name="info_bluetooth_connection_successful">Connection successful established</string>
@@ -107,7 +107,7 @@
<string name="question_really_delete_user">Do you really want to delete the user? </string> <string name="question_really_delete_user">Do you really want to delete the user? </string>
<string name="label_bluetooth_title">Bluetooth</string> <string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Search for Bluetooth scale</string> <string name="label_bluetooth_enable">Search for scale on startup</string>
<string name="label_device_name">Device Name</string> <string name="label_device_name">Device Name</string>
<string name="label_device_type">Device Type</string> <string name="label_device_type">Device Type</string>