use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class MiBand2FWInstallHandler method maybeAddFw53Hint.
private void maybeAddFw53Hint(InstallActivity installActivity, GBDevice device) {
HuamiFirmwareType type = getFirmwareType();
if (type != HuamiFirmwareType.FIRMWARE) {
return;
}
Version deviceVersion = getFirmwareVersionOf(device);
if (deviceVersion != null) {
Version v53 = MiBandConst.MI2_FW_VERSION_INTERMEDIATE_UPGRADE_53;
if (deviceVersion.compareTo(v53) < 0) {
String vInstall = getHelper().format(getHelper().getFirmwareVersion());
try {
if (vInstall == null || new Version(vInstall).compareTo(v53) > 0) {
String newInfoText = getContext().getString(R.string.mi2_fw_installhandler_fw53_hint, v53.get()) + "\n\n" + installActivity.getInfoText();
installActivity.setInfoText(newInfoText);
}
} catch (IllegalArgumentException e) {
String newInfoText = getContext().getString(R.string.mi2_fw_installhandler_fw53_hint, v53.get()) + "\n\n" + installActivity.getInfoText() + "\n\n" + getContext().getString(R.string.error_version_check_extreme_caution, vInstall);
installActivity.setInfoText(newInfoText);
}
}
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class HuamiSupport method setLanguage.
protected HuamiSupport setLanguage(TransactionBuilder builder) {
String localeString = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString("language", "auto");
if (localeString == null || localeString.equals("auto")) {
String language = Locale.getDefault().getLanguage();
String country = Locale.getDefault().getCountry();
if (country == null) {
// sometimes country is null, no idea why, guess it.
country = language;
}
localeString = language + "_" + country.toUpperCase();
}
LOG.info("Setting device to locale: " + localeString);
final byte[] command_new = HuamiService.COMMAND_SET_LANGUAGE_NEW_TEMPLATE.clone();
System.arraycopy(localeString.getBytes(), 0, command_new, 3, localeString.getBytes().length);
byte[] command_old;
switch(localeString.substring(0, 2)) {
case "es":
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SPANISH;
break;
case "zh":
if (localeString.equals("zh_CN")) {
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_SIMPLIFIED_CHINESE;
} else {
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_TRADITIONAL_CHINESE;
}
break;
default:
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
}
if (force2021Protocol) {
writeToConfiguration(builder, command_new);
} else {
final byte[] finalCommand_old = command_old;
builder.add(new ConditionalWriteAction(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION)) {
@Override
protected byte[] checkCondition() {
if ((gbDevice.getType() == DeviceType.AMAZFITBIP && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("0.1.0.77")) < 0) || (gbDevice.getType() == DeviceType.AMAZFITCOR && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("1.0.7.23")) < 0)) {
return finalCommand_old;
} else {
return command_new;
}
}
});
}
return this;
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method renderWidgets.
private void renderWidgets() {
Version firmwareVersion = getCleanFWVersion();
if (firmwareVersion != null && firmwareVersion.compareTo(new Version("1.0.2.20")) >= 0) {
// this does not work on newer firmware versions
return;
}
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDeviceSupport().getDevice().getAddress()));
boolean forceWhiteBackground = prefs.getBoolean("force_white_color_scheme", false);
boolean drawCircles = prefs.getBoolean("widget_draw_circles", false);
Bitmap circleBitmap = null;
if (drawCircles) {
circleBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_8888);
Canvas circleCanvas = new Canvas(circleBitmap);
Paint circlePaint = new Paint();
circlePaint.setAntiAlias(true);
circlePaint.setColor(forceWhiteBackground ? Color.WHITE : Color.BLACK);
circlePaint.setStyle(Paint.Style.FILL);
circlePaint.setStrokeWidth(3);
circleCanvas.drawCircle(38, 38, 35, circlePaint);
circlePaint.setColor(forceWhiteBackground ? Color.BLACK : Color.WHITE);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeWidth(3);
circleCanvas.drawCircle(38, 38, 35, circlePaint);
}
try {
ArrayList<AssetImage> widgetImages = new ArrayList<>();
if (this.backGroundImage != null) {
widgetImages.add(this.backGroundImage);
}
for (int i = 0; i < widgets.size(); i++) {
Widget w = widgets.get(i);
if (!(w instanceof CustomWidget)) {
if (w.getWidgetType() == Widget.WidgetType.LAST_NOTIFICATION) {
Bitmap widgetBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_8888);
Canvas widgetCanvas = new Canvas(widgetBitmap);
if (drawCircles) {
widgetCanvas.drawBitmap(circleBitmap, 0, 0, null);
}
Paint p = new Paint();
p.setStyle(Paint.Style.FILL);
p.setTextSize(10);
p.setColor(Color.WHITE);
if (this.lastPostedApp != null) {
Bitmap icon = Bitmap.createScaledBitmap(appIconCache.get(this.lastPostedApp), 40, 40, true);
if (icon != null) {
widgetCanvas.drawBitmap(icon, (float) (38 - (icon.getWidth() / 2.0)), (float) (38 - (icon.getHeight() / 2.0)), null);
}
}
widgetImages.add(AssetImageFactory.createAssetImage(widgetBitmap, true, w.getAngle(), w.getDistance(), 1));
} else if (drawCircles) {
widgetImages.add(AssetImageFactory.createAssetImage(circleBitmap, true, w.getAngle(), w.getDistance(), 1));
}
continue;
}
CustomWidget widget = (CustomWidget) w;
Bitmap widgetBitmap = Bitmap.createBitmap(76, 76, Bitmap.Config.ARGB_8888);
Canvas widgetCanvas = new Canvas(widgetBitmap);
if (drawCircles) {
widgetCanvas.drawBitmap(circleBitmap, 0, 0, null);
}
for (CustomWidgetElement element : widget.getElements()) {
if (element.getWidgetElementType() == CustomWidgetElement.WidgetElementType.TYPE_BACKGROUND) {
File imageFile = new File(element.getValue());
if (!imageFile.exists() || !imageFile.isFile()) {
LOG.debug("Image file " + element.getValue() + " not found");
continue;
}
Bitmap imageBitmap = BitmapFactory.decodeFile(element.getValue());
if (imageBitmap == null) {
LOG.debug("image file " + element.getValue() + " could not be decoded");
continue;
}
Bitmap scaledBitmap = Bitmap.createScaledBitmap(imageBitmap, 76, 76, false);
widgetCanvas.drawBitmap(scaledBitmap, 0, 0, null);
break;
}
}
for (CustomWidgetElement element : widget.getElements()) {
if (element.getWidgetElementType() == CustomWidgetElement.WidgetElementType.TYPE_TEXT) {
Paint textPaint = new Paint();
textPaint.setStrokeWidth(4);
textPaint.setTextSize(17f);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setColor(forceWhiteBackground ? Color.BLACK : Color.WHITE);
textPaint.setTextAlign(Paint.Align.CENTER);
widgetCanvas.drawText(element.getValue(), element.getX(), element.getY() - (textPaint.descent() + textPaint.ascent()) / 2f, textPaint);
} else if (element.getWidgetElementType() == CustomWidgetElement.WidgetElementType.TYPE_IMAGE) {
Bitmap imageBitmap = BitmapFactory.decodeFile(element.getValue());
widgetCanvas.drawBitmap(imageBitmap, element.getX() - imageBitmap.getWidth() / 2f, element.getY() - imageBitmap.getHeight() / 2f, null);
}
}
widgetImages.add(AssetImageFactory.createAssetImage(widgetBitmap, true, widget.getAngle(), widget.getDistance(), 1));
}
AssetImage[] images = widgetImages.toArray(new AssetImage[0]);
ArrayList<AssetImage> pushFiles = new ArrayList<>(4);
imgloop: for (AssetImage image : images) {
for (AssetImage pushedImage : pushFiles) {
// no need to send same file multiple times, filtering by name since name is hash
if (image.getFileName().equals(pushedImage.getFileName()))
continue imgloop;
}
pushFiles.add(image);
}
if (pushFiles.size() > 0) {
queueWrite(new AssetFilePutRequest(pushFiles.toArray(new AssetImage[0]), FileHandle.ASSET_BACKGROUND_IMAGES, this));
}
// queueWrite(new FileDeleteRequest((short) 0x0503));
queueWrite(new ImagesSetRequest(images, this));
} catch (IOException e) {
LOG.error("Error while rendering widgets", e);
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method initializeAfterAuthentication.
private void initializeAfterAuthentication(boolean authenticated) {
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZING));
if (!authenticated) {
GB.toast(getContext().getString(R.string.fossil_hr_auth_failed), Toast.LENGTH_LONG, GB.ERROR);
initializeAfterWatchConfirmation(false);
return;
}
boolean versionSupportsConfirmation = getCleanFWVersion().compareTo(new Version("1.0.2.22")) != -1;
if (!versionSupportsConfirmation) {
initializeAfterWatchConfirmation(true);
return;
}
boolean shouldAuthenticateOnWatch = getDeviceSpecificPreferences().getBoolean("enable_on_device_confirmation", true);
if (!shouldAuthenticateOnWatch) {
GB.toast("Skipping on-device confirmation", Toast.LENGTH_SHORT, GB.INFO);
initializeAfterWatchConfirmation(false);
return;
}
confirmOnWatch();
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method loadWidgets.
private void loadWidgets() {
Version firmwareVersion = getCleanFWVersion();
if (firmwareVersion != null && firmwareVersion.compareTo(new Version("1.0.2.20")) >= 0) {
// this does not work on newer firmware versions
return;
}
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDeviceSupport().getDevice().getAddress()));
boolean forceWhiteBackground = prefs.getBoolean("force_white_color_scheme", false);
String fontColor = forceWhiteBackground ? "black" : "default";
Widget[] oldWidgets = widgets.toArray(new Widget[0]);
widgets.clear();
String widgetJson = GBApplication.getPrefs().getPreferences().getString("FOSSIL_HR_WIDGETS", "{}");
String customWidgetJson = GBApplication.getPrefs().getString("QHYBRID_CUSTOM_WIDGETS", "[]");
try {
JSONObject widgetConfig = new JSONObject(widgetJson);
JSONArray customWidgets = new JSONArray(customWidgetJson);
Iterator<String> keyIterator = widgetConfig.keys();
HashMap<String, Integer> positionMap = new HashMap<>(4);
positionMap.put("top", 0);
positionMap.put("right", 90);
positionMap.put("bottom", 180);
positionMap.put("left", 270);
while (keyIterator.hasNext()) {
String position = keyIterator.next();
String identifier = widgetConfig.getString(position);
Widget.WidgetType type = Widget.WidgetType.fromJsonIdentifier(identifier);
Widget widget = null;
if (type != null) {
widget = new Widget(type, positionMap.get(position), 63, fontColor);
} else {
identifier = identifier.substring(7);
for (int i = 0; i < customWidgets.length(); i++) {
JSONObject customWidget = customWidgets.getJSONObject(i);
if (customWidget.getString("name").equals(identifier)) {
boolean drawCircle = false;
if (customWidget.has("drawCircle"))
drawCircle = customWidget.getBoolean("drawCircle");
CustomWidget newWidget = new CustomWidget(customWidget.getString("name"), positionMap.get(position), 63, fontColor);
JSONArray elements = customWidget.getJSONArray("elements");
for (int i2 = 0; i2 < elements.length(); i2++) {
JSONObject element = elements.getJSONObject(i2);
if (element.getString("type").equals("text")) {
newWidget.addElement(new CustomTextWidgetElement(element.getString("id"), element.getString("value"), element.getInt("x"), element.getInt("y")));
} else if (element.getString("type").equals("background")) {
newWidget.addElement(new CustomBackgroundWidgetElement(element.getString("id"), element.getString("value")));
}
}
widget = newWidget;
}
}
}
if (widget == null)
continue;
widgets.add(widget);
}
} catch (JSONException e) {
LOG.error("Error while updating widgets", e);
}
for (Widget oldWidget : oldWidgets) {
if (!(oldWidget instanceof CustomWidget))
continue;
CustomWidget customOldWidget = (CustomWidget) oldWidget;
for (CustomWidgetElement oldElement : customOldWidget.getElements()) {
for (Widget newWidget : widgets) {
if (newWidget instanceof CustomWidget) {
((CustomWidget) newWidget).updateElementValue(oldElement.getId(), oldElement.getValue());
}
}
}
}
uploadWidgets();
}
Aggregations