1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

Fossil Hybrid HR: Show widget previews in watchface designer

This commit is contained in:
Arjan Schrijver 2021-07-11 20:51:44 +02:00 committed by Gitea
parent e4be137286
commit 7d23044a45
4 changed files with 17 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -293,8 +293,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
widgetPaint.setColor(Color.RED);
widgetPaint.setStyle(Paint.Style.STROKE);
widgetPaint.setStrokeWidth(5);
Bitmap widgetBitmap = Bitmap.createBitmap((int)(widgetSize * scaleFactor), (int)(widgetSize * scaleFactor), Bitmap.Config.ARGB_8888);
Canvas widgetCanvas = new Canvas(widgetBitmap);
Bitmap widgetNoPreviewBitmap = Bitmap.createBitmap((int)(widgetSize * scaleFactor), (int)(widgetSize * scaleFactor), Bitmap.Config.ARGB_8888);
Canvas widgetCanvas = new Canvas(widgetNoPreviewBitmap);
widgetCanvas.drawRect(0, 0, widgetSize * scaleFactor, widgetSize * scaleFactor, widgetPaint);
for (int i=0; i<widgets.size(); i++) {
HybridHRWatchfaceWidget widget = widgets.get(i);
@ -304,7 +304,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
layoutParams.setMargins((int) ((widget.getPosX() - widgetSize/2) * scaleFactor), (int) ((widget.getPosY() - widgetSize/2) * scaleFactor), 0, 0);
ImageView widgetView = new ImageView(this);
widgetView.setId(i);
widgetView.setImageBitmap(widgetBitmap);
try {
widgetView.setImageBitmap(Bitmap.createScaledBitmap(widget.getPreviewImage(this), (int)(widgetSize * scaleFactor), (int)(widgetSize * scaleFactor), true));
} catch (IOException e) {
widgetView.setImageBitmap(widgetNoPreviewBitmap);
}
widgetView.setLayoutParams(layoutParams);
widgetView.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -16,6 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.IOException;
public class HybridHRWatchfaceWidget {
private String widgetType;
private int posX;
@ -31,6 +37,10 @@ public class HybridHRWatchfaceWidget {
return widgetType;
}
public Bitmap getPreviewImage(Context context) throws IOException {
return BitmapFactory.decodeStream(context.getAssets().open("fossil_hr/" + widgetType + "_preview.png"));
}
public int getPosX() {
return posX;
}