mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
changed image and asset related classes
This commit is contained in:
parent
19d68c62c6
commit
9d34447b0d
File diff suppressed because one or more lines are too long
@ -0,0 +1,19 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file;
|
||||
|
||||
public class AssetFile {
|
||||
private String fileName;
|
||||
private byte[] fileData;
|
||||
|
||||
public AssetFile(String fileName, byte[] fileData) {
|
||||
this.fileName = fileName;
|
||||
this.fileData = fileData;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public byte[] getFileData() {
|
||||
return fileData;
|
||||
}
|
||||
}
|
@ -10,33 +10,35 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.utils.StringUtils;
|
||||
|
||||
public class AssetFilePutRequest extends FilePutRequest {
|
||||
public AssetFilePutRequest(byte[] fileName, byte[] file, FossilWatchAdapter adapter) {
|
||||
super((short) 0x0701, prepareFileData(fileName, file), adapter);
|
||||
public AssetFilePutRequest(AssetFile[] files, FossilWatchAdapter adapter) throws IOException {
|
||||
super((short) 0x0700, prepareFileData(files), adapter);
|
||||
}
|
||||
public AssetFilePutRequest(byte[][] fileNames, byte[][] files, FossilWatchAdapter adapter) throws IOException {
|
||||
super((short) 0x0701, prepareFileData(fileNames, files), adapter);
|
||||
public AssetFilePutRequest(AssetFile file, FossilWatchAdapter adapter) throws IOException {
|
||||
super((short) 0x0700, prepareFileData(file), adapter);
|
||||
}
|
||||
|
||||
private static byte[] prepareFileData(byte[][] fileNames, byte[][] files) throws IOException {
|
||||
private static byte[] prepareFileData(AssetFile[] files) throws IOException {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
|
||||
for(int i = 0; i < fileNames.length; i++){
|
||||
for(int i = 0; i < files.length; i++){
|
||||
stream.write(
|
||||
prepareFileData(fileNames[i], files[i])
|
||||
prepareFileData(files[i])
|
||||
);
|
||||
}
|
||||
|
||||
return stream.toByteArray();
|
||||
}
|
||||
|
||||
private static byte[] prepareFileData(byte[] fileNameNullTerminated, byte[] file){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(fileNameNullTerminated.length + 2 + file.length);
|
||||
private static byte[] prepareFileData(AssetFile file){
|
||||
int size = file.getFileName().length() + file.getFileData().length;
|
||||
ByteBuffer buffer = ByteBuffer.allocate(size + 3);
|
||||
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
buffer.putShort((short)(fileNameNullTerminated.length + file.length));
|
||||
buffer.put(fileNameNullTerminated);
|
||||
buffer.put(file);
|
||||
buffer.putShort((short)(size));
|
||||
buffer.put(file.getFileName().getBytes());
|
||||
buffer.put((byte) 0x00);
|
||||
buffer.put(file.getFileData());
|
||||
|
||||
return buffer.array();
|
||||
}
|
||||
|
@ -5,15 +5,16 @@ import androidx.annotation.NonNull;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Image {
|
||||
private int angle, distance, indexZ;
|
||||
private String imageFile;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.AssetFile;
|
||||
|
||||
public Image(int angle, int distance, int indexZ, String imageFile) {
|
||||
public class AssetImage extends AssetFile {
|
||||
private int angle, distance, indexZ;
|
||||
|
||||
protected AssetImage(String fileName, byte[] fileData, int angle, int distance, int indexZ) {
|
||||
super(fileName, fileData);
|
||||
this.angle = angle;
|
||||
this.distance = distance;
|
||||
this.indexZ = indexZ;
|
||||
this.imageFile = imageFile;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -25,7 +26,7 @@ public class Image {
|
||||
public JSONObject toJsonObject(){
|
||||
try {
|
||||
return new JSONObject()
|
||||
.put("image_name", this.imageFile)
|
||||
.put("image_name", getFileName())
|
||||
.put("pos",
|
||||
new JSONObject()
|
||||
.put("angle", angle)
|
||||
@ -62,11 +63,5 @@ public class Image {
|
||||
this.indexZ = indexZ;
|
||||
}
|
||||
|
||||
public String getImageFile() {
|
||||
return imageFile;
|
||||
}
|
||||
|
||||
public void setImageFile(String imageFile) {
|
||||
this.imageFile = imageFile;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.image;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class AssetImageFactory {
|
||||
public static AssetImage createAssetImage(String fileName, byte[] fileData, int angle, int distance, int indexZ){
|
||||
return new AssetImage(fileName, fileData, angle, distance, indexZ);
|
||||
}
|
||||
|
||||
public static AssetImage createAssetImage(String fileName, Bitmap fileData, boolean RLEencode, int angle, int distance, int indexZ){
|
||||
return null;
|
||||
}
|
||||
}
|
@ -8,14 +8,14 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.foss
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.json.JsonPutRequest;
|
||||
|
||||
public class ImagesPutRequest extends JsonPutRequest {
|
||||
public ImagesPutRequest(Image[] images, FossilWatchAdapter adapter) {
|
||||
super((short) 0x0500, prepareObject(images), adapter);
|
||||
public ImagesPutRequest(AssetImage[] images, FossilWatchAdapter adapter) {
|
||||
super((short) 0x0503, prepareObject(images), adapter);
|
||||
}
|
||||
|
||||
private static JSONObject prepareObject(Image[] images){
|
||||
private static JSONObject prepareObject(AssetImage[] images){
|
||||
try {
|
||||
JSONArray imageArray = new JSONArray();
|
||||
for (Image image : images) imageArray.put(image.toJsonObject());
|
||||
for (AssetImage image : images) imageArray.put(image.toJsonObject());
|
||||
return new JSONObject()
|
||||
.put("push",
|
||||
new JSONObject()
|
||||
|
@ -1,10 +1,14 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.notification;
|
||||
|
||||
public class NotificationImage {
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.AssetFile;
|
||||
|
||||
public class NotificationImage extends AssetFile {
|
||||
private String packageName;
|
||||
private byte[] imageData;
|
||||
|
||||
public NotificationImage(String packageName, byte[] imageData) {
|
||||
//TODO this is defo not functional
|
||||
super("whatever", imageData);
|
||||
this.packageName = packageName;
|
||||
this.imageData = imageData;
|
||||
}
|
||||
|
@ -8,20 +8,21 @@ import java.util.stream.Stream;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.AssetFile;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.AssetFilePutRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.utils.StringUtils;
|
||||
|
||||
public class NotificationImagePutRequest extends AssetFilePutRequest {
|
||||
private NotificationImagePutRequest(String packageName, byte[] file, FossilWatchAdapter adapter) {
|
||||
super(prepareFileCrc(packageName), file, adapter);
|
||||
private NotificationImagePutRequest(String packageName, AssetFile file, FossilWatchAdapter adapter) throws IOException {
|
||||
super(file, adapter);
|
||||
}
|
||||
|
||||
private NotificationImagePutRequest(NotificationImage image, FossilWatchAdapter adapter) {
|
||||
super(prepareFileCrc(image.getPackageName()), image.getImageData(), adapter);
|
||||
private NotificationImagePutRequest(NotificationImage image, FossilWatchAdapter adapter) throws IOException {
|
||||
super(image, adapter);
|
||||
}
|
||||
|
||||
public NotificationImagePutRequest(String[] fileNames, byte[][] files, FossilWatchAdapter adapter) throws IOException {
|
||||
super(prepareFileCrc(fileNames), files, adapter);
|
||||
public NotificationImagePutRequest(NotificationImage[] images, FossilWatchAdapter adapter) throws IOException {
|
||||
super(images, adapter);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user