本文整理汇总了Java中android.view.InputDevice.getDeviceIds方法的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.getDeviceIds方法的具体用法?Java InputDevice.getDeviceIds怎么用?Java InputDevice.getDeviceIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.getDeviceIds方法的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: 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);
}
}
示例5: areSonyXperiaGamepadKeysSwapped
import android.view.InputDevice; //导入方法依赖的package包/类
private static boolean areSonyXperiaGamepadKeysSwapped() {
// The cross and circle buttons on Sony Xperia phones are swapped
// in different regions
// http://developer.sonymobile.com/2011/02/13/xperia-play-game-keys/
final char DEFAULT_O_BUTTON_LABEL = 0x25CB;
boolean swapped = false;
int[] deviceIds = InputDevice.getDeviceIds();
for (int i= 0; deviceIds != null && i < deviceIds.length; i++) {
KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(deviceIds[i]);
if (keyCharacterMap != null && DEFAULT_O_BUTTON_LABEL ==
keyCharacterMap.getDisplayLabel(KeyEvent.KEYCODE_DPAD_CENTER)) {
swapped = true;
break;
}
}
return swapped;
}
示例6: 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);
}
}
示例7: 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;
}
}
}
示例8: 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;
}
}
示例9: 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;
}
示例10: 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);
}
示例11: getInputDeviceIds
import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public int[] getInputDeviceIds() {
// add any hitherto unknown devices to our
// collection of watched input devices
int[] activeDevices = InputDevice.getDeviceIds();
long time = SystemClock.elapsedRealtime();
for ( int id : activeDevices ) {
long[] lastContact = mDevices.get(id);
if ( null == lastContact ) {
// we have a new device
mDevices.put(id, new long[] { time });
}
}
return activeDevices;
}
示例12: getDetailedItems
import android.view.InputDevice; //导入方法依赖的package包/类
public List<ItemDetails> getDetailedItems() {
List<ItemDetails> detailedItems = new ArrayList<>();
int[] ids = InputDevice.getDeviceIds();
for (int id : ids) {
InputDevice device = InputDevice.getDevice(id);
detailedItems.add(new ItemDetails(device.getName(), device.toString()));
}
return detailedItems;
}
示例13: getContents
import android.view.InputDevice; //导入方法依赖的package包/类
public String getContents() {
StringBuilder sb = new StringBuilder();
Formatter f = new Formatter(sb, Locale.US);
int[] ids = InputDevice.getDeviceIds();
f.format("Device count: %d\n", ids.length);
for (int i = 0; i < ids.length; i++) {
int id = ids[i];
InputDevice device = InputDevice.getDevice(id);
f.format("#%d: id = 0x%x\n%s\n", i, id, device);
}
return sb.toString();
}
示例14: isGameControllerConnected
import android.view.InputDevice; //导入方法依赖的package包/类
public boolean isGameControllerConnected() {
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)) {
return true;
}
}
return false;
}
示例15: getHardwareDevices
import android.view.InputDevice; //导入方法依赖的package包/类
public ArrayList<String> getHardwareDevices() {
ArrayList<String> devices = new ArrayList<String>();
for(int deviceId : InputDevice.getDeviceIds()) {
devices.add(InputDevice.getDevice(deviceId).getName());
}
return devices;
}