From e1aa88d22aeb7f62c25bba26e142cf69144395a8 Mon Sep 17 00:00:00 2001 From: dakhnod Date: Thu, 21 Nov 2019 23:22:55 +0100 Subject: [PATCH] added some logging --- .../devices/qhybrid/ConfigActivity.java | 118 ++++++++++-------- .../adapter/fossil/FossilWatchAdapter.java | 3 + .../ConfigurationGetRequest.java | 3 +- 3 files changed, 68 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java index 5ab1a4900..aa41f6b3c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/ConfigActivity.java @@ -57,6 +57,8 @@ import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; +import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails; +import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.buttonconfig.ConfigPayload; @@ -394,62 +396,68 @@ public class ConfigActivity extends AbstractGBActivity { }); } - final String buttonJson = device.getDeviceInfo(FossilWatchAdapter.ITEM_BUTTONS).getDetails(); - if (buttonJson != null && !buttonJson.isEmpty()) { - try { - final JSONArray buttonConfig = new JSONArray(buttonJson); - LinearLayout buttonLayout = findViewById(R.id.buttonConfigLayout); - buttonLayout.removeAllViews(); - findViewById(R.id.buttonOverwriteButtons).setVisibility(View.GONE); - final ConfigPayload[] payloads = ConfigPayload.values(); - final String[] names = new String[payloads.length]; - for (int i = 0; i < payloads.length; i++) - names[i] = payloads[i].getDescription(); - for (int i = 0; i < buttonConfig.length(); i++) { - final int currentIndex = i; - String configName = buttonConfig.getString(i); - TextView buttonTextView = new TextView(ConfigActivity.this); - buttonTextView.setTextColor(Color.WHITE); - buttonTextView.setTextSize(20); - try { - ConfigPayload payload = ConfigPayload.valueOf(configName); - buttonTextView.setText("Button " + (i + 1) + ": " + payload.getDescription()); - } catch (IllegalArgumentException e) { - buttonTextView.setText("Button " + (i + 1) + ": Unknown"); - } - - buttonTextView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AlertDialog dialog = new AlertDialog.Builder(ConfigActivity.this) - .setItems(names, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - ConfigPayload selected = payloads[which]; - - try { - buttonConfig.put(currentIndex, selected.toString()); - device.addDeviceInfo(new GenericItem(FossilWatchAdapter.ITEM_BUTTONS, buttonConfig.toString())); - updateSettings(); - LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS)); - } catch (JSONException e) { - e.printStackTrace(); - } - } - }) - .setTitle("Button " + (currentIndex + 1)) - .create(); - dialog.show(); - } - }); - - buttonLayout.addView(buttonTextView); - } - } catch (JSONException e) { - e.printStackTrace(); - GB.toast("error parsing button config", Toast.LENGTH_LONG, GB.ERROR); + ItemWithDetails buttonInfo = device.getDeviceInfo(FossilWatchAdapter.ITEM_BUTTONS); + try { + JSONArray buttonConfig = new JSONArray(new String[]{"Unknown", "Unknown", "Unknown"}); + String buttonJson = null; + if (buttonInfo != null) { + buttonJson = buttonInfo.getDetails(); } + if (buttonJson != null && !buttonJson.isEmpty()) { + buttonConfig = new JSONArray(buttonJson); + } + + final JSONArray finalButtonConfig = buttonConfig; + LinearLayout buttonLayout = findViewById(R.id.buttonConfigLayout); + buttonLayout.removeAllViews(); + findViewById(R.id.buttonOverwriteButtons).setVisibility(View.GONE); + final ConfigPayload[] payloads = ConfigPayload.values(); + final String[] names = new String[payloads.length]; + for (int i = 0; i < payloads.length; i++) + names[i] = payloads[i].getDescription(); + for (int i = 0; i < buttonConfig.length(); i++) { + final int currentIndex = i; + String configName = buttonConfig.getString(i); + TextView buttonTextView = new TextView(ConfigActivity.this); + buttonTextView.setTextColor(Color.WHITE); + buttonTextView.setTextSize(20); + try { + ConfigPayload payload = ConfigPayload.valueOf(configName); + buttonTextView.setText("Button " + (i + 1) + ": " + payload.getDescription()); + } catch (IllegalArgumentException e) { + buttonTextView.setText("Button " + (i + 1) + ": Unknown"); + } + + buttonTextView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AlertDialog dialog = new AlertDialog.Builder(ConfigActivity.this) + .setItems(names, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + ConfigPayload selected = payloads[which]; + try { + finalButtonConfig.put(currentIndex, selected.toString()); + device.addDeviceInfo(new GenericItem(FossilWatchAdapter.ITEM_BUTTONS, finalButtonConfig.toString())); + updateSettings(); + LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS)); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }) + .setTitle("Button " + (currentIndex + 1)) + .create(); + dialog.show(); + } + }); + + buttonLayout.addView(buttonTextView); + } + } catch ( + JSONException e) { + e.printStackTrace(); } } }); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java index 6cd28e79e..ceca3c43a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java @@ -447,6 +447,9 @@ public class FossilWatchAdapter extends WatchAdapter { @Override public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { super.onMtuChanged(gatt, mtu, status); + + log("MTU changed: " + mtu); + this.MTU = mtu; getDeviceSupport().getDevice().addDeviceInfo(new GenericItem(ITEM_MTU, String.valueOf(mtu))); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java index 69a9c72f0..007ac6d71 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil/configuration/ConfigurationGetRequest.java @@ -4,9 +4,10 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; +import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupAndGetRequest; -public class ConfigurationGetRequest extends FileLookupAndGetRequest { +public class ConfigurationGetRequest extends FileGetRequest { public ConfigurationGetRequest(FossilWatchAdapter adapter) { super((byte) 8, adapter); }