diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java index 5996da4b9..05682a3ad 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooCoordinator.java @@ -16,6 +16,9 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.devices.divoom; +import android.content.Context; +import android.net.Uri; + import androidx.annotation.NonNull; import java.util.regex.Pattern; @@ -23,6 +26,7 @@ import java.util.regex.Pattern; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; @@ -51,6 +55,11 @@ public class PixooCoordinator extends AbstractBLEDeviceCoordinator { return PixooSupport.class; } + @Override + public InstallHandler findInstallHandler(final Uri uri, final Context context) { + PixooInstallHandler installHandler = new PixooInstallHandler(uri, context); + return installHandler.isValid() ? installHandler : null; + } @Override public int getDeviceNameResource() { return R.string.devicetype_pixoo; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java new file mode 100644 index 000000000..0155dd41a --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/divoom/PixooInstallHandler.java @@ -0,0 +1,50 @@ +/* Copyright (C) 2023 Andreas Shimokawa + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ + +package nodomain.freeyourgadget.gadgetbridge.devices.divoom; + +import android.content.Context; +import android.net.Uri; + +import nodomain.freeyourgadget.gadgetbridge.activities.InstallActivity; +import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; +import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; + +public class PixooInstallHandler implements InstallHandler { + private final Context mContext; + private final Uri mUri; + + public PixooInstallHandler(Uri uri, Context context) { + mContext = context; + mUri = uri; + } + + @Override + public boolean isValid() { + return true; + } + + @Override + public void validateInstallation(InstallActivity installActivity, GBDevice device) { + installActivity.setInstallEnabled(true); + } + + @Override + public void onStartInstall(GBDevice device) { + + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooIOThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooIOThread.java index d9fd8e1b8..e6fc3fa17 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooIOThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooIOThread.java @@ -21,6 +21,7 @@ import static nodomain.freeyourgadget.gadgetbridge.util.GB.hexdump; import android.bluetooth.BluetoothAdapter; import android.content.Context; +import android.net.Uri; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,5 +59,4 @@ public class PixooIOThread extends BtClassicIoThread { LOG.debug("read " + bytes + " bytes. " + hexdump(buffer, 0, bytes)); return Arrays.copyOf(buffer, bytes); } - } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java index 01a26d618..97258a5d8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooProtocol.java @@ -23,6 +23,8 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.provider.MediaStore; import androidx.localbroadcastmanager.content.LocalBroadcastManager; @@ -30,6 +32,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; @@ -348,10 +351,25 @@ public class PixooProtocol extends GBDeviceProtocol { return null; } final Bitmap bmp = BitmapUtil.toBitmap(icon); + + return encodeShowFrame(bmp); + } + + protected byte[] encodeShowFrame(Uri uri) { + try { + Bitmap bitmap = MediaStore.Images.Media.getBitmap(GBApplication.getContext().getContentResolver(), uri); + return encodeShowFrame(bitmap); + } catch (IOException e) { + LOG.error("could not decode Image",e); + } + return null; + } + + private byte[] encodeShowFrame(Bitmap bitmap) { final Bitmap bmpResized = Bitmap.createBitmap(16, 16, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bmpResized); final Rect rect = new Rect(0, 0, 16, 16); - canvas.drawBitmap(bmp, null, rect, null); + canvas.drawBitmap(bitmap, null, rect, null); // construct palette with unique colors diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooSupport.java index 6fdfcb26a..e595899b1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/divoom/PixooSupport.java @@ -17,6 +17,8 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.divoom; +import android.net.Uri; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +56,11 @@ public class PixooSupport extends AbstractSerialDeviceSupport { return new PixooProtocol(getDevice()); } + @Override + public void onInstallApp(Uri uri) { + getDeviceIOThread().write(((PixooProtocol) getDeviceProtocol()).encodeShowFrame(uri)); + } + @Override protected GBDeviceIoThread createDeviceIOThread() { return new PixooIOThread(getDevice(), getContext(), (PixooProtocol) getDeviceProtocol(),