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


Java InputDevice.SOURCE_JOYSTICK属性代码示例

本文整理汇总了Java中android.view.InputDevice.SOURCE_JOYSTICK属性的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.SOURCE_JOYSTICK属性的具体用法?Java InputDevice.SOURCE_JOYSTICK怎么用?Java InputDevice.SOURCE_JOYSTICK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.view.InputDevice的用法示例。


在下文中一共展示了InputDevice.SOURCE_JOYSTICK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onGenericMotionEvent

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    mInputManager.onGenericMotionEvent(event);

    // Check that the event came from a joystick or gamepad since a generic
    // motion event could be almost anything. API level 18 adds the useful
    // event.isFromSource() helper function.
    int eventSource = event.getSource();
    if ((((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
            ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK))
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        int id = event.getDeviceId();
        if (-1 != id) {
            Ship curShip = getShipForId(id);
            if (curShip.onGenericMotionEvent(event)) {
                return true;
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:21,代码来源:GameView.java

示例2: onGenericMotionEvent

@Override
public boolean onGenericMotionEvent(MotionEvent ev) {
    if ((ev.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && ev.getAction() == MotionEvent.ACTION_MOVE) {

        if (rollingSpiderDeviceController != null) {

            if (mAutoPilotMode) {
                autoPiloting(ev);
            } else {
                normalPiloting(ev);
            }

            if (mTrianglePressed) {
                doTrick(ev);
            }
        }
    }
    return true;
}
 
开发者ID:sonyxperiadev,项目名称:DroneControl,代码行数:19,代码来源:RollingSpiderActivity.java

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

示例4: onGenericMotionEvent

@Override public boolean onGenericMotionEvent(MotionEvent event) {

		if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) {

			// Process all historical movement samples in the batch
			final int historySize = event.getHistorySize();

			// Process the movements starting from the
			// earliest historical position in the batch
			for (int i = 0; i < historySize; i++) {
				// Process the event at historical position i
				process_axis_state(event, i);
			}

			// Process the current movement sample in the batch (position -1)
			process_axis_state(event, -1);
			return true;


		};

		return super.onGenericMotionEvent(event);
	}
 
开发者ID:ianholing,项目名称:Crazy-wheel-godot-google-play,代码行数:23,代码来源:GodotView.java

示例5: dispatchGenericMotionEvent

public boolean dispatchGenericMotionEvent(MotionEvent event){
    //Check for a joystick event
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) !=
            InputDevice.SOURCE_JOYSTICK ||
            event.getAction() != MotionEvent.ACTION_MOVE)
        return false;

    InputDevice inputDevice = event.getDevice();

    float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
    float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
    if (inputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f)
        return false;

    float x = AndroidDevices.getCenteredAxis(event, inputDevice,
            MotionEvent.AXIS_X);

    if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){
        if (Math.abs(x) > 0.3){
            seek(x > 0.0f ? 10000 : -10000);
            mLastMove = System.currentTimeMillis();
            return true;
        }
    }
    return true;
}
 
开发者ID:hanhailong,项目名称:VCL-Android,代码行数:26,代码来源:AudioPlayerActivity.java

示例6: getGameControllerIds

private List<Integer> getGameControllerIds() {
	List<Integer> gameControllerDeviceIds = new ArrayList<>();

	int[] deviceIds = InputDevice.getDeviceIds();
	for (int deviceId : deviceIds) {
		InputDevice dev = InputDevice.getDevice(deviceId);
		int sources = dev.getSources();

		if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
				|| ((sources & InputDevice.SOURCE_JOYSTICK)
				== InputDevice.SOURCE_JOYSTICK)) {

			if (!gameControllerDeviceIds.contains(deviceId)) {
				gameControllerDeviceIds.add(deviceId);
			}
		}
	}

	return gameControllerDeviceIds;
}
 
开发者ID:TheFakeMontyOnTheRun,项目名称:knightsofalentejo,代码行数:20,代码来源:GameActivity.java

示例7: checkGameControllers

/**
 * Check for any game controllers that are connected already.
 */
private void checkGameControllers() {
    Log.d(TAG, "checkGameControllers");
    int[] deviceIds = mInputManager.getInputDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();

        // Verify that the device has gamepad buttons, control sticks, or
        // both.
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
                || ((sources & InputDevice.SOURCE_JOYSTICK)
                    == InputDevice.SOURCE_JOYSTICK)) {
            // This device is a game controller. Store its device ID.
            if (!mConnectedDevices.contains(deviceId)) {
                mConnectedDevices.add(deviceId);
                if (mCurrentDeviceId == -1) {
                    mCurrentDeviceId = deviceId;
                    mControllerView.setCurrentControllerNumber(dev.getControllerNumber());
                    mControllerView.invalidate();
                }
            }
        }
    }
}
 
开发者ID:googlesamples,项目名称:androidtv-VisualGameController,代码行数:27,代码来源:FullscreenActivity.java

