1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Pixoo: Quick hack to "install" any image on the pixoo

This commit is contained in:
Andreas Shimokawa 2023-12-26 20:38:13 +01:00
parent b77ba8b74c
commit 177fa56bb9
5 changed files with 86 additions and 2 deletions

View File

@ -16,6 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
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;

View File

@ -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 <http://www.gnu.org/licenses/>. */
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) {
}
}

View File

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

View File

@ -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

View File

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