本文整理汇总了Java中android.view.InputDevice.getDevice方法的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.getDevice方法的具体用法?Java InputDevice.getDevice怎么用?Java InputDevice.getDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.getDevice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
示例3: getGameControllerIds
import android.view.InputDevice; //导入方法依赖的package包/类
private List<Integer> getGameControllerIds() {
List<Integer> gameControllerDeviceIds = new ArrayList<>();
int[] deviceIds = InputDevice.getDeviceIds();
for (int deviceId : deviceIds) {
InputDevice dev = InputDevice.getDevice(deviceId);
int sources = dev.getSources();
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((sources & InputDevice.SOURCE_JOYSTICK)
== InputDevice.SOURCE_JOYSTICK)) {
if (!gameControllerDeviceIds.contains(deviceId)) {
gameControllerDeviceIds.add(deviceId);
}
}
}
return gameControllerDeviceIds;
}
示例4: Gamepad
import android.view.InputDevice; //导入方法依赖的package包/类
public Gamepad(int serviceId, int deviceId) {
id = serviceId;
axes = new float[Axis.values().length];
dpad = new boolean[4];
triggers = new float[2];
InputDevice device = InputDevice.getDevice(deviceId);
if (device != null) {
// LTRIGGER/RTRIGGER don't seem to be exposed on older
// versions of Android.
if (device.getMotionRange(MotionEvent.AXIS_LTRIGGER) != null && device.getMotionRange(MotionEvent.AXIS_RTRIGGER) != null) {
triggerAxes = new int[]{MotionEvent.AXIS_LTRIGGER,
MotionEvent.AXIS_RTRIGGER};
} else if (device.getMotionRange(MotionEvent.AXIS_BRAKE) != null && device.getMotionRange(MotionEvent.AXIS_GAS) != null) {
triggerAxes = new int[]{MotionEvent.AXIS_BRAKE,
MotionEvent.AXIS_GAS};
} else {
triggerAxes = null;
}
}
}
示例5: scanForGamepads
import android.view.InputDevice; //导入方法依赖的package包/类
private static void scanForGamepads() {
int[] deviceIds = InputDevice.getDeviceIds();
if (deviceIds == null) {
return;
}
for (int i=0; i < deviceIds.length; i++) {
InputDevice device = InputDevice.getDevice(deviceIds[i]);
if (device == null) {
continue;
}
if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD) {
continue;
}
addGamepad(device);
}
}
示例6: checkGameControllers
import android.view.InputDevice; //导入方法依赖的package包/类
/**
* Check for any game controllers that are connected already.
*/
private void checkGameControllers() {
Log.d(TAG, "checkGameControllers");
int[] deviceIds = mInputManager.getInputDeviceIds();
for (int deviceId : deviceIds) {
InputDevice dev = InputDevice.getDevice(deviceId);
int sources = dev.getSources();
// Verify that the device has gamepad buttons, control sticks, or
// both.
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((sources & InputDevice.SOURCE_JOYSTICK)
== InputDevice.SOURCE_JOYSTICK)) {
// This device is a game controller. Store its device ID.
if (!mConnectedDevices.contains(deviceId)) {
mConnectedDevices.add(deviceId);
if (mCurrentDeviceId == -1) {
mCurrentDeviceId = deviceId;
mControllerView.setCurrentControllerNumber(dev.getControllerNumber());
mControllerView.invalidate();
}
}
}
}
}
示例7: onInputDeviceRemoved
import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public void onInputDeviceRemoved(int deviceId) {
Log.d(TAG, "onInputDeviceRemoved: " + deviceId);
mConnectedDevices.remove(new Integer(deviceId));
if (mCurrentDeviceId == deviceId) {
mCurrentDeviceId = -1;
}
if (mConnectedDevices.size() == 0) {
mControllerView.setCurrentControllerNumber(-1);
mControllerView.invalidate();
} else {
mCurrentDeviceId = mConnectedDevices.get(0);
InputDevice dev = InputDevice.getDevice(mCurrentDeviceId);
if (dev != null) {
mControllerView.setCurrentControllerNumber(dev.getControllerNumber());
mControllerView.invalidate();
}
}
}
示例8: gatherControllers
import android.view.InputDevice; //导入方法依赖的package包/类
private void gatherControllers(boolean sendEvent) {
// gather all joysticks and gamepads, remove any disconnected ones
IntMap<AndroidController> removedControllers = new IntMap<AndroidController>();
removedControllers.putAll(controllerMap);
for(int deviceId: InputDevice.getDeviceIds()) {
InputDevice device = InputDevice.getDevice(deviceId);
AndroidController controller = controllerMap.get(deviceId);
if(controller != null) {
removedControllers.remove(deviceId);
} else {
addController(deviceId, sendEvent);
}
}
for(Entry<AndroidController> entry: removedControllers.entries()) {
removeController(entry.key);
}
}
示例9: addController
import android.view.InputDevice; //导入方法依赖的package包/类
protected void addController(int deviceId, boolean sendEvent) {
InputDevice device = InputDevice.getDevice(deviceId);
if(!isController(device)) return;
String name = device.getName();
AndroidController controller = new AndroidController(deviceId, name);
controllerMap.put(deviceId, controller);
if(sendEvent) {
synchronized(eventQueue) {
AndroidControllerEvent event = eventPool.obtain();
event.type = AndroidControllerEvent.CONNECTED;
event.controller = controller;
eventQueue.add(event);
}
} else {
controllers.add(controller);
}
Gdx.app.log(TAG, "added controller '" + name + "'");
}
示例10: getAxisValue
import android.view.InputDevice; //导入方法依赖的package包/类
private float getAxisValue(MotionEvent motionEvent, int axis) {
InputDevice device = InputDevice.getDevice(mDeviceId);
if (device == null) {
return 0f;
}
MotionRange range = device.getMotionRange(axis, motionEvent.getSource());
if (range == null) {
return 0f;
}
final float flat = range.getFlat();
final float value = motionEvent.getAxisValue(axis);
if (Math.abs(value) > flat) {
return value;
}
return 0f;
}
示例11: lookupTouchpadHardwareResolution
import android.view.InputDevice; //导入方法依赖的package包/类
/** Looks up the hardware resolution of the Glass touchpad. */
private void lookupTouchpadHardwareResolution() {
int[] deviceIds = InputDevice.getDeviceIds();
for (int deviceId : deviceIds) {
InputDevice device = InputDevice.getDevice(deviceId);
if ((device.getSources() & InputDevice.SOURCE_TOUCHPAD) != 0) {
logVerbose("Touchpad motion range: x-axis [%d, %d] y-axis [%d, %d]",
device.getMotionRange(MotionEvent.AXIS_X).getMin(),
device.getMotionRange(MotionEvent.AXIS_X).getMax(),
device.getMotionRange(MotionEvent.AXIS_Y).getMin(),
device.getMotionRange(MotionEvent.AXIS_Y).getMax());
mTouchpadHardwareWidth = device.getMotionRange(MotionEvent.AXIS_X).getRange();
mTouchpadHardwareHeight = device.getMotionRange(MotionEvent.AXIS_Y).getRange();
// Stop after we've seen the first touchpad device, because there might be multiple
// devices in this list if the user is currently screencasting with MyGlass. The
// first one will always be the hardware touchpad.
break;
}
}
}
示例12: isRecognizedInputDevice
import android.view.InputDevice; //导入方法依赖的package包/类
private static boolean isRecognizedInputDevice(UsbDevice device) {
// On KitKat and later, we can determine if this VID and PID combo
// matches an existing input device and defer to the built-in controller
// support in that case. Prior to KitKat, we'll always return true to be safe.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
for (int id : InputDevice.getDeviceIds()) {
InputDevice inputDev = InputDevice.getDevice(id);
if (inputDev == null) {
// Device was removed while looping
continue;
}
if (inputDev.getVendorId() == device.getVendorId() &&
inputDev.getProductId() == device.getProductId()) {
return true;
}
}
return false;
}
else {
return true;
}
}
示例13: getTouchDeviceName
import android.view.InputDevice; //导入方法依赖的package包/类
@Nullable
public static String getTouchDeviceName() {
for (int id : InputDevice.getDeviceIds()) {
InputDevice device = InputDevice.getDevice(id);
if (supportSource(device, InputDevice.SOURCE_TOUCHSCREEN) || supportSource(device, InputDevice.SOURCE_TOUCHPAD)) {
return device.getName();
}
}
return null;
}
示例14: inputGetInputDeviceIds
import android.view.InputDevice; //导入方法依赖的package包/类
/**
* This method is called by SDL using JNI.
* @return an array which may be empty but is never null.
*/
public static int[] inputGetInputDeviceIds(int sources) {
int[] ids = InputDevice.getDeviceIds();
int[] filtered = new int[ids.length];
int used = 0;
for (int i = 0; i < ids.length; ++i) {
InputDevice device = InputDevice.getDevice(ids[i]);
if ((device != null) && ((device.getSources() & sources) != 0)) {
filtered[used++] = device.getId();
}
}
return Arrays.copyOf(filtered, used);
}
示例15: isDeviceSDLJoystick
import android.view.InputDevice; //导入方法依赖的package包/类
public static boolean isDeviceSDLJoystick(int deviceId) {
InputDevice device = InputDevice.getDevice(deviceId);
// We cannot use InputDevice.isVirtual before API 16, so let's accept
// only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
if ((device == null) || (deviceId < 0)) {
return false;
}
int sources = device.getSources();
return (((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) ||
((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
);
}