mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
Fossil Hybrid HR: Use embedded background image from .wapp file for editor
This commit is contained in:
@@ -486,7 +486,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.appmanager_app_delete_cache:
|
case R.id.appmanager_app_delete_cache:
|
||||||
String baseName = selectedApp.getUUID().toString();
|
String baseName = selectedApp.getUUID().toString();
|
||||||
String[] suffixToDelete = new String[]{mCoordinator.getAppFileExtension(), ".json", "_config.js", "_preset.json", ".png", "_preview.png"};
|
String[] suffixToDelete = new String[]{mCoordinator.getAppFileExtension(), ".json", "_config.js", "_preset.json", ".png", "_preview.png", "_bg.png"};
|
||||||
for (String suffix : suffixToDelete) {
|
for (String suffix : suffixToDelete) {
|
||||||
File fileToDelete = new File(appCacheDir,baseName + suffix);
|
File fileToDelete = new File(appCacheDir,baseName + suffix);
|
||||||
if (!fileToDelete.delete()) {
|
if (!fileToDelete.delete()) {
|
||||||
|
@@ -20,6 +20,7 @@ import android.content.Context;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
@@ -221,6 +222,36 @@ public class FossilFileReader {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bitmap getBackground() {
|
||||||
|
try {
|
||||||
|
if (filenamesIcons != null) {
|
||||||
|
String filename = null;
|
||||||
|
if (filenamesIcons.contains("background.raw")) {
|
||||||
|
filename = "background.raw";
|
||||||
|
} else if (filenamesIcons.contains("background")) {
|
||||||
|
filename = "background";
|
||||||
|
} else {
|
||||||
|
JSONObject config = getConfigJSON("customWatchFace");
|
||||||
|
JSONArray layout = config.getJSONArray("layout");
|
||||||
|
JSONObject firstLayoutItem = layout.getJSONObject(0);
|
||||||
|
if (firstLayoutItem.getString("type").equals("image")) {
|
||||||
|
filename = firstLayoutItem.getString("name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filename != null) {
|
||||||
|
byte[] rawImage = getImageFileContents(filename);
|
||||||
|
Bitmap decodedImage = ImageConverter.decodeFromRAWImage(rawImage, 240, 240);
|
||||||
|
return BitmapUtil.getCircularBitmap(decodedImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Couldn't read background image from wapp file: ", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
LOG.warn("No background image found in wapp file");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] getImageFileContents(String filename) throws IOException {
|
private byte[] getImageFileContents(String filename) throws IOException {
|
||||||
return getFileContentsByName(filename, appIconStart, layout_start, false);
|
return getFileContentsByName(filename, appIconStart, layout_start, false);
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ public class FossilHRInstallHandler implements InstallHandler {
|
|||||||
if (fossilFile.isFirmware()) {
|
if (fossilFile.isFirmware()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveAppInCache(fossilFile, null, fossilFile.getPreview(), mCoordinator, mContext);
|
saveAppInCache(fossilFile, fossilFile.getBackground(), fossilFile.getPreview(), mCoordinator, mContext);
|
||||||
// refresh list
|
// refresh list
|
||||||
manager.sendBroadcast(new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST));
|
manager.sendBroadcast(new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST));
|
||||||
}
|
}
|
||||||
|
@@ -127,29 +127,27 @@ public class ImageConverter {
|
|||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap decodeFromRAWImage(byte[] rawImage, int width, int height) {
|
public static Bitmap decodeFromRAWImage(byte[] rawImage, int width, int height) throws Exception {
|
||||||
int imageSize = rawImage.length;
|
int imageSize = rawImage.length;
|
||||||
if (imageSize * 4 != width * height) {
|
if (imageSize * 4 != width * height) {
|
||||||
// imageSize is multiplied by 4 because there are 2-bit pixels stored in every byte
|
// imageSize is multiplied by 4 because there are four 2-bit pixels stored in every byte
|
||||||
LOG.warn("decodeFromRAWImage: provided pixels (" + imageSize * 4 + ") not equal to resolution " + width + "*" + height);
|
throw new Exception("decodeFromRAWImage: provided pixels (" + imageSize * 4 + ") not equal to resolution " + width + "*" + height);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
ByteBuffer buf = ByteBuffer.wrap(rawImage);
|
ByteBuffer buf = ByteBuffer.wrap(rawImage);
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
int posX = 0;
|
int posX = 239;
|
||||||
int posY = 0;
|
int posY = 239;
|
||||||
while (buf.remaining() > 0) {
|
while (buf.remaining() > 0) {
|
||||||
int currentPixels = Byte.toUnsignedInt(buf.get());
|
int currentPixels = Byte.toUnsignedInt(buf.get());
|
||||||
for (int shift=0; shift<=6; shift+=2) {
|
for (int shift=6; shift>=0; shift-=2) {
|
||||||
//for (int shift=6; shift>=0; shift-=2) {
|
|
||||||
int color = ((currentPixels >> shift) & 0b00000011) << 6;
|
int color = ((currentPixels >> shift) & 0b00000011) << 6;
|
||||||
int combinedColor = Color.rgb(color, color, color);
|
int combinedColor = Color.rgb(color, color, color);
|
||||||
bitmap.setPixel(posX, posY, combinedColor);
|
bitmap.setPixel(posX, posY, combinedColor);
|
||||||
posX++;
|
posX--;
|
||||||
if (posX >= width) {
|
if (posX < 0) {
|
||||||
posX = 0;
|
posX = 239;
|
||||||
posY++;
|
posY--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user