本文整理汇总了Java中android.view.InputEvent类的典型用法代码示例。如果您正苦于以下问题:Java InputEvent类的具体用法?Java InputEvent怎么用?Java InputEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputEvent类属于android.view包,在下文中一共展示了InputEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleInputEvent
import android.view.InputEvent; //导入依赖的package包/类
@Override
public boolean handleInputEvent(@NonNull InputEvent event) {
if (event instanceof KeyEvent) {
KeyEvent keyEvent = (KeyEvent) event;
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_DPAD_CENTER) return false;
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
if (mFastForwardAction != null && mSelectedActionId == mFastForwardAction.getId()) {
if (keyEvent.getRepeatCount() == 0) {
mCurrentMode = MODE_FAST_FORWARD;
invokeFastForwardAction();
}
}
else if (mRewindAction != null && mSelectedActionId == mRewindAction.getId()) {
if (keyEvent.getRepeatCount() == 0) {
mCurrentMode = MODE_REWIND;
invokeRewindAction();
}
}
}
else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
mCurrentMode = MODE_NOTHING;
}
}
return false;
}
示例2: hook
import android.view.InputEvent; //导入依赖的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);
}
}
});
}
示例3: MotionEventSender
import android.view.InputEvent; //导入依赖的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();
}
}
示例4: setEvent
import android.view.InputEvent; //导入依赖的package包/类
@Override
public boolean setEvent(InputEvent event) {
VolumeKeyEvent volumeKeyEvent = (VolumeKeyEvent) event;
if (volumeKeyEvent.getVolumeKeyEventType() == VolumeKeyEvent.VOLUME_KEY_EVENT_NATIVE && volumeKeyEvent.isVolumeKeyEvent()) {
if (volumeKeyEvent.getAction() == KeyEvent.ACTION_DOWN) {
if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
volumeDownPressed = true;
} else if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
volumeUpPressed = true;
}
} else if (volumeKeyEvent.getAction() == KeyEvent.ACTION_UP) {
if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
volumeDownPressed = false;
} else if (volumeKeyEvent.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
volumeUpPressed = false;
}
}
this.isActionModePerformed();
return true;
}
return false;
}
示例5: saveEvent
import android.view.InputEvent; //导入依赖的package包/类
@Override
public void saveEvent()
{
// Para evitar el problema de acceder en modo ASYNC_HOLD al evento original tras haberse encolado y terminado el proceso del evento por el navegador
// En Android lo normal es reutilizar el objeto evento para siguientes eventos por ello tenemos que hacer una copia
if (evtNative == null) return;
// http://stackoverflow.com/questions/1626667/how-to-use-parcel-in-android
Parcel parcelOut = Parcel.obtain();
parcelOut.writeValue(evtNative);
byte[] data = parcelOut.marshall();
parcelOut.recycle();
Parcel parcelIn = Parcel.obtain();
parcelIn.unmarshall(data, 0, data.length);
parcelIn.setDataPosition(0);
this.evtNative = (InputEvent) parcelIn.readValue(evtNative.getClass().getClassLoader());
parcelIn.recycle();
}
示例6: onInterceptInputEvent
import android.view.InputEvent; //导入依赖的package包/类
private boolean onInterceptInputEvent(InputEvent event) {
if (DEBUG) Log.v(TAG, "onInterceptInputEvent status " + mFadingStatus + " event " + event);
boolean consumeEvent = (mFadingStatus == IDLE && mBgAlpha == 0);
if (event instanceof KeyEvent) {
if (consumeEvent) {
consumeEvent = isConsumableKey((KeyEvent) event);
}
int keyCode = ((KeyEvent) event).getKeyCode();
// Back key typically means we're leaving the fragment
if (keyCode != KeyEvent.KEYCODE_BACK) {
tickle();
}
} else {
tickle();
}
return consumeEvent;
}
示例7: EventInput
import android.view.InputEvent; //导入依赖的package包/类
public EventInput() throws Exception {
//Get the instance of InputManager class using reflection
String methodName = "getInstance";
Object[] objArr = new Object[0];
im = (InputManager) InputManager.class.getDeclaredMethod(methodName, new Class[0])
.invoke(null, objArr);
//Make MotionEvent.obtain() method accessible
methodName = "obtain";
MotionEvent.class.getDeclaredMethod(methodName, new Class[0]).setAccessible(true);
//Get the reference to injectInputEvent method
methodName = "injectInputEvent";
injectInputEventMethod = InputManager.class.getMethod(
methodName, new Class[]{InputEvent.class, Integer.TYPE});
}
示例8: getContextForEvent
import android.view.InputEvent; //导入依赖的package包/类
private InputDeviceContext getContextForEvent(InputEvent event) {
// Unknown devices use the default context
if (event.getDeviceId() == 0) {
return defaultContext;
}
else if (event.getDevice() == null) {
// During device removal, sometimes we can get events after the
// input device has been destroyed. In this case we'll see a
// != 0 device ID but no device attached.
return null;
}
// Return the existing context if it exists
InputDeviceContext context = inputDeviceContexts.get(event.getDeviceId());
if (context != null) {
return context;
}
// Otherwise create a new context
context = createInputDeviceContextForDevice(event.getDevice());
inputDeviceContexts.put(event.getDeviceId(), context);
return context;
}
示例9: injectMethodFacade
import android.view.InputEvent; //导入依赖的package包/类
private void injectMethodFacade(InputEvent event) {
try {
injectInputEventMethod.invoke(inputManager, event, 2 /* InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH */);
} catch (Exception e) {
e.printStackTrace();
exitFailure();
}
}
示例10: setEvent
import android.view.InputEvent; //导入依赖的package包/类
@Override
public boolean setEvent(InputEvent event) {
VolumeKeyEvent volumeKeyEvent = (VolumeKeyEvent) event;
if (volumeKeyEvent.getVolumeKeyEventType() == VolumeKeyEvent.VOLUME_KEY_EVENT_ROCKER && volumeKeyEvent.isVolumeKeyEvent()) {
buffer[current_ptr] = volumeKeyEvent.getPrevCurrentValue()[0];
current_ptr++;
buffer[current_ptr] = volumeKeyEvent.getPrevCurrentValue()[1];
current_ptr++;
if (current_ptr == MAX_BUFFER_SIZE) {
current_ptr = 0;
}
return this.isActionModePerformed();
}
return false;
}
示例11: ActivityViewWrapper
import android.view.InputEvent; //导入依赖的package包/类
public ActivityViewWrapper(Context ctx) {
try {
Class<?> clazz = Class.forName("android.app.ActivityView");
mDefaultCtor = clazz.getConstructor(Context.class);
mActivityView = (View)mDefaultCtor.newInstance(ctx);
mStartActivityMethod = clazz.getMethod("startActivity", Intent.class);
mInjectInputEvent = clazz.getDeclaredMethod("injectInputEvent", InputEvent.class);
mInjectInputEvent.setAccessible(true);
} catch (Exception e) {
Log.e(TAG, "ActivityViewWrapper failed " + e);
}
}
示例12: injectInputEvent
import android.view.InputEvent; //导入依赖的package包/类
public boolean injectInputEvent(InputEvent e) {
try {
return (Boolean) mInjectInputEvent.invoke(mActivityView, e);
} catch (Exception ex) {
Log.e(TAG, "ActivitityViewWrapper failed injectInputEvent", ex);
}
return false;
}
示例13: isDpadDevice
import android.view.InputEvent; //导入依赖的package包/类
public static boolean isDpadDevice(InputEvent event) {
// Check that input comes from a device with directional pads.
if ((event.getSource() & InputDevice.SOURCE_DPAD)
!= InputDevice.SOURCE_DPAD) {
return true;
} else {
return false;
}
}
示例14: getInputDeviceState
import android.view.InputEvent; //导入依赖的package包/类
private InputDeviceState getInputDeviceState(InputEvent event) {
final int deviceId = event.getDeviceId();
InputDeviceState state = mInputDeviceStates.get(deviceId);
if (state == null) {
final InputDevice device = event.getDevice();
if (device == null) {
return null;
}
state = new InputDeviceState(device);
mInputDeviceStates.put(deviceId, state);
Log.i(TAG, device.toString());
}
return state;
}
示例15: initializeJoystickHandlerIfPossibleAndNecessary
import android.view.InputEvent; //导入依赖的package包/类
/**
* Until we get a joystick event, it is not certain what InputDevice corresponds to the joystick
* Though there are methods for introspection, I was in a hurry and this does the job.
*/
private void initializeJoystickHandlerIfPossibleAndNecessary(InputEvent event)
/*************************************************************************/
{
if ((!joystickHandler_.isInitialized()) && (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0)
joystickHandler_.initializeDevice(event.getDevice());
}