• Amministratore
  •  
    Support Ukraine
    If you experience any problems with the forum (it is not visible, there is no way to post messages, or some functionality does not work), please let us know. If you have problems with registration or you did not receive confirmation letter, let us know and we will activate your account manually.
    If you get an "The submitted form was invalid. Try submitting again" error, delete cookies, then try again.
     

Change data type of widget

A branch of the forum to discuss everything that is connected with Huami Zepp OS.

Moderatori: asoo, Watchmens

Regole del forum
All communication in this branch should only be in English.
Rispondi
toolsrme
Messaggi: 19
Iscritto il: 04 ago 2023, 18:36
Località: Missouri
Has thanked: 9 times
Contatta:

Change data type of widget

Messaggio da toolsrme »

Is there a way to change the data type of a widget and thus the data it displays?

For example if I have the following:

Codice: Seleziona tutto

text_font = hmUI.createWidget(hmUI.widget.TEXT_FONT, {
  x: 0,  y: 0,  w: 120,  h: 96, text_size: 55,
  char_space: 0, line_space: 0,
  color: 0xFFFF0000,
  align_h: hmUI.align.CENTER_H,
  align_v: hmUI.align.TOP,
  text_style: hmUI.text_style.ELLIPSIS,
  type: hmUI.data_type.HEART,
  show_level: hmUI.show_level.ONLY_NORMAL,
});
and a button runs code like:

Codice: Seleziona tutto

text_font.setProperty(hmUI.prop.MORE, {type: hmUI.data_type.CAL});
How can I get that change to take and display calories instead of heart rate? Or is this not possible?

Trying to get this to work on a T-Rex 2.
Avatar utente
SashaCX75
Messaggi: 820
Iscritto il: 26 ott 2019, 15:18
Località: Ukraine
Has thanked: 13 times
Been thanked: 1029 times
Contatta:

Messaggio da SashaCX75 »

I don't know if you can change the widget type. But you can definitely make several different widgets and change their visibility.
toolsrme
Messaggi: 19
Iscritto il: 04 ago 2023, 18:36
Località: Missouri
Has thanked: 9 times
Contatta:

Messaggio da toolsrme »

Thanks @SashaCX75

That’s how I’ve done it currently. I have a number of widgets that are the same in all ways except for data_type and rotate through them via display settings. Just trying to simplify the script and cut down on duplication.
Jason Henry
Messaggi: 7
Iscritto il: 05 gen 2024, 10:16
Località: London
Has thanked: 1 time
Contatta:

Messaggio da Jason Henry »

Possibly related to fitness tracking or health data. In the provided code snippets, you're creating a text widget (`text_font`) initially set to display heart rate (`hmUI.data_type.HEART`). Later, you're attempting to change the data type to calories (`hmUI.data_type.CAL`) with the `setProperty` method.

The approach you've taken seems correct based on the code you've shared. If the library supports dynamic updates to the data type, calling `setProperty` with the new data type should update the widget to display calories instead of heart rate. However, the success of this operation depends on the capabilities and documentation of the library you're using (T-Rex 2 in this case).

Make sure that the library supports the switching of data types for widgets, and check the documentation for any specific instructions or considerations when changing the data type dynamically. If the provided code doesn't work as expected.

It's also worth verifying that the widget (`text_font`) is correctly linked to the UI element you want to modify, and that there are no conflicting settings or restrictions preventing the data type switch.
toolsrme
Messaggi: 19
Iscritto il: 04 ago 2023, 18:36
Località: Missouri
Has thanked: 9 times
Contatta:

Messaggio da toolsrme »

Thanks Jason. Yes it is correctly linked as setting its visibility is working just fine. I've looked for documentation on data_type and haven't found anything yet, either way, on whether dynamically changing it is supported or not. Unfortunately not everything is documented as thoroughly as I would like though.

The one thing I haven't checked yet is if you can create the widget initially without defining the data type and then set it for the first time and see if it works. Not sure if it is only settable in the creation or if it's only recognized the first time. This is one of those things that would be nice to have, but hasn't become necessary yet. :)
Rispondi

Torna a “Zepp OS”

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite