mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 09:17:29 +01:00
Fossil Hybrid HR: Support widget color inversion
This commit is contained in:
parent
3645e36ab6
commit
6000dd525e
@ -274,9 +274,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
break;
|
||||
|
||||
}
|
||||
int widgetColor = layoutItem.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE_ON_BLACK : HybridHRWatchfaceWidget.COLOR_BLACK_ON_WHITE;
|
||||
widgets.add(new HybridHRWatchfaceWidget(widgetName,
|
||||
layoutItem.getJSONObject("pos").getInt("x"),
|
||||
layoutItem.getJSONObject("pos").getInt("y")));
|
||||
layoutItem.getJSONObject("pos").getInt("y"),
|
||||
widgetColor));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
@ -373,6 +375,13 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
if ((widget != null) && (widgetTypesArray.contains(widget.getWidgetType()))) {
|
||||
typeSpinner.setSelection(widgetTypesArray.indexOf(widget.getWidgetType()));
|
||||
}
|
||||
// Configure widget color dropdown
|
||||
final Spinner colorSpinner = layout.findViewById(R.id.watchface_widget_color_spinner);
|
||||
ArrayAdapter<String> widgetColorAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, new String[]{getString(R.string.watchface_dialog_widget_color_white), getString(R.string.watchface_dialog_widget_color_black)});
|
||||
colorSpinner.setAdapter(widgetColorAdapter);
|
||||
if (widget != null) {
|
||||
colorSpinner.setSelection(widget.getColor());
|
||||
}
|
||||
// Set X coordinate
|
||||
final EditText posX = layout.findViewById(R.id.watchface_widget_pos_x);
|
||||
if (widget != null) {
|
||||
@ -446,9 +455,9 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
if (selectedPosY > 240) selectedPosY = 240;
|
||||
String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition());
|
||||
if (index >= 0) {
|
||||
widgets.set(index, new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY));
|
||||
widgets.set(index, new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition()));
|
||||
} else {
|
||||
widgets.add(new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY));
|
||||
widgets.add(new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition()));
|
||||
}
|
||||
renderWatchfacePreview();
|
||||
}
|
||||
|
@ -61,28 +61,28 @@ public class HybridHRWatchfaceFactory {
|
||||
widget.put("type", "comp");
|
||||
widget.put("name", widgetDesc.getWidgetType());
|
||||
widget.put("goal_ring", false);
|
||||
widget.put("color", "white");
|
||||
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE_ON_BLACK ? "white" : "black");
|
||||
widget.put("bg", "_00.rle");
|
||||
break;
|
||||
case "widgetWeather":
|
||||
widget.put("type", "comp");
|
||||
widget.put("name", widgetDesc.getWidgetType());
|
||||
widget.put("goal_ring", false);
|
||||
widget.put("color", "white");
|
||||
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE_ON_BLACK ? "white" : "black");
|
||||
widget.put("bg", "_01.rle");
|
||||
break;
|
||||
case "widgetSteps":
|
||||
widget.put("type", "comp");
|
||||
widget.put("name", widgetDesc.getWidgetType());
|
||||
widget.put("goal_ring", false);
|
||||
widget.put("color", "white");
|
||||
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE_ON_BLACK ? "white" : "black");
|
||||
widget.put("bg", "_02.rle");
|
||||
break;
|
||||
case "widgetHR":
|
||||
widget.put("type", "comp");
|
||||
widget.put("name", widgetDesc.getWidgetType());
|
||||
widget.put("goal_ring", false);
|
||||
widget.put("color", "white");
|
||||
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE_ON_BLACK ? "white" : "black");
|
||||
widget.put("bg", "_03.rle");
|
||||
break;
|
||||
default:
|
||||
|
@ -25,15 +25,22 @@ import java.util.LinkedHashMap;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil.invertBitmapColors;
|
||||
|
||||
public class HybridHRWatchfaceWidget {
|
||||
private String widgetType;
|
||||
private int posX;
|
||||
private int posY;
|
||||
private int color = 0;
|
||||
|
||||
public HybridHRWatchfaceWidget(String widgetType, int posX, int posY) {
|
||||
public static int COLOR_WHITE_ON_BLACK = 0;
|
||||
public static int COLOR_BLACK_ON_WHITE = 1;
|
||||
|
||||
public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color) {
|
||||
this.widgetType = widgetType;
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, String> getAvailableWidgetTypes(Context context) {
|
||||
@ -50,7 +57,12 @@ public class HybridHRWatchfaceWidget {
|
||||
}
|
||||
|
||||
public Bitmap getPreviewImage(Context context) throws IOException {
|
||||
return BitmapFactory.decodeStream(context.getAssets().open("fossil_hr/" + widgetType + "_preview.png"));
|
||||
Bitmap preview = BitmapFactory.decodeStream(context.getAssets().open("fossil_hr/" + widgetType + "_preview.png"));
|
||||
if (color == COLOR_WHITE_ON_BLACK) {
|
||||
return preview;
|
||||
} else {
|
||||
return invertBitmapColors(preview);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPosX() {
|
||||
@ -68,4 +80,8 @@ public class HybridHRWatchfaceWidget {
|
||||
public void setPosY(int posY) {
|
||||
this.posY = posY;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,33 @@ public class BitmapUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invert the colors of a Bitmap
|
||||
*
|
||||
* @param bmp input bitmap
|
||||
* @return new bitmap
|
||||
*/
|
||||
public static Bitmap invertBitmapColors(Bitmap bmp)
|
||||
{
|
||||
ColorMatrix colorMatrix_Inverted =
|
||||
new ColorMatrix(new float[] {
|
||||
-1, 0, 0, 0, 255,
|
||||
0, -1, 0, 0, 255,
|
||||
0, 0, -1, 0, 255,
|
||||
0, 0, 0, 1, 0});
|
||||
|
||||
Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
|
||||
|
||||
Canvas canvas = new Canvas(ret);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix_Inverted));
|
||||
canvas.drawBitmap(bmp, 0, 0, paint);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Crops a circular image from the center of the provided Bitmap.
|
||||
* From: https://www.tutorialspoint.com/android-how-to-crop-circular-area-from-bitmap
|
||||
|
@ -14,6 +14,16 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/watchface_dialog_widget_color" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/watchface_widget_color_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -1227,4 +1227,7 @@
|
||||
<string name="watchface_dialog_widget_preset_left">Left</string>
|
||||
<string name="watchface_dialog_widget_preset_right">Right</string>
|
||||
<string name="qhybrid_title_watchface_designer">Watchface designer</string>
|
||||
<string name="watchface_dialog_widget_color">Color:</string>
|
||||
<string name="watchface_dialog_widget_color_white">White on black</string>
|
||||
<string name="watchface_dialog_widget_color_black">Black on white</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user