android.view.MotionEvent#getSource ( )源码实例Demo

下面列出了android.view.MotionEvent#getSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jmonkeyengine   文件: AndroidInputHandler14.java
@Override
    public boolean onHover(View view, MotionEvent event) {
        if (view != getView()) {
            return false;
        }

        boolean consumed = false;

        int source = event.getSource();
//        logger.log(Level.INFO, "onTouch source: {0}", source);

        boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN);
//        logger.log(Level.INFO, "onTouch source: {0}, isTouch: {1}",
//                new Object[]{source, isTouch});

        if (isTouch && touchInput != null) {
            // send the event to the touch processor
            consumed = ((AndroidTouchInput14)touchInput).onHover(event);
        }

        return consumed;
    }
 
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        List<MotionRange> motionRanges = event.getDevice().getMotionRanges();
        for(MotionRange mr : motionRanges){
            int axis = mr.getAxis();
            if(event.getAxisValue(axis) > 0.5 || event.getAxisValue(axis) < -0.5){
                Log.i(TAG, "Axis found: " + MotionEvent.axisToString(axis));
                this.mAxisName = MotionEvent.axisToString(axis);
                mValueTextView.setText(mAxisName);
            }
        }
    }else{
        Log.i(TAG, "Not a joystick event.");
    }
    return true;
}
 
源代码3 项目: Camera2   文件: FilmstripGestureRecognizer.java
public boolean onGenericMotionEvent(MotionEvent event)
{
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_SCROLL:
            {
                final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                final float vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);

                if (hscroll != 0.0f || vscroll != 0.0f)
                {
                    mListener.onMouseScroll(hscroll, vscroll);
                }
            }
        }
    }

    return true;
}
 
源代码4 项目: AndroidStudyDemo   文件: ZrcAbsListView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (Build.VERSION.SDK_INT >= 12) {
        if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                if (mTouchMode == TOUCH_MODE_REST) {
                    final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (vscroll != 0) {
                        final int delta = (int) (vscroll * getVerticalScrollFactor());
                        if (!trackMotionScroll(delta, delta)) {
                            return true;
                        }
                    }
                }
            }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
源代码5 项目: jmonkeyengine   文件: AndroidInputHandler14.java
@Override
    public boolean onGenericMotion(View view, MotionEvent event) {
        if (view != getView()) {
            return false;
        }

        boolean consumed = false;

        int source = event.getSource();
//        logger.log(Level.INFO, "onGenericMotion source: {0}", source);

        boolean isJoystick =
                ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
                ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK);

        if (isJoystick && joyInput != null) {
//            logger.log(Level.INFO, "onGenericMotion source: {0}, isJoystick: {1}",
//                    new Object[]{source, isJoystick});
            // send the event to the touch processor
            consumed = consumed || ((AndroidJoyInput14)joyInput).onGenericMotion(event);
        }

        return consumed;
    }
 
源代码6 项目: letv   文件: AbsHListView.java
@TargetApi(12)
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & 2) != 0) {
        switch (event.getAction()) {
            case 8:
                if (this.mTouchMode == -1) {
                    float hscroll = event.getAxisValue(10);
                    if (hscroll != 0.0f) {
                        int delta = (int) (getHorizontalScrollFactor() * hscroll);
                        if (!trackMotionScroll(delta, delta)) {
                            return true;
                        }
                    }
                }
                break;
        }
    }
    return super.onGenericMotionEvent(event);
}
 
private MotionEvent transformEvent(MotionEvent e, int headerPosition) {
    if (headerPosition == MATCHED_STICKIED_HEADER) {
        return e;
    }

    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    MotionEvent.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();

    View headerHolder = getChildAt(headerPosition);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].y -= headerHolder.getTop();
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
源代码8 项目: ViewSupport   文件: MotionEventHelper.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;
        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;
}
 
源代码9 项目: Trebuchet   文件: PagedView.java
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
源代码10 项目: FairEmail   文件: WebViewEx.java
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_SCROLL &&
            (event.getSource() & InputDevice.SOURCE_MOUSE) != 0)
        return false;
    return super.onGenericMotionEvent(event);
}
 
源代码11 项目: codeexamples-android   文件: GameControllerInput.java
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    // Check that the event came from a joystick since a generic motion event
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        // Update device state for visualization and logging.
        InputDeviceState state = getInputDeviceState(event);
        if (state != null && state.onJoystickMotion(event)) {
            mSummaryAdapter.show(state);
        }
    }
    return super.dispatchGenericMotionEvent(event);
}
 
