Example usage for android.view MotionEvent getSource

List of usage examples for android.view MotionEvent getSource

Introduction

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

Prototype

@Override
public final int getSource() 

Source Link

Usage

From source file:Main.java

public static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) {
    if (device == null) {
        return 0;
    }//from w  ww.  j  a  va2 s.  c  o  m
    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: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();
    }//w  ww.j av a 2 s .c  om
    return 0;
}

From source file:Main.java

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();

    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;//from   www  .  j a va 2  s  .  c om
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }

    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);

    return n;
}

From source file:Main.java

private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();
    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount; i++) {
        xy[2 * i] = pointerCoords[i].x;/*from  w  ww.  j a v a 2 s.  com*/
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount; i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation);
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords,
            metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}

From source file:Main.java

public static JSONObject CreateJSonObjectFromMotionEvent(MotionEvent e) throws JSONException {
    JSONObject jObj = new JSONObject();
    jObj.put("downTime", e.getDownTime());
    jObj.put("eventTime", e.getEventTime());
    jObj.put("action", e.getAction());
    jObj.put("pointerCount", e.getPointerCount());
    jObj.put("metaState", e.getMetaState());
    jObj.put("buttonState", e.getButtonState());
    jObj.put("xPrecision", e.getXPrecision());
    jObj.put("yPrecision", e.getYPrecision());
    jObj.put("deviceId", e.getDeviceId());
    jObj.put("edgeFlags", e.getEdgeFlags());
    jObj.put("source", e.getSource());
    jObj.put("flags", e.getFlags());

    for (int i = 0; i < e.getPointerCount(); i++) {
        PointerProperties prop = new PointerProperties();
        e.getPointerProperties(i, prop);

        PointerCoords coords = new PointerCoords();
        e.getPointerCoords(i, coords);//w ww. java 2 s. com

        JSONObject pointer = JObjFromPointer(prop, coords);
        jObj.accumulate("pointers", pointer);
    }

    return jObj;
}

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   w w  w.j a v a2 s  .  c  o  m*/
    }
    return 0;
}

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  ww  w. jav  a2s  . c o  m*/
    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:tv.piratemedia.flightcontroller.ControlActivity.java

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK
            && event.getAction() == MotionEvent.ACTION_MOVE) {

        final int historySize = event.getHistorySize();

        // Process the movements starting from the
        // earliest historical position in the batch
        for (int i = 0; i < historySize; i++) {
            // Process the event at historical position i
            processJoystickInput(event, i);
        }//  ww w. ja va  2s .c  o  m

        // Process the current movement sample in the batch (position -1)
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}

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  a2s  .c o 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;
}

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

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final LayoutManager lm = getLayoutManager();
    if (lm == null) {
        return false;
    }//from w  w  w .  jav  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);
                scrollBy((int) (hScroll * hFactor), (int) (vScroll * vFactor));
            }
        }
    }
    return false;
}