1

I use a ControlExtension for Sony SmartWatch 2 and I have a click-handler:

@Override
public void onObjectClick(final ControlObjectClickEvent event) {
    switch (event.getClickType())
    {
        case Control.Intents.CLICK_TYPE_LONG:
        Log.i("onObjectClick", "long press");
        break;

        case Control.Intents.CLICK_TYPE_SHORT:
        Log.i("onObjectClick", "press");
        break;
    }
}

When I click on the button, I get press in my LogCat as expected.
When I hold the button I get long press (just as I want it).
But when I release the button after a long-press, I get press again.

How can I change this behavior?

Flat Eric
  • 7,971
  • 9
  • 36
  • 45

1 Answers1

0

Have you tried handling a long click like this?

ControlView upperLeft = mLayout.findViewById(R.id.sample_control_object_1);
upperLeft.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public void onLongClick() {
                // handle click action here
            }
        });
mldeveloper
  • 2,253
  • 1
  • 13
  • 14
  • I tried it but the function seems to be never called. The same for setOnClickListener. I registered the handlers in the constructor of the ControlExtension after mLayout = parseLayout(layout); and added a log entry to make sure it is called. – Flat Eric Mar 24 '14 at 20:19
  • Did you ensure that in your layout you have set android:clickable="true" for the View that is being clicked? – mldeveloper Mar 25 '14 at 20:52
  • Yes I did, although I think it is not necessary for a button. I managed it now by setting a flag on long-press to ignore the next press event. Anyway, the real device seems to behave totally different than the accessory emulator (there, the long press does not work at all, I cannot set the text of a button and texts look much larger than in the emulator) – Flat Eric Mar 25 '14 at 21:25
  • 1
    For the text size ensure that you are not using scaling (use px rather than sp) otherwise the font size will vary depending on which device you have the SW2 paired to. Not sure why long press and button text is not working for you, those should be working fine. If you can't figure it out post a code snippet and I can help. – mldeveloper Mar 26 '14 at 17:27
  • Using px solved the size problem, thanks. For the other problem, I will post a new question if I can't get it work until tomorrow. – Flat Eric Mar 26 '14 at 18:21