Wear OS Custom Rotary Function

Viewed 29

I have been trying to add a custom function to my bevel / rotary input for wear OS. Simply I just want to increment a number when I turn the bevel one way or another.

If anyone would have any examples of custom Rotary Input with the .XML I would appreciate it! Sadly I can't seem to figure out from the documentation alone.

1 Answers

Look at onGenericMotionEvent. There are quiet a few examples on github

For example https://github.com/VladimirWrites/AnalogWatchFace/blob/ae09ed77b2c0ae89cdc32123ce7d229830188a8a/wear/src/main/java/com/vlad1m1r/watchface/settings/base/BaseRecyclerActivity.kt

open class MyActivity : AppCompatActivity() {

    override fun onGenericMotionEvent(event: MotionEvent?): Boolean {
        if (event?.action == MotionEvent.ACTION_SCROLL && RotaryEncoderHelper.isFromRotaryEncoder(event)) {
            val delta = -RotaryEncoderHelper.getRotaryAxisValue(event) * RotaryEncoderHelper.getScaledScrollFactor(this)

            myCustomScrollHandler(delta)

            return true
        }
        return super.onGenericMotionEvent(event)
    }
}
Related