CXR-L(EN)
cxr-l-sdk · v1.0.1 · snapshot 2026-05-13· ↗ source

Glasses Custom View

Android: Glasses-side Custom View

Scenario

In a CUSTOMVIEW session, deliver layout JSON and icon resources (Base64) from the phone to render UI on the glasses, and support open / update / close. CXRLSample demonstrates a composition of LinearLayout, TextView, and ImageView, plus two rounds of icon switching.

Prerequisites

  • You have completed “Connection and Session”. The current CXRLink is CUSTOMVIEW and connect(token) has been called.
  • ICustomViewCbk is registered (see the Sample CustomViewTypeViewModel).

Key APIs

MethodDescription
customViewSetIcons(String)Pass the icon-list JSON string. In the Sample it is called when onCXRLConnected(true) and iconsString is not empty.
customViewOpen(String)Pass the full view-tree JSON (first open).
customViewUpdate(String)Pass the update JSON (serialized from UpdateViewJson).
customViewClose()Close the current Custom View.

The icon JSON format is generated by toJson(list: List<IconInfo>) in the Sample. Each element contains name and data (Base64).

Callbacks (ICustomViewCbk)

CallbackSample behavior
onCustomViewOpenedMarks the Custom View as opened.
onCustomViewUpdatedLogs.
onCustomViewClosedClears the “opened” mark.
onCustomViewIconsSentLogs “icons sent successfully”.
onCustomViewError(code, msg?)Clears the “opened” mark on errors.
connect_okcustomViewSetIconscustomViewOpencustomViewUpdate_optionalcustomViewClose
  1. After the connection succeeds and the icon string is ready, call customViewSetIcons (it can also be triggered automatically in the connection callback).
  2. Call customViewOpen to deliver the root layout and child node props.
  3. For partial refresh, build UpdateViewJson (contains only changed node id and props) and call customViewUpdate.
  4. When leaving, call customViewClose.

Constraints

  • In the layout JSON, the name of an ImageView must match IconInfo.name in the icon list, otherwise the resource cannot be resolved.
  • JSON field names and units (dp/sp) must match the protocol. Before changing the structure, read Sample models such as SelfViewJson, TextViewProps, ImageViewProps.
  • Custom View is different from app control under a CustomApp session—do not mix session types.
  • Scene building: only after customViewOpen succeeds and you receive onCustomViewOpened (customViewOpened == true in the Sample) should you enter sub-capabilities such as Audio and Photo (in the Sample, CustomViewTypeScreen shows “Enter Audio / Enter Photo” only after the view is opened).

Sample reference paths

  • activities/customViewType/CustomViewTypeViewModel.kt
  • activities/customViewType/CustomViewTypeActivity.kt
  • dataBean/selfView/*
Marcin Miazga