本文整理汇总了Java中android.view.InputDevice.SOURCE_GAMEPAD属性的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.SOURCE_GAMEPAD属性的具体用法?Java InputDevice.SOURCE_GAMEPAD怎么用?Java InputDevice.SOURCE_GAMEPAD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.SOURCE_GAMEPAD属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onGenericMotionEvent
@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);
}
示例2: onKeyUp
@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
return super.onKeyUp(keyCode, event);
};
int source = event.getSource();
if ((source & InputDevice.SOURCE_JOYSTICK) != 0 || (source & InputDevice.SOURCE_DPAD) != 0 || (source & InputDevice.SOURCE_GAMEPAD) != 0) {
int button = get_godot_button(keyCode);
int device = event.getDeviceId();
GodotLib.joybutton(device, button, false);
return true;
} else {
GodotLib.key(keyCode, event.getUnicodeChar(0), false);
};
return super.onKeyUp(keyCode, event);
}
示例3: getGameControllerIds
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
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: onKeyEvent
/** This function MUST be called on the UI thread */
@Override
public boolean onKeyEvent(KeyEvent event) {
if (Versions.preHCMR1) {
return false;
}
if ((event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD
&& event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_ZOOM_IN:
return animatedScale(0.2f);
case KeyEvent.KEYCODE_ZOOM_OUT:
return animatedScale(-0.2f);
}
}
return false;
}
示例6: checkGameControllers
/**
* 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: isDeviceSDLJoystick
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: onGenericMotion
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
float x, y;
int action;
switch ( event.getSource() ) {
case InputDevice.SOURCE_JOYSTICK:
case InputDevice.SOURCE_GAMEPAD:
case InputDevice.SOURCE_DPAD:
return SDLActivity.handleJoystickMotionEvent(event);
case InputDevice.SOURCE_MOUSE:
action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_SCROLL:
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
SDLActivity.onNativeMouse(0, action, x, y);
return true;
case MotionEvent.ACTION_HOVER_MOVE:
x = event.getX(0);
y = event.getY(0);
SDLActivity.onNativeMouse(0, action, x, y);
return true;
default:
break;
}
break;
default:
break;
}
// Event was not managed
return false;
}
示例9: findControllersAndAttachShips
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);
}
}
}
示例10: processGamepadDeviceId
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;
}
示例11: isGameControllerConnected
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;
}
示例12: refreshGamepads
@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)));
}
}
}
示例13: onKeyDown
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
GodotLib.quit();
// press 'back' button should not terminate program
// normal handle 'back' event in game logic
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
return super.onKeyDown(keyCode, event);
};
int source = event.getSource();
//Log.e(TAG, String.format("Key down! source %d, device %d, joystick %d, %d, %d", event.getDeviceId(), source, (source & InputDevice.SOURCE_JOYSTICK), (source & InputDevice.SOURCE_DPAD), (source & InputDevice.SOURCE_GAMEPAD)));
if ((source & InputDevice.SOURCE_JOYSTICK) != 0 || (source & InputDevice.SOURCE_DPAD) != 0 || (source & InputDevice.SOURCE_GAMEPAD) != 0) {
if (event.getRepeatCount() > 0) // ignore key echo
return true;
int button = get_godot_button(keyCode);
int device = event.getDeviceId();
//Log.e(TAG, String.format("joy button down! button %x, %d, device %d", keyCode, button, device));
GodotLib.joybutton(device, button, true);
return true;
} else {
GodotLib.key(keyCode, event.getUnicodeChar(0), true);
};
return super.onKeyDown(keyCode, event);
}
示例14: onInputDeviceAdded
@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);
}
}
示例15: isGamepadKey
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private static boolean isGamepadKey(KeyEvent event) {
if (Build.VERSION.SDK_INT < 12) {
return false;
}
return (event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD;
}