当前位置: 首页>>代码示例>>Java>>正文


Java InputDevice.MotionRange方法代码示例

本文整理汇总了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;
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:19,代码来源:GameView.java

示例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;
}
 
开发者ID:jiaZengShen,项目名称:vlc_android_win,代码行数:22,代码来源:AndroidDevices.java

示例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;
}
 
开发者ID:StepicOrg,项目名称:stepik-android,代码行数:22,代码来源:AndroidDevices.java

示例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;
	}
 
开发者ID:ianholing,项目名称:Crazy-wheel-godot-google-play,代码行数:23,代码来源:GodotView.java

示例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;
}
 
开发者ID:luoqii,项目名称:ApkLauncher,代码行数:17,代码来源:GameView.java

示例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;
}
 
开发者ID:googlesamples,项目名称:androidtv-VisualGameController,代码行数:27,代码来源:FullscreenActivity.java

示例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;
}
 
开发者ID:huntergdavis,项目名称:cantstoptherock,代码行数:23,代码来源:FlyingHeroGamePanel.java

示例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;
}
 
开发者ID:willowgarage,项目名称:shield_teleop,代码行数:27,代码来源:JoystickNode.java

示例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;
}
 
开发者ID:tramzel,项目名称:overplayed,代码行数:18,代码来源:ControlView.java

示例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;
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:29,代码来源:SDLActivity.java

示例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;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:30,代码来源:Utils.java

示例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);
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:12,代码来源:GamepadUtils.java

示例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;
}
 
开发者ID:moonlight-stream,项目名称:moonlight-android,代码行数:13,代码来源:ControllerHandler.java

示例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;
}
 
开发者ID:tramzel,项目名称:overplayed,代码行数:15,代码来源:ControlView.java

示例15: compare

import android.view.InputDevice; //导入方法依赖的package包/类
@Override
public int compare(InputDevice.MotionRange arg0, InputDevice.MotionRange arg1) {
    return arg0.getAxis() - arg1.getAxis();
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:5,代码来源:SDLActivity.java


注:本文中的android.view.InputDevice.MotionRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。