1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 02:46:50 +01:00

Make list refresh automatically when Miband MAC was entered or removed. Update README.md

This commit is contained in:
Andreas Shimokawa 2015-04-19 12:35:23 +02:00
parent ee0b92ac44
commit b74319fee9
3 changed files with 42 additions and 14 deletions

View File

@ -29,8 +29,8 @@ How to use (Miband):
1. Add your Mibands MAC address manually for now (Settings -> Debug)
2. Configure other notifications as desired
3. Restart Gadgetbridge, after that, the device should be visible
4. Tap it to connect
3. Go back to the "Gadgetbridge" Activity
4. Tap the "MI" device to connect
5. To test, chose "Debug" from the menu and play around
Known Issues:

View File

@ -49,10 +49,8 @@ public class ControlCenter extends Activity {
String deviceAddress = intent.getStringExtra("device_address");
GBDevice.State state = GBDevice.State.values()[intent.getIntExtra("device_state", 0)];
String firmwareVersion = intent.getStringExtra("firmware_version");
if (deviceList.isEmpty()) {
refreshPairedDevices();
mGBDeviceAdapter.notifyDataSetChanged();
}
refreshPairedDevices();
mGBDeviceAdapter.notifyDataSetChanged();
if (deviceAddress != null) {
for (GBDevice device : deviceList) {
if (device.getAddress().equals(deviceAddress)) {
@ -118,6 +116,7 @@ public class ControlCenter extends Activity {
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
startService(versionInfoIntent);
}
@Override
@ -147,10 +146,8 @@ public class ControlCenter extends Activity {
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
return true;
case R.id.action_refresh:
if (deviceList.isEmpty()) {
refreshPairedDevices();
mGBDeviceAdapter.notifyDataSetChanged();
}
refreshPairedDevices();
mGBDeviceAdapter.notifyDataSetChanged();
}
return super.onOptionsItemSelected(item);
@ -163,7 +160,16 @@ public class ControlCenter extends Activity {
}
private void refreshPairedDevices() {
GBDevice connectedDevice = null;
for (GBDevice device : deviceList) {
if (device.getState() == GBDevice.State.CONNECTED) {
connectedDevice = device;
}
}
deviceList.clear();
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
Toast.makeText(this, "Bluetooth is not supported.", Toast.LENGTH_SHORT).show();
} else if (!btAdapter.isEnabled()) {
@ -171,7 +177,7 @@ public class ControlCenter extends Activity {
} else {
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
for (BluetoothDevice device : pairedDevices) {
GBDevice.Type deviceType = GBDevice.Type.UNKNOWN;
GBDevice.Type deviceType;
if (device.getName().indexOf("Pebble") == 0) {
deviceType = GBDevice.Type.PEBBLE;
} else if (device.getName().equals("MI")) {
@ -179,7 +185,11 @@ public class ControlCenter extends Activity {
} else {
continue;
}
deviceList.add(new GBDevice(device.getAddress(), device.getName(), deviceType));
if (connectedDevice != null && (device.getAddress().equals(connectedDevice.getAddress()))) {
deviceList.add(connectedDevice);
} else {
deviceList.add(new GBDevice(device.getAddress(), device.getName(), deviceType));
}
}
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
@ -188,7 +198,9 @@ public class ControlCenter extends Activity {
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");
}
}

View File

@ -8,6 +8,7 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v4.content.LocalBroadcastManager;
import android.view.MenuItem;
public class SettingsActivity extends PreferenceActivity {
@ -49,10 +50,25 @@ public class SettingsActivity extends PreferenceActivity {
getPreferenceScreen().addPreference(fakeHeaderDev);
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
// their values. When their values change, their summaries are updated
// to reflect the new value, per the Android Design guidelines.
bindPreferenceSummaryToValue(findPreference("development_miaddr"));
//bindPreferenceSummaryToValue(findPreference("notifications_sms_whenscreenon"));
}