示例8: onGenericMotionEvent

@Override
public boolean onGenericMotionEvent(MotionEvent event) {

    // Check that the event came from a game controller
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) ==
            InputDevice.SOURCE_JOYSTICK &&

            ((event.getAction() == MotionEvent.ACTION_MOVE) || (event.getAction() == MotionEvent.ACTION_DOWN))) {

        // Process all historical movement samples in the batch
        final int historySize = event.getHistorySize();

        // Process the movements starting from the
        // earliest historical position in the batch
        for (int i = 0; i < historySize; i++) {
            // Process the event at historical position i
            processJoystickInput(event, i);
        }

        // Process the current movement sample in the batch (position -1)
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
 
开发者ID:huntergdavis,项目名称:cantstoptherock,代码行数:25,代码来源:FlyingHeroGamePanel.java

示例9: handleMotionEvent

@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,代码行数:28,代码来源:SDLActivity.java

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

示例11: findControllersAndAttachShips

void findControllersAndAttachShips() {
    int[] deviceIds = mInputManager.getInputDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = mInputManager.getInputDevice(deviceId);
        int sources = dev.getSources();
        // if the device is a gamepad/joystick, create a ship to represent it
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
                ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            // if the device has a gamepad or joystick
            getShipForId(deviceId);
        }
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:13,代码来源:GameView.java

示例12: isGameControllerConnected

public boolean isGameControllerConnected() {
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
            ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:PacktPublishing,项目名称:Android-Game-Programming,代码行数:12,代码来源:MainMenuFragment.java

示例13: dispatchGenericMotionEvent

@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;
}
 
开发者ID:PacktPublishing,项目名称:Android-Game-Programming,代码行数:29,代码来源:GamepadInputController.java

示例14: onGenericMotionEvent

@Override
public boolean onGenericMotionEvent(MotionEvent ev) {
    if ((ev.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && ev.getAction() == MotionEvent.ACTION_MOVE) {

        if (bebopDeviceController != null) {
            if (mAutoPilotMode) {
                autoPiloting(ev);
            } else {
                normalPiloting(ev);
            }

            if (mTrianglePressed) {
                doTrick(ev);
            } else {

                if (ev.getAxisValue(MotionEvent.AXIS_HAT_X) == 1) {
                    mPan = CAMERA_MAX_PAN_RIGHT;
                } else if (ev.getAxisValue(MotionEvent.AXIS_HAT_X) == -1) {
                    mPan = CAMERA_MAX_PAN_LEFT;
                } else {
                    mPan = CAMERA_DEFAULT;
                }

                if (mTilt < CAMERA_MAX_TILT_UP) {
                    if (ev.getAxisValue(MotionEvent.AXIS_HAT_Y) == -1) {
                        mTilt += CAMERA_TILT_STEP;
                    }
                }
                if (mTilt > CAMERA_MAX_TILT_DOWN) {
                    if (ev.getAxisValue(MotionEvent.AXIS_HAT_Y) == 1) {
                        mTilt -= CAMERA_TILT_STEP;
                    }
                }
                bebopDeviceController.sendCameraOrientation(mTilt, mPan);
            }
        }
    }
    return true;
}
 
开发者ID:sonyxperiadev,项目名称:DroneControl,代码行数:39,代码来源:BebopActivity.java

示例15: refreshGamepads

@TargetApi(16)
private void refreshGamepads() throws JSONException
{
	int[] deviceIds = InputDevice.getDeviceIds();
	this.gamepads = new JSONArray();
	for (int i = 0; i < deviceIds.length; i++)
	{
		int deviceId = deviceIds[i];

		InputDevice inputDevice = InputDevice.getDevice(deviceId);
		int sources = inputDevice.getSources();
		boolean isJoystick = (sources & InputDevice.SOURCE_JOYSTICK) != 0;
		boolean isGamepad = (sources & InputDevice.SOURCE_GAMEPAD) != 0;
		boolean isVirtual = inputDevice.isVirtual();
		int motionRangesCount = inputDevice.getMotionRanges().size();
		// Only handle joysticks or gamepads that have more than one motionRanges
		// and that are not virtual (the NVIDIA Shield has virtual mouse cursor
		// that is identified as a joystick).
		if (!isVirtual && (isJoystick || isGamepad) && motionRangesCount > 0)
		{
			// System.out.println(inputDevice.getName() + ": isJoystick = "
			// + isJoystick + ", isGamepad = " + isGamepad + ", isVirtual = "
			// + isVirtual + ", motionRangesCount = " + motionRangesCount);
			gamepads.put(createGamepadForInputDevice(InputDevice
					.getDevice(deviceId)));
		}
	}
}
 
开发者ID:WinnipegAndroid,项目名称:cordova-android-tv,代码行数:28,代码来源:CordovaPluginGamepad.java


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