Display¶
Iristick smart glasses have a small display on the right side, located on a movable arm. The following table shows the display resolution for various Iristick models. Applications should however be able to handle other display sizes.
Models | Resolution |
---|---|
G1 / G2 | 428 × 240 |
H1 | 640 × 400 |
By default, the display mirrors the content of the phone screen. This behavior can be overridden to either show custom UI with standard Android widgets and layouts, or to draw directly to the underlying surface.
Tip
Please read the Getting Started guide for a discussion on the default behavior of the display.
Example code
The Clock Display Example provided in the SDK package shows how
to draw standard UI elements on the display. It uses a TextView
to show
a clock.
The Bubbles Display Example shows how to directly draw on the display
using the 2D drawing API of the Canvas
class. It shows a bunch of
colored bubbles floating around on the display.
Opening the display¶
Before any drawing can occur, the display must first be opened.
The Headset
objects provides two methods for this:
openDisplay()
results in a Display
object for drawing
Android widgets; openDisplaySurface()
results in a
Surface
for direct drawing.
@Override
public void onHeadsetConnected(@NonNull Headset headset) {
headset.openDisplay(new DisplayListener() {
@Override
public void onDisplayOpened(@NonNull Display display) {
/* This method is called when the display is opened and ready
* for use.
*/
}
@Override
public void onDisplaySurfaceOpened(@NonNull Surface surface,
int width, int height,
int density) {
/* This method would have been called instead of onDisplayOpened
* if we had opened the display with openDisplaySurface().
*/
}
@Override
public void onDisplayClosed(int reason) {
/* This method is called when the display is closed.
* It is also called instead of the above two methods if the
* display could not be opened.
*/
}
}, null);
}
When you no longer need the display, you can close it with a call to the
closeDisplay()
method of the Headset
object.
Note
The display can only be opened by one application at the same time. Trying to open the display while another app is drawing on it, will result in an error (if the requesting app has lower priority) or closing the display in the other app (if the requesting app has higher priority, e.g., it is in foreground).
Likewise, it is not possible to open the display twice. You have to close it first before you can reopen it.
Drawing standard widgets¶
To show a window with standard UI elements on the Iristick display, subclass
the Presentation
class. A Presentation
is a special kind
of dialog window that displays its content on a secondary display.
Presentation automatically adapt resources to the dimensions and density of the
secondary display.
class MyPresentation extends Presentation {
MyPresentation(@NonNull Context outerContext, @NonNull Display display) {
super(outerContext, display);
/* Prevent widgets on the display from stealing focus. */
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.presentation_screen);
/* Perform any initialization here, such as retrieving widgets
* with findViewById().
*/
}
@Override
public void onStop() {
/* Called when the presentation is dismissed. Do cleanup here. */
super.onStop();
}
}
The presentation is closely linked to the display on which it shows its
contents. It requires a Display
object representing the secondary
display as an argument to its constructor.
You can get this object by opening the display with the
openDisplay()
method of the Headset
object.
When opening the display was successful, the onDisplayOpened()
of your display
listener is called. You can create and show your presentation there.
@Override
public void onDisplayOpened(@NonNull Display display) {
new MyPresentation(this, display).show();
}
Presentations are automatically dismissed when the display is closed.
Note
You must use the Context
provided by the presentation for layouts and
views shown in the presentation and the regular activity context or fragment
context for layouts and views shown on the screen of the phone.
This ensures proper scaling of the views and text.
You can get the presentation's context with the presentation's
getContext()
method.
Drawing directly on the display¶
To directly draw on the display bypassing the Android view hierarchy, open the
display with openDisplaySurface()
to get a
Surface
object representing the raw display surface.
Surface
objects can be used at multiple places in the Android API.
For example, one can call lockCanvas()
to use the Canvas
2D
drawing API.