Make list refresh automatically when Miband MAC was entered or removed. Update README.md
parent
ee0b92ac44
commit
b74319fee9
|
@ -29,8 +29,8 @@ How to use (Miband):
|
||||||
|
|
||||||
1. Add your Mibands MAC address manually for now (Settings -> Debug)
|
1. Add your Mibands MAC address manually for now (Settings -> Debug)
|
||||||
2. Configure other notifications as desired
|
2. Configure other notifications as desired
|
||||||
3. Restart Gadgetbridge, after that, the device should be visible
|
3. Go back to the "Gadgetbridge" Activity
|
||||||
4. Tap it to connect
|
4. Tap the "MI" device to connect
|
||||||
5. To test, chose "Debug" from the menu and play around
|
5. To test, chose "Debug" from the menu and play around
|
||||||
|
|
||||||
Known Issues:
|
Known Issues:
|
||||||
|
|
|
@ -49,10 +49,8 @@ public class ControlCenter extends Activity {
|
||||||
String deviceAddress = intent.getStringExtra("device_address");
|
String deviceAddress = intent.getStringExtra("device_address");
|
||||||
GBDevice.State state = GBDevice.State.values()[intent.getIntExtra("device_state", 0)];
|
GBDevice.State state = GBDevice.State.values()[intent.getIntExtra("device_state", 0)];
|
||||||
String firmwareVersion = intent.getStringExtra("firmware_version");
|
String firmwareVersion = intent.getStringExtra("firmware_version");
|
||||||
if (deviceList.isEmpty()) {
|
|
||||||
refreshPairedDevices();
|
refreshPairedDevices();
|
||||||
mGBDeviceAdapter.notifyDataSetChanged();
|
mGBDeviceAdapter.notifyDataSetChanged();
|
||||||
}
|
|
||||||
if (deviceAddress != null) {
|
if (deviceAddress != null) {
|
||||||
for (GBDevice device : deviceList) {
|
for (GBDevice device : deviceList) {
|
||||||
if (device.getAddress().equals(deviceAddress)) {
|
if (device.getAddress().equals(deviceAddress)) {
|
||||||
|
@ -118,6 +116,7 @@ public class ControlCenter extends Activity {
|
||||||
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
|
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||||
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
|
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
|
||||||
startService(versionInfoIntent);
|
startService(versionInfoIntent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -147,11 +146,9 @@ public class ControlCenter extends Activity {
|
||||||
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
|
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_refresh:
|
case R.id.action_refresh:
|
||||||
if (deviceList.isEmpty()) {
|
|
||||||
refreshPairedDevices();
|
refreshPairedDevices();
|
||||||
mGBDeviceAdapter.notifyDataSetChanged();
|
mGBDeviceAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +160,16 @@ public class ControlCenter extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshPairedDevices() {
|
private void refreshPairedDevices() {
|
||||||
|
GBDevice connectedDevice = null;
|
||||||
|
for (GBDevice device : deviceList) {
|
||||||
|
if (device.getState() == GBDevice.State.CONNECTED) {
|
||||||
|
connectedDevice = device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviceList.clear();
|
||||||
|
|
||||||
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
if (btAdapter == null) {
|
if (btAdapter == null) {
|
||||||
Toast.makeText(this, "Bluetooth is not supported.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Bluetooth is not supported.", Toast.LENGTH_SHORT).show();
|
||||||
} else if (!btAdapter.isEnabled()) {
|
} else if (!btAdapter.isEnabled()) {
|
||||||
|
@ -171,7 +177,7 @@ public class ControlCenter extends Activity {
|
||||||
} else {
|
} else {
|
||||||
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
||||||
for (BluetoothDevice device : pairedDevices) {
|
for (BluetoothDevice device : pairedDevices) {
|
||||||
GBDevice.Type deviceType = GBDevice.Type.UNKNOWN;
|
GBDevice.Type deviceType;
|
||||||
if (device.getName().indexOf("Pebble") == 0) {
|
if (device.getName().indexOf("Pebble") == 0) {
|
||||||
deviceType = GBDevice.Type.PEBBLE;
|
deviceType = GBDevice.Type.PEBBLE;
|
||||||
} else if (device.getName().equals("MI")) {
|
} else if (device.getName().equals("MI")) {
|
||||||
|
@ -179,8 +185,12 @@ public class ControlCenter extends Activity {
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (connectedDevice != null && (device.getAddress().equals(connectedDevice.getAddress()))) {
|
||||||
|
deviceList.add(connectedDevice);
|
||||||
|
} else {
|
||||||
deviceList.add(new GBDevice(device.getAddress(), device.getName(), deviceType));
|
deviceList.add(new GBDevice(device.getAddress(), device.getName(), deviceType));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String miAddr = sharedPrefs.getString("development_miaddr", null);
|
String miAddr = sharedPrefs.getString("development_miaddr", null);
|
||||||
|
@ -188,7 +198,9 @@ public class ControlCenter extends Activity {
|
||||||
deviceList.add(new GBDevice(miAddr, "MI", GBDevice.Type.MIBAND));
|
deviceList.add(new GBDevice(miAddr, "MI", GBDevice.Type.MIBAND));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deviceList.isEmpty()) {
|
if (connectedDevice != null) {
|
||||||
|
hintTextView.setText("tap connected device for App Mananger");
|
||||||
|
} else if (!deviceList.isEmpty()) {
|
||||||
hintTextView.setText("tap a device to connect");
|
hintTextView.setText("tap a device to connect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
public class SettingsActivity extends PreferenceActivity {
|
public class SettingsActivity extends PreferenceActivity {
|
||||||
|
@ -49,10 +50,25 @@ public class SettingsActivity extends PreferenceActivity {
|
||||||
getPreferenceScreen().addPreference(fakeHeaderDev);
|
getPreferenceScreen().addPreference(fakeHeaderDev);
|
||||||
addPreferencesFromResource(R.xml.pref_development);
|
addPreferencesFromResource(R.xml.pref_development);
|
||||||
|
|
||||||
|
|
||||||
|
final Preference developmentMiaddr = findPreference("development_miaddr");
|
||||||
|
bindPreferenceSummaryToValue(developmentMiaddr);
|
||||||
|
|
||||||
|
developmentMiaddr.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
|
Intent refreshIntent = new Intent(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
||||||
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent);
|
||||||
|
preference.setSummary(newVal.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
|
||||||
// their values. When their values change, their summaries are updated
|
// their values. When their values change, their summaries are updated
|
||||||
// to reflect the new value, per the Android Design guidelines.
|
// to reflect the new value, per the Android Design guidelines.
|
||||||
bindPreferenceSummaryToValue(findPreference("development_miaddr"));
|
|
||||||
//bindPreferenceSummaryToValue(findPreference("notifications_sms_whenscreenon"));
|
//bindPreferenceSummaryToValue(findPreference("notifications_sms_whenscreenon"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue