當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。