From 961c0aa97c2ba0879c9167a5ae3b423db0c27035 Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Fri, 3 Jan 2020 02:33:47 +0100 Subject: [PATCH] added some widget example code (WIP) --- .../service/devices/qhybrid/QHybridSupport.java | 8 ++++++++ .../devices/qhybrid/adapter/WatchAdapter.java | 3 +++ .../adapter/fossil_hr/FossilHRWatchAdapter.java | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java index 6f2d80470..f3beb1853 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java @@ -88,6 +88,7 @@ public class QHybridSupport extends QHybridBaseSupport { public static final String QHYBRID_COMMAND_OVERWRITE_BUTTONS = "nodomain.freeyourgadget.gadgetbridge.Q_OVERWRITE_BUTTONS"; public static final String QHYBRID_COMMAND_SET_MENU_MESSAGE = "nodomain.freeyourgadget.gadgetbridge.Q_SET_MENU_MESSAGE"; public static final String QHYBRID_COMMAND_SEND_MENU_ITEMS = "nodomain.freeyourgadget.gadgetbridge.Q_SEND_MENU_ITEMS"; + public static final String QHYBRID_COMMAND_SET_WIDGET_CONTENT = "nodomain.freeyourgadget.gadgetbridge.Q_SET_WIDGET_CONTENT"; private static final String QHYBRID_ACTION_SET_ACTIVITY_HAND = "nodomain.freeyourgadget.gadgetbridge.Q_SET_ACTIVITY_HAND"; @@ -231,6 +232,7 @@ public class QHybridSupport extends QHybridBaseSupport { IntentFilter globalFilter = new IntentFilter(); globalFilter.addAction(QHYBRID_ACTION_SET_ACTIVITY_HAND); globalFilter.addAction(QHYBRID_COMMAND_SET_MENU_MESSAGE); + globalFilter.addAction(QHYBRID_COMMAND_SET_WIDGET_CONTENT); BroadcastReceiver globalCommandReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -262,6 +264,12 @@ public class QHybridSupport extends QHybridBaseSupport { break; } + case QHYBRID_COMMAND_SET_WIDGET_CONTENT: { + String id = String.valueOf(intent.getExtras().get("EXTRA_WIDGET_ID")); + String content = String.valueOf(intent.getExtras().get("EXTRA_CONTENT")); + watchAdapter.setWidgetContent(id, content); + break; + } } } }; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java index e967069d2..c561f2ea2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java @@ -105,4 +105,7 @@ public abstract class WatchAdapter { public void setMusicState(MusicStateSpec stateSpec) { } + + public void setWidgetContent(String widgetID, String content) { + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index 73bea520d..85a782787 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -86,11 +86,16 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { overwriteButtons(null); - drawWidgetText("19.00"); + drawWidgetText("-"); queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZED)); } + @Override + public void setWidgetContent(String widgetID, String content) { + drawWidgetText(content); + } + private void drawWidgetText(String text){ try { @@ -108,8 +113,15 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { circlePaint.setStrokeWidth(4); circlePaint.setTextSize(17f); circlePaint.setStyle(Paint.Style.FILL); + circlePaint.setTextAlign(Paint.Align.CENTER); - testCanvas.drawText(text, 16, 60, circlePaint); + testCanvas.drawText("ETH", 38, 76f / 3f * 1f - (circlePaint.descent() + circlePaint.ascent()) / 2f, circlePaint); + testCanvas.drawText(text, 38, 76f / 3f * 2f - (circlePaint.descent() + circlePaint.ascent()) / 2f, circlePaint); + + circlePaint.setStrokeWidth(1); + circlePaint.setStyle(Paint.Style.STROKE); + + // for(int i = 0; i <= 3; i++) testCanvas.drawLine(0, 76f / 3f * i - (i / 3), 76, 76f / 3f * i - (i / 3), circlePaint); AssetImage image = AssetImageFactory.createAssetImage( StringUtils.bytesToHex(