1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 18:45:49 +01:00

Fossil HR: added button to delete background

This commit is contained in:
Daniel Dakhno 2020-04-08 03:20:39 +02:00
parent 379fa746a3
commit bbf60248c3
3 changed files with 40 additions and 11 deletions

View File

@ -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() {

View File

@ -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();
}

View File

@ -96,11 +96,26 @@
android:layout_height="wrap_content"
android:text="add widget" />
<Button
android:id="@+id/qhybrid_set_background"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="set background" />
android:weightSum="2"
android:orientation="horizontal">
<Button
android:id="@+id/qhybrid_unset_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="delete background"
android:layout_weight="1"/>
<Button
android:id="@+id/qhybrid_set_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="set background"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>