源代码12 项目: crazyflie-android-client   文件: MainActivity.java
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    // Check that the event came from a joystick since a generic motion event could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE && mController instanceof GamepadController) {
        mGamepadController.dealWithMotionEvent(event);
        updateFlightData();
        return true;
    } else {
        return super.dispatchGenericMotionEvent(event);
    }
}
 
源代码13 项目: Alite   文件: AndroidView.java
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
	if (game.getCurrentScreen() == null) {
		return true;
	}
	if (isController(event.getSource())) {
		if (Dpad.isDpadDevice(event)) {
			if (game.getCurrentScreen() != null) {
				game.getCurrentScreen().processDPad(dpad.getDirectionPressed(event));
			}
		} 
		// Check that the event came from a game controller
        if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) ==
                InputDevice.SOURCE_JOYSTICK &&
                event.getAction() == MotionEvent.ACTION_MOVE) {

            // Process all historical movement samples in the batch
            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(game.getCurrentScreen(), event, i);
            }

            // Process the current movement sample in the batch (position -1)
            processJoystickInput(game.getCurrentScreen(), event, -1);
        }
	}
	return super.onGenericMotionEvent(event);
}
 
源代码14 项目: JotaTextEditor   文件: ApiWrapper.java
static public int getSourceOfEvent( MotionEvent event )
{
    return event.getSource();
}
 
private static boolean isFromTouchpadInGlassDevice(MotionEvent motionEvent) {
  return (Build.DEVICE.contains("glass")
          || Build.DEVICE.contains("Glass")
          || Build.DEVICE.contains("wingman"))
      && ((motionEvent.getSource() & InputDevice.SOURCE_TOUCHPAD) != 0);
}
 
源代码16 项目: citra_android   文件: MotionAlertDialog.java
private boolean onMotionEvent(MotionEvent event)
{
  if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
    return false;
  if (event.getAction() != MotionEvent.ACTION_MOVE)
    return false;

  InputDevice input = event.getDevice();

  List<InputDevice.MotionRange> motionRanges = input.getMotionRanges();

  int numMovedAxis = 0;
  float axisMoveValue = 0.0f;
  InputDevice.MotionRange lastMovedRange = null;
  char lastMovedDir = '?';
  if (mWaitingForEvent)
  {
    // Get only the axis that seem to have moved (more than .5)
    for (InputDevice.MotionRange range : motionRanges)
    {
      int axis = range.getAxis();
      float origValue = event.getAxisValue(axis);
      float value = mControllerMappingHelper.scaleAxis(input, axis, origValue);
      if (Math.abs(value) > 0.5f)
      {
        // It is common to have multiple axis with the same physical input. For example,
        // shoulder butters are provided as both AXIS_LTRIGGER and AXIS_BRAKE.
        // To handle this, we ignore an axis motion that's the exact same as a motion
        // we already saw. This way, we ignore axis with two names, but catch the case
        // where a joystick is moved in two directions.
        // ref: bottom of https://developer.android.com/training/game-controllers/controller-input.html
        if (value != axisMoveValue)
        {
          axisMoveValue = value;
          numMovedAxis++;
          lastMovedRange = range;
          lastMovedDir = value < 0.0f ? '-' : '+';
        }
      }
    }

    // If only one axis moved, that's the winner.
    if (numMovedAxis == 1)
    {
      mWaitingForEvent = false;
      saveMotionInput(input, lastMovedRange, lastMovedDir);
    }
  }

  return true;
}
 
源代码17 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码18 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * Dispatch a trackball event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the trackball action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendTrackballEventSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
        event.setSource(InputDevice.SOURCE_TRACKBALL);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码19 项目: android_9.0.0_r45   文件: Instrumentation.java
/**
 * Dispatch a trackball event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the trackball action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendTrackballEventSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
        event.setSource(InputDevice.SOURCE_TRACKBALL);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
源代码20 项目: libcommon   文件: MotionEventUtils.java
/**
 * 指定したMotionEventの入力ソースが指定したクラスかどうかをチェック
 * @param event
 * @param sourceClass
 * @return
 */
public static boolean isFromSource(@NonNull final MotionEvent event,
	final int sourceClass) {

	return (event.getSource() & sourceClass) == sourceClass;
}