Skip to content

Instantly share code, notes, and snippets.

@meteozond
Last active March 22, 2024 22:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meteozond/9e788c7e32655beeb5370372741545dd to your computer and use it in GitHub Desktop.
Save meteozond/9e788c7e32655beeb5370372741545dd to your computer and use it in GitHub Desktop.
interface BaseCreateWidgetParam {
show_level: hmUI.show_level
}
interface ImageParam extends BaseCreateWidgetParam{
/**
* The path of the image. Reference folder-structure structure.
*/
src: string
/**
* The width of the component. If not passed, the width of the image itself will be used.
*/
w?: number
/**
* The height of the component. If not passed, the height of the image itself will be used.
*/
h?: number
/**
* The x-axis coordinate of the component.
*/
x: number
/**
* The y-axis coordinate of the component.
*/
y: number
/**
* Horizontal offset of the image relative to the widget coordinates.
*/
pos_x?: number
/**
* Vertical offset of the image relative to the widget coordinates.
*/
pos_y?: number
/**
* The rotation angle of the picture (the 12-point direction is 0 degrees).
*/
angle?: number
/**
* The rotation center of the picture along the x-axis.
*/
center_x?: number
/**
* The rotation center of the picture along the y-axis.
*/
center_y?: number
// Additional properties with descriptions
// ...
// Examples of additional properties:
/**
* Example additional property 1.
*/
exampleProperty1?: string
/**
* Example additional property 2.
*/
exampleProperty2?: boolean
}
interface TextImageParam extends BaseCreateWidgetParam {
/**
* The x-axis coordinate of the component.
*/
x: number
/**
* The y-axis coordinate of the component.
*/
y: number
/**
* The width of the component. It will be calculated automatically according to the type if not specified.
*/
w?: number
/**
* The height of the component. It will be calculated automatically according to the type if not specified.
*/
h?: number
/**
* Image font array. To be sorted from 0-9.
*/
font_array: any[] // Replace 'any' with the specific array type that contains font images
/**
* The type of data. See the data_type.
*/
type?: number
/**
* It is used to specify the text content to be displayed. The 'type' attribute will be disabled when this field is specified. The content only supports 0-9.
*/
text?: string
/**
* Simplified Chinese Units.
*/
unit_sc?: string
/**
* English Units.
*/
unit_en?: string
/**
* Traditional Chinese Unit.
*/
unit_tc?: string
/**
* Chinese Simplified (English Units).
*/
imperial_unit_sc?: string
/**
* English imperial units.
*/
imperial_unit_en?: string
/**
* Traditional Chinese (English Units).
*/
imperial_unit_tc?: string
/**
* Negative sign picture.
*/
negative_image?: string
/**
* Decimal-point-pictures can be used as separators.
*/
dont_path?: string
/**
* The font of space.
*/
h_space?: number
/**
* Horizontal axis alignment (see ALIGN for values).
*/
align_h?: hmUI.align // Replace 'ALIGN' with the specific type for horizontal alignment
}
interface ArcProgressParam extends BaseCreateWidgetParam {
/**
* Center of the circle - x coordinate.
*/
center_x: number
/**
* Center of the circle - y coordinate.
*/
center_y: number
/**
* Radius of the circle.
*/
radius: number
/**
* The angle at the beginning of the arc. (0 degrees is the positive three o'clock direction)
*/
start_angle: number
/**
* The angle at the end of the arc. (0 degrees is the positive three o'clock direction)
*/
end_angle: number
/**
* Width of the circular arc.
*/
line_width: number
/**
* Color of the circular arc.
*/
color: number
/**
* Background image.
*/
src_bg?: string
/**
* The scale of the arc progress. [0-100]
*/
level?: number
}
interface ImageProgressParam extends BaseCreateWidgetParam {
/**
* Array of x-coordinates of the images.
*/
x: number[]
/**
* Array of y-coordinates of the images.
*/
y: number[]
/**
* Array of images.
*/
image_array: any[] // Replace 'any' with the specific array type that contains images
/**
* The length of the array.
*/
image_length: number
/**
* Progress level [1-image_length].
*/
level?: number
}
interface ImageLevelParam extends BaseCreateWidgetParam {
/**
* The x-coordinate of the component.
*/
x: number
/**
* The y-coordinate of the component.
*/
y: number
/**
* Array of images.
*/
image_array: string[]
/**
* Size of the array.
*/
image_length: number
/**
* The width of the component. (optional)
*/
w?: number
/**
* The height of the component. (optional)
*/
h?: number
/**
* Picture drawn [0-image_length]
*/
level?: number
}
interface ImageAnimParam extends BaseCreateWidgetParam {
/**
* The x-coordinate of the animation.
*/
x: number
/**
* The y-coordinate of the animation.
*/
y: number
/**
* The path to the image for animation.
*/
anim_path: string
/**
* The name to the image for animation.
*/
anim_prefix: string
/**
* Image extensions.
*/
anim_ext: string
/**
* Number of frames of animation.
*/
anim_fps: number
/**
* Number of animation repetitions, can be set 0: infinite repetition, 1: single repetition.
*/
repeat_count: number
/**
* Whether to repeat the playback this value is true if repeat_count is 0.
*/
anim_repeat?: boolean
/**
* The number of images.
*/
anim_size: number
/**
* The status of the animation. Refer to hmUI.anim_status.
*/
anim_status: hmUI.anim_status.START | hmUI.anim_status.STOP | hmUI.anim_status.PAUSE | hmUI.anim_status.RESUME
/**
* This function is a callback when the animation is executed successfully. Repeat_count is invalid if 0. Parameters anim is an instance to create the animation.
*/
anim_complete_call?: () => void
}
interface ImagePointerParam extends BaseCreateWidgetParam {
/**
* The center of rotation of the pointer itself, x offset.
*/
x: number
/**
* The center of rotation of the pointer itself, y offset.
*/
y: number
/**
* Rotation angle of the image, 0 degrees in the 12-point direction.
*/
angle?: number
/**
* Center of rotation of the image.
*/
center_x: number
/**
* Center of rotation of the image.
*/
center_y: number
/**
* Path to the image.
*/
src: string
}
interface ImageStatusParam extends BaseCreateWidgetParam {
x: number
y: number
type: hmUI.system_status
src: string
}
interface ImageTimeParam extends BaseCreateWidgetParam {
hour_zero: number, // Whether to make up zero.
hour_startX: number,
hour_startY: number,
hour_array: string[],
hour_space: number, // The interval between each array.
// Units
hour_unit_sc: string,
hour_unit_tc: string,
hour_unit_en: string,
hour_align: hmUI.align,
// minute second Replaces hour.
minute_follow: number, // Whether to follow.
second_follow: number, // Whether to follow.
// omitted as above
am_x: number,
am_y: number,
am_sc_path: string,
am_en_path: string
// pm as above. Prefix changed from am to pm.
}
interface TimePointerParam extends BaseCreateWidgetParam {
hour_centerX: number, // Center of pointer rotation corresponds to centerX.
hour_centerY: number, // Center of pointer rotation corresponds to centerY.
hour_posX: number, // The pointer's own center of rotation, corresponds to the x in position.
hour_posY: number, // Pointer's own center of rotation, corresponds to y in position.
hour_path: string, // Path of the pointer.
hour_cover_path: string, // Pointer circle image.
hour_cover_y: number,
hour_cover_x: number
// Minute and seconds as same as above, just replace hour with minute/second.
}
interface ImageDateParam extends BaseCreateWidgetParam {
year_startX: number
year_startY: number
year_unit_sc: string, // Unit
year_unit_tc: string
year_unit_en: string
year_align: hmUI.align,
year_space: number, // Spacing of text.
year_zero: number, // Whether to make up zeroes.
year_follow: number, // Whether to follow.
year_en_array: string[],
year_sc_array: string[],
year_tc_array: string[],
year_is_character: boolean // This field is invalid for the year and defaults to false. When true, the incoming images are 12 for the month and 31 for the day.
// Month and day as above, need to replace the prefix with month/day.
// year_is_character year set this field is invalid.
// xx_follow is whether to follow or not. If month is set to 1, there is no need to specify x y for month. It will follow the month day after the year is drawn.
// Once xx_is_character is set to true month must upload 12 sheets day upload 31 sheets, otherwise there will be an error.
}
interface ImageWeekParam extends BaseCreateWidgetParam {
x: number,
y: number,
// w,h cannot be set, use the actual width and height of the image in the weekArray.
week_en: string[]
week_tc: string[]
week_sc: string[]
}
interface DatePointerParam extends BaseCreateWidgetParam {
scale_x: number,
scale_y: number,
scale_sc: string, // Background image, optional.
scale_tc: string,
scale_en: string,
center_x: number,
center_y: number,
src: string, // Image.
posX: number,
posY: number,
cover_x: number, //Pointer above the hat.
cover_y: number,
cover_path: string,
start_angle: number, //Point 0 is positive. You can write negative numbers.
end_angle: number,
type: hmUI.date.WEEK | hmUI.date.DAY | hmUI.date.MONTH //Refer to the table above.
}
interface ImgClickParam extends BaseCreateWidgetParam {
x: number,
y: number,
w: number,
h: number,
src: string, // Image to be displayed when clicked.
type: hmUI.data_type
//Must write.The action to jump.
}
interface GradkientPolylineParam extends BaseCreateWidgetParam {
x: number,
y: number,
w: number,
h: number,
type: hmUI.data_type //If you set the type, the function below can be used to let the firmware draw the data, currently only HEART and SLEEP are supported.
}
interface WatchFaceEditBGParam extends BaseCreateWidgetParam {
edit_id: number,
x: number,
y: number,
bg_config: {id: number, preview: string, path: string}[]
count: number
default_id: number
fg: string
tips_x: number
tips_y: number
tips_bg: number
}
declare namespace hmUI {
/**
* @enum {number}
* @readonly
* @description System status options.
*/
enum system_status {
/**
* Bluetooth Disconnect.
*/
DISCONNECT = 0,
/**
* Do not disturb.
*/
DISTURB = 1,
/**
* Lock screen on.
*/
LOCK = 2,
/**
* Alarm clock on.
*/
CLOCK = 3,
}
/**
* @enum {number}
* @readonly
* @description Align options
*/
enum align {
/**
* Horizontal axis - left aligned.
*/
LEFT = 1,
/**
* Horizontal axis - right aligned.
*/
RIGHT = 2,
/**
* Horizontal axis - centered.
*/
CENTER_H = 16,
/**
* Vertical axis - topmost
*/
TOP = 4,
/**
* Vertical Axis - Bottom
*/
BOTTOM = 8,
/**
* Vertical axis - centered
*/
CENTER_V = 32
}
/**
* @enum {number}
* @readonly
* @description Animation status options.
*/
enum anim_status {
/**
* Start animation only pause and stop are allowed to be called after starting the animation.
*/
START = 0,
/**
* Pause animation can only be called after starting the animation and resuming it.
*/
PAUSE = 1,
/**
* Resume animation can only be called after pausing the animation.
*/
RESUME = 2,
/**
* Stop animation can only be called after starting the animation and resuming it.
*/
STOP = 3,
}
/**
* @enum {number}
* @readonly
* @description
*/
enum prop {
X = 1,
Y = 2,
W = 3,
H = 4,
POS_X = 5,
POS_Y = 6,
ANGLE = 7,
CENTER_X = 8,
CENTER_Y = 9,
SRC = 10,
TEXT = 11,
COLOR = 12,
START_ANGLE = 13,
END_ANGLE = 14,
LINE_WIDTH = 15,
LINE_START_X = 16,
LINE_START_Y = 17,
LINE_END_X = 18,
LINE_END_Y = 19,
LINE_PROGRESS = 20,
SRC_BG = 21,
SRC_PROGRESS = 22,
SRC_INDICATOR = 23,
ALIGN_H = 24,
ALIGN_V = 25,
IMAGE_ARRAY = 26,
IMAGE_LENGTH = 27,
LEVEL = 28,
TYPE = 29,
TEXT_SIZE = 30,
FONT = 31,
ID = 32,
DATASET = 33,
ANIM_STATUS = 34,
ANIM_IS_RUNNING = 35,
ANIM_IS_PAUSE = 36,
ANIM_IS_STOP = 37,
ANIM = 38,
RADIUS = 39,
ALPHA = 40,
VISIBLE = 41,
INIT = 42,
CHECKED = 43,
SHOW = 44,
UNCHECKED = 45,
CURRENT_SELECT = 46,
TEXT_STYLE = 47,
CHAR_SPACE = 48,
LINE_SPACE = 49,
END_X = 50,
CURRENT_TYPE = 51,
UPDATE_DATA = 52,
SELECT_INDEX = 53,
CURRENT_CONFIG = 54,
ITEM_MORE = 55,
ITEM_REFRESH = 56,
LIST_TOP = 57
}
/**
* TEXT_STYLE
*/
enum text_style {
/**
* Single line overflow characters display...
*/
ELLIPSIS=2,
/**
* Marquee
*/
NONE=3,
CHAR_WRAP=0,
WRAP=1,
}
/**
* @enum {number}
* @readonly
* @description
*/
enum widget {
/**
* The image widget is used to display images and supports image rotation.
*/
IMG = 1,
GROUP = 65536,
TEXT = 2,
ARC = 3,
FILL_RECT = 4,
STROKE_RECT = 5,
/**
* Support displaying text as images, you need to pass in the image font array font_array.
*/
TEXT_IMG = 6,
/**
* Arc progress widget draws arc progress, supports start angle, line width, end angle, color, progress scale.
*/
ARC_PROGRESS = 7,
LINE_PROGRESS = 8,
/**
* Display the images sequentially according to the given order.
*/
IMG_PROGRESS = 9,
/**
* Given an array of pictures, display the corresponding pictures according to the progress (the level property).
*/
IMG_LEVEL = 10,
/**
* Pointer component based on IMG image component.
*/
IMG_POINTER = 11,
/**
* year_is_character year set this field is invalid.
* xx_follow is whether to follow or not. If month is set to 1, there is no need to specify x y for month. It will follow the month day after the year is drawn.
* Once xx_is_character is set to true month must upload 12 sheets day upload 31 sheets, otherwise there will be an error.
*/
IMG_DATE = 13,
IMG_WEEK = 14,
IMG_TIME = 12,
/**
* Play the pre-given image at the set frame rate to create an animation effect.
*/
IMG_ANIM = 15,
IMG_STATUS = 16,
IMG_CLICK = 17,
TEXT_TIME = 18,
TIME_NUM = 19,
CYCLE_LIST = 20,
CIRCLE = 21,
STATE_BUTTON = 22,
RADIO_GROUP = 65537,
CHECKBOX_GROUP = 65538,
BUTTON = 23,
SLIDE_SWITCH = 24,
DIALOG = 25,
SCROLL_LIST = 26,
CYCLE_IMAGE_TEXT_LIST = 27,
TIME_POINTER = 28,
WATCHFACE_EDIT_MASK = 29,
WATCHFACE_EDIT_FG_MASK = 30,
WATCHFACE_EDIT_GROUP = 65539,
/**
* Editable backgrounds
* When editable background + editable widget, widget omits 100%mask
* If only editable background, just remove the top two layers
* Just write your own ids and don't repeat them.
*/
WATCHFACE_EDIT_BG = 31,
HISTOGRAM = 32,
DATE_POINTER = 33,
TEXT_FONT = 34,
WIDGET_DELEGATE = 35,
GRADKIENT_POLYLINE = 36,
PICK_TIME = 512,
PICK_DATE = 513,
/**
* Editable pointers
* 100% Cover cannot be omitted if there is no editable background.
* ID Do not repeat.
*
* pointerEdit.getProperty(hmUI.prop.CURRENT_CONFIG,true) //The second parameter is whether to export the second hand property.
*
* This function returns the configuration of the user-selected pointer style attribute and assigns it directly to TIME_POINTER.
*/
WATCHFACE_EDIT_POINTER = 65540,
ARC_PROGRESS_FILL = 37,
QRCODE = 38,
BARCODE = 39
}
/**
* @enum {number}
* @readonly
* @description
*/
enum date {
MONTH = 0,
DAY = 1,
WEEK =2,
}
/**
* @enum {number}
* @readonly
* @description
*/
enum show_level {
ONLY_NORMAL = 1,
ONAL_AOD = 2,
ONLY_AOD = 2,
ONLY_EDIT = 4,
ALL = 7,
}
/**
* @enum {number}
* @readonly
* @description
*/
enum data_type {
/**
* Electricity
*/
BATTERY = 0,
/**
* Current Step Count
*/
STEP = 1,
/**
* Target number of steps
*/
STEP_TARGET = 2,
/**
* Current Calories
*/
CAL = 3,
/**
* Target Calories
*/
CAL_TARGET = 4,
/**
* Current heart rate
*/
HEART = 5,
/**
* Today PAI
*/
PAI_DAILY = 6,
/**
* Total PAI
*/
PAI_WEEKLY = 7,
/**
* Distance
*/
DISTANCE = 8,
/**
* Current stand
*/
STAND = 9,
/**
* Target stand
*/
STAND_TARGET = 10,
/**
* Current temperature
*/
WEATHER_CURRENT = 11,
/**
* Current low temperature
*/
WEATHER_LOW = 12,
/**
* Current high temperature
*/
WEATHER_HIGH = 13,
/**
* Ultraviolet light
*/
UVI = 14,
/**
* Air Quality
*/
AQI = 15,
/**
* Humidity
*/
HUMIDITY = 16,
/**
* Current Activities
*/
ACTIVITY = 17,
/**
* Target Activities
*/
ACTIVITY_TARGET = 18,
/**
* Fat Burning
*/
FAT_BURNING = 19,
/**
* Fat Burning Goals
*/
FAT_BURNING_TARGET = 20,
/**
* Sunrise and sunset will be displayed according to the time
*/
SUN_CURRENT = 21,
/**
* Sunrise
*/
SUN_RISE = 22,
/**
* Sunset
*/
SUN_SET = 23,
/**
* Wind Power
*/
WIND = 24,
/**
* Pressure
*/
STRESS = 25,
/**
* Blood oxygen
*/
SPO2 = 26,
/**
* Pneumatic pressure
*/
ALTIMETER = 27,
/**
* Moon phase. Only progress is supported
*/
MOON = 28,
/**
* Climbing a building
*/
FLOOR = 29,
/**
* Alarm Clock
*/
ALARM_CLOCK = 30,
/**
* Countdown
*/
COUNT_DOWN = 31,
/**
* Stopwatch
*/
STOP_WATCH = 32,
/**
* Sleep
*/
SLEEP = 33
}
function createWidget(widgetType: hmUI.widget.IMG, ImageParam): Widget
function createWidget(widgetType: hmUI.widget.TEXT_IMG, TextImageParam): Widget
function createWidget(widgetType: hmUI.widget.ARC_PROGRESS, ArcProgressParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_PROGRESS, ImageProgressParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_LEVEL, ImageLevelParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_ANIM, ImageAnimParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_POINTER, ImagePointerParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_STATUS, ImageStatusParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_TIME, ImageTimeParam): Widget
function createWidget(widgetType: hmUI.widget.TIME_POINTER, TimePointerParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_WEEK, ImageWeekParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_DATE, ImageDateParam): Widget
function createWidget(widgetType: hmUI.widget.DATE_POINTER, DatePointerParam): Widget
function createWidget(widgetType: hmUI.widget.IMG_CLICK, ImgClickParam): Widget
function createWidget(widgetType: hmUI.widget.GRADKIENT_POLYLINE, GradkientPolylineParam): Widget
function createWidget(widgetType: hmUI.widget.WATCHFACE_EDIT_BG, WatchFaceEditBGParam): Widget
/**
* Delete the UI widget.
* @param widget
*/
function deleteWidget(widget: Widget): void
}
interface setPropertyParam {
x: number
y: number
w: number
h: number
text: string,
color: number, // 0x34e073
align_h: hmUI.align
}
declare class Widget {
setProperty(propertyId: hmUI.prop, val: setPropertyParam): void
getProperty(key: hmUI.prop): any
}
declare namespace __$$hmAppManager$$__ {
class currentApp {
static current: any
static __globals__: any
}
}
interface WidgetFactoryParam {
onInit: () => void
onReady: () => void
onShow: () => void
onHide: () => void
onDestory: () => void
}
declare namespace DeviceRuntimeCore {
function WidgetFactory(param: WidgetFactoryParam)
function HmDomApi()
function WatchFace()
}
declare namespace Logger {
function getLogger()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment