From bbf60248c3f00886f2f14e4f9f3116d947f1d9d7 Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Wed, 8 Apr 2020 03:20:39 +0200 Subject: [PATCH] Fossil HR: added button to delete background --- .../devices/qhybrid/HRConfigActivity.java | 9 ++++++++ .../fossil_hr/FossilHRWatchAdapter.java | 19 +++++++++------ .../layout/activity_qhybrid_hr_settings.xml | 23 +++++++++++++++---- 3 files changed, 40 insertions(+), 11 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 680348269..89f95e755 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 @@ -125,6 +125,15 @@ public class HRConfigActivity extends AbstractGBActivity implements View.OnClick } }); + findViewById(R.id.qhybrid_unset_background).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_SET_BACKGROUND_IMAGE); + intent.putIntegerArrayListExtra("EXTRA_PIXELS", null); + LocalBroadcastManager.getInstance(HRConfigActivity.this).sendBroadcast(intent); + } + }); + for (int i = 0; i < widgetButtonsMapping.size(); i++) { final int widgetButtonId = widgetButtonsMapping.keyAt(i); findViewById(widgetButtonId).setOnClickListener(new View.OnClickListener() { 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 b3aae5b96..0e00325ed 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 @@ -187,13 +187,18 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { @Override public void setBackgroundImage(byte[] pixels) { - this.backGroundImage = AssetImageFactory.createAssetImage(pixels, 0, 0, 0); - try { - FileOutputStream fos = new FileOutputStream(getBackgroundFile(), false); - fos.write(pixels); - } catch (IOException e) { - GB.log("error saving background", GB.ERROR, e); - GB.toast("error persistent saving background", Toast.LENGTH_LONG, GB.ERROR); + if(pixels == null){ + getBackgroundFile().delete(); + this.backGroundImage = null; + }else{ + this.backGroundImage = AssetImageFactory.createAssetImage(pixels, 0, 0, 0); + try { + FileOutputStream fos = new FileOutputStream(getBackgroundFile(), false); + fos.write(pixels); + } catch (IOException e) { + GB.log("error saving background", GB.ERROR, e); + GB.toast("error persistent saving background", Toast.LENGTH_LONG, GB.ERROR); + } } renderWidgets(); } diff --git a/app/src/main/res/layout/activity_qhybrid_hr_settings.xml b/app/src/main/res/layout/activity_qhybrid_hr_settings.xml index 778ea7d66..42911e6bd 100644 --- a/app/src/main/res/layout/activity_qhybrid_hr_settings.xml +++ b/app/src/main/res/layout/activity_qhybrid_hr_settings.xml @@ -96,11 +96,26 @@ android:layout_height="wrap_content" android:text="add widget" /> - -