本文整理汇总了Java中android.view.InputDevice.MotionRange方法的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.MotionRange方法的具体用法?Java InputDevice.MotionRange怎么用?Java InputDevice.MotionRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.InputDevice
的用法示例。
在下文中一共展示了InputDevice.MotionRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: processAxis
import android.view.InputDevice; //导入方法依赖的package包/类
/**
* Normalizes joystick values between -1.0 and 1.0. Though Android guarantees
* this, it is a useful function if one finds that the joystick values are not
* correct. Doesn't do any harm to call it.
*/
public static float processAxis(InputDevice.MotionRange range, float axisvalue)
/*************************************************************************/
{
float absAxisValue = Math.abs(axisvalue);
float deadZone = range.getFlat();
if (absAxisValue <= deadZone)
{
return 0.0f;
}
float normalizedValue;
if (axisvalue < 0.0f)
{
normalizedValue = absAxisValue / range.getMin();
}
else
{
normalizedValue = absAxisValue / range.getMax();
}
return normalizedValue;
}
示例9: 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;
}
示例10: handleMotionEvent
import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public boolean handleMotionEvent(MotionEvent event) {
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
int actionPointerIndex = event.getActionIndex();
int action = event.getActionMasked();
switch(action) {
case MotionEvent.ACTION_MOVE:
SDLJoystick joystick = getJoystick(event.getDeviceId());
if ( joystick != null ) {
for (int i = 0; i < joystick.axes.size(); i++) {
InputDevice.MotionRange range = joystick.axes.get(i);
/* Normalize the value to -1...1 */
float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
SDLActivity.onNativeJoy(joystick.device_id, i, value );
}
for (int i = 0; i < joystick.hats.size(); i+=2) {
int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) );
int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) );
SDLActivity.onNativeHat(joystick.device_id, i/2, hatX, hatY );
}
}
break;
default:
break;
}
}
return true;
}
示例11: getJoystickZone
import android.view.InputDevice; //导入方法依赖的package包/类
public static int getJoystickZone(MotionEvent event) {
int joystickZone = JOYSTICK_ZONE_CENTER;
InputDevice.MotionRange range = event.getDevice().getMotionRange(MotionEvent.AXIS_X, event.getSource());
if (range != null) {
float valueX = event.getAxisValue(MotionEvent.AXIS_X);
float deadZoneThreshold = range.getRange() * JOYSTICK_DEAD_ZONE_THRESHOLD_PERCENT / 2;
float farZoneThreshold = range.getRange() * JOYSTICK_FAR_ZONE_THRESHOLD_PERCENT / 2;
// Get the current joystick state depending on the position
if (valueX <= -farZoneThreshold) {
joystickZone = Utils.JOYSTICK_ZONE_FAR_LEFT;
}
else if (valueX <= -deadZoneThreshold) {
joystickZone = Utils.JOYSTICK_ZONE_LEFT;
}
else if (valueX < deadZoneThreshold) {
joystickZone = Utils.JOYSTICK_ZONE_CENTER;
}
else if (valueX < farZoneThreshold) {
joystickZone = Utils.JOYSTICK_ZONE_RIGHT;
}
else {
joystickZone = Utils.JOYSTICK_ZONE_FAR_RIGHT;
}
}
return joystickZone;
}
示例12: isValueInDeadZone
import android.view.InputDevice; //导入方法依赖的package包/类
public static boolean isValueInDeadZone(MotionEvent event, int axis) {
float threshold;
if (sDeadZoneThresholdOverride >= 0) {
threshold = sDeadZoneThresholdOverride;
} else {
InputDevice.MotionRange range = event.getDevice().getMotionRange(axis);
threshold = range.getFlat() + range.getFuzz();
}
float value = event.getAxisValue(axis);
return (Math.abs(value) < threshold);
}
示例13: 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;
}
示例14: processAxis
import android.view.InputDevice; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static float processAxis(InputDevice.MotionRange range, float axisvalue) {
float absaxisvalue = Math.abs(axisvalue);
float deadzone = range.getFlat();
if (absaxisvalue <= deadzone) {
return 0.0f;
}
float normalizedvalue;
if (axisvalue < 0.0f)
normalizedvalue = absaxisvalue / range.getMin();
else
normalizedvalue = absaxisvalue / range.getMax();
return normalizedvalue;
}
示例15: compare
import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public int compare(InputDevice.MotionRange arg0, InputDevice.MotionRange arg1) {
return arg0.getAxis() - arg1.getAxis();
}