本文整理了Java中android.view.MotionEvent.getSource()
方法的一些代码示例,展示了MotionEvent.getSource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.getSource()
方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:getSource
暂无
代码示例来源:origin: libgdx/libgdx
public boolean onGenericMotion (MotionEvent event, AndroidInput input) {
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) return false;
final int action = event.getAction() & MotionEvent.ACTION_MASK;
int x = 0, y = 0;
int scrollAmount = 0;
long timeStamp = System.nanoTime();
synchronized (input) {
switch (action) {
case MotionEvent.ACTION_HOVER_MOVE:
x = (int)event.getX();
y = (int)event.getY();
if ((x != deltaX) || (y != deltaY)) { // Avoid garbage events
postTouchEvent(input, TouchEvent.TOUCH_MOVED, x, y, 0, timeStamp);
deltaX = x;
deltaY = y;
}
break;
case MotionEvent.ACTION_SCROLL:
scrollAmount = (int)-Math.signum(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
postTouchEvent(input, TouchEvent.TOUCH_SCROLLED, 0, 0, scrollAmount, timeStamp);
}
}
Gdx.app.getGraphics().requestRendering();
return true;
}
代码示例来源:origin: libgdx/libgdx
public boolean onGenericMotion (MotionEvent event, AndroidInput input) {
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) return false;
final int action = event.getAction() & MotionEvent.ACTION_MASK;
int x = 0, y = 0;
int scrollAmount = 0;
long timeStamp = System.nanoTime();
synchronized (input) {
switch (action) {
case MotionEvent.ACTION_HOVER_MOVE:
x = (int)event.getX();
y = (int)event.getY();
if ((x != deltaX) || (y != deltaY)) { // Avoid garbage events
postTouchEvent(input, TouchEvent.TOUCH_MOVED, x, y, 0, timeStamp);
deltaX = x;
deltaY = y;
}
break;
case MotionEvent.ACTION_SCROLL:
scrollAmount = (int)-Math.signum(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
postTouchEvent(input, TouchEvent.TOUCH_SCROLLED, 0, 0, scrollAmount, timeStamp);
}
}
Gdx.app.getGraphics().requestRendering();
return true;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public boolean onTouch(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 = touchInput.onTouch(event);
}
return consumed;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@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;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@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;
}
代码示例来源:origin: libgdx/libgdx
@Override
public boolean onGenericMotion (View view, MotionEvent motionEvent) {
if((motionEvent.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) return false;
AndroidController controller = controllerMap.get(motionEvent.getDeviceId());
if(controller != null) {
代码示例来源:origin: TonicArtos/StickyGridHeaders
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;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
event.getSource();
代码示例来源:origin: stackoverflow.com
public boolean onGenericMotionEvent(MotionEvent event) {
if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
//handle the event
return true;
}
else {
return false;
}
}
代码示例来源:origin: moagrius/TileView
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL: {
代码示例来源:origin: MrWangChong/DragPhotoView
/**
* Determines whether the event is from the given source.
* @param source The input source to check against.
* @return Whether the event is from the given source.
*/
public static boolean isFromSource(MotionEvent event, int source) {
return (event.getSource() & source) == source;
}
代码示例来源:origin: MrWangChong/DragPhotoView
/**
* Gets the source of the event.
*
* @return The event source or {@link InputDeviceCompat#SOURCE_UNKNOWN} if unknown.
* @deprecated Call {@link MotionEvent#getSource()} directly. This method will be
* removed in a future release.
*/
@Deprecated
public static int getSource(MotionEvent event) {
return event.getSource();
}
代码示例来源:origin: Ramotion/direct-select-android
@Override
public boolean onTouchEvent(MotionEvent ev) {
return ev.getSource() == DSListView.MOTION_EVENT_SOURCE && super.onTouchEvent(ev);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f)
selectNext()
else
selectPrev();
return true;
}
}
return super.onGenericMotionEvent(event);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f)
selectNext()
else
selectPrev();
return true;
}
}
return super.onGenericMotionEvent(event);
}
代码示例来源:origin: bitcraze/crazyflie-android-client
@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);
}
}
代码示例来源:origin: Unity-Technologies/unity-ads-android
@TargetApi(14)
public boolean onInterceptTouchEvent(MotionEvent e) {
super.onInterceptTouchEvent(e);
if (_shouldCapture) {
if (_motionEvents.size() < _maxEvents) {
boolean isObscured = (e.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0;
synchronized (_motionEvents) {
_motionEvents.add(new AdUnitMotionEvent(e.getActionMasked(), isObscured, e.getToolType(0), e.getSource(), e.getDeviceId(), e.getX(0), e.getY(0), e.getEventTime(), e.getPressure(0), e.getSize(0)));
}
}
}
return false;
}
代码示例来源:origin: qiubiteme/android_api_demos
private static float getCenteredAxis(MotionEvent event, InputDevice device,
int axis, int historyPos) {
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;
}
代码示例来源:origin: li2/learning-android-open-source
private static float getCenteredAxis(MotionEvent event, InputDevice device,
int axis, int historyPos) {
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;
}
代码示例来源:origin: appium/appium-espresso-driver
public void pointerMove(List<Long> x, List<Long> y,
final PointerType pointerType,
final KeyInputState globalKeyInputState,
@Nullable final MotionEvent downEvent) throws AppiumException {
int metaState = getMetaState(globalKeyInputState);
(new MotionEventBuilder())
.withAction(ACTION_MOVE)
.withDownTime(downTime)
.withPointerType(pointerType)
.withX(x)
.withY(y)
.withMetaState(metaState)
.withSource(downEvent != null ? downEvent.getSource() : 0)
.build()
.run(uiController);
}
内容来源于网络,如有侵权,请联系作者删除!