当前位置: 首页>>代码示例>>Java>>正文


Java MotionEvent.getSource方法代码示例

本文整理汇总了Java中android.view.MotionEvent.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getSource方法的具体用法?Java MotionEvent.getSource怎么用?Java MotionEvent.getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.getSource方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@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);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:AbsHListView.java

示例2: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
	if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_SCROLL: {
			if (mTouchMode == TOUCH_MODE_REST) {
				final float hscroll = event
						.getAxisValue(MotionEvent.AXIS_HSCROLL);
				if (hscroll != 0) {
					final int delta = (int) (hscroll * getHorizontalScrollFactor());
					if (!trackMotionScroll(delta, delta)) {
						return true;
					}
				}
			}
		}
		}
	}
	return super.onGenericMotionEvent(event);
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:22,代码来源:AbsHListView.java

示例3: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    mInputManager.onGenericMotionEvent(event);

    // Check that the event came from a joystick or gamepad since a generic
    // motion event could be almost anything. API level 18 adds the useful
    // event.isFromSource() helper function.
    int eventSource = event.getSource();
    if ((((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
            ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK))
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        int id = event.getDeviceId();
        if (-1 != id) {
            Ship curShip = getShipForId(id);
            if (curShip.onGenericMotionEvent(event)) {
                return true;
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:22,代码来源:GameView.java

示例4: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onGenericMotionEvent(MotionEvent event) {

	if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_SCROLL: {
			final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
			if(DBG) Log.d(TAG,"onGenericMotionEvent ACTION_SCROLL vscroll="+vscroll);
			if (vscroll != 0) {
				final int index = mLayout.getFrontCoverIndex();
				int targetIndex;
				if (index+vscroll<0) {
					targetIndex=0;
				} else if (index+vscroll >= mCovers.size()-1) {
					targetIndex = mCovers.size()-1;
				} else {
					targetIndex = (int)(index+vscroll+0.5);
				}
				float targetScroll = mLayout.getScrollingPositionToCenterThisCover(targetIndex);
				mAnimHandler.startScrollingAnimPosition(targetScroll, AnimHandler.SPEED_FAST);
			}
		}
		}
	}
	return super.onGenericMotionEvent(event);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:27,代码来源:CoverRoll3D.java

示例5: processGenericEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
public void processGenericEvent(final MotionEvent event)
{
	// Joysticks are supported since Honeycomb, but I don't care about it, because very few devices have it
	if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
	{
		// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, on Nvidia Shield and some other joysticks
		DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
			event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
			event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
			event.getAxisValue(MotionEvent.AXIS_LTRIGGER), event.getAxisValue(MotionEvent.AXIS_RTRIGGER),
			event.getAxisValue(MotionEvent.AXIS_HAT_X), event.getAxisValue(MotionEvent.AXIS_HAT_Y),
			processGamepadDeviceId(event.getDevice()) );
		return;
	}
	// Process mousewheel
	if( event.getAction() == MotionEvent.ACTION_SCROLL )
	{
		int scrollX = Math.round(event.getAxisValue(MotionEvent.AXIS_HSCROLL));
		int scrollY = Math.round(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
		DemoGLSurfaceView.nativeMouseWheel(scrollX, scrollY);
		return;
	}
	super.processGenericEvent(event);
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:25,代码来源:Video.java

示例6: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@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);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:31,代码来源:PagedView.java

示例7: handleMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean handleMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
        int actionPointerIndex = event.getActionIndex();
        int action = event.getActionMasked();
        switch(action) {
            case MotionEvent.ACTION_MOVE:
                SDLJoystick joystick = getJoystick(event.getDeviceId());
                if ( joystick != null ) {
                    for (int i = 0; i < joystick.axes.size(); i++) {
                        InputDevice.MotionRange range = joystick.axes.get(i);
                        /* Normalize the value to -1...1 */
                        float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
                        SDLActivity.onNativeJoy(joystick.device_id, i, value );
                    }
                    for (int i = 0; i < joystick.hats.size(); i+=2) {
                        int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) );
                        int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) );
                        SDLActivity.onNativeHat(joystick.device_id, i/2, hatX, hatY );
                    }
                }
                break;
            default:
                break;
        }
    }
    return true;
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:29,代码来源:SDLActivity.java

示例8: onGenericMotion

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
    float x, y;
    int action;

    switch ( event.getSource() ) {
        case InputDevice.SOURCE_JOYSTICK:
        case InputDevice.SOURCE_GAMEPAD:
        case InputDevice.SOURCE_DPAD:
            return SDLActivity.handleJoystickMotionEvent(event);

        case InputDevice.SOURCE_MOUSE:
            action = event.getActionMasked();
            switch (action) {
                case MotionEvent.ACTION_SCROLL:
                    x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
                    y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
                    SDLActivity.onNativeMouse(0, action, x, y);
                    return true;

                case MotionEvent.ACTION_HOVER_MOVE:
                    x = event.getX(0);
                    y = event.getY(0);

                    SDLActivity.onNativeMouse(0, action, x, y);
                    return true;

                default:
                    break;
            }
            break;

        default:
            break;
    }

    // Event was not managed
    return false;
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:40,代码来源:SDLActivity.java

