From e0c09f259fb634d971a84c457e3c1ec47d0c190b Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Wed, 8 Apr 2020 02:18:13 +0200 Subject: [PATCH 1/2] Fossil HR: removed per-widget circle settings --- .../devices/qhybrid/HRConfigActivity.java | 5 +++-- .../devices/qhybrid/WidgetSettingsActivity.java | 10 +--------- .../adapter/fossil_hr/FossilHRWatchAdapter.java | 5 ++--- .../requests/fossil_hr/widget/CustomWidget.java | 12 +----------- .../res/layout/qhybrid_activity_widget_settings.xml | 6 ------ 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HRConfigActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HRConfigActivity.java index ba104f634..c506b65eb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HRConfigActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HRConfigActivity.java @@ -1,5 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; @@ -188,7 +189,6 @@ public class HRConfigActivity extends AbstractGBActivity implements View.OnClick JSONObject widgetObject = new JSONObject(); widgetObject .put("name", widget.getName()) - .put("drawCircle", widget.getDrawCircle()) .put("elements", elementArray); widgetArray.put(widgetObject); @@ -209,7 +209,7 @@ public class HRConfigActivity extends AbstractGBActivity implements View.OnClick for (int i = 0; i < customWidgets.length(); i++) { JSONObject customWidgetObject = customWidgets.getJSONObject(i); CustomWidget widget = new CustomWidget( - customWidgetObject.getString("name"), 0, 0, "default", false // FIXME: handle force white background + customWidgetObject.getString("name"), 0, 0, "default" // FIXME: handle force white background ); JSONArray elements = customWidgetObject.getJSONArray("elements"); @@ -475,6 +475,7 @@ public class HRConfigActivity extends AbstractGBActivity implements View.OnClick super(HRConfigActivity.this, 0, objects); } + @SuppressLint("ResourceType") @NonNull @Override public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/WidgetSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/WidgetSettingsActivity.java index 06dc97b4c..b5d863345 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/WidgetSettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/WidgetSettingsActivity.java @@ -50,10 +50,9 @@ public class WidgetSettingsActivity extends AbstractGBActivity { if(getIntent().hasExtra("EXTRA_WIDGET")){ subject = (CustomWidget) getIntent().getExtras().get("EXTRA_WIDGET"); ((EditText) findViewById(R.id.qhybrid_widget_name)).setText(subject.getName()); - ((CheckBox)findViewById(R.id.qhybrid_widget_circle)).setChecked(subject.getDrawCircle()); resultCode = RESULT_CODE_WIDGET_UPDATED; }else{ - subject = new CustomWidget("", 0, 63, "default", false); // FIXME: handle force white background + subject = new CustomWidget("", 0, 63, "default"); // FIXME: handle force white background resultCode = RESULT_CODE_WIDGET_CREATED; findViewById(R.id.qhybrid_widget_delete).setEnabled(false); } @@ -96,13 +95,6 @@ public class WidgetSettingsActivity extends AbstractGBActivity { showElementDialog(null); } }); - - ((CheckBox)findViewById(R.id.qhybrid_widget_circle)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - subject.setDrawCircle(b); - } - }); } private void showElementDialog(@Nullable final CustomWidgetElement element){ 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 9d7721a20..4e947f786 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 @@ -199,8 +199,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { customWidget.getString("name"), positionMap.get(position), 63, - fontColor, - drawCircle + fontColor ); JSONArray elements = customWidget.getJSONArray("elements"); @@ -266,7 +265,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { boolean backgroundDrawn = false; - if(widget.getDrawCircle() && !backgroundDrawn){ + if(!backgroundDrawn){ Paint circlePaint = new Paint(); circlePaint.setColor(forceWhiteBackground ? Color.WHITE : Color.BLACK); circlePaint.setStyle(Paint.Style.FILL); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java index 1440d7aff..d6f1f0af3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java @@ -9,22 +9,12 @@ public class CustomWidget extends Widget { private ArrayList elements = new ArrayList<>(); private int angle, distance; private String name; - private boolean drawCircle; - public CustomWidget(String name, int angle, int distance, String fontColor, boolean drawCircle) { + public CustomWidget(String name, int angle, int distance, String fontColor) { super(null, angle, distance, fontColor); this.angle = angle; this.distance = distance; this.name = name; - this.drawCircle = drawCircle; - } - - public boolean getDrawCircle(){ - return this.drawCircle; - } - - public void setDrawCircle(boolean drawCircle){ - this.drawCircle = drawCircle; } public int getAngle() { diff --git a/app/src/main/res/layout/qhybrid_activity_widget_settings.xml b/app/src/main/res/layout/qhybrid_activity_widget_settings.xml index d84138554..a5c25077b 100644 --- a/app/src/main/res/layout/qhybrid_activity_widget_settings.xml +++ b/app/src/main/res/layout/qhybrid_activity_widget_settings.xml @@ -43,12 +43,6 @@ android:layout_height="wrap_content" android:text="add element" /> - - Date: Wed, 8 Apr 2020 03:00:45 +0200 Subject: [PATCH 2/2] Fossil HR: centralized widget settings option for all widgets --- .../fossil_hr/FossilHRWatchAdapter.java | 48 ++++++++++++------- .../fossil_hr/widget/CustomWidget.java | 16 ------- .../requests/fossil_hr/widget/Widget.java | 16 +++++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../res/xml/devicesettings_fossilhybridhr.xml | 5 ++ 6 files changed, 55 insertions(+), 32 deletions(-) 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 4e947f786..abdee8b31 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 @@ -246,6 +246,24 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { private void renderWidgets() { Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDeviceSupport().getDevice().getAddress())); boolean forceWhiteBackground = prefs.getBoolean("force_white_color_scheme", false); + boolean drawCircles = prefs.getBoolean("widget_draw_circles", false); + + Bitmap circleBitmap = null; + if(drawCircles) { + circleBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_8888); + Canvas circleCanvas = new Canvas(circleBitmap); + Paint circlePaint = new Paint(); + circlePaint.setColor(forceWhiteBackground ? Color.WHITE : Color.BLACK); + circlePaint.setStyle(Paint.Style.FILL); + circlePaint.setStrokeWidth(3); + circleCanvas.drawCircle(38, 38, 37, circlePaint); + + circlePaint.setColor(forceWhiteBackground ? Color.BLACK : Color.WHITE); + circlePaint.setStyle(Paint.Style.STROKE); + circlePaint.setStrokeWidth(3); + circleCanvas.drawCircle(38, 38, 37, circlePaint); + } + try { ArrayList widgetImages = new ArrayList<>(); @@ -253,29 +271,28 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { widgetImages.add(this.backGroundImage); } - for (int i = 0; i < this.widgets.size(); i++) { Widget w = widgets.get(i); - if(!(w instanceof CustomWidget)) continue; + if(!(w instanceof CustomWidget)){ + if(drawCircles) { + widgetImages.add(AssetImageFactory.createAssetImage( + circleBitmap, + true, + w.getAngle(), + w.getDistance(), + 1 + )); + } + continue; + }; CustomWidget widget = (CustomWidget) w; Bitmap widgetBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_8888); Canvas widgetCanvas = new Canvas(widgetBitmap); - boolean backgroundDrawn = false; - - if(!backgroundDrawn){ - Paint circlePaint = new Paint(); - circlePaint.setColor(forceWhiteBackground ? Color.WHITE : Color.BLACK); - circlePaint.setStyle(Paint.Style.FILL); - circlePaint.setStrokeWidth(3); - widgetCanvas.drawCircle(38, 38, 37, circlePaint); - - circlePaint.setColor(forceWhiteBackground ? Color.BLACK : Color.WHITE); - circlePaint.setStyle(Paint.Style.STROKE); - circlePaint.setStrokeWidth(3); - widgetCanvas.drawCircle(38, 38, 37, circlePaint); + if(drawCircles){ + widgetCanvas.drawBitmap(circleBitmap, 0, 0, null); } for (CustomWidgetElement element : widget.getElements()) { @@ -298,7 +315,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { 0, 0, null); - backgroundDrawn = true; break; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java index d6f1f0af3..18e989701 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/CustomWidget.java @@ -17,26 +17,10 @@ public class CustomWidget extends Widget { this.name = name; } - public int getAngle() { - return angle; - } - - public int getDistance() { - return distance; - } - public void setElements(ArrayList elements) { this.elements = elements; } - public void setAngle(int angle) { - this.angle = angle; - } - - public void setDistance(int distance) { - this.distance = distance; - } - public void setName(String name) { this.name = name; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/Widget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/Widget.java index 19de46906..da99f51c4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/Widget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/widget/Widget.java @@ -21,6 +21,22 @@ public class Widget implements Serializable { this.fontColor = fontColor; } + public int getAngle() { + return angle; + } + + public int getDistance() { + return distance; + } + + public void setAngle(int angle) { + this.angle = angle; + } + + public void setDistance(int distance) { + this.distance = distance; + } + @NonNull @Override public String toString() { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7e2f76f0a..32652b454 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -860,4 +860,5 @@ Amazfit Bip S Firmwareüberprüfung deaktivieren Aktiviere das flashen von Firmware, die nicht für dieses Gerät bestimmt ist (auf eigenes Risiko) + Widget-Kreise zeichnen \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e7c29a8cf..e4a9bb55d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -815,6 +815,7 @@ Long press button action Location access must be granted and enabled for scanning to work properly + Draw widget circles %d hour diff --git a/app/src/main/res/xml/devicesettings_fossilhybridhr.xml b/app/src/main/res/xml/devicesettings_fossilhybridhr.xml index 4217e9401..763680186 100644 --- a/app/src/main/res/xml/devicesettings_fossilhybridhr.xml +++ b/app/src/main/res/xml/devicesettings_fossilhybridhr.xml @@ -27,6 +27,11 @@ android:key="force_white_color_scheme" android:summary="@string/pref_summary_force_white_color_scheme" android:title="@string/pref_title_force_white_color_scheme" /> + +