Example usage for android.view MotionEvent getAxisValue

List of usage examples for android.view MotionEvent getAxisValue

Introduction

In this page you can find the example usage for android.view MotionEvent getAxisValue.

Prototype

public final float getAxisValue(int axis) 

Source Link

Document

#getAxisValue(int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:Main.java

public static float getRelativeAxisY(MotionEvent event) {
    return event.getAxisValue(AXIS_RELATIVE_Y);
}

From source file:Main.java

public static float getRelativeAxisX(MotionEvent event) {
    return event.getAxisValue(AXIS_RELATIVE_X);
}

From source file:Main.java

public static boolean eventHasRelativeMouseAxes(MotionEvent event) {
    if (!nvExtensionSupported) {
        return false;
    }//from w  ww . j  a  v  a  2s .co  m
    return event.getAxisValue(AXIS_RELATIVE_X) != 0 || event.getAxisValue(AXIS_RELATIVE_Y) != 0;
}

From source file:tv.piratemedia.flightcontroller.ControlActivity.java

private static float getTriggerValue(MotionEvent event, InputDevice device, int axis, int historyPos) {
    final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());
    if (range != null) {
        final float value = historyPos < 0 ? event.getAxisValue(axis)
                : event.getHistoricalAxisValue(axis, historyPos);
        return value / range.getRange();
    }/*from  w  w w .j a  va 2  s .  c  o m*/
    return 0;
}

From source file:Main.java

public static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) {
    if (device == null) {
        return 0;
    }//from   w  w w.  jav a  2 s .com
    final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());
    if (range != null) {
        final float flat = range.getFlat();
        final float value = historyPos < 0 ? event.getAxisValue(axis)
                : event.getHistoricalAxisValue(axis, historyPos);

        // Ignore axis values that are within the 'flat' region of the
        // joystick axis center.
        // A joystick at rest does not always report an absolute position of
        // (0,0).
        if (Math.abs(value) > flat) {
            return value;
        }
    }
    return 0;
}

From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java

private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) {
    final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());

    // A joystick at rest does not always report an absolute position of
    // (0,0). Use the getFlat() method to determine the range of values
    // bounding the joystick axis center.
    if (range != null) {
        final float flat = range.getFlat();
        final float value = historyPos < 0 ? event.getAxisValue(axis)
                : event.getHistoricalAxisValue(axis, historyPos);

        // Ignore axis values that are within the 'flat' region of the
        // joystick axis center.
        if (Math.abs(value) > flat) {
            return value;
        }//from   ww w. j  ava2  s .c  o m
    }
    return 0;
}

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayActivity.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    // This method will handle gamepad events
    if (event.getAxisValue(MotionEvent.AXIS_LTRIGGER) > GAMEPAD_TRIGGER_INTENSITY_ON
            && !gamepadTriggerPressed) {
        getMediaController().getTransportControls().rewind();
        gamepadTriggerPressed = true;// w  w w.  j a va 2s  .c o  m
    } else if (event.getAxisValue(MotionEvent.AXIS_RTRIGGER) > GAMEPAD_TRIGGER_INTENSITY_ON
            && !gamepadTriggerPressed) {
        getMediaController().getTransportControls().fastForward();
        gamepadTriggerPressed = true;
    } else if (event.getAxisValue(MotionEvent.AXIS_LTRIGGER) < GAMEPAD_TRIGGER_INTENSITY_OFF
            && event.getAxisValue(MotionEvent.AXIS_RTRIGGER) < GAMEPAD_TRIGGER_INTENSITY_OFF) {
        gamepadTriggerPressed = false;
    }
    return super.onGenericMotionEvent(event);
}

From source file:org.mariotaku.twidere.util.MouseScrollDirectionDecider.java

public boolean guessDirection(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        return false;
    }/*from w w w.  jav a 2  s.  c  om*/
    if (event.getAction() != MotionEventCompat.ACTION_SCROLL)
        return false;
    verticalScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
    horizontalScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
    verticalView.onGenericMotionEvent(event);
    horizontalView.onGenericMotionEvent(event);
    return verticalScroll != 0 || horizontalScroll != 0;
}

From source file:foam.jellyfish.StarwispActivity.java

@Override
public boolean onGenericMotionEvent(final MotionEvent event) {
    //Get the player #
    int player = OuyaController.getPlayerNumByDeviceId(event.getDeviceId());

    Log.i("starwisp", "ogme");

    // Joystick/*w ww.j  av a 2 s. c  o  m*/
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
        //Get all the axis for the event
        float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X);
        float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y);

        float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X);
        float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y);
        float L2 = event.getAxisValue(OuyaController.AXIS_L2);
        float R2 = event.getAxisValue(OuyaController.AXIS_R2);

        Log.i("starwisp", "controller " + LS_X + " " + LS_Y + RS_X + " " + RS_Y + L2 + " " + R2);

        Scheme.eval("(on-fling " + LS_X * -500 + " " + LS_Y * -500 + ")");
    }

    //Touchpad
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        //Print the pixel coordinates of the cursor
        Log.i("starwisp", "Cursor X: " + event.getX() + "Cursor Y: " + event.getY());
    }

    return true;
}

From source file:org.mariotaku.twidere.view.RecyclerViewBackport.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final LayoutManager lm = getLayoutManager();
    if (lm == null) {
        return false;
    }//  w  w  w  .  j a  v  a 2 s .  co  m
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        if (event.getAction() == MotionEventCompat.ACTION_SCROLL) {
            final float vScroll, hScroll;
            if (lm.canScrollVertically()) {
                vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (!mMouseScrollDirectionDecider.isVerticalAvailable()) {
                    mMouseScrollDirectionDecider.guessDirection(event);
                }
            } else {
                vScroll = 0f;
            }
            if (lm.canScrollHorizontally()) {
                hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (!mMouseScrollDirectionDecider.isHorizontalAvailable()) {
                    mMouseScrollDirectionDecider.guessDirection(event);
                }
            } else {
                hScroll = 0f;
            }
            if ((vScroll != 0 || hScroll != 0)) {
                final float scrollFactor = getScrollFactorBackport();
                float horizontalDirection = mMouseScrollDirectionDecider.getHorizontalDirection();
                float verticalDirection = mMouseScrollDirectionDecider.getVerticalDirection();
                final float hFactor = scrollFactor * (horizontalDirection != 0 ? horizontalDirection : -1);
                final float vFactor = scrollFactor * (verticalDirection != 0 ? verticalDirection : -1);
                smoothScrollBy((int) (hScroll * hFactor), (int) (vScroll * vFactor));
            }
        }
    }
    return false;
}