Repository navigation
EN SpeedometerIndicator JSON
This page describes the saved (persisted) format of the speedometer indicator in a project, in Mixel and in templates. The indicator class itself does not write JSON: it declares properties in defineProperties(), and saving is done by the indicator layer and the SDK properties. For the user instruction on editing a template by hand, see the Speedometer JSON page.
The page is for a plugin author who wants to understand a saved project or template: where the layer placement is stored, where the speedometer settings are stored, and which keys must not be renamed without a migration.
The indicator layer is saved in two modes:
-
toJSON(false)— the real Mixel state: the sensor is written assourceIdandsensorId, and the layer hassizeandpositionInParent. -
toJSON(true)— the template state: the sensor does not write thesourceIdandsensorIdkeys (the object is empty), andmaketis written instead ofsizeandpositionInParent. When a template is loaded, a suitable project sensor is picked automatically for theDistanceproperty.
The other properties (speedScale, font, textTemplate, the colors, the stroke width) are written the same way in both modes.
The layer name is built from the plugin identifier and the indicator name:
{
"name": "com.velitask.plugin.example.speedometer",
"data": {
"properties": {}
}
}Stable parts of the name:
| Part | Value |
|---|---|
Plugin identifier (Plagin.UID) |
com.velitask.plugin.example |
Indicator name (SpeedometerIndicator.NAME) |
speedometer |
Besides properties, data contains the common layer fields (visibility, opacity, nested layers, etc.); they do not belong to the indicator and are not described here.
In a real Mixel the layer has size and positionInParent; the exact form of their State fields is determined by the current runtime, so it is shown in abbreviated form below. The sensor stores the identifiers of the project's source and sensor.
{
"name": "com.velitask.plugin.example.speedometer",
"data": {
"size": { "...": "layer size state" },
"positionInParent": { "...": "layer position state" },
"properties": {
"Distance": {
"sourceId": { "value": 1 },
"sensorId": { "value": 2 }
},
"speedScale": { "value": 2 },
"font": {
"name": "Dialog",
"style": 0,
"size": 48,
"color": { "r": 255, "g": 255, "b": 255, "a": 255 }
},
"textTemplate": {
"template": "{curr}",
"vars": { "curr": "%.0f" }
},
"bgColor": { "r": 204, "g": 204, "b": 204, "a": 51 },
"scaleColor": { "r": 255, "g": 255, "b": 255, "a": 255 },
"arrowFillColor": { "r": 204, "g": 88, "b": 84, "a": 255 },
"arrowStrokeColor": { "r": 255, "g": 255, "b": 255, "a": 255 },
"arrowStrokeWidth": {}
}
}
}The sourceId and sensorId numbers in the example are illustrative. Take the exact form of the State fields from the current runtime.
In a template, maket is written instead of size and positionInParent (when a layer with a parent is written to a template, it is the proportional preset with the shares x, y, w, h; on reading, auto and fill are also allowed). The Distance property is empty. The values of the other properties are the initial values from the code.
{
"name": "com.velitask.plugin.example.speedometer",
"data": {
"maket": { "preset": "auto" },
"properties": {
"Distance": {},
"speedScale": { "value": 2 },
"font": {
"name": "Dialog",
"style": 0,
"size": 48,
"color": { "r": 255, "g": 255, "b": 255, "a": 255 }
},
"textTemplate": {
"template": "{curr}",
"vars": { "curr": "%.0f" }
},
"bgColor": { "r": 204, "g": 204, "b": 204, "a": 51 },
"scaleColor": { "r": 255, "g": 255, "b": 255, "a": 255 },
"arrowFillColor": { "r": 204, "g": 88, "b": 84, "a": 255 },
"arrowStrokeColor": { "r": 255, "g": 255, "b": 255, "a": 255 },
"arrowStrokeWidth": {}
}
}
}An untouched property may be written as an empty object: arrowStrokeWidth has no saved value, and getDefault() returns 2.5, so the object is empty; on reading, a missing key gives the same value 2.5. An empty object for Distance means "no sensor selected".
The order of the rows matches defineProperties().
| JSON key | Java property | SDK type | User meaning | Default |
|---|---|---|---|---|
Distance |
mDistance |
DistanceSensorProperty |
The distance sensor whose atom provides the speed. | Empty selection: {} in a template. |
speedScale |
mSpeedScale |
EnumArrayProperty<SpeedScale> |
Scale maximum. |
{"value":2} (160 km/h). |
font |
mText |
FontColorProperty |
Font and color of the number in the center. | Dialog, plain, 48, white. |
textTemplate |
mTemplate |
SpeedometerTextTemplateProperty (TextTemplateProperty) |
Template of the number in the center. |
{curr}, format %.0f. |
bgColor |
mBgColor |
ColorProperty |
Color of the round background. |
204, 204, 204, 51. |
scaleColor |
mScaleColor |
ColorProperty |
Color of the scale ticks and numbers. |
255, 255, 255, 255. |
arrowFillColor |
mArrowFillColor |
ColorProperty |
Needle fill. |
204, 88, 84, 255. |
arrowStrokeColor |
mArrowStrokeColor |
ColorProperty |
Needle stroke and center dot. |
255, 255, 255, 255. |
arrowStrokeWidth |
mArrowStrokeWidth |
DoubleProperty |
Needle stroke width. |
2.5; {} in a template. |
Value formats:
-
Distance—sourceIdandsensorId, each of the form{"value": <long>}; in a template the object is empty. -
speedScale— the index of theSpeedScaleoption.
value |
Scale |
|---|---|
0 |
40 km/h |
1 |
80 km/h |
2 |
160 km/h |
3 |
320 km/h |
-
font— a flat object:name(string),style(0plain,1bold,2italic),size(integer 1–999) andcolor(r,g,b,ain the range 0–255). -
textTemplate—template(string) andvars(the format of each variable). There is one variable:curr. - Color properties — a flat object
r,g,b,a(0–255); forbgColorthe defaultais51. -
arrowStrokeWidth— an object{"value": number}; an empty object means the default value.
The night and racing skins overwrite the properties font (color only), bgColor, scaleColor, arrowFillColor and arrowStrokeColor; they do not change the text template or the stroke width.
The values of the night skin, written as property state:
{
"font": { "name": "Dialog", "style": 0, "size": 48, "color": { "r": 170, "g": 170, "b": 170, "a": 255 } },
"bgColor": { "r": 17, "g": 17, "b": 17, "a": 170 },
"scaleColor": { "r": 136, "g": 136, "b": 136, "a": 255 },
"arrowFillColor": { "r": 85, "g": 43, "b": 42, "a": 255 },
"arrowStrokeColor": { "r": 170, "g": 170, "b": 170, "a": 255 }
}The values of the racing skin:
{
"font": { "name": "Dialog", "style": 0, "size": 48, "color": { "r": 255, "g": 255, "b": 0, "a": 255 } },
"bgColor": { "r": 17, "g": 17, "b": 17, "a": 204 },
"scaleColor": { "r": 255, "g": 255, "b": 0, "a": 255 },
"arrowFillColor": { "r": 255, "g": 48, "b": 48, "a": 255 },
"arrowStrokeColor": { "r": 255, "g": 255, "b": 0, "a": 255 }
}-
Plagin.UID(com.velitask.plugin.example) must not be changed without a migration of saved projects. -
Indicator.getName()(speedometer) must not be changed without a migration. - The property names (
Distance,speedScale,font,textTemplate,bgColor,scaleColor,arrowFillColor,arrowStrokeColor,arrowStrokeWidth) must not be renamed without a migration: loading goes by names. - The order of the
SpeedScaleelements defines the value ofspeedScale.value: reordering or inserting in the middle changes the meaning of already saved projects. - Renaming a property is more dangerous than changing the order: the order mostly affects the interface, while state loading goes by names.