示例9: onGenericMotionEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onGenericMotionEvent (final MotionEvent event) {
	if (event.getAction() == MotionEvent.ACTION_MOVE && (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) {
		GenericGamepad gamepad = Mapper.instance.resolveGamepad(event.getDevice().getDescriptor(), event.getDeviceId());
		
		if (gamepad == null) {
			Log.d(LOGTAG, "Event from unknown descriptor " + event.getDevice().getDescriptor());
			return false;
		}
		
		float axisRx = 0;
		float axisRy = 0;
		
		if (gamepad.axisRx != 0) {
			axisRx = event.getAxisValue(Math.abs(gamepad.axisRx)) * (gamepad.axisRx > 0 ? 1 : -1);
		}
		if (gamepad.axisRx != 0) {
			axisRy = event.getAxisValue(Math.abs(gamepad.axisRy)) * (gamepad.axisRy > 0 ? 1 : -1);
		}
		if (Math.abs(axisRx) < 0.1) {
			axisRx = 0;
		}
		if (Math.abs(axisRy) < 0.1) {
			axisRy = 0;
		}

		gamepadMouseMoveX = axisRx * 2;
		gamepadMouseMoveY = axisRy * 2;
		
		float hatx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
		float haty = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
		
		float axisx = event.getAxisValue(MotionEvent.AXIS_X);
		float axisy = event.getAxisValue(MotionEvent.AXIS_Y);
		
		listener.onAxisChange(gamepad, axisx, axisy, hatx, haty, axisRx, axisRy);
		
		String deviceDescriptor = event.getDevice().getDescriptor();
		int deviceId = event.getDevice().getId();
		
		float triggerL = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
		float triggerR = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
		if (triggerL == 0) {
			triggerL = event.getAxisValue(MotionEvent.AXIS_BRAKE);
		}
		if (triggerR == 0) {
			triggerR = event.getAxisValue(MotionEvent.AXIS_GAS);
		}
		
		listener.onTriggers(deviceDescriptor, deviceId, Math.abs(triggerL)>=deadzone, Math.abs(triggerR)>=deadzone);
		listener.onTriggersAnalog(gamepad, deviceId, triggerL, triggerR);

		return true;

	}
	return false;
}
 
开发者ID:fcatrin,项目名称:retroxlibs,代码行数:57,代码来源:AnalogGamepad.java

示例10: getSource

import android.view.MotionEvent; //导入方法依赖的package包/类
public static int getSource(MotionEvent event) {
    return event.getSource();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:4,代码来源:MotionEventCompatGingerbread.java

示例11: process

import android.view.MotionEvent; //导入方法依赖的package包/类
public void process(final MotionEvent event)
{
	int hwMouseEvent =  ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE || Globals.ForceHardwareMouse) ? Mouse.MOUSE_HW_INPUT_MOUSE :
						((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) ? Mouse.MOUSE_HW_INPUT_STYLUS :
						Mouse.MOUSE_HW_INPUT_FINGER;
	if( ExternalMouseDetected != hwMouseEvent )
	{
		ExternalMouseDetected = hwMouseEvent;
		DemoGLSurfaceView.nativeHardwareMouseDetected(hwMouseEvent);
	}
	super.process(event);
	if( !Globals.FingerHover && ExternalMouseDetected == Mouse.MOUSE_HW_INPUT_FINGER )
		return; // Finger hover disabled in settings
	if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1
	{
		int action;
		// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
		if( touchEvents[0].down )
			action = Mouse.SDL_FINGER_UP;
		else
			action = Mouse.SDL_FINGER_HOVER;
		touchEvents[0].down = false;
		touchEvents[0].x = (int)event.getX();
		touchEvents[0].y = (int)event.getY();
		touchEvents[0].pressure = Mouse.MAX_HOVER_DISTANCE;
		touchEvents[0].size = 0;
		//if( event.getAxisValue(MotionEvent.AXIS_DISTANCE) != 0.0f )
		InputDevice device = InputDevice.getDevice(event.getDeviceId());
		if( device != null && device.getMotionRange(MotionEvent.AXIS_DISTANCE) != null &&
			device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange() > 0.0f )
			touchEvents[0].pressure = (int)((event.getAxisValue(MotionEvent.AXIS_DISTANCE) -
					device.getMotionRange(MotionEvent.AXIS_DISTANCE).getMin()) * Mouse.MAX_PRESSURE / device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange());
		DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
	}
	if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_EXIT ) // Update screen for finger hover
	{
		touchEvents[0].pressure = Mouse.HOVER_REDRAW_SCREEN;
		touchEvents[0].size = 0;
		DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, Mouse.SDL_FINGER_HOVER, 0, touchEvents[0].pressure, touchEvents[0].size );
	}
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:42,代码来源:Video.java


注:本文中的android.view.MotionEvent.getSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。