RotaryEncoder

public class RotaryEncoder
extends Object

java.lang.Object
   ↳ android.support.wearable.input.RotaryEncoder


This class is deprecated.
The functionality in this class can be achieved using standard platform APIs. For checking whether an event came from the rotary encoder, use MotionEvent.getSource(), and use MotionEvent.getAxisValue(int) to obtain the axis value of the rotation.

Collection of helper methods for processing rotary encoder events. Most widgets already support these events, but custom behavior can be added if desired. To do so, either override onGenericMotionEvent(MotionEvent) or specify a custom handler via setOnGenericMotionListener(OnGenericMotionListener).

 public class MyCustomView extends View {
   // ...

   @Override
   public boolean onGenericMotionEvent(MotionEvent ev) {
     if (ev.getAction() == MotionEvent.ACTION_SCROLL
         && RotaryEncoder.isFromRotaryEncoder(ev)) {
       // Note that we negate the delta value here in order to get the right scroll direction.
       float delta = -RotaryEncoder.getRotaryAxisValue(ev)
           * RotaryEncoder.getScaledScrollFactor(getContext());
       scrollBy(0, Math.round(delta));
       return true;
     }
     return super.onGenericMotionEvent(ev);
   }

   // ...
 }
 
 

Summary

Public methods

static float getRotaryAxisValue(MotionEvent ev)

This method is deprecated. use MotionEvent.getAxisValue(int) instead, using axis MotionEvent.AXIS_SCROLL.

static float getScaledScrollFactor(Context context)

This method is deprecated. use either ViewConfigurationCompat.getScaledVerticalScrollFactor(ViewConfiguration, Context) or ViewConfigurationCompat.getScaledHorizontalScrollFactor(ViewConfiguration, Context) instead

static boolean isFromRotaryEncoder(MotionEvent ev)

This method is deprecated. use MotionEvent.getSource(), checking for InputDeviceCompat.SOURCE_ROTARY_ENCODER.

Inherited methods

Public methods

getRotaryAxisValue

public static float getRotaryAxisValue (MotionEvent ev)

This method is deprecated.
use MotionEvent.getAxisValue(int) instead, using axis MotionEvent.AXIS_SCROLL.

Parameters
ev MotionEvent

Returns
float The raw axis value (i.e. the amount the encoder was rotated) if the passed event is from a rotary encoder, and zero otherwise. This value should be multiplied against getScaledScrollFactor(Context) to determine the distance to scroll in pixels.

getScaledScrollFactor

public static float getScaledScrollFactor (Context context)

This method is deprecated.
use either ViewConfigurationCompat.getScaledVerticalScrollFactor(ViewConfiguration, Context) or ViewConfigurationCompat.getScaledHorizontalScrollFactor(ViewConfiguration, Context) instead

Parameters
context Context

Returns
float The scaling factor that rotary axis values should be multiplied against to determine how many pixels to scroll.

isFromRotaryEncoder

public static boolean isFromRotaryEncoder (MotionEvent ev)

This method is deprecated.
use MotionEvent.getSource(), checking for InputDeviceCompat.SOURCE_ROTARY_ENCODER.

Checks whether a MotionEvent was generated by a rotary encoder. Does not check the action type of the event; you should do this as well, e.g. event.getAction() == MotionEvent.ACTION_SCROLL. At the moment, rotary encoders only generate ACTION_SCROLL events, but they may generate other types of events in the future.

Parameters
ev MotionEvent

Returns
boolean True if this event was generated by a rotary encoder.