# RotaryEncoder

Summary:[Methods](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder#inhmethods)  

# RotaryEncoder

`
public


class
RotaryEncoder
`  
`

extends `[Object](http://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|----------------------------------------------|
| [java.lang.Object](http://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.wearable.input.RotaryEncoder |

<br />

*** ** * ** ***

<br />

**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()](http://developer.android.com/reference/android/view/MotionEvent.html#getSource()), and use[MotionEvent.getAxisValue(int)](http://developer.android.com/reference/android/view/MotionEvent.html#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)](http://developer.android.com/reference/android/view/View.html#onGenericMotionEvent(android.view.MotionEvent))or specify a custom handler via[setOnGenericMotionListener(OnGenericMotionListener)](http://developer.android.com/reference/android/view/View.html#setOnGenericMotionListener(android.view.View.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);
       }

       // ...
     }
     
     
<br />

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                  ||
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static float`   | ` `[getRotaryAxisValue](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder.html#getRotaryAxisValue(android.view.MotionEvent))`(`[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)` ev) ` *This method is deprecated. use[MotionEvent.getAxisValue(int)](http://developer.android.com/reference/android/view/MotionEvent.html#getAxisValue(int))instead, using axis[MotionEvent.AXIS_SCROLL](http://developer.android.com/reference/android/view/MotionEvent.html#AXIS_SCROLL).*                                                                                                                                                                                                                                                                                                              |
| ` static float`   | ` `[getScaledScrollFactor](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder.html#getScaledScrollFactor(android.content.Context))`(`[Context](http://developer.android.com/reference/android/content/Context.html)` context) ` *This method is deprecated. use either[ViewConfigurationCompat.getScaledVerticalScrollFactor(ViewConfiguration, Context)](https://developer.android.com/reference/androidx/core/view/ViewConfigurationCompat.html#getScaledVerticalScrollFactor(android.view.ViewConfiguration,%20android.content.Context))or[ViewConfigurationCompat.getScaledHorizontalScrollFactor(ViewConfiguration, Context)](https://developer.android.com/reference/androidx/core/view/ViewConfigurationCompat.html#getScaledHorizontalScrollFactor(android.view.ViewConfiguration,%20android.content.Context))instead* |
| ` static boolean` | ` `[isFromRotaryEncoder](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder.html#isFromRotaryEncoder(android.view.MotionEvent))`(`[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)` ev) ` *This method is deprecated. use[MotionEvent.getSource()](http://developer.android.com/reference/android/view/MotionEvent.html#getSource()), checking for[InputDeviceCompat.SOURCE_ROTARY_ENCODER](https://developer.android.com/reference/androidx/core/view/InputDeviceCompat.html#SOURCE_ROTARY_ENCODER).*                                                                                                                                                                                                                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](http://developer.android.com/reference/java/lang/Object.html)` ` |------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| | ` `[Object](http://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                               | | ` boolean`                                                                         | ` equals(`[Object](http://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                            | ` finalize() `                                                                            | | ` final `[Class](http://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                            | | ` int`                                                                             | ` hashCode() `                                                                            | | ` final void`                                                                      | ` notify() `                                                                              | | ` final void`                                                                      | ` notifyAll() `                                                                           | | ` `[String](http://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                            | | ` final void`                                                                      | ` wait(long arg0, int arg1) `                                                             | | ` final void`                                                                      | ` wait(long arg0) `                                                                       | | ` final void`                                                                      | ` wait() `                                                                                | ||

## Public methods

### getRotaryAxisValue

```
public static float getRotaryAxisValue (MotionEvent ev)
```

<br />

**This method is deprecated.**   
use[MotionEvent.getAxisValue(int)](http://developer.android.com/reference/android/view/MotionEvent.html#getAxisValue(int))instead, using axis[MotionEvent.AXIS_SCROLL](http://developer.android.com/reference/android/view/MotionEvent.html#AXIS_SCROLL).

<br />

<br />

|         Parameters         ||
|------|----------------------|
| `ev` | `MotionEvent` <br /> |

|                                                                                                                                                                                                    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)](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder.html#getScaledScrollFactor(android.content.Context))to determine the distance to scroll in pixels. <br /> |

**See also:**

- [isFromRotaryEncoder(MotionEvent)](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder.html#isFromRotaryEncoder(android.view.MotionEvent))
- [MotionEvent.getAxisValue(int)](http://developer.android.com/reference/android/view/MotionEvent.html#getAxisValue(int))  

### getScaledScrollFactor

```
public static float getScaledScrollFactor (Context context)
```

<br />

**This method is deprecated.**   
use either[ViewConfigurationCompat.getScaledVerticalScrollFactor(ViewConfiguration, Context)](https://developer.android.com/reference/androidx/core/view/ViewConfigurationCompat.html#getScaledVerticalScrollFactor(android.view.ViewConfiguration,%20android.content.Context))or[ViewConfigurationCompat.getScaledHorizontalScrollFactor(ViewConfiguration, Context)](https://developer.android.com/reference/androidx/core/view/ViewConfigurationCompat.html#getScaledHorizontalScrollFactor(android.view.ViewConfiguration,%20android.content.Context))instead

<br />

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

|                                                             Returns                                                             ||
|---------|------------------------------------------------------------------------------------------------------------------------|
| `float` | The scaling factor that rotary axis values should be multiplied against to determine how many pixels to scroll. <br /> |

**See also:**

- [getRotaryAxisValue(MotionEvent)](https://developer.android.com/reference/android/support/wearable/input/RotaryEncoder.html#getRotaryAxisValue(android.view.MotionEvent))  

### isFromRotaryEncoder

```
public static boolean isFromRotaryEncoder (MotionEvent ev)
```

<br />

**This method is deprecated.**   
use[MotionEvent.getSource()](http://developer.android.com/reference/android/view/MotionEvent.html#getSource()), checking for[InputDeviceCompat.SOURCE_ROTARY_ENCODER](https://developer.android.com/reference/androidx/core/view/InputDeviceCompat.html#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.

<br />

|         Parameters         ||
|------|----------------------|
| `ev` | `MotionEvent` <br /> |

|                                 Returns                                 ||
|-----------|--------------------------------------------------------------|
| `boolean` | True if this event was generated by a rotary encoder. <br /> |