mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Fossil Hybrid HR: Use embedded background image from .wapp file for editor
This commit is contained in:
parent
75dd5f1863
commit
305078f253
@ -486,7 +486,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.appmanager_app_delete_cache:
|
||||
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) {
|
||||
File fileToDelete = new File(appCacheDir,baseName + suffix);
|
||||
if (!fileToDelete.delete()) {
|
||||
|
@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
@ -221,6 +222,36 @@ public class FossilFileReader {
|
||||
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 {
|
||||
return getFileContentsByName(filename, appIconStart, layout_start, false);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class FossilHRInstallHandler implements InstallHandler {
|
||||
if (fossilFile.isFirmware()) {
|
||||
return;
|
||||
}
|
||||
saveAppInCache(fossilFile, null, fossilFile.getPreview(), mCoordinator, mContext);
|
||||
saveAppInCache(fossilFile, fossilFile.getBackground(), fossilFile.getPreview(), mCoordinator, mContext);
|
||||
// refresh list
|
||||
manager.sendBroadcast(new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST));
|
||||
}
|
||||
|
@ -127,29 +127,27 @@ public class ImageConverter {
|
||||
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;
|
||||
if (imageSize * 4 != width * height) {
|
||||
// imageSize is multiplied by 4 because there are 2-bit pixels stored in every byte
|
||||
LOG.warn("decodeFromRAWImage: provided pixels (" + imageSize * 4 + ") not equal to resolution " + width + "*" + height);
|
||||
return null;
|
||||
// imageSize is multiplied by 4 because there are four 2-bit pixels stored in every byte
|
||||
throw new Exception("decodeFromRAWImage: provided pixels (" + imageSize * 4 + ") not equal to resolution " + width + "*" + height);
|
||||
}
|
||||
ByteBuffer buf = ByteBuffer.wrap(rawImage);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
int posX = 0;
|
||||
int posY = 0;
|
||||
int posX = 239;
|
||||
int posY = 239;
|
||||
while (buf.remaining() > 0) {
|
||||
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 combinedColor = Color.rgb(color, color, color);
|
||||
bitmap.setPixel(posX, posY, combinedColor);
|
||||
posX++;
|
||||
if (posX >= width) {
|
||||
posX = 0;
|
||||
posY++;
|
||||
posX--;
|
||||
if (posX < 0) {
|
||||
posX = 239;
|
||||
posY--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user