Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Documentation
Sidebar

Supporting Haptic Input

SDL now supports "haptic" input: input from something other than a touch screen. This could include trackpads, click-wheels, etc. These kinds of inputs work by knowing which views on the screen are touchable and focusing / highlighting on those areas when the user moves the trackpad or click wheel. When the user selects within a view, the center of that area will be "touched".

Note

Currently, there are no RPCs for knowing which view is highlighted, so your UI will have to remain static (i.e. you should not create a scrolling menu in your SDL app).

You will also need to implement touch input support in order to receive touches on the views.

Automatic Focusable Rects

SDL has support for automatically detecting focusable views within your UI and sending that data to the head unit. You will still need to tell SDL when your UI changes so that it can re-scan and detect the views to be sent.

The easiest way to use this is by taking advantage of SDL's Presentation class. This will automatically check if the capability is available and instantiate the manager for you. All you have to do is set your layout:

public static class MyPresentation extends SdlRemoteDisplay {

    public MyPresentation(Context context, Display display) {
        super(context, display);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.haptic_layout);
        LinearLayout videoView = (LinearLayout) findViewById(R.id.cat_view);
        videoView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                // ...Update something on the ui

                MyPresentation.this.invalidate();
            }
        });
    }
}

This will go through your view that was passed in and then find and send the rects to the head unit for use. When your UI changes, call invalidate() from your class that extends SdlRemoteDisplay.

Manual Focusable Rects

It is also possible that you may want to create your own rects instead of using the automated methods in the Presentation class. It is important that if sending this data yourself that you also use the SystemCapabilityManager to check if you are on a head unit that supports this feature. If the capability is available, it is easy to build the area you want to become selectable:

public void sendHapticData() {

    Rectangle rectangle = new Rectangle();
    rectangle.setX((float) 1.0);
    rectangle.setY((float) 1.0);
    rectangle.setWidth((float) 1.0);
    rectangle.setHeight((float) 1.0);

    HapticRect hapticRect = new HapticRect();
    hapticRect.setId(123);
    hapticRect.setRect(rec);

    ArrayList<HapticRect> hapticArray = new ArrayList<HapticRect>();
    hapticArray.add(0, hr);

    SendHapticData sendHapticData = new SendHapticData();
    sendHapticData.setHapticRectData(hapticArray);

    sdlManager.sendRPC(sendHapticData);

}

Each SendHapticData rpc should contain the entirety of all clickable areas to be accessed via haptic controls.

View on GitHub.com
Previous Section Next Section