本文整理汇总了Java中android.view.InputDevice类的典型用法代码示例。如果您正苦于以下问题:Java InputDevice类的具体用法?Java InputDevice怎么用?Java InputDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InputDevice类属于android.view包,在下文中一共展示了InputDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTouchEvent
import android.view.InputDevice; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Selection may be beginning. Sync the TextView with the buffer.
refreshTextFromBuffer();
}
// Mouse input is treated differently:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) {
if (onMouseEvent(event, terminalView.bridge)) {
return true;
}
terminalView.viewPager.setPagingEnabled(true);
} else {
if (terminalView.onTouchEvent(event)) {
return true;
}
}
return super.onTouchEvent(event);
}
示例2: onGenericMotionEvent
import android.view.InputDevice; //导入依赖的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);
}
示例3: onGenericMotionEvent
import android.view.InputDevice; //导入依赖的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);
}
示例4: getCenteredAxis
import android.view.InputDevice; //导入依赖的package包/类
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;
}
示例5: handleMessage
import android.view.InputDevice; //导入依赖的package包/类
public void handleMessage(Message m) {
switch (m.what) {
case MSG_INJECT_KEY:
final long eventTime = SystemClock.uptimeMillis();
final InputManager inputManager = (InputManager)
XposedHelpers.callStaticMethod(InputManager.class, "getInstance");
int flags = KeyEvent.FLAG_FROM_SYSTEM;
XposedHelpers.callMethod(inputManager, "injectInputEvent",
new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN, m.arg1, 0,
0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0);
XposedHelpers.callMethod(inputManager, "injectInputEvent",
new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP, m.arg1, 0,
0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0);
break;
}
}
示例6: injectKey
import android.view.InputDevice; //导入依赖的package包/类
public static void injectKey(final int keyCode) {
Handler handler = (Handler) XposedHelpers.getObjectField(mPhoneWindowManager, "mHandler");
if (handler == null) return;
handler.post(new Runnable() {
@Override
public void run() {
try {
final long eventTime = SystemClock.uptimeMillis();
final InputManager inputManager = (InputManager)
mContext.getSystemService(Context.INPUT_SERVICE);
int flags = KeyEvent.FLAG_FROM_SYSTEM;
XposedHelpers.callMethod(inputManager, "injectInputEvent",
new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN,
keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags,
InputDevice.SOURCE_UNKNOWN), 0);
XposedHelpers.callMethod(inputManager, "injectInputEvent",
new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP,
keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags,
InputDevice.SOURCE_UNKNOWN), 0);
} catch (Throwable t) {
XposedBridge.log(t);
}
}
});
}
示例7: hook
import android.view.InputDevice; //导入依赖的package包/类
public static void hook(ClassLoader loader) {
final Class<?> CLASS_POINTER_EVENT_DISPATCHER = XposedHelpers.findClass(POINTER_EVENT_DISPATCHER_PATH, loader);
XposedHelpers.findAndHookMethod(CLASS_POINTER_EVENT_DISPATCHER, "onInputEvent", InputEvent.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
try {
if (param.args[0] instanceof MotionEvent) {
MotionEvent event = (MotionEvent) param.args[0];
//XpLog.i("input x "+event.getX());
//XpLog.i("input y "+event.getY());
if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
PhoneWindowManagerHook.gesturesListener.onPointerEvent(event);
}
}
} catch (Exception e) {
XpLog.e(e);
}
}
});
}
示例8: onGenericMotionEvent
import android.view.InputDevice; //导入依赖的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);
}
示例9: processGenericEvent
import android.view.InputDevice; //导入依赖的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);
}
示例10: onKeyDown
import android.view.InputDevice; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, final KeyEvent event)
{
if( keyCode == KeyEvent.KEYCODE_BACK )
{
if( (event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE )
{
// Stupid Samsung and stupid Acer remaps right mouse button to BACK key
nativeMouseButtonsPressed(2, 1);
return true;
}
else if( mClient.isKeyboardWithoutTextInputShown() )
{
return true;
}
}
if( nativeKey( keyCode, 1, event.getUnicodeChar(), DifferentTouchInput.processGamepadDeviceId(event.getDevice()) ) == 0 )
return super.onKeyDown(keyCode, event);
return true;
}
示例11: onKeyUp
import android.view.InputDevice; //导入依赖的package包/类
@Override
public boolean onKeyUp(int keyCode, final KeyEvent event)
{
if( keyCode == KeyEvent.KEYCODE_BACK )
{
if( (event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE )
{
// Stupid Samsung and stupid Acer remaps right mouse button to BACK key
nativeMouseButtonsPressed(2, 0);
return true;
}
else if( mClient.isKeyboardWithoutTextInputShown() )
{
mClient.showScreenKeyboardWithoutTextInputField(0); // Hide keyboard
return true;
}
}
if( nativeKey( keyCode, 0, event.getUnicodeChar(), DifferentTouchInput.processGamepadDeviceId(event.getDevice()) ) == 0 )
return super.onKeyUp(keyCode, event);
//if( keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU )
// DimSystemStatusBar.get().dim(mClient._videoLayout);
return true;
}
示例12: hasConnectedController
import android.view.InputDevice; //导入依赖的package包/类
/**
* Function that returns if any controller is paired/plugged/turned on
*/
private boolean hasConnectedController(){
/*Get a list of valid input ids and iterate through them*/
for (int deviceId : InputDevice.getDeviceIds()) {
InputDevice currentDevice = InputDevice.getDevice(deviceId);
/*Device ID of the controller*/
String controllerName = currentDevice.getName().toLowerCase(Locale.ENGLISH);
/*Check to see if a known controller is connected*/
if (controllerName.contains("controller") ||
controllerName.contains("conteroller") ||
controllerName.contains("contoroller") ||
controllerName.contains("pad") ||
controllerName.contains("joystick") ||
controllerName.contains("nintendo")) {
//|| (this.hidDevicesOK && controllerName.equals("hid_device"))){
return true;
}
}
return false;
}
示例13: sendKeyAndWaitForEvent
import android.view.InputDevice; //导入依赖的package包/类
/**
* Send keys and blocks until the first specified accessibility event.
*
* Most key presses will cause some UI change to occur. If the device is busy, this will
* block until the device begins to process the key press at which point the call returns
* and normal wait for idle processing may begin. If no events are detected for the
* timeout period specified, the call will return anyway with false.
*
* @param keyCode
* @param metaState
* @param eventType
* @param timeout
* @return true if events is received, otherwise false.
*/
public boolean sendKeyAndWaitForEvent(final int keyCode, final int metaState, final int eventType, long timeout) {
Runnable command = new Runnable() {
@Override
public void run() {
final long eventTime = SystemClock.uptimeMillis();
KeyEvent downEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
if (injectEventSync(downEvent)) {
KeyEvent upEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD);
injectEventSync(upEvent);
}
}
};
return runAndWaitForEvents(command, new WaitForAnyEventPredicate(eventType), timeout) != null;
}
示例14: onGenericMotionEvent
import android.view.InputDevice; //导入依赖的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 vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
if (vscroll != 0 && !trackMotionScroll((int) vscroll)) {
return true;
}
}
}
}
}
return super.onGenericMotionEvent(event);
}
示例15: MotionEventSender
import android.view.InputDevice; //导入依赖的package包/类
public MotionEventSender() {
try {
Method imInstanceMethod = InputManager.class.getDeclaredMethod("getInstance");
imInstanceMethod.setAccessible(true);
inputManager = (InputManager) imInstanceMethod.invoke(null);
injectInputEventMethod = InputManager.class.getDeclaredMethod("injectInputEvent",
android.view.InputEvent.class,
int.class);
int[] deviceIds = InputDevice.getDeviceIds();
for (int inputDeviceId : deviceIds) {
InputDevice inputDevice = InputDevice.getDevice(inputDeviceId);
int deviceSources = inputDevice.getSources();
if ((deviceSources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
DEVICE_ID = inputDeviceId;
break;
}
}
} catch (Exception e) {
e.printStackTrace();
exitFailure();
}
}