本文整理汇总了Java中android.view.InputDevice.getSources方法的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.getSources方法的具体用法?Java InputDevice.getSources怎么用?Java InputDevice.getSources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.getSources方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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();
}
}
}
}
}
示例5: 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;
}
}
}
示例6: 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);
}
示例7: 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)
);
}
示例8: findControllersAndAttachShips
import android.view.InputDevice; //导入方法依赖的package包/类
void findControllersAndAttachShips() {
int[] deviceIds = mInputManager.getInputDeviceIds();
for (int deviceId : deviceIds) {
InputDevice dev = mInputManager.getInputDevice(deviceId);
int sources = dev.getSources();
// if the device is a gamepad/joystick, create a ship to represent it
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
// if the device has a gamepad or joystick
getShipForId(deviceId);
}
}
}
示例9: processGamepadDeviceId
import android.view.InputDevice; //导入方法依赖的package包/类
public static int processGamepadDeviceId(InputDevice device)
{
if( device == null )
return 0;
int source = device.getSources();
if( (source & InputDevice.SOURCE_CLASS_JOYSTICK) != InputDevice.SOURCE_CLASS_JOYSTICK &&
(source & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD )
{
return 0;
}
int deviceId = device.getId();
for( int i = 0; i < gamepadIds.length; i++ )
{
if (gamepadIds[i] == deviceId)
return i + 1;
}
for( int i = 0; i < gamepadIds.length; i++ )
{
if (gamepadIds[i] == 0)
{
Log.i("SDL", "libSDL: gamepad added: deviceId " + deviceId + " gamepadId " + (i + 1));
gamepadIds[i] = deviceId;
return i + 1;
}
}
return 0;
}
示例10: 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;
}
示例11: refreshGamepads
import android.view.InputDevice; //导入方法依赖的package包/类
@TargetApi(16)
private void refreshGamepads() throws JSONException
{
int[] deviceIds = InputDevice.getDeviceIds();
this.gamepads = new JSONArray();
for (int i = 0; i < deviceIds.length; i++)
{
int deviceId = deviceIds[i];
InputDevice inputDevice = InputDevice.getDevice(deviceId);
int sources = inputDevice.getSources();
boolean isJoystick = (sources & InputDevice.SOURCE_JOYSTICK) != 0;
boolean isGamepad = (sources & InputDevice.SOURCE_GAMEPAD) != 0;
boolean isVirtual = inputDevice.isVirtual();
int motionRangesCount = inputDevice.getMotionRanges().size();
// Only handle joysticks or gamepads that have more than one motionRanges
// and that are not virtual (the NVIDIA Shield has virtual mouse cursor
// that is identified as a joystick).
if (!isVirtual && (isJoystick || isGamepad) && motionRangesCount > 0)
{
// System.out.println(inputDevice.getName() + ": isJoystick = "
// + isJoystick + ", isGamepad = " + isGamepad + ", isVirtual = "
// + isVirtual + ", motionRangesCount = " + motionRangesCount);
gamepads.put(createGamepadForInputDevice(InputDevice
.getDevice(deviceId)));
}
}
}
示例12: availablePointerAndHoverTypes
import android.view.InputDevice; //导入方法依赖的package包/类
/**
* @return an array of two ints: result[0] represents the pointer-types and result[1] represents
* the hover-types supported by the device, where each int is the union (bitwise OR) of
* corresponding type (PointerType/HoverType) bits.
*/
@CalledByNative
private static int[] availablePointerAndHoverTypes() {
int[] result = new int[2];
result[0] = result[1] = 0;
for (int deviceId : InputDevice.getDeviceIds()) {
InputDevice inputDevice = InputDevice.getDevice(deviceId);
if (inputDevice == null) continue;
int sources = inputDevice.getSources();
if (hasSource(sources, InputDevice.SOURCE_MOUSE)
|| hasSource(sources, InputDevice.SOURCE_STYLUS)
|| hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
|| hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
result[0] |= PointerType.FINE;
} else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
result[0] |= PointerType.COARSE;
}
if (hasSource(sources, InputDevice.SOURCE_MOUSE)
|| hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
|| hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
result[1] |= HoverType.HOVER;
} else if (hasSource(sources, InputDevice.SOURCE_STYLUS)
|| hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
result[1] |= HoverType.NONE;
}
// Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
// SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
}
if (result[0] == 0) result[0] = PointerType.NONE;
if (result[1] == 0) result[1] = HoverType.NONE;
return result;
}
示例13: onInputDeviceAdded
import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public void onInputDeviceAdded(int deviceId) {
InputDevice device = InputDevice.getDevice(deviceId);
if (device == null) {
return;
}
if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
addGamepad(device);
}
}
示例14: isGamepad
import android.view.InputDevice; //导入方法依赖的package包/类
/**
* Utility method to determine if input device is a gamepad.
*
* @param device
* @return
*/
private boolean isGamepad(InputDevice device) {
if ((device.getSources() &
InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD
|| (device.getSources() &
InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) {
return true;
}
return false;
}
示例15: 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) {
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;
}
}
}