本文整理汇总了Java中android.view.InputDevice.getMotionRange方法的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.getMotionRange方法的具体用法?Java InputDevice.getMotionRange怎么用?Java InputDevice.getMotionRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.getMotionRange方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCenteredAxis
import android.view.InputDevice; //导入方法依赖的package包/类
private static float getCenteredAxis(MotionEvent event, InputDevice device,
int axis, int historyPos) {
final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());
if (range != null) {
final float flat = range.getFlat();
final float value = historyPos < 0 ? event.getAxisValue(axis)
: event.getHistoricalAxisValue(axis, historyPos);
// Ignore axis values that are within the 'flat' region of the
// joystick axis center.
// A joystick at rest does not always report an absolute position of
// (0,0).
if (Math.abs(value) > flat) {
return value;
}
}
return 0;
}
示例2: getCenteredAxis
import android.view.InputDevice; //导入方法依赖的package包/类
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
public static float getCenteredAxis(MotionEvent event,
InputDevice device, int axis) {
final InputDevice.MotionRange range =
device.getMotionRange(axis, event.getSource());
// A joystick at rest does not always report an absolute position of
// (0,0). Use the getFlat() method to determine the range of values
// bounding the joystick axis center.
if (range != null) {
final float flat = range.getFlat();
final float value = event.getAxisValue(axis);
// Ignore axis values that are within the 'flat' region of the
// joystick axis center.
if (Math.abs(value) > flat) {
return value;
}
}
return 0;
}
示例3: getCenteredAxis
import android.view.InputDevice; //导入方法依赖的package包/类
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
public static float getCenteredAxis(MotionEvent event,
InputDevice device, int axis) {
final InputDevice.MotionRange range =
device.getMotionRange(axis, event.getSource());
// A joystick at rest does not always report an absolute position of
// (0,0). Use the getFlat() method to determine the range of values
// bounding the joystick axis center.
if (range != null) {
final float flat = range.getFlat();
final float value = event.getAxisValue(axis);
// Ignore axis values that are within the 'flat' region of the
// joystick axis center.
if (Math.abs(value) > flat) {
return value;
}
}
return 0;
}
示例4: axis_value
import android.view.InputDevice; //导入方法依赖的package包/类
public float axis_value(MotionEvent p_event, InputDevice p_device, int p_axis, int p_pos) {
final InputDevice.MotionRange range = p_device.getMotionRange(p_axis, p_event.getSource());
if (range == null)
return 0;
//Log.e(TAG, String.format("axis ranges %f, %f, %f", range.getRange(), range.getMin(), range.getMax()));
final float flat = range.getFlat();
final float value =
p_pos < 0 ? p_event.getAxisValue(p_axis):
p_event.getHistoricalAxisValue(p_axis, p_pos);
final float absval = Math.abs(value);
if (absval <= flat) {
return 0;
};
final float ret = (value - range.getMin()) / range.getRange() * 2 - 1.0f;
return ret;
}
示例5: 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;
}
}
}
示例6: getCenteredAxis
import android.view.InputDevice; //导入方法依赖的package包/类
private static float getCenteredAxis(MotionEvent event, InputDevice device,
int axis, int historyPos) {
final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());
if (range != null) {
final float flat = range.getFlat();
final float value = historyPos < 0 ? event.getAxisValue(axis)
: event.getHistoricalAxisValue(axis, historyPos);
// Ignore axis values that are within the 'flat' region of the joystick axis center.
// A joystick at rest does not always report an absolute position of (0,0).
if (Math.abs(value) > flat) {
return value;
}
}
return 0;
}
示例7: getCenteredAxis
import android.view.InputDevice; //导入方法依赖的package包/类
/**
* Get centered position for axis input by considering flat area.
*
* @param event
* @param device
* @param axis
* @return
*/
private float getCenteredAxis(MotionEvent event, InputDevice device, int axis) {
InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource());
// A joystick at rest does not always report an absolute position of
// (0,0). Use the getFlat() method to determine the range of values
// bounding the joystick axis center.
if (range != null) {
float flat = range.getFlat();
float value = event.getAxisValue(axis);
// Ignore axis values that are within the 'flat' region of the
// joystick axis center.
if (Math.abs(value) > flat) {
return value;
}
}
return 0;
}
示例8: 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;
}
示例9: getCenteredAxis
import android.view.InputDevice; //导入方法依赖的package包/类
private static float getCenteredAxis(MotionEvent event,
InputDevice device, int axis, int historyPos) {
final InputDevice.MotionRange range =
device.getMotionRange(axis, event.getSource());
// A joystick at rest does not always report an absolute position of
// (0,0). Use the getFlat() method to determine the range of values
// bounding the joystick axis center.
if (range != null) {
final float flat = range.getFlat();
final float value =
historyPos < 0 ? event.getAxisValue(axis):
event.getHistoricalAxisValue(axis, historyPos);
// Ignore axis values that are within the 'flat' region of the
// joystick axis center.
if (Math.abs(value) > flat) {
return value;
}
}
return 0;
}
示例10: processJoystickInput
import android.view.InputDevice; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private void processJoystickInput(InputDevice device, MotionEvent event, int historyPos) {
for (int i = 0; i < Overplayed.boundAxis.length; i++) {
InputDevice.MotionRange range = device.getMotionRange(Overplayed.boundAxis[i], event.getSource());
if (range != null) {
float axisValue;
if (historyPos >= 0) {
axisValue = event.getHistoricalAxisValue(Overplayed.boundAxis[i], historyPos);
} else {
axisValue = event.getAxisValue(Overplayed.boundAxis[i]);
}
parent.analogState.set(i, (short) ((processAxis(range, axisValue) + 1f) * .5f * Short.MAX_VALUE));
}
}
parent.thread.changed = true;
}
示例11: dispatchGenericMotionEvent
import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
int source = event.getSource();
if ((source & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK) {
return false;
}
mHorizontalFactor = event.getAxisValue(MotionEvent.AXIS_X);
mVerticalFactor = event.getAxisValue(MotionEvent.AXIS_Y);
InputDevice device = event.getDevice();
MotionRange rangeX = device.getMotionRange(MotionEvent.AXIS_X, source);
if (Math.abs(mHorizontalFactor) <= rangeX.getFlat()) {
mHorizontalFactor = event.getAxisValue(MotionEvent.AXIS_HAT_X);
MotionRange rangeHatX = device.getMotionRange(MotionEvent.AXIS_HAT_X, source);
if (Math.abs(mHorizontalFactor) <= rangeHatX.getFlat()) {
mHorizontalFactor = 0;
}
}
MotionRange rangeY = device.getMotionRange(MotionEvent.AXIS_Y, source);
if (Math.abs(mVerticalFactor) <= rangeY.getFlat()) {
mVerticalFactor = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
MotionRange rangeHatY = device.getMotionRange(MotionEvent.AXIS_HAT_Y, source);
if (Math.abs(mVerticalFactor) <= rangeHatY.getFlat()) {
mVerticalFactor = 0;
}
}
return true;
}
示例12: getMotionRangeForJoystickAxis
import android.view.InputDevice; //导入方法依赖的package包/类
private static InputDevice.MotionRange getMotionRangeForJoystickAxis(InputDevice dev, int axis) {
InputDevice.MotionRange range;
// First get the axis for SOURCE_JOYSTICK
range = dev.getMotionRange(axis, InputDevice.SOURCE_JOYSTICK);
if (range == null) {
// Now try the axis for SOURCE_GAMEPAD
range = dev.getMotionRange(axis, InputDevice.SOURCE_GAMEPAD);
}
return range;
}
示例13: process
import android.view.InputDevice; //导入方法依赖的package包/类
public void process(final MotionEvent event)
{
int hwMouseEvent = ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE || Globals.ForceHardwareMouse) ? Mouse.MOUSE_HW_INPUT_MOUSE :
((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) ? Mouse.MOUSE_HW_INPUT_STYLUS :
Mouse.MOUSE_HW_INPUT_FINGER;
if( ExternalMouseDetected != hwMouseEvent )
{
ExternalMouseDetected = hwMouseEvent;
DemoGLSurfaceView.nativeHardwareMouseDetected(hwMouseEvent);
}
super.process(event);
if( !Globals.FingerHover && ExternalMouseDetected == Mouse.MOUSE_HW_INPUT_FINGER )
return; // Finger hover disabled in settings
if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1
{
int action;
// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
if( touchEvents[0].down )
action = Mouse.SDL_FINGER_UP;
else
action = Mouse.SDL_FINGER_HOVER;
touchEvents[0].down = false;
touchEvents[0].x = (int)event.getX();
touchEvents[0].y = (int)event.getY();
touchEvents[0].pressure = Mouse.MAX_HOVER_DISTANCE;
touchEvents[0].size = 0;
//if( event.getAxisValue(MotionEvent.AXIS_DISTANCE) != 0.0f )
InputDevice device = InputDevice.getDevice(event.getDeviceId());
if( device != null && device.getMotionRange(MotionEvent.AXIS_DISTANCE) != null &&
device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange() > 0.0f )
touchEvents[0].pressure = (int)((event.getAxisValue(MotionEvent.AXIS_DISTANCE) -
device.getMotionRange(MotionEvent.AXIS_DISTANCE).getMin()) * Mouse.MAX_PRESSURE / device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange());
DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
}
if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_EXIT ) // Update screen for finger hover
{
touchEvents[0].pressure = Mouse.HOVER_REDRAW_SCREEN;
touchEvents[0].size = 0;
DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, Mouse.SDL_FINGER_HOVER, 0, touchEvents[0].pressure, touchEvents[0].size );
}
}