Search code examples
.nettizentizen-wearable-sdk

Tizen Watch Bezel Interaction


I'm trying to develop a simple app for a Galaxy Watch that includes a counter that increments and decrements using the rotatable bezel, but I'm having trouble with getting it to respond to rotation events. I've created a page that implements BezelInteractionPage and a simple class containing the counter that implements IRotaryEventReceiver and updates a Label whenever it detects a rotation event, and set the page's RotaryFocusObject to an instance of the latter class, which I think mirrors what is done in one of the examples in the Tizen.CircularUI GitHub repo. Here's my code:

public class MainPage : BezelInteractionPage
{
    public MainPage()
    {
        Label text = new Label
        {
            Text = "0"
        };
        var proxy = new RotaryFocusProxy(text);

        Content = new StackLayout
        {
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.Center,
            Children =
            {
                text
            }
        };

        RotaryFocusObject = proxy;
    }
}

class RotaryFocusProxy : IRotaryEventReceiver
{
    private int x;
    private Label label;

    public RotaryFocusProxy(Label l)
    {
        x = 0;
        label = l;
    }

    public void Rotate(RotaryEventArgs args)
    {
        if (args.IsClockwise)
            x++;
        else
            x--;
        label.Text = x.ToString();
    }
}

Aside from the main class, this is the only file in the project, which I created from the "Blank App (Xamarin.Forms)" template. The label shows up, but it doesn't update when I rotate the bezel.

An alternate way I've tried is to use a CircleStepper, but I can't figure out how to customize the size and formatting of the text it uses or cause it to respond to bezel rotation without having to be tapped first. I also don't really like the little shadow it has behind it when it's in focus, so I'd prefer not to use it if I don't have to.


Solution

  • I've created empty wearable project and added your code. In my case it worked as expected.

    Please try creating empty project from template Tizen Wearable App and adding your code snippet. You may need to update CircularUI nuget in that empty project.

    Update:

    The reason why rotary events weren't delivered is that "Blank App (Xamarin.Forms)" template doesn't have CircularUI out of the box. Apart from adding CircularUI nuget it's necessary to add initialization in Main method:

    static void Main(string[] args)
    {
        var app = new Program();
        Forms.Init(app);
        
        //This is the missing initialization code
        global::Tizen.Wearable.CircularUI.Forms.FormsCircularUI.Init();
    
        app.Run(args);
    }