本文整理汇总了Java中android.view.InputDevice.SOURCE_DPAD属性的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.SOURCE_DPAD属性的具体用法?Java InputDevice.SOURCE_DPAD怎么用?Java InputDevice.SOURCE_DPAD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.SOURCE_DPAD属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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)
);
}
示例3: 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;
}
示例4: 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);
}
示例5: isDpadDevice
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;
}
}
示例6: checkUiChoice
/**
* Check if the input event make us think that user is on TV.
* If it is the case and if the Ui mode is not setup, then we propose to try the TV UI.
* @param event
*/
private void checkUiChoice(InputEvent event) {
// Make sure we go through this method only once
if (sUiChoiceCheckDone) {
return;
}
sUiChoiceCheckDone = true;
// No need to check more if this APK does not integrate the leanback UI (this is decided at build time)
if (!EntryActivity.isLeanbackUiAvailable()) {
return;
}
boolean probablyTv = false;
switch (event.getSource()) {
// All these case mean the user is probably on TV
case InputDevice.SOURCE_KEYBOARD:
case InputDevice.SOURCE_TOUCHPAD:
case InputDevice.SOURCE_DPAD:
case InputDevice.SOURCE_GAMEPAD:
case InputDevice.SOURCE_JOYSTICK:
case InputDevice.SOURCE_HDMI:
Log.d(TAG, "event source = "+event.getSource()+" -> probably TV");
probablyTv = true;
break;
case InputDevice.SOURCE_STYLUS:
case InputDevice.SOURCE_TOUCHSCREEN:
case InputDevice.SOURCE_TRACKBALL:
case InputDevice.SOURCE_MOUSE:
default:
Log.d(TAG, "event source = "+event.getSource()+" -> probably not TV");
probablyTv = false;
break;
}
if (!probablyTv) {
return;
}
final String uiMode = PreferenceManager.getDefaultSharedPreferences(this)
.getString(UiChoiceDialog.UI_CHOICE_LEANBACK_KEY, "unset");
// If the choice has not been done yet, ask user
if (uiMode.equals("unset") &&
!getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { // no UI choice to do on actual AndroidTV devices
new UiChoiceDialog().show(getFragmentManager(), "UiChoiceDialog");
